blob: 24f4da7739c165fc850cf2f9303b05f35bd4afdf [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
25 @staticmethod
26 def log(fmt, *args, **kwargs):
27 sys.stderr.write((fmt + '\n').format(*args, **kwargs))
28
29 def error(self, fmt, *args, **kwargs):
30 self.log('Error: ' + fmt, *args, **kwargs)
31 self.error_count += 1
32
33 def warning(self, fmt, *args, **kwargs):
34 self.log('Warning: ' + fmt, *args, **kwargs)
35 self.warning_count += 1
36
37class TestCaseOutcomes:
38 """The outcomes of one test case across many configurations."""
39 # pylint: disable=too-few-public-methods
40
41 def __init__(self):
Gilles Peskine3d863f22020-06-26 13:02:30 +020042 # Collect a list of witnesses of the test case succeeding or failing.
43 # Currently we don't do anything with witnesses except count them.
44 # The format of a witness is determined by the read_outcome_file
45 # function; it's the platform and configuration joined by ';'.
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020046 self.successes = []
47 self.failures = []
48
49 def hits(self):
50 """Return the number of times a test case has been run.
51
52 This includes passes and failures, but not skips.
53 """
54 return len(self.successes) + len(self.failures)
55
Valerio Settia2663322023-03-24 08:20:18 +010056def execute_reference_driver_tests(ref_component, driver_component, outcome_file):
Valerio Setti22992a02023-03-29 11:15:28 +020057 """Run the tests specified in ref_component and driver_component. Results
58 are stored in the output_file and they will be used for the following
Valerio Settia2663322023-03-24 08:20:18 +010059 coverage analysis"""
60 # If the outcome file already exists, we assume that the user wants to
61 # perform the comparison analysis again without repeating the tests.
62 if os.path.exists(outcome_file):
63 Results.log("Outcome file (" + outcome_file + ") already exists. " + \
64 "Tests will be skipped.")
65 return
66
67 shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
68 " " + ref_component + " " + driver_component
Valerio Settif109c662023-03-29 11:15:44 +020069 Results.log("Running: " + shell_command)
Valerio Settia2663322023-03-24 08:20:18 +010070 ret_val = subprocess.run(shell_command.split(), check=False).returncode
71
72 if ret_val != 0:
73 Results.log("Error: failed to run reference/driver components")
74 sys.exit(ret_val)
75
Tomás Gonzálezb401e112023-08-11 15:22:04 +010076def analyze_coverage(results, outcomes, allow_list, full_coverage):
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020077 """Check that all available test cases are executed at least once."""
Gilles Peskine686c2922022-01-07 15:58:38 +010078 available = check_test_cases.collect_available_test_cases()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020079 for key in available:
80 hits = outcomes[key].hits() if key in outcomes else 0
Tomás González07bdcc22023-08-11 14:59:03 +010081 if hits == 0 and key not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +010082 if full_coverage:
83 results.error('Test case not executed: {}', key)
84 else:
85 results.warning('Test case not executed: {}', key)
Tomás González07bdcc22023-08-11 14:59:03 +010086 elif hits != 0 and key in allow_list:
87 # Test Case should be removed from the allow list.
88 results.warning('Allow listed test case was executed: {}', key)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020089
Valerio Setti3002c992023-01-18 17:28:36 +010090def analyze_driver_vs_reference(outcomes, component_ref, component_driver,
91 ignored_suites, ignored_test=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +020092 """Check that all tests executed in the reference component are also
93 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +010094 Skip:
95 - full test suites provided in ignored_suites list
96 - only some specific test inside a test suite, for which the corresponding
97 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +020098 """
Przemek Stekiel4e955902022-10-21 13:42:08 +020099 available = check_test_cases.collect_available_test_cases()
100 result = True
101
102 for key in available:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200103 # Continue if test was not executed by any component
104 hits = outcomes[key].hits() if key in outcomes else 0
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200105 if hits == 0:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200106 continue
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100107 # Skip ignored test suites
108 full_test_suite = key.split(';')[0] # retrieve full test suite name
109 test_string = key.split(';')[1] # retrieve the text string of this test
110 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100111 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100112 continue
Valerio Setti3002c992023-01-18 17:28:36 +0100113 if ((full_test_suite in ignored_test) and
114 (test_string in ignored_test[full_test_suite])):
115 continue
Przemek Stekiel4e955902022-10-21 13:42:08 +0200116 # Search for tests that run in reference component and not in driver component
117 driver_test_passed = False
118 reference_test_passed = False
119 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100120 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200121 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100122 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200123 reference_test_passed = True
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100124 if(reference_test_passed and not driver_test_passed):
Valerio Setti3951d1b2023-03-13 18:37:34 +0100125 Results.log(key)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200126 result = False
127 return result
128
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100129def analyze_outcomes(outcomes, args):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200130 """Run all analyses on the given outcome collection."""
131 results = Results()
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100132 analyze_coverage(results, outcomes, args['allow_list'],
133 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200134 return results
135
136def read_outcome_file(outcome_file):
137 """Parse an outcome file and return an outcome collection.
138
139An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
140The keys are the test suite name and the test case description, separated
141by a semicolon.
142"""
143 outcomes = {}
144 with open(outcome_file, 'r', encoding='utf-8') as input_file:
145 for line in input_file:
146 (platform, config, suite, case, result, _cause) = line.split(';')
147 key = ';'.join([suite, case])
148 setup = ';'.join([platform, config])
149 if key not in outcomes:
150 outcomes[key] = TestCaseOutcomes()
151 if result == 'PASS':
152 outcomes[key].successes.append(setup)
153 elif result == 'FAIL':
154 outcomes[key].failures.append(setup)
155 return outcomes
156
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200157def do_analyze_coverage(outcome_file, args):
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100158 """Perform coverage analysis."""
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200159 outcomes = read_outcome_file(outcome_file)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100160 Results.log("\n*** Analyze coverage ***\n")
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100161 results = analyze_outcomes(outcomes, args)
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200162 return results.error_count == 0
Przemek Stekiel4e955902022-10-21 13:42:08 +0200163
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200164def do_analyze_driver_vs_reference(outcome_file, args):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200165 """Perform driver vs reference analyze."""
Valerio Settia2663322023-03-24 08:20:18 +0100166 execute_reference_driver_tests(args['component_ref'], \
167 args['component_driver'], outcome_file)
168
Valerio Setti3002c992023-01-18 17:28:36 +0100169 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100170
Przemek Stekiel4e955902022-10-21 13:42:08 +0200171 outcomes = read_outcome_file(outcome_file)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100172 Results.log("\n*** Analyze driver {} vs reference {} ***\n".format(
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100173 args['component_driver'], args['component_ref']))
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100174 return analyze_driver_vs_reference(outcomes, args['component_ref'],
Valerio Setti3002c992023-01-18 17:28:36 +0100175 args['component_driver'], ignored_suites,
176 args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200177
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100178# List of tasks with a function that can handle this task and additional arguments if required
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200179TASKS = {
180 'analyze_coverage': {
181 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100182 'args': {
183 'allow_list': [],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100184 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100185 }
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100186 },
Valerio Settia2663322023-03-24 08:20:18 +0100187 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
188 # 1. Run tests and then analysis:
189 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
190 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
191 # 2. Let this script run both automatically:
192 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200193 'analyze_driver_vs_reference_hash': {
194 'test_function': do_analyze_driver_vs_reference,
195 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100196 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
197 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100198 'ignored_suites': [
199 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100200 'md.psa', # purposefully depends on whether drivers are present
Valerio Setti3002c992023-01-18 17:28:36 +0100201 ],
202 'ignored_tests': {
203 }
204 }
205 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200206 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100207 'test_function': do_analyze_driver_vs_reference,
208 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200209 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
210 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100211 'ignored_suites': [
212 'ecdsa',
213 'ecdh',
214 'ecjpake',
215 ],
216 'ignored_tests': {
217 'test_suite_random': [
218 'PSA classic wrapper: ECDSA signature (SECP256R1)',
219 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200220 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
221 # so we must ignore disparities in the tests for which ECP_C
222 # is required.
223 'test_suite_ecp': [
224 'ECP check public-private #1 (OK)',
225 'ECP check public-private #2 (group none)',
226 'ECP check public-private #3 (group mismatch)',
227 'ECP check public-private #4 (Qx mismatch)',
228 'ECP check public-private #5 (Qy mismatch)',
229 'ECP check public-private #6 (wrong Qx)',
230 'ECP check public-private #7 (wrong Qy)',
231 'ECP gen keypair [#1]',
232 'ECP gen keypair [#2]',
233 'ECP gen keypair [#3]',
234 'ECP gen keypair wrapper',
235 'ECP point muladd secp256r1 #1',
236 'ECP point muladd secp256r1 #2',
237 'ECP point multiplication Curve25519 (element of order 2: origin) #3',
238 'ECP point multiplication Curve25519 (element of order 4: 1) #4',
239 'ECP point multiplication Curve25519 (element of order 8) #5',
240 'ECP point multiplication Curve25519 (normalized) #1',
241 'ECP point multiplication Curve25519 (not normalized) #2',
242 'ECP point multiplication rng fail Curve25519',
243 'ECP point multiplication rng fail secp256r1',
244 'ECP test vectors Curve25519',
245 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)',
246 'ECP test vectors brainpoolP256r1 rfc 7027',
247 'ECP test vectors brainpoolP384r1 rfc 7027',
248 'ECP test vectors brainpoolP512r1 rfc 7027',
249 'ECP test vectors secp192k1',
250 'ECP test vectors secp192r1 rfc 5114',
251 'ECP test vectors secp224k1',
252 'ECP test vectors secp224r1 rfc 5114',
253 'ECP test vectors secp256k1',
254 'ECP test vectors secp256r1 rfc 5114',
255 'ECP test vectors secp384r1 rfc 5114',
256 'ECP test vectors secp521r1 rfc 5114',
Valerio Settie50a75f2023-05-19 17:43:06 +0200257 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200258 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100259 }
260 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200261 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200262 'test_function': do_analyze_driver_vs_reference,
263 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200264 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
265 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200266 'ignored_suites': [
267 # Ignore test suites for the modules that are disabled in the
268 # accelerated test case.
269 'ecp',
270 'ecdsa',
271 'ecdh',
272 'ecjpake',
273 ],
274 'ignored_tests': {
275 'test_suite_random': [
276 'PSA classic wrapper: ECDSA signature (SECP256R1)',
277 ],
278 'test_suite_psa_crypto': [
279 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
280 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
281 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
282 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
283 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
284 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
285 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
286 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
287 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
288 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
289 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
290 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
291 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200292 ],
293 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200294 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
295 # is automatically enabled in build_info.h (backward compatibility)
296 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
297 # consequence compressed points are supported in the reference
298 # component but not in the accelerated one, so they should be skipped
299 # while checking driver's coverage.
300 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
301 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
302 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
303 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
304 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
305 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
306 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
307 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
308 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
309 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
310 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
311 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
312 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
313 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
314 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
315 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200316 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200317 }
318 }
319 },
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200320 'analyze_driver_vs_reference_no_bignum': {
321 'test_function': do_analyze_driver_vs_reference,
322 'args': {
323 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
324 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
325 'ignored_suites': [
326 # Ignore test suites for the modules that are disabled in the
327 # accelerated test case.
328 'ecp',
329 'ecdsa',
330 'ecdh',
331 'ecjpake',
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200332 'bignum_core',
333 'bignum_random',
334 'bignum_mod',
335 'bignum_mod_raw',
336 'bignum.generated',
337 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200338 ],
339 'ignored_tests': {
340 'test_suite_random': [
341 'PSA classic wrapper: ECDSA signature (SECP256R1)',
342 ],
343 'test_suite_psa_crypto': [
344 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
345 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
346 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
347 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
348 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
349 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
350 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
351 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
352 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
353 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
354 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
355 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
356 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
357 ],
358 'test_suite_pkparse': [
359 # See the description provided above in the
360 # analyze_driver_vs_reference_no_ecp_at_all component.
361 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
362 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
363 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
364 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
365 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
366 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
367 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
368 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
369 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
370 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
371 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
372 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
373 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
374 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
375 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
376 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
377 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200378 'test_suite_asn1parse': [
379 # This test depends on BIGNUM_C
380 'INTEGER too large for mpi',
381 ],
382 'test_suite_asn1write': [
383 # Following tests depends on BIGNUM_C
384 'ASN.1 Write mpi 0 (1 limb)',
385 'ASN.1 Write mpi 0 (null)',
386 'ASN.1 Write mpi 0x100',
387 'ASN.1 Write mpi 0x7f',
388 'ASN.1 Write mpi 0x7f with leading 0 limb',
389 'ASN.1 Write mpi 0x80',
390 'ASN.1 Write mpi 0x80 with leading 0 limb',
391 'ASN.1 Write mpi 0xff',
392 'ASN.1 Write mpi 1',
393 'ASN.1 Write mpi, 127*8 bits',
394 'ASN.1 Write mpi, 127*8+1 bits',
395 'ASN.1 Write mpi, 127*8-1 bits',
396 'ASN.1 Write mpi, 255*8 bits',
397 'ASN.1 Write mpi, 255*8-1 bits',
398 'ASN.1 Write mpi, 256*8-1 bits',
399 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200400 'test_suite_debug': [
401 # Following tests depends on BIGNUM_C
402 'Debug print mbedtls_mpi #2: 3 bits',
403 'Debug print mbedtls_mpi: 0 (empty representation)',
404 'Debug print mbedtls_mpi: 0 (non-empty representation)',
405 'Debug print mbedtls_mpi: 49 bits',
406 'Debug print mbedtls_mpi: 759 bits',
407 'Debug print mbedtls_mpi: 764 bits #1',
408 'Debug print mbedtls_mpi: 764 bits #2',
409 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200410 }
411 }
412 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200413 'analyze_driver_vs_reference_ffdh_alg': {
414 'test_function': do_analyze_driver_vs_reference,
415 'args': {
416 'component_ref': 'test_psa_crypto_config_reference_ffdh',
417 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200418 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200419 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200420 }
421 },
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200422}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200423
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200424def main():
425 try:
426 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200427 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200428 help='Outcome file to analyze')
Przemek Stekiel542d9322022-11-17 09:43:34 +0100429 parser.add_argument('task', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100430 help='Analysis to be done. By default, run all tasks. '
431 'With one or more TASK, run only those. '
432 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100433 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100434 parser.add_argument('--list', action='store_true',
435 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100436 parser.add_argument('--require-full-coverage', action='store_true',
437 dest='full_coverage', help="Require all available "
438 "test cases to be executed and issue an error "
439 "otherwise. This flag is ignored if 'task' is "
440 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200441 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200442
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100443 if options.list:
444 for task in TASKS:
Valerio Setti3951d1b2023-03-13 18:37:34 +0100445 Results.log(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100446 sys.exit(0)
447
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200448 result = True
Przemek Stekiel4e955902022-10-21 13:42:08 +0200449
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200450 if options.task == 'all':
Przemek Stekield3068af2022-11-14 16:15:19 +0100451 tasks = TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100452 else:
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100453 tasks = re.split(r'[, ]+', options.task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100454
Przemek Stekield3068af2022-11-14 16:15:19 +0100455 for task in tasks:
456 if task not in TASKS:
Valerio Setti3951d1b2023-03-13 18:37:34 +0100457 Results.log('Error: invalid task: {}'.format(task))
Przemek Stekield3068af2022-11-14 16:15:19 +0100458 sys.exit(1)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100459
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100460 TASKS['analyze_coverage']['args']['full_coverage'] = \
461 options.full_coverage
462
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100463 for task in TASKS:
464 if task in tasks:
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200465 if not TASKS[task]['test_function'](options.outcomes, TASKS[task]['args']):
466 result = False
Przemek Stekiel4e955902022-10-21 13:42:08 +0200467
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200468 if result is False:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200469 sys.exit(1)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100470 Results.log("SUCCESS :-)")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200471 except Exception: # pylint: disable=broad-except
472 # Print the backtrace and exit explicitly with our chosen status.
473 traceback.print_exc()
474 sys.exit(120)
475
476if __name__ == '__main__':
477 main()