Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | """Analyze the test outcomes from a full CI run. |
| 4 | |
| 5 | This script can also run on outcomes from a partial run, but the results are |
| 6 | less likely to be useful. |
| 7 | """ |
| 8 | |
| 9 | import argparse |
| 10 | import sys |
| 11 | import traceback |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 12 | import re |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 13 | import subprocess |
| 14 | import os |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 15 | |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 16 | import check_test_cases |
| 17 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 18 | class 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 | |
| 37 | class TestCaseOutcomes: |
| 38 | """The outcomes of one test case across many configurations.""" |
| 39 | # pylint: disable=too-few-public-methods |
| 40 | |
| 41 | def __init__(self): |
Gilles Peskine | 3d863f2 | 2020-06-26 13:02:30 +0200 | [diff] [blame] | 42 | # 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 Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 46 | 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 Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 56 | def execute_reference_driver_tests(ref_component, driver_component, outcome_file): |
Valerio Setti | 22992a0 | 2023-03-29 11:15:28 +0200 | [diff] [blame] | 57 | """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 Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 59 | 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 Setti | f109c66 | 2023-03-29 11:15:44 +0200 | [diff] [blame] | 69 | Results.log("Running: " + shell_command) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 70 | 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ález | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 76 | def analyze_coverage(results, outcomes, allow_list, full_coverage): |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 77 | """Check that all available test cases are executed at least once.""" |
Gilles Peskine | 686c292 | 2022-01-07 15:58:38 +0100 | [diff] [blame] | 78 | available = check_test_cases.collect_available_test_cases() |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 79 | for key in available: |
| 80 | hits = outcomes[key].hits() if key in outcomes else 0 |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 81 | if hits == 0 and key not in allow_list: |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 82 | if full_coverage: |
| 83 | results.error('Test case not executed: {}', key) |
| 84 | else: |
| 85 | results.warning('Test case not executed: {}', key) |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 86 | 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 Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 89 | |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 90 | def analyze_driver_vs_reference(outcomes, component_ref, component_driver, |
| 91 | ignored_suites, ignored_test=None): |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 92 | """Check that all tests executed in the reference component are also |
| 93 | executed in the corresponding driver component. |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 94 | 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 Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 98 | """ |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 99 | available = check_test_cases.collect_available_test_cases() |
| 100 | result = True |
| 101 | |
| 102 | for key in available: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 103 | # Continue if test was not executed by any component |
| 104 | hits = outcomes[key].hits() if key in outcomes else 0 |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 105 | if hits == 0: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 106 | continue |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 107 | # 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é-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 111 | if test_suite in ignored_suites or full_test_suite in ignored_suites: |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 112 | continue |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 113 | if ((full_test_suite in ignored_test) and |
| 114 | (test_string in ignored_test[full_test_suite])): |
| 115 | continue |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 116 | # 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 Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 120 | if component_driver in entry: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 121 | driver_test_passed = True |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 122 | if component_ref in entry: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 123 | reference_test_passed = True |
Manuel Pégourié-Gonnard | c6967d2 | 2022-12-30 13:40:34 +0100 | [diff] [blame] | 124 | if(reference_test_passed and not driver_test_passed): |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 125 | Results.log(key) |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 126 | result = False |
| 127 | return result |
| 128 | |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 129 | def analyze_outcomes(outcomes, args): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 130 | """Run all analyses on the given outcome collection.""" |
| 131 | results = Results() |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 132 | analyze_coverage(results, outcomes, args['allow_list'], |
| 133 | args['full_coverage']) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 134 | return results |
| 135 | |
| 136 | def read_outcome_file(outcome_file): |
| 137 | """Parse an outcome file and return an outcome collection. |
| 138 | |
| 139 | An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects. |
| 140 | The keys are the test suite name and the test case description, separated |
| 141 | by 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 Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 157 | def do_analyze_coverage(outcome_file, args): |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 158 | """Perform coverage analysis.""" |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 159 | outcomes = read_outcome_file(outcome_file) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 160 | Results.log("\n*** Analyze coverage ***\n") |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 161 | results = analyze_outcomes(outcomes, args) |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 162 | return results.error_count == 0 |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 163 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 164 | def do_analyze_driver_vs_reference(outcome_file, args): |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 165 | """Perform driver vs reference analyze.""" |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 166 | execute_reference_driver_tests(args['component_ref'], \ |
| 167 | args['component_driver'], outcome_file) |
| 168 | |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 169 | ignored_suites = ['test_suite_' + x for x in args['ignored_suites']] |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 170 | |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 171 | outcomes = read_outcome_file(outcome_file) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 172 | Results.log("\n*** Analyze driver {} vs reference {} ***\n".format( |
Manuel Pégourié-Gonnard | c6967d2 | 2022-12-30 13:40:34 +0100 | [diff] [blame] | 173 | args['component_driver'], args['component_ref'])) |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 174 | return analyze_driver_vs_reference(outcomes, args['component_ref'], |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 175 | args['component_driver'], ignored_suites, |
| 176 | args['ignored_tests']) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 177 | |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 178 | # List of tasks with a function that can handle this task and additional arguments if required |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 179 | TASKS = { |
| 180 | 'analyze_coverage': { |
| 181 | 'test_function': do_analyze_coverage, |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 182 | 'args': { |
| 183 | 'allow_list': [], |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 184 | 'full_coverage': False, |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 185 | } |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 186 | }, |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 187 | # 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 Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 193 | 'analyze_driver_vs_reference_hash': { |
| 194 | 'test_function': do_analyze_driver_vs_reference, |
| 195 | 'args': { |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 196 | 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa', |
| 197 | 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa', |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 198 | 'ignored_suites': [ |
| 199 | 'shax', 'mdx', # the software implementations that are being excluded |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 200 | 'md.psa', # purposefully depends on whether drivers are present |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 201 | ], |
| 202 | 'ignored_tests': { |
| 203 | } |
| 204 | } |
| 205 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 206 | 'analyze_driver_vs_reference_ecp_light_only': { |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 207 | 'test_function': do_analyze_driver_vs_reference, |
| 208 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 209 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', |
| 210 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 211 | '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 Setti | 0c477d3 | 2023-04-07 15:54:20 +0200 | [diff] [blame] | 220 | # 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 Setti | e50a75f | 2023-05-19 17:43:06 +0200 | [diff] [blame] | 257 | ], |
Valerio Setti | 5f54020 | 2023-06-30 17:20:49 +0200 | [diff] [blame] | 258 | } |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 259 | } |
| 260 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 261 | 'analyze_driver_vs_reference_no_ecp_at_all': { |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 262 | 'test_function': do_analyze_driver_vs_reference, |
| 263 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 264 | '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 Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 266 | '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 Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 292 | ], |
| 293 | 'test_suite_pkparse': [ |
Valerio Setti | 5bd2523 | 2023-06-19 19:32:14 +0200 | [diff] [blame] | 294 | # 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 Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 316 | ], |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | }, |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 320 | '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 Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 332 | 'bignum_core', |
| 333 | 'bignum_random', |
| 334 | 'bignum_mod', |
| 335 | 'bignum_mod_raw', |
| 336 | 'bignum.generated', |
| 337 | 'bignum.misc', |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 338 | ], |
| 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 Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 378 | '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 Setti | e0be95e | 2023-08-01 09:07:43 +0200 | [diff] [blame] | 400 | '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é-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | }, |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 413 | '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 Stekiel | 84f4ff1 | 2023-07-04 12:35:31 +0200 | [diff] [blame] | 418 | 'ignored_suites': ['dhm'], |
Przemek Stekiel | 565353e | 2023-07-05 11:07:07 +0200 | [diff] [blame] | 419 | 'ignored_tests': {} |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 420 | } |
| 421 | }, |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 422 | } |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 423 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 424 | def main(): |
| 425 | try: |
| 426 | parser = argparse.ArgumentParser(description=__doc__) |
Przemek Stekiel | 58bbc23 | 2022-10-24 08:10:10 +0200 | [diff] [blame] | 427 | parser.add_argument('outcomes', metavar='OUTCOMES.CSV', |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 428 | help='Outcome file to analyze') |
Przemek Stekiel | 542d932 | 2022-11-17 09:43:34 +0100 | [diff] [blame] | 429 | parser.add_argument('task', default='all', nargs='?', |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 430 | 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 Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 433 | 'comma/space-separated list of tasks. ') |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 434 | parser.add_argument('--list', action='store_true', |
| 435 | help='List all available tasks and exit.') |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 436 | 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 Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 441 | options = parser.parse_args() |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 442 | |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 443 | if options.list: |
| 444 | for task in TASKS: |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 445 | Results.log(task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 446 | sys.exit(0) |
| 447 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 448 | result = True |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 449 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 450 | if options.task == 'all': |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 451 | tasks = TASKS.keys() |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 452 | else: |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 453 | tasks = re.split(r'[, ]+', options.task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 454 | |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 455 | for task in tasks: |
| 456 | if task not in TASKS: |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 457 | Results.log('Error: invalid task: {}'.format(task)) |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 458 | sys.exit(1) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 459 | |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame^] | 460 | TASKS['analyze_coverage']['args']['full_coverage'] = \ |
| 461 | options.full_coverage |
| 462 | |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 463 | for task in TASKS: |
| 464 | if task in tasks: |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 465 | if not TASKS[task]['test_function'](options.outcomes, TASKS[task]['args']): |
| 466 | result = False |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 467 | |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 468 | if result is False: |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 469 | sys.exit(1) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 470 | Results.log("SUCCESS :-)") |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 471 | 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 | |
| 476 | if __name__ == '__main__': |
| 477 | main() |