blob: ddacf2e06ef88ffdba7a72f18152bdfaa538bcd0 [file] [log] [blame]
Gilles Peskine15c2cbf2020-06-25 18:36:28 +02001#!/usr/bin/env python3
2
3"""Analyze the test outcomes from a full CI run.
4
5This script can also run on outcomes from a partial run, but the results are
6less likely to be useful.
7"""
8
9import argparse
10import sys
11import traceback
Przemek Stekiel85c54ea2022-11-17 11:50:23 +010012import re
Valerio Settia2663322023-03-24 08:20:18 +010013import subprocess
14import os
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020015
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020016import check_test_cases
17
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020018class Results:
19 """Process analysis results."""
20
21 def __init__(self):
22 self.error_count = 0
23 self.warning_count = 0
24
Valerio Setti2cff8202023-10-18 14:36:47 +020025 def new_section(self, fmt, *args, **kwargs):
26 self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs)
27
Valerio Settiaaef0bc2023-10-10 09:42:13 +020028 def info(self, fmt, *args, **kwargs):
Valerio Setti8070dbe2023-10-17 12:29:30 +020029 self._print_line('Info: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020030
31 def error(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020032 self.error_count += 1
Valerio Setti8070dbe2023-10-17 12:29:30 +020033 self._print_line('Error: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020034
35 def warning(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020036 self.warning_count += 1
Valerio Setti8070dbe2023-10-17 12:29:30 +020037 self._print_line('Warning: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020038
Valerio Setti3f339892023-10-17 10:42:11 +020039 @staticmethod
Valerio Setti8070dbe2023-10-17 12:29:30 +020040 def _print_line(fmt, *args, **kwargs):
Valerio Setti735794c2023-10-18 08:05:15 +020041 sys.stderr.write((fmt + '\n').format(*args, **kwargs))
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020042
43class TestCaseOutcomes:
44 """The outcomes of one test case across many configurations."""
45 # pylint: disable=too-few-public-methods
46
47 def __init__(self):
Gilles Peskine3d863f22020-06-26 13:02:30 +020048 # Collect a list of witnesses of the test case succeeding or failing.
49 # Currently we don't do anything with witnesses except count them.
50 # The format of a witness is determined by the read_outcome_file
51 # function; it's the platform and configuration joined by ';'.
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020052 self.successes = []
53 self.failures = []
54
55 def hits(self):
56 """Return the number of times a test case has been run.
57
58 This includes passes and failures, but not skips.
59 """
60 return len(self.successes) + len(self.failures)
61
Valerio Settif075e472023-10-17 11:03:16 +020062def execute_reference_driver_tests(results: Results, ref_component, driver_component, \
Valerio Setti781c2342023-10-17 12:47:35 +020063 outcome_file):
Valerio Setti22992a02023-03-29 11:15:28 +020064 """Run the tests specified in ref_component and driver_component. Results
65 are stored in the output_file and they will be used for the following
Valerio Settia2663322023-03-24 08:20:18 +010066 coverage analysis"""
67 # If the outcome file already exists, we assume that the user wants to
68 # perform the comparison analysis again without repeating the tests.
69 if os.path.exists(outcome_file):
Valerio Setti39d4b9d2023-10-18 14:30:03 +020070 results.info("Outcome file ({}) already exists. Tests will be skipped.", outcome_file)
Valerio Settia2663322023-03-24 08:20:18 +010071 return
72
73 shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
74 " " + ref_component + " " + driver_component
Valerio Setti39d4b9d2023-10-18 14:30:03 +020075 results.info("Running: {}", shell_command)
Valerio Settia2663322023-03-24 08:20:18 +010076 ret_val = subprocess.run(shell_command.split(), check=False).returncode
77
78 if ret_val != 0:
Valerio Settif075e472023-10-17 11:03:16 +020079 results.error("failed to run reference/driver components")
Valerio Settia2663322023-03-24 08:20:18 +010080
Tomás Gonzálezb401e112023-08-11 15:22:04 +010081def analyze_coverage(results, outcomes, allow_list, full_coverage):
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020082 """Check that all available test cases are executed at least once."""
Gilles Peskine686c2922022-01-07 15:58:38 +010083 available = check_test_cases.collect_available_test_cases()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020084 for key in available:
85 hits = outcomes[key].hits() if key in outcomes else 0
Tomás González07bdcc22023-08-11 14:59:03 +010086 if hits == 0 and key not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +010087 if full_coverage:
88 results.error('Test case not executed: {}', key)
89 else:
90 results.warning('Test case not executed: {}', key)
Tomás González07bdcc22023-08-11 14:59:03 +010091 elif hits != 0 and key in allow_list:
92 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +010093 if full_coverage:
Tomás Gonzáleza0631442023-08-22 12:17:57 +010094 results.error('Allow listed test case was executed: {}', key)
Tomás González7ebb18f2023-08-22 09:40:23 +010095 else:
96 results.warning('Allow listed test case was executed: {}', key)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020097
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +020098def name_matches_pattern(name, str_or_re):
99 """Check if name matches a pattern, that may be a string or regex.
100 - If the pattern is a string, name must be equal to match.
101 - If the pattern is a regex, name must fully match.
102 """
Manuel Pégourié-Gonnardb2695432023-10-23 09:30:40 +0200103 # The CI's python is too old for re.Pattern
104 #if isinstance(str_or_re, re.Pattern):
105 if not isinstance(str_or_re, str):
Manuel Pégourié-Gonnard9d9c2342023-10-26 09:37:40 +0200106 return str_or_re.fullmatch(name)
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200107 else:
Manuel Pégourié-Gonnard9d9c2342023-10-26 09:37:40 +0200108 return str_or_re == name
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200109
Valerio Settif075e472023-10-17 11:03:16 +0200110def analyze_driver_vs_reference(results: Results, outcomes,
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200111 component_ref, component_driver,
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200112 ignored_suites, ignored_tests=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200113 """Check that all tests executed in the reference component are also
114 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100115 Skip:
116 - full test suites provided in ignored_suites list
117 - only some specific test inside a test suite, for which the corresponding
118 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200119 """
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200120 seen_reference_passing = False
121 for key in outcomes:
Manuel Pégourié-Gonnard4da369f2023-10-18 09:40:32 +0200122 # key is like "test_suite_foo.bar;Description of test case"
123 (full_test_suite, test_string) = key.split(';')
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100124 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200125
126 # Immediately skip fully-ignored test suites
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100127 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100128 continue
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200129
130 # For ignored test cases inside test suites, just remember and:
131 # don't issue an error if they're skipped with drivers,
132 # but issue an error if they're not (means we have a bad entry).
133 ignored = False
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200134 if full_test_suite in ignored_tests:
Manuel Pégourié-Gonnardd36a37f2023-10-26 09:41:59 +0200135 for str_or_re in ignored_tests[test_suite]:
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200136 if name_matches_pattern(test_string, str_or_re):
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200137 ignored = True
Manuel Pégourié-Gonnard4da369f2023-10-18 09:40:32 +0200138
Przemek Stekiel4e955902022-10-21 13:42:08 +0200139 # Search for tests that run in reference component and not in driver component
140 driver_test_passed = False
141 reference_test_passed = False
142 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100143 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200144 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100145 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200146 reference_test_passed = True
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200147 seen_reference_passing = True
Manuel Pégourié-Gonnardc51c4112023-10-30 10:21:22 +0100148 if reference_test_passed and not driver_test_passed and not ignored:
149 results.error("PASS -> SKIP/FAIL: {}", key)
150 if ignored and driver_test_passed:
151 results.error("uselessly ignored: {}", key)
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200152
153 if not seen_reference_passing:
154 results.error("no passing test in reference component: bad outcome file?")
Przemek Stekiel4e955902022-10-21 13:42:08 +0200155
Valerio Setti781c2342023-10-17 12:47:35 +0200156def analyze_outcomes(results: Results, outcomes, args):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200157 """Run all analyses on the given outcome collection."""
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100158 analyze_coverage(results, outcomes, args['allow_list'],
159 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200160
161def read_outcome_file(outcome_file):
162 """Parse an outcome file and return an outcome collection.
163
164An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
165The keys are the test suite name and the test case description, separated
166by a semicolon.
167"""
168 outcomes = {}
169 with open(outcome_file, 'r', encoding='utf-8') as input_file:
170 for line in input_file:
171 (platform, config, suite, case, result, _cause) = line.split(';')
172 key = ';'.join([suite, case])
173 setup = ';'.join([platform, config])
174 if key not in outcomes:
175 outcomes[key] = TestCaseOutcomes()
176 if result == 'PASS':
177 outcomes[key].successes.append(setup)
178 elif result == 'FAIL':
179 outcomes[key].failures.append(setup)
180 return outcomes
181
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800182def do_analyze_coverage(results: Results, outcomes_or_file, args):
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100183 """Perform coverage analysis."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200184 results.new_section("Analyze coverage")
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800185 outcomes = read_outcome_file(outcomes_or_file) \
186 if isinstance(outcomes_or_file, str) else outcomes_or_file
Valerio Setti781c2342023-10-17 12:47:35 +0200187 analyze_outcomes(results, outcomes, args)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200188
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800189def do_analyze_driver_vs_reference(results: Results, outcomes_or_file, args):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200190 """Perform driver vs reference analyze."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200191 results.new_section("Analyze driver {} vs reference {}",
192 args['component_driver'], args['component_ref'])
Valerio Settib0c618e2023-10-16 14:19:49 +0200193
Valerio Setti3002c992023-01-18 17:28:36 +0100194 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100195
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800196 if isinstance(outcomes_or_file, str):
197 execute_reference_driver_tests(results, args['component_ref'], \
198 args['component_driver'], outcomes_or_file)
199 outcomes = read_outcome_file(outcomes_or_file)
200 else:
201 outcomes = outcomes_or_file
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200202
Valerio Setti781c2342023-10-17 12:47:35 +0200203 analyze_driver_vs_reference(results, outcomes,
204 args['component_ref'], args['component_driver'],
205 ignored_suites, args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200206
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100207# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200208KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200209 'analyze_coverage': {
210 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100211 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100212 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100213 # Algorithm not supported yet
214 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
215 # Algorithm not supported yet
216 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100217 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100218 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100219 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100220 },
Valerio Settia2663322023-03-24 08:20:18 +0100221 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
222 # 1. Run tests and then analysis:
223 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
224 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
225 # 2. Let this script run both automatically:
226 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200227 'analyze_driver_vs_reference_hash': {
228 'test_function': do_analyze_driver_vs_reference,
229 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100230 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
231 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100232 'ignored_suites': [
233 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100234 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200235 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100236 ],
237 'ignored_tests': {
238 }
239 }
240 },
Valerio Settib6b301f2023-10-04 12:05:05 +0200241 'analyze_driver_vs_reference_cipher_aead': {
242 'test_function': do_analyze_driver_vs_reference,
243 'args': {
244 'component_ref': 'test_psa_crypto_config_reference_cipher_aead',
245 'component_driver': 'test_psa_crypto_config_accel_cipher_aead',
Valerio Setti507e08f2023-10-26 09:44:06 +0200246 # Modules replaced by drivers.
Valerio Settib6b301f2023-10-04 12:05:05 +0200247 'ignored_suites': [
Valerio Setti507e08f2023-10-26 09:44:06 +0200248 # low-level (block/stream) cipher modules
249 'aes', 'aria', 'camellia', 'des', 'chacha20',
250 # AEAD modes
251 'ccm', 'chachapoly', 'cmac', 'gcm',
252 # The Cipher abstraction layer
253 'cipher',
Valerio Settib6b301f2023-10-04 12:05:05 +0200254 ],
255 'ignored_tests': {
Valerio Setti507e08f2023-10-26 09:44:06 +0200256 # PEM decryption is not supported so far.
257 # The rest of PEM (write, unencrypted read) works though.
Valerio Setti7448cee2023-10-04 15:46:42 +0200258 'test_suite_pem': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200259 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
Valerio Setti7448cee2023-10-04 15:46:42 +0200260 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200261 # Following tests depend on AES_C/DES_C but are not about
262 # them really, just need to know some error code is there.
Valerio Setti7448cee2023-10-04 15:46:42 +0200263 'test_suite_error': [
264 'Low and high error',
265 'Single low error'
266 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200267 # Similar to test_suite_error above.
Valerio Setti7448cee2023-10-04 15:46:42 +0200268 'test_suite_version': [
269 'Check for MBEDTLS_AES_C when already present',
Valerio Setti93941442023-10-13 09:19:52 +0200270 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200271 # The en/decryption part of PKCS#12 is not supported so far.
272 # The rest of PKCS#12 (key derivation) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200273 'test_suite_pkcs12': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200274 re.compile(r'PBE Encrypt, .*'),
275 re.compile(r'PBE Decrypt, .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200276 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200277 # The en/decryption part of PKCS#5 is not supported so far.
278 # The rest of PKCS#5 (PBKDF2) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200279 'test_suite_pkcs5': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200280 re.compile(r'PBES2 Encrypt, .*'),
281 re.compile(r'PBES2 Decrypt .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200282 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200283 # Encrypted keys are not supported so far.
Valerio Setti5cd18f92023-10-13 15:14:07 +0200284 # pylint: disable=line-too-long
Valerio Setti93941442023-10-13 09:19:52 +0200285 'test_suite_pkparse': [
286 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
287 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200288 re.compile(r'Parse RSA Key .*\(PKCS#8 encrypted .*\)'),
Valerio Setti93941442023-10-13 09:19:52 +0200289 ],
Valerio Settib6b301f2023-10-04 12:05:05 +0200290 }
291 }
292 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200293 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100294 'test_function': do_analyze_driver_vs_reference,
295 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200296 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
297 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100298 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200299 # Modules replaced by drivers
300 'ecdsa', 'ecdh', 'ecjpake',
Valerio Setti42d5f192023-03-20 13:54:41 +0100301 ],
302 'ignored_tests': {
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200303 # This test wants a legacy function that takes f_rng, p_rng
304 # arguments, and uses legacy ECDSA for that. The test is
305 # really about the wrapper around the PSA RNG, not ECDSA.
Valerio Setti42d5f192023-03-20 13:54:41 +0100306 'test_suite_random': [
307 'PSA classic wrapper: ECDSA signature (SECP256R1)',
308 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200309 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
310 # so we must ignore disparities in the tests for which ECP_C
311 # is required.
312 'test_suite_ecp': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200313 re.compile(r'ECP check public-private .*'),
314 re.compile(r'ECP gen keypair .*'),
315 re.compile(r'ECP point muladd .*'),
316 re.compile(r'ECP point multiplication .*'),
317 re.compile(r'ECP test vectors .*'),
Valerio Setti482a0b92023-08-18 15:55:10 +0200318 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200319 'test_suite_ssl': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200320 # This deprecated function is only present when ECP_C is On.
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200321 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
322 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200323 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100324 }
325 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200326 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200327 'test_function': do_analyze_driver_vs_reference,
328 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200329 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
330 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200331 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200332 # Modules replaced by drivers
333 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
Valerio Settie618cb02023-04-12 14:59:16 +0200334 ],
335 'ignored_tests': {
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200336 # See ecp_light_only
Valerio Settie618cb02023-04-12 14:59:16 +0200337 'test_suite_random': [
338 'PSA classic wrapper: ECDSA signature (SECP256R1)',
339 ],
Valerio Settiaddeee42023-06-14 10:46:55 +0200340 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200341 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
342 # is automatically enabled in build_info.h (backward compatibility)
343 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
344 # consequence compressed points are supported in the reference
345 # component but not in the accelerated one, so they should be skipped
346 # while checking driver's coverage.
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200347 re.compile(r'Parse EC Key .*compressed\)'),
348 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Settiaddeee42023-06-14 10:46:55 +0200349 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200350 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200351 'test_suite_ssl': [
352 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
353 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200354 }
355 }
356 },
Valerio Setti307810b2023-08-15 10:12:25 +0200357 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200358 'test_function': do_analyze_driver_vs_reference,
359 'args': {
360 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
361 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
362 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200363 # Modules replaced by drivers
364 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
365 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
366 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200367 ],
368 'ignored_tests': {
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200369 # See ecp_light_only
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200370 'test_suite_random': [
371 'PSA classic wrapper: ECDSA signature (SECP256R1)',
372 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200373 # See no_ecp_at_all
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200374 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200375 re.compile(r'Parse EC Key .*compressed\)'),
376 re.compile(r'Parse Public EC Key .*compressed\)'),
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200377 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200378 'test_suite_asn1parse': [
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200379 'INTEGER too large for mpi',
380 ],
381 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200382 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200383 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200384 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200385 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Settie0be95e2023-08-01 09:07:43 +0200386 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200387 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200388 'test_suite_ssl': [
389 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
390 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200391 }
392 }
393 },
Valerio Setti307810b2023-08-15 10:12:25 +0200394 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
395 'test_function': do_analyze_driver_vs_reference,
396 'args': {
397 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
398 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
399 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200400 # Modules replaced by drivers
401 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
402 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
403 'bignum.generated', 'bignum.misc',
Valerio Setti307810b2023-08-15 10:12:25 +0200404 ],
405 'ignored_tests': {
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200406 # See ecp_light_only
Valerio Setti307810b2023-08-15 10:12:25 +0200407 'test_suite_random': [
408 'PSA classic wrapper: ECDSA signature (SECP256R1)',
409 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200410 # See no_ecp_at_all
Valerio Setti307810b2023-08-15 10:12:25 +0200411 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200412 re.compile(r'Parse EC Key .*compressed\)'),
413 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Setti307810b2023-08-15 10:12:25 +0200414 ],
415 'test_suite_asn1parse': [
Valerio Setti307810b2023-08-15 10:12:25 +0200416 'INTEGER too large for mpi',
417 ],
418 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200419 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200420 ],
421 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200422 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200423 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200424 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200425 'test_suite_ssl': [
426 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
427 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200428 }
429 }
430 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200431 'analyze_driver_vs_reference_ffdh_alg': {
432 'test_function': do_analyze_driver_vs_reference,
433 'args': {
434 'component_ref': 'test_psa_crypto_config_reference_ffdh',
435 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200436 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200437 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200438 }
439 },
Valerio Settif01d6482023-08-04 13:51:18 +0200440 'analyze_driver_vs_reference_tfm_config': {
441 'test_function': do_analyze_driver_vs_reference,
442 'args': {
443 'component_ref': 'test_tfm_config',
444 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200445 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200446 # Modules replaced by drivers
Yanray Wang57790962023-10-31 13:39:07 +0800447 'asn1parse', 'asn1write',
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200448 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
449 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
450 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200451 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200452 'ignored_tests': {
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200453 # See ecp_light_only
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200454 'test_suite_random': [
455 'PSA classic wrapper: ECDSA signature (SECP256R1)',
456 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200457 }
458 }
459 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200460}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200461
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200462def main():
Valerio Settif075e472023-10-17 11:03:16 +0200463 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200464
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200465 try:
466 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200467 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200468 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200469 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100470 help='Analysis to be done. By default, run all tasks. '
471 'With one or more TASK, run only those. '
472 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100473 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100474 parser.add_argument('--list', action='store_true',
475 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100476 parser.add_argument('--require-full-coverage', action='store_true',
477 dest='full_coverage', help="Require all available "
478 "test cases to be executed and issue an error "
479 "otherwise. This flag is ignored if 'task' is "
480 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200481 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200482
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100483 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200484 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200485 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100486 sys.exit(0)
487
Valerio Settidfd7ca62023-10-09 16:30:11 +0200488 if options.specified_tasks == 'all':
489 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100490 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200491 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200492 for task in tasks_list:
493 if task not in KNOWN_TASKS:
Manuel Pégourié-Gonnard62d61312023-10-20 10:51:57 +0200494 sys.stderr.write('invalid task: {}\n'.format(task))
Valerio Settifb2750e2023-10-17 10:11:45 +0200495 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100496
Valerio Settidfd7ca62023-10-09 16:30:11 +0200497 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100498
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800499 # If the outcome file already exists, we assume that the user wants to
500 # perform the comparison.
501 # Share the contents among tasks to improve performance.
502 if os.path.exists(options.outcomes):
503 main_results.info("Read outcome file from {}.", options.outcomes)
504 outcomes_or_file = read_outcome_file(options.outcomes)
505 else:
506 outcomes_or_file = options.outcomes
507
Valerio Settifb2750e2023-10-17 10:11:45 +0200508 for task in tasks_list:
509 test_function = KNOWN_TASKS[task]['test_function']
510 test_args = KNOWN_TASKS[task]['args']
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800511 test_function(main_results, outcomes_or_file, test_args)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100512
Valerio Settif6f64cf2023-10-17 12:28:26 +0200513 main_results.info("Overall results: {} warnings and {} errors",
514 main_results.warning_count, main_results.error_count)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200515
Valerio Setti8d178be2023-10-17 12:23:55 +0200516 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200517
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200518 except Exception: # pylint: disable=broad-except
519 # Print the backtrace and exit explicitly with our chosen status.
520 traceback.print_exc()
521 sys.exit(120)
522
523if __name__ == '__main__':
524 main()