blob: c6891bb4323ddcf24a94b9c046808c00077395f1 [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
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020076def analyze_coverage(results, outcomes):
77 """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
81 if hits == 0:
82 # Make this a warning, not an error, as long as we haven't
83 # fixed this branch to have full coverage of test cases.
84 results.warning('Test case not executed: {}', key)
85
Valerio Setti3002c992023-01-18 17:28:36 +010086def analyze_driver_vs_reference(outcomes, component_ref, component_driver,
87 ignored_suites, ignored_test=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +020088 """Check that all tests executed in the reference component are also
89 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +010090 Skip:
91 - full test suites provided in ignored_suites list
92 - only some specific test inside a test suite, for which the corresponding
93 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +020094 """
Przemek Stekiel4e955902022-10-21 13:42:08 +020095 available = check_test_cases.collect_available_test_cases()
96 result = True
97
98 for key in available:
Przemek Stekiel4e955902022-10-21 13:42:08 +020099 # Continue if test was not executed by any component
100 hits = outcomes[key].hits() if key in outcomes else 0
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200101 if hits == 0:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200102 continue
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100103 # Skip ignored test suites
104 full_test_suite = key.split(';')[0] # retrieve full test suite name
105 test_string = key.split(';')[1] # retrieve the text string of this test
106 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100107 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100108 continue
Valerio Setti3002c992023-01-18 17:28:36 +0100109 if ((full_test_suite in ignored_test) and
110 (test_string in ignored_test[full_test_suite])):
111 continue
Przemek Stekiel4e955902022-10-21 13:42:08 +0200112 # Search for tests that run in reference component and not in driver component
113 driver_test_passed = False
114 reference_test_passed = False
115 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100116 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200117 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100118 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200119 reference_test_passed = True
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100120 if(reference_test_passed and not driver_test_passed):
Valerio Setti3951d1b2023-03-13 18:37:34 +0100121 Results.log(key)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200122 result = False
123 return result
124
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200125def analyze_outcomes(outcomes):
126 """Run all analyses on the given outcome collection."""
127 results = Results()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +0200128 analyze_coverage(results, outcomes)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200129 return results
130
131def read_outcome_file(outcome_file):
132 """Parse an outcome file and return an outcome collection.
133
134An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
135The keys are the test suite name and the test case description, separated
136by a semicolon.
137"""
138 outcomes = {}
139 with open(outcome_file, 'r', encoding='utf-8') as input_file:
140 for line in input_file:
141 (platform, config, suite, case, result, _cause) = line.split(';')
142 key = ';'.join([suite, case])
143 setup = ';'.join([platform, config])
144 if key not in outcomes:
145 outcomes[key] = TestCaseOutcomes()
146 if result == 'PASS':
147 outcomes[key].successes.append(setup)
148 elif result == 'FAIL':
149 outcomes[key].failures.append(setup)
150 return outcomes
151
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200152def do_analyze_coverage(outcome_file, args):
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100153 """Perform coverage analysis."""
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200154 del args # unused
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200155 outcomes = read_outcome_file(outcome_file)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100156 Results.log("\n*** Analyze coverage ***\n")
Przemek Stekiel4e955902022-10-21 13:42:08 +0200157 results = analyze_outcomes(outcomes)
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200158 return results.error_count == 0
Przemek Stekiel4e955902022-10-21 13:42:08 +0200159
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200160def do_analyze_driver_vs_reference(outcome_file, args):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200161 """Perform driver vs reference analyze."""
Valerio Settia2663322023-03-24 08:20:18 +0100162 execute_reference_driver_tests(args['component_ref'], \
163 args['component_driver'], outcome_file)
164
Valerio Setti3002c992023-01-18 17:28:36 +0100165 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100166
Przemek Stekiel4e955902022-10-21 13:42:08 +0200167 outcomes = read_outcome_file(outcome_file)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100168 Results.log("\n*** Analyze driver {} vs reference {} ***\n".format(
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100169 args['component_driver'], args['component_ref']))
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100170 return analyze_driver_vs_reference(outcomes, args['component_ref'],
Valerio Setti3002c992023-01-18 17:28:36 +0100171 args['component_driver'], ignored_suites,
172 args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200173
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100174# List of tasks with a function that can handle this task and additional arguments if required
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200175TASKS = {
176 'analyze_coverage': {
177 'test_function': do_analyze_coverage,
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100178 'args': {}
179 },
Valerio Settia2663322023-03-24 08:20:18 +0100180 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
181 # 1. Run tests and then analysis:
182 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
183 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
184 # 2. Let this script run both automatically:
185 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200186 'analyze_driver_vs_reference_hash': {
187 'test_function': do_analyze_driver_vs_reference,
188 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100189 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
190 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100191 'ignored_suites': [
192 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100193 'md.psa', # purposefully depends on whether drivers are present
Valerio Setti3002c992023-01-18 17:28:36 +0100194 ],
195 'ignored_tests': {
196 }
197 }
198 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200199 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100200 'test_function': do_analyze_driver_vs_reference,
201 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200202 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
203 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100204 'ignored_suites': [
205 'ecdsa',
206 'ecdh',
207 'ecjpake',
208 ],
209 'ignored_tests': {
210 'test_suite_random': [
211 'PSA classic wrapper: ECDSA signature (SECP256R1)',
212 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200213 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
214 # so we must ignore disparities in the tests for which ECP_C
215 # is required.
216 'test_suite_ecp': [
217 'ECP check public-private #1 (OK)',
218 'ECP check public-private #2 (group none)',
219 'ECP check public-private #3 (group mismatch)',
220 'ECP check public-private #4 (Qx mismatch)',
221 'ECP check public-private #5 (Qy mismatch)',
222 'ECP check public-private #6 (wrong Qx)',
223 'ECP check public-private #7 (wrong Qy)',
224 'ECP gen keypair [#1]',
225 'ECP gen keypair [#2]',
226 'ECP gen keypair [#3]',
227 'ECP gen keypair wrapper',
228 'ECP point muladd secp256r1 #1',
229 'ECP point muladd secp256r1 #2',
230 'ECP point multiplication Curve25519 (element of order 2: origin) #3',
231 'ECP point multiplication Curve25519 (element of order 4: 1) #4',
232 'ECP point multiplication Curve25519 (element of order 8) #5',
233 'ECP point multiplication Curve25519 (normalized) #1',
234 'ECP point multiplication Curve25519 (not normalized) #2',
235 'ECP point multiplication rng fail Curve25519',
236 'ECP point multiplication rng fail secp256r1',
237 'ECP test vectors Curve25519',
238 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)',
239 'ECP test vectors brainpoolP256r1 rfc 7027',
240 'ECP test vectors brainpoolP384r1 rfc 7027',
241 'ECP test vectors brainpoolP512r1 rfc 7027',
242 'ECP test vectors secp192k1',
243 'ECP test vectors secp192r1 rfc 5114',
244 'ECP test vectors secp224k1',
245 'ECP test vectors secp224r1 rfc 5114',
246 'ECP test vectors secp256k1',
247 'ECP test vectors secp256r1 rfc 5114',
248 'ECP test vectors secp384r1 rfc 5114',
249 'ECP test vectors secp521r1 rfc 5114',
Valerio Settie50a75f2023-05-19 17:43:06 +0200250 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200251 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100252 }
253 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200254 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200255 'test_function': do_analyze_driver_vs_reference,
256 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200257 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
258 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200259 'ignored_suites': [
260 # Ignore test suites for the modules that are disabled in the
261 # accelerated test case.
262 'ecp',
263 'ecdsa',
264 'ecdh',
265 'ecjpake',
266 ],
267 'ignored_tests': {
268 'test_suite_random': [
269 'PSA classic wrapper: ECDSA signature (SECP256R1)',
270 ],
271 'test_suite_psa_crypto': [
272 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
273 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
274 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
275 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
276 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
277 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
278 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
279 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
280 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
281 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
282 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
283 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
284 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200285 ],
286 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200287 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
288 # is automatically enabled in build_info.h (backward compatibility)
289 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
290 # consequence compressed points are supported in the reference
291 # component but not in the accelerated one, so they should be skipped
292 # while checking driver's coverage.
293 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
294 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
295 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
296 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
297 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
298 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
299 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
300 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
301 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
302 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
303 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
304 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
305 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
306 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
307 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
308 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200309 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200310 }
311 }
312 },
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200313 'analyze_driver_vs_reference_no_bignum': {
314 'test_function': do_analyze_driver_vs_reference,
315 'args': {
316 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
317 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
318 'ignored_suites': [
319 # Ignore test suites for the modules that are disabled in the
320 # accelerated test case.
321 'ecp',
322 'ecdsa',
323 'ecdh',
324 'ecjpake',
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200325 'bignum_core',
326 'bignum_random',
327 'bignum_mod',
328 'bignum_mod_raw',
329 'bignum.generated',
330 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200331 ],
332 'ignored_tests': {
333 'test_suite_random': [
334 'PSA classic wrapper: ECDSA signature (SECP256R1)',
335 ],
336 'test_suite_psa_crypto': [
337 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
338 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
339 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
340 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
341 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
342 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
343 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
344 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
345 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
346 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
347 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
348 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
349 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
350 ],
351 'test_suite_pkparse': [
352 # See the description provided above in the
353 # analyze_driver_vs_reference_no_ecp_at_all component.
354 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
355 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
356 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
357 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
358 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
359 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
360 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
361 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
362 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
363 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
364 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
365 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
366 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
367 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
368 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
369 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
370 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200371 'test_suite_asn1parse': [
372 # This test depends on BIGNUM_C
373 'INTEGER too large for mpi',
374 ],
375 'test_suite_asn1write': [
376 # Following tests depends on BIGNUM_C
377 'ASN.1 Write mpi 0 (1 limb)',
378 'ASN.1 Write mpi 0 (null)',
379 'ASN.1 Write mpi 0x100',
380 'ASN.1 Write mpi 0x7f',
381 'ASN.1 Write mpi 0x7f with leading 0 limb',
382 'ASN.1 Write mpi 0x80',
383 'ASN.1 Write mpi 0x80 with leading 0 limb',
384 'ASN.1 Write mpi 0xff',
385 'ASN.1 Write mpi 1',
386 'ASN.1 Write mpi, 127*8 bits',
387 'ASN.1 Write mpi, 127*8+1 bits',
388 'ASN.1 Write mpi, 127*8-1 bits',
389 'ASN.1 Write mpi, 255*8 bits',
390 'ASN.1 Write mpi, 255*8-1 bits',
391 'ASN.1 Write mpi, 256*8-1 bits',
392 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200393 'test_suite_debug': [
394 # Following tests depends on BIGNUM_C
395 'Debug print mbedtls_mpi #2: 3 bits',
396 'Debug print mbedtls_mpi: 0 (empty representation)',
397 'Debug print mbedtls_mpi: 0 (non-empty representation)',
398 'Debug print mbedtls_mpi: 49 bits',
399 'Debug print mbedtls_mpi: 759 bits',
400 'Debug print mbedtls_mpi: 764 bits #1',
401 'Debug print mbedtls_mpi: 764 bits #2',
402 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200403 }
404 }
405 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200406 'analyze_driver_vs_reference_ffdh_alg': {
407 'test_function': do_analyze_driver_vs_reference,
408 'args': {
409 'component_ref': 'test_psa_crypto_config_reference_ffdh',
410 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200411 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200412 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200413 }
414 },
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200415}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200416
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200417def main():
418 try:
419 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200420 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200421 help='Outcome file to analyze')
Przemek Stekiel542d9322022-11-17 09:43:34 +0100422 parser.add_argument('task', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100423 help='Analysis to be done. By default, run all tasks. '
424 'With one or more TASK, run only those. '
425 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100426 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100427 parser.add_argument('--list', action='store_true',
428 help='List all available tasks and exit.')
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200429 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200430
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100431 if options.list:
432 for task in TASKS:
Valerio Setti3951d1b2023-03-13 18:37:34 +0100433 Results.log(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100434 sys.exit(0)
435
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200436 result = True
Przemek Stekiel4e955902022-10-21 13:42:08 +0200437
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200438 if options.task == 'all':
Przemek Stekield3068af2022-11-14 16:15:19 +0100439 tasks = TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100440 else:
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100441 tasks = re.split(r'[, ]+', options.task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100442
Przemek Stekield3068af2022-11-14 16:15:19 +0100443 for task in tasks:
444 if task not in TASKS:
Valerio Setti3951d1b2023-03-13 18:37:34 +0100445 Results.log('Error: invalid task: {}'.format(task))
Przemek Stekield3068af2022-11-14 16:15:19 +0100446 sys.exit(1)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100447
448 for task in TASKS:
449 if task in tasks:
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200450 if not TASKS[task]['test_function'](options.outcomes, TASKS[task]['args']):
451 result = False
Przemek Stekiel4e955902022-10-21 13:42:08 +0200452
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200453 if result is False:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200454 sys.exit(1)
Valerio Setti3951d1b2023-03-13 18:37:34 +0100455 Results.log("SUCCESS :-)")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200456 except Exception: # pylint: disable=broad-except
457 # Print the backtrace and exit explicitly with our chosen status.
458 traceback.print_exc()
459 sys.exit(120)
460
461if __name__ == '__main__':
462 main()