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 |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 15 | import typing |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 16 | |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 17 | import check_test_cases |
| 18 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 19 | |
Pengyu Lv | 550cd6f | 2023-11-29 09:17:59 +0800 | [diff] [blame] | 20 | # `ComponentOutcomes` is a named tuple which is defined as: |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 21 | # ComponentOutcomes( |
| 22 | # successes = { |
| 23 | # "<suite_case>", |
| 24 | # ... |
| 25 | # }, |
| 26 | # failures = { |
| 27 | # "<suite_case>", |
| 28 | # ... |
| 29 | # } |
| 30 | # ) |
| 31 | # suite_case = "<suite>;<case>" |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 32 | ComponentOutcomes = typing.NamedTuple('ComponentOutcomes', |
| 33 | [('successes', typing.Set[str]), |
| 34 | ('failures', typing.Set[str])]) |
| 35 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 36 | # `Outcomes` is a representation of the outcomes file, |
| 37 | # which defined as: |
| 38 | # Outcomes = { |
| 39 | # "<component>": ComponentOutcomes, |
| 40 | # ... |
| 41 | # } |
| 42 | Outcomes = typing.Dict[str, ComponentOutcomes] |
| 43 | |
| 44 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 45 | class Results: |
| 46 | """Process analysis results.""" |
| 47 | |
| 48 | def __init__(self): |
| 49 | self.error_count = 0 |
| 50 | self.warning_count = 0 |
| 51 | |
Valerio Setti | 2cff820 | 2023-10-18 14:36:47 +0200 | [diff] [blame] | 52 | def new_section(self, fmt, *args, **kwargs): |
| 53 | self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs) |
| 54 | |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 55 | def info(self, fmt, *args, **kwargs): |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 56 | self._print_line('Info: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 57 | |
| 58 | def error(self, fmt, *args, **kwargs): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 59 | self.error_count += 1 |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 60 | self._print_line('Error: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 61 | |
| 62 | def warning(self, fmt, *args, **kwargs): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 63 | self.warning_count += 1 |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 64 | self._print_line('Warning: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 65 | |
Valerio Setti | 3f33989 | 2023-10-17 10:42:11 +0200 | [diff] [blame] | 66 | @staticmethod |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 67 | def _print_line(fmt, *args, **kwargs): |
Valerio Setti | 735794c | 2023-10-18 08:05:15 +0200 | [diff] [blame] | 68 | sys.stderr.write((fmt + '\n').format(*args, **kwargs)) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 69 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 70 | def execute_reference_driver_tests(results: Results, ref_component: str, driver_component: str, \ |
| 71 | outcome_file: str) -> None: |
Valerio Setti | 22992a0 | 2023-03-29 11:15:28 +0200 | [diff] [blame] | 72 | """Run the tests specified in ref_component and driver_component. Results |
| 73 | 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] | 74 | coverage analysis""" |
Pengyu Lv | 20e3ca3 | 2023-11-28 15:30:03 +0800 | [diff] [blame] | 75 | results.new_section("Test {} and {}", ref_component, driver_component) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 76 | |
| 77 | shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \ |
| 78 | " " + ref_component + " " + driver_component |
Valerio Setti | 39d4b9d | 2023-10-18 14:30:03 +0200 | [diff] [blame] | 79 | results.info("Running: {}", shell_command) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 80 | ret_val = subprocess.run(shell_command.split(), check=False).returncode |
| 81 | |
| 82 | if ret_val != 0: |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 83 | results.error("failed to run reference/driver components") |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 84 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 85 | def analyze_coverage(results: Results, outcomes: Outcomes, |
| 86 | allow_list: typing.List[str], full_coverage: bool) -> None: |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 87 | """Check that all available test cases are executed at least once.""" |
Gilles Peskine | 78ae4f6 | 2024-05-21 20:26:18 +0200 | [diff] [blame] | 88 | # Make sure that the generated data files are present (and up-to-date). |
| 89 | # This allows analyze_outcomes.py to run correctly on a fresh Git |
| 90 | # checkout. |
| 91 | cp = subprocess.run(['make', 'generated_files'], |
| 92 | cwd='tests', |
Gilles Peskine | 2ad2f32 | 2024-05-22 09:35:11 +0200 | [diff] [blame] | 93 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 94 | check=False) |
Gilles Peskine | 78ae4f6 | 2024-05-21 20:26:18 +0200 | [diff] [blame] | 95 | if cp.returncode != 0: |
| 96 | sys.stderr.write(cp.stdout.decode('utf-8')) |
Gilles Peskine | 2ad2f32 | 2024-05-22 09:35:11 +0200 | [diff] [blame] | 97 | results.error("Failed \"make generated_files\" in tests. " |
| 98 | "Coverage analysis may be incorrect.") |
Gilles Peskine | 686c292 | 2022-01-07 15:58:38 +0100 | [diff] [blame] | 99 | available = check_test_cases.collect_available_test_cases() |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 100 | for suite_case in available: |
Pengyu Lv | 5dcfd0c | 2023-11-29 18:03:28 +0800 | [diff] [blame] | 101 | hit = any(suite_case in comp_outcomes.successes or |
| 102 | suite_case in comp_outcomes.failures |
| 103 | for comp_outcomes in outcomes.values()) |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 104 | |
Pengyu Lv | 5dcfd0c | 2023-11-29 18:03:28 +0800 | [diff] [blame] | 105 | if not hit and suite_case not in allow_list: |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 106 | if full_coverage: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 107 | results.error('Test case not executed: {}', suite_case) |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 108 | else: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 109 | results.warning('Test case not executed: {}', suite_case) |
Pengyu Lv | 5dcfd0c | 2023-11-29 18:03:28 +0800 | [diff] [blame] | 110 | elif hit and suite_case in allow_list: |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 111 | # Test Case should be removed from the allow list. |
Tomás González | 7ebb18f | 2023-08-22 09:40:23 +0100 | [diff] [blame] | 112 | if full_coverage: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 113 | results.error('Allow listed test case was executed: {}', suite_case) |
Tomás González | 7ebb18f | 2023-08-22 09:40:23 +0100 | [diff] [blame] | 114 | else: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 115 | results.warning('Allow listed test case was executed: {}', suite_case) |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 116 | |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 117 | IgnoreEntry = typing.Union[str, typing.Pattern] |
| 118 | |
| 119 | def name_matches_pattern(name: str, str_or_re: IgnoreEntry) -> bool: |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 120 | """Check if name matches a pattern, that may be a string or regex. |
| 121 | - If the pattern is a string, name must be equal to match. |
| 122 | - If the pattern is a regex, name must fully match. |
| 123 | """ |
Manuel Pégourié-Gonnard | b269543 | 2023-10-23 09:30:40 +0200 | [diff] [blame] | 124 | # The CI's python is too old for re.Pattern |
| 125 | #if isinstance(str_or_re, re.Pattern): |
| 126 | if not isinstance(str_or_re, str): |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 127 | return str_or_re.fullmatch(name) is not None |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 128 | else: |
Manuel Pégourié-Gonnard | 9d9c234 | 2023-10-26 09:37:40 +0200 | [diff] [blame] | 129 | return str_or_re == name |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 130 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 131 | def analyze_driver_vs_reference(results: Results, outcomes: Outcomes, |
| 132 | component_ref: str, component_driver: str, |
| 133 | ignored_suites: typing.List[str], ignored_tests=None) -> None: |
Sam Berry | e262c23 | 2024-06-21 10:03:37 +0100 | [diff] [blame] | 134 | """Check that all tests passing in the driver component are also |
| 135 | passing in the corresponding reference component. |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 136 | Skip: |
| 137 | - full test suites provided in ignored_suites list |
| 138 | - only some specific test inside a test suite, for which the corresponding |
| 139 | output string is provided |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 140 | """ |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 141 | ref_outcomes = outcomes.get("component_" + component_ref) |
| 142 | driver_outcomes = outcomes.get("component_" + component_driver) |
| 143 | |
Pengyu Lv | 59b9efc | 2023-11-28 11:15:00 +0800 | [diff] [blame] | 144 | if ref_outcomes is None or driver_outcomes is None: |
| 145 | results.error("required components are missing: bad outcome file?") |
| 146 | return |
| 147 | |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 148 | if not ref_outcomes.successes: |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 149 | results.error("no passing test in reference component: bad outcome file?") |
| 150 | return |
| 151 | |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 152 | for suite_case in ref_outcomes.successes: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 153 | # suite_case is like "test_suite_foo.bar;Description of test case" |
| 154 | (full_test_suite, test_string) = suite_case.split(';') |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 155 | test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 156 | |
| 157 | # Immediately skip fully-ignored test suites |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 158 | 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] | 159 | continue |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 160 | |
| 161 | # For ignored test cases inside test suites, just remember and: |
| 162 | # don't issue an error if they're skipped with drivers, |
| 163 | # but issue an error if they're not (means we have a bad entry). |
| 164 | ignored = False |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 165 | for str_or_re in (ignored_tests.get(full_test_suite, []) + |
| 166 | ignored_tests.get(test_suite, [])): |
| 167 | if name_matches_pattern(test_string, str_or_re): |
| 168 | ignored = True |
Manuel Pégourié-Gonnard | 4da369f | 2023-10-18 09:40:32 +0200 | [diff] [blame] | 169 | |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 170 | if not ignored and not suite_case in driver_outcomes.successes: |
Elena Uziunaite | c21675e | 2024-09-02 15:32:07 +0100 | [diff] [blame] | 171 | results.error("SKIP/FAIL -> PASS: {}", suite_case) |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 172 | if ignored and suite_case in driver_outcomes.successes: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 173 | results.error("uselessly ignored: {}", suite_case) |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 174 | |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 175 | def read_outcome_file(outcome_file: str) -> Outcomes: |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 176 | """Parse an outcome file and return an outcome collection. |
Pengyu Lv | c2e8f3a | 2023-11-28 17:22:04 +0800 | [diff] [blame] | 177 | """ |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 178 | outcomes = {} |
| 179 | with open(outcome_file, 'r', encoding='utf-8') as input_file: |
| 180 | for line in input_file: |
Pengyu Lv | dd1d6a7 | 2023-11-27 17:57:31 +0800 | [diff] [blame] | 181 | (_platform, component, suite, case, result, _cause) = line.split(';') |
Pengyu Lv | 451ec8a | 2023-11-28 17:59:05 +0800 | [diff] [blame] | 182 | # Note that `component` is not unique. If a test case passes on Linux |
| 183 | # and fails on FreeBSD, it'll end up in both the successes set and |
| 184 | # the failures set. |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame] | 185 | suite_case = ';'.join([suite, case]) |
Pengyu Lv | dd1d6a7 | 2023-11-27 17:57:31 +0800 | [diff] [blame] | 186 | if component not in outcomes: |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 187 | outcomes[component] = ComponentOutcomes(set(), set()) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 188 | if result == 'PASS': |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 189 | outcomes[component].successes.add(suite_case) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 190 | elif result == 'FAIL': |
Pengyu Lv | 18908ec | 2023-11-28 12:11:52 +0800 | [diff] [blame] | 191 | outcomes[component].failures.add(suite_case) |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 192 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 193 | return outcomes |
| 194 | |
Gilles Peskine | 19ef1ae | 2024-09-16 19:12:09 +0200 | [diff] [blame] | 195 | |
| 196 | class Task: |
| 197 | """Base class for outcome analysis tasks.""" |
| 198 | |
| 199 | def __init__(self, options) -> None: |
| 200 | """Pass command line options to the tasks. |
| 201 | |
| 202 | Each task decides which command line options it cares about. |
| 203 | """ |
| 204 | pass |
| 205 | |
Gilles Peskine | f646dbf | 2024-09-16 19:15:29 +0200 | [diff] [blame] | 206 | def section_name(self) -> str: |
| 207 | """The section name to use in results.""" |
| 208 | |
Gilles Peskine | 19ef1ae | 2024-09-16 19:12:09 +0200 | [diff] [blame] | 209 | def run(self, results: Results, outcomes: Outcomes): |
| 210 | """Run the analysis on the specified outcomes. |
| 211 | |
| 212 | Signal errors via the results objects |
| 213 | """ |
| 214 | raise NotImplementedError |
| 215 | |
| 216 | |
Gilles Peskine | f646dbf | 2024-09-16 19:15:29 +0200 | [diff] [blame] | 217 | class CoverageTask(Task): |
| 218 | """Analyze test coverage.""" |
| 219 | |
| 220 | ALLOW_LIST = [ |
| 221 | # Algorithm not supported yet |
| 222 | 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA', |
| 223 | # Algorithm not supported yet |
| 224 | 'test_suite_psa_crypto_metadata;Cipher: XTS', |
| 225 | ] |
| 226 | |
| 227 | def __init__(self, options) -> None: |
| 228 | super().__init__(options) |
| 229 | self.full_coverage = options.full_coverage #type: bool |
| 230 | |
| 231 | @staticmethod |
| 232 | def section_name() -> str: |
| 233 | return "Analyze coverage" |
| 234 | |
| 235 | def run(self, results: Results, outcomes: Outcomes): |
| 236 | """Check that all test cases are executed at least once.""" |
| 237 | analyze_coverage(results, outcomes, |
| 238 | self.ALLOW_LIST, self.full_coverage) |
| 239 | |
| 240 | |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 241 | class DriverVSReference(Task): |
| 242 | """Compare outcomes from testing with and without a driver. |
| 243 | |
| 244 | There are 2 options to use analyze_driver_vs_reference_xxx locally: |
| 245 | 1. Run tests and then analysis: |
| 246 | - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver> |
| 247 | - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
| 248 | 2. Let this script run both automatically: |
| 249 | - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
| 250 | """ |
| 251 | |
| 252 | # Override the following in child classes. |
| 253 | # Configuration name (all.sh component) used as the reference. |
| 254 | REFERENCE = '' |
| 255 | # Configuration name (all.sh component) used as the driver. |
| 256 | DRIVER = '' |
| 257 | # Ignored test suites (without the test_suite_ prefix). |
| 258 | IGNORED_SUITES = [] #type: typing.List[str] |
| 259 | # Map test suite names (with the test_suite_prefix) to a list of ignored |
| 260 | # test cases. Each element in the list can be either a string or a regex; |
| 261 | # see the `name_matches_pattern` function. |
| 262 | IGNORED_TESTS = {} #type: typing.Dict[str, typing.List[IgnoreEntry]] |
| 263 | |
| 264 | def section_name(self) -> str: |
| 265 | return f"Analyze driver {self.DRIVER} vs reference {self.REFERENCE}" |
| 266 | |
| 267 | def run(self, results: Results, outcomes: Outcomes) -> None: |
| 268 | """Compare driver test outcomes with reference outcomes.""" |
| 269 | ignored_suites = ['test_suite_' + x for x in self.IGNORED_SUITES] |
| 270 | analyze_driver_vs_reference(results, outcomes, |
| 271 | self.REFERENCE, self.DRIVER, |
| 272 | ignored_suites, self.IGNORED_TESTS) |
| 273 | |
| 274 | |
| 275 | def driver_vs_reference_factory(name: str, |
| 276 | args: typing.Dict[str, typing.Any] |
| 277 | ) -> typing.Type[DriverVSReference]: |
| 278 | """Build a driver-vs-reference class from dynamic data.""" |
| 279 | return type('Drivervsreference_' + name, |
| 280 | (DriverVSReference,), |
| 281 | { |
| 282 | 'REFERENCE': args['component_ref'], |
| 283 | 'DRIVER': args['component_driver'], |
| 284 | 'IGNORED_SUITES': args['ignored_suites'], |
| 285 | 'IGNORED_TESTS': args['ignored_tests'], |
| 286 | }) |
| 287 | |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 288 | # List of tasks with a function that can handle this task and additional arguments if required |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 289 | KNOWN_TASKS = { |
Gilles Peskine | f646dbf | 2024-09-16 19:15:29 +0200 | [diff] [blame] | 290 | 'analyze_coverage': CoverageTask, |
| 291 | |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 292 | 'analyze_driver_vs_reference_hash': driver_vs_reference_factory('hash', { |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 293 | 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa', |
| 294 | 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa', |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 295 | 'ignored_suites': [ |
| 296 | 'shax', 'mdx', # the software implementations that are being excluded |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 297 | 'md.psa', # purposefully depends on whether drivers are present |
Gilles Peskine | 35b49c4 | 2023-10-04 12:28:41 +0200 | [diff] [blame] | 298 | 'psa_crypto_low_hash.generated', # testing the builtins |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 299 | ], |
| 300 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 301 | 'test_suite_config': [ |
| 302 | re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'), |
| 303 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 304 | 'test_suite_platform': [ |
| 305 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 306 | # component uses a sanitizer but the reference component |
| 307 | # doesn't, we have a PASS vs SKIP mismatch. |
| 308 | 'Check mbedtls_calloc overallocation', |
| 309 | ], |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 310 | } |
| 311 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 312 | ), |
| 313 | 'analyze_driver_vs_reference_hmac': driver_vs_reference_factory('hmac', { |
Valerio Setti | 20cea94 | 2024-01-22 16:23:25 +0100 | [diff] [blame] | 314 | 'component_ref': 'test_psa_crypto_config_reference_hmac', |
| 315 | 'component_driver': 'test_psa_crypto_config_accel_hmac', |
| 316 | 'ignored_suites': [ |
Valerio Setti | cd89b0b | 2024-01-24 14:24:55 +0100 | [diff] [blame] | 317 | # These suites require legacy hash support, which is disabled |
Valerio Setti | 89d8a12 | 2024-01-26 15:04:05 +0100 | [diff] [blame] | 318 | # in the accelerated component. |
Valerio Setti | cd89b0b | 2024-01-24 14:24:55 +0100 | [diff] [blame] | 319 | 'shax', 'mdx', |
Valerio Setti | 20cea94 | 2024-01-22 16:23:25 +0100 | [diff] [blame] | 320 | # This suite tests builtins directly, but these are missing |
| 321 | # in the accelerated case. |
| 322 | 'psa_crypto_low_hash.generated', |
| 323 | ], |
| 324 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 325 | 'test_suite_config': [ |
| 326 | re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'), |
| 327 | re.compile(r'.*\bMBEDTLS_MD_C\b') |
| 328 | ], |
Valerio Setti | 20cea94 | 2024-01-22 16:23:25 +0100 | [diff] [blame] | 329 | 'test_suite_md': [ |
| 330 | # Builtin HMAC is not supported in the accelerate component. |
| 331 | re.compile('.*HMAC.*'), |
| 332 | # Following tests make use of functions which are not available |
| 333 | # when MD_C is disabled, as it happens in the accelerated |
| 334 | # test component. |
| 335 | re.compile('generic .* Hash file .*'), |
| 336 | 'MD list', |
| 337 | ], |
| 338 | 'test_suite_md.psa': [ |
| 339 | # "legacy only" tests require hash algorithms to be NOT |
| 340 | # accelerated, but this of course false for the accelerated |
| 341 | # test component. |
| 342 | re.compile('PSA dispatch .* legacy only'), |
| 343 | ], |
| 344 | 'test_suite_platform': [ |
| 345 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 346 | # component uses a sanitizer but the reference component |
| 347 | # doesn't, we have a PASS vs SKIP mismatch. |
| 348 | 'Check mbedtls_calloc overallocation', |
| 349 | ], |
| 350 | } |
| 351 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 352 | ), |
| 353 | 'analyze_driver_vs_reference_cipher_aead_cmac': driver_vs_reference_factory('cipher_aead_cmac', { |
Manuel Pégourié-Gonnard | 7f48d5e | 2024-01-08 10:55:09 +0100 | [diff] [blame] | 354 | 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac', |
| 355 | 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac', |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 356 | # Modules replaced by drivers. |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 357 | 'ignored_suites': [ |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 358 | # low-level (block/stream) cipher modules |
| 359 | 'aes', 'aria', 'camellia', 'des', 'chacha20', |
Manuel Pégourié-Gonnard | 7f48d5e | 2024-01-08 10:55:09 +0100 | [diff] [blame] | 360 | # AEAD modes and CMAC |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 361 | 'ccm', 'chachapoly', 'cmac', 'gcm', |
| 362 | # The Cipher abstraction layer |
| 363 | 'cipher', |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 364 | ], |
| 365 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 366 | 'test_suite_config': [ |
| 367 | re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'), |
| 368 | re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'), |
| 369 | re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'), |
| 370 | re.compile(r'.*\bMBEDTLS_CIPHER_.*'), |
| 371 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 372 | # PEM decryption is not supported so far. |
| 373 | # The rest of PEM (write, unencrypted read) works though. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 374 | 'test_suite_pem': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 375 | re.compile(r'PEM read .*(AES|DES|\bencrypt).*'), |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 376 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 377 | 'test_suite_platform': [ |
| 378 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 379 | # component uses a sanitizer but the reference component |
| 380 | # doesn't, we have a PASS vs SKIP mismatch. |
| 381 | 'Check mbedtls_calloc overallocation', |
| 382 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 383 | # Following tests depend on AES_C/DES_C but are not about |
| 384 | # them really, just need to know some error code is there. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 385 | 'test_suite_error': [ |
| 386 | 'Low and high error', |
| 387 | 'Single low error' |
| 388 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 389 | # Similar to test_suite_error above. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 390 | 'test_suite_version': [ |
| 391 | 'Check for MBEDTLS_AES_C when already present', |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 392 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 393 | # The en/decryption part of PKCS#12 is not supported so far. |
| 394 | # The rest of PKCS#12 (key derivation) works though. |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 395 | 'test_suite_pkcs12': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 396 | re.compile(r'PBE Encrypt, .*'), |
| 397 | re.compile(r'PBE Decrypt, .*'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 398 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 399 | # The en/decryption part of PKCS#5 is not supported so far. |
| 400 | # The rest of PKCS#5 (PBKDF2) works though. |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 401 | 'test_suite_pkcs5': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 402 | re.compile(r'PBES2 Encrypt, .*'), |
| 403 | re.compile(r'PBES2 Decrypt .*'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 404 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 405 | # Encrypted keys are not supported so far. |
Valerio Setti | 5cd18f9 | 2023-10-13 15:14:07 +0200 | [diff] [blame] | 406 | # pylint: disable=line-too-long |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 407 | 'test_suite_pkparse': [ |
| 408 | 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)', |
| 409 | 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)', |
Pengyu Lv | a1ddcfa | 2023-11-28 09:46:01 +0800 | [diff] [blame] | 410 | re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 411 | ], |
Sam Berry | 4beeb0c | 2024-06-27 14:18:22 +0100 | [diff] [blame] | 412 | # Encrypted keys are not supported so far. |
| 413 | 'ssl-opt': [ |
| 414 | 'TLS: password protected server key', |
| 415 | 'TLS: password protected client key', |
| 416 | 'TLS: password protected server key, two certificates', |
| 417 | ], |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 418 | } |
| 419 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 420 | ), |
| 421 | 'analyze_driver_vs_reference_ecp_light_only': driver_vs_reference_factory('ecp_light_only', { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 422 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', |
| 423 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 424 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 425 | # Modules replaced by drivers |
| 426 | 'ecdsa', 'ecdh', 'ecjpake', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 427 | ], |
| 428 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 429 | 'test_suite_config': [ |
| 430 | re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), |
| 431 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 432 | 'test_suite_platform': [ |
| 433 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 434 | # component uses a sanitizer but the reference component |
| 435 | # doesn't, we have a PASS vs SKIP mismatch. |
| 436 | 'Check mbedtls_calloc overallocation', |
| 437 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 438 | # This test wants a legacy function that takes f_rng, p_rng |
| 439 | # arguments, and uses legacy ECDSA for that. The test is |
| 440 | # really about the wrapper around the PSA RNG, not ECDSA. |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 441 | 'test_suite_random': [ |
| 442 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 443 | ], |
Valerio Setti | 0c477d3 | 2023-04-07 15:54:20 +0200 | [diff] [blame] | 444 | # In the accelerated test ECP_C is not set (only ECP_LIGHT is) |
| 445 | # so we must ignore disparities in the tests for which ECP_C |
| 446 | # is required. |
| 447 | 'test_suite_ecp': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 448 | re.compile(r'ECP check public-private .*'), |
Gilles Peskine | 3b17ae7 | 2023-06-23 11:08:39 +0200 | [diff] [blame] | 449 | re.compile(r'ECP calculate public: .*'), |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 450 | re.compile(r'ECP gen keypair .*'), |
| 451 | re.compile(r'ECP point muladd .*'), |
| 452 | re.compile(r'ECP point multiplication .*'), |
| 453 | re.compile(r'ECP test vectors .*'), |
Valerio Setti | 482a0b9 | 2023-08-18 15:55:10 +0200 | [diff] [blame] | 454 | ], |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 455 | 'test_suite_ssl': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 456 | # This deprecated function is only present when ECP_C is On. |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 457 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 458 | ], |
Valerio Setti | 5f54020 | 2023-06-30 17:20:49 +0200 | [diff] [blame] | 459 | } |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 460 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 461 | ), |
| 462 | 'analyze_driver_vs_reference_no_ecp_at_all': driver_vs_reference_factory('no_ecp_at_all', { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 463 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all', |
| 464 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all', |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 465 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 466 | # Modules replaced by drivers |
| 467 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 468 | ], |
| 469 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 470 | 'test_suite_config': [ |
| 471 | re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), |
| 472 | re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'), |
| 473 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 474 | 'test_suite_platform': [ |
| 475 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 476 | # component uses a sanitizer but the reference component |
| 477 | # doesn't, we have a PASS vs SKIP mismatch. |
| 478 | 'Check mbedtls_calloc overallocation', |
| 479 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 480 | # See ecp_light_only |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 481 | 'test_suite_random': [ |
| 482 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 483 | ], |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 484 | 'test_suite_pkparse': [ |
Valerio Setti | 5bd2523 | 2023-06-19 19:32:14 +0200 | [diff] [blame] | 485 | # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED |
| 486 | # is automatically enabled in build_info.h (backward compatibility) |
| 487 | # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a |
| 488 | # consequence compressed points are supported in the reference |
| 489 | # component but not in the accelerated one, so they should be skipped |
| 490 | # while checking driver's coverage. |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 491 | re.compile(r'Parse EC Key .*compressed\)'), |
| 492 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 493 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 494 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 495 | 'test_suite_ssl': [ |
| 496 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 497 | ], |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 498 | } |
| 499 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 500 | ), |
| 501 | 'analyze_driver_vs_reference_ecc_no_bignum': driver_vs_reference_factory('ecc_no_bignum', { |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 502 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum', |
| 503 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum', |
| 504 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 505 | # Modules replaced by drivers |
| 506 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
| 507 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 508 | 'bignum.generated', 'bignum.misc', |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 509 | ], |
| 510 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 511 | 'test_suite_config': [ |
| 512 | re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'), |
| 513 | re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), |
| 514 | re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'), |
| 515 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 516 | 'test_suite_platform': [ |
| 517 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 518 | # component uses a sanitizer but the reference component |
| 519 | # doesn't, we have a PASS vs SKIP mismatch. |
| 520 | 'Check mbedtls_calloc overallocation', |
| 521 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 522 | # See ecp_light_only |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 523 | 'test_suite_random': [ |
| 524 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 525 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 526 | # See no_ecp_at_all |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 527 | 'test_suite_pkparse': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 528 | re.compile(r'Parse EC Key .*compressed\)'), |
| 529 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 530 | ], |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 531 | 'test_suite_asn1parse': [ |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 532 | 'INTEGER too large for mpi', |
| 533 | ], |
| 534 | 'test_suite_asn1write': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 535 | re.compile(r'ASN.1 Write mpi.*'), |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 536 | ], |
Valerio Setti | e0be95e | 2023-08-01 09:07:43 +0200 | [diff] [blame] | 537 | 'test_suite_debug': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 538 | re.compile(r'Debug print mbedtls_mpi.*'), |
Valerio Setti | e0be95e | 2023-08-01 09:07:43 +0200 | [diff] [blame] | 539 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 540 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 541 | 'test_suite_ssl': [ |
| 542 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 543 | ], |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 544 | } |
| 545 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 546 | ), |
| 547 | 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': driver_vs_reference_factory('ecc_ffdh_no_bignum', { |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 548 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum', |
| 549 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum', |
| 550 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 551 | # Modules replaced by drivers |
| 552 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm', |
| 553 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 554 | 'bignum.generated', 'bignum.misc', |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 555 | ], |
| 556 | 'ignored_tests': { |
Gilles Peskine | ff3b821 | 2024-04-30 14:25:30 +0200 | [diff] [blame] | 557 | 'ssl-opt': [ |
| 558 | # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C |
| 559 | # (because it needs custom groups, which PSA does not |
| 560 | # provide), even with MBEDTLS_USE_PSA_CRYPTO. |
| 561 | re.compile(r'PSK callback:.*\bdhe-psk\b.*'), |
| 562 | ], |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 563 | 'test_suite_config': [ |
| 564 | re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'), |
| 565 | re.compile(r'.*\bMBEDTLS_DHM_C\b.*'), |
| 566 | re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), |
| 567 | re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'), |
| 568 | re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'), |
| 569 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 570 | 'test_suite_platform': [ |
| 571 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 572 | # component uses a sanitizer but the reference component |
| 573 | # doesn't, we have a PASS vs SKIP mismatch. |
| 574 | 'Check mbedtls_calloc overallocation', |
| 575 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 576 | # See ecp_light_only |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 577 | 'test_suite_random': [ |
| 578 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 579 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 580 | # See no_ecp_at_all |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 581 | 'test_suite_pkparse': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 582 | re.compile(r'Parse EC Key .*compressed\)'), |
| 583 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 584 | ], |
| 585 | 'test_suite_asn1parse': [ |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 586 | 'INTEGER too large for mpi', |
| 587 | ], |
| 588 | 'test_suite_asn1write': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 589 | re.compile(r'ASN.1 Write mpi.*'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 590 | ], |
| 591 | 'test_suite_debug': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 592 | re.compile(r'Debug print mbedtls_mpi.*'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 593 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 594 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 595 | 'test_suite_ssl': [ |
| 596 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 597 | ], |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 598 | } |
| 599 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 600 | ), |
| 601 | 'analyze_driver_vs_reference_ffdh_alg': driver_vs_reference_factory('ffdh_alg', { |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 602 | 'component_ref': 'test_psa_crypto_config_reference_ffdh', |
| 603 | 'component_driver': 'test_psa_crypto_config_accel_ffdh', |
Przemek Stekiel | 84f4ff1 | 2023-07-04 12:35:31 +0200 | [diff] [blame] | 604 | 'ignored_suites': ['dhm'], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 605 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 606 | 'test_suite_config': [ |
| 607 | re.compile(r'.*\bMBEDTLS_DHM_C\b.*'), |
| 608 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 609 | 'test_suite_platform': [ |
| 610 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 611 | # component uses a sanitizer but the reference component |
| 612 | # doesn't, we have a PASS vs SKIP mismatch. |
| 613 | 'Check mbedtls_calloc overallocation', |
| 614 | ], |
| 615 | } |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 616 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 617 | ), |
| 618 | 'analyze_driver_vs_reference_tfm_config': driver_vs_reference_factory('tfm_config', { |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 619 | 'component_ref': 'test_tfm_config_no_p256m', |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 620 | 'component_driver': 'test_tfm_config_p256m_driver_accel_ec', |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 621 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 622 | # Modules replaced by drivers |
Yanray Wang | 5779096 | 2023-10-31 13:39:07 +0800 | [diff] [blame] | 623 | 'asn1parse', 'asn1write', |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 624 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
| 625 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 626 | 'bignum.generated', 'bignum.misc', |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 627 | ], |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 628 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 629 | 'test_suite_config': [ |
| 630 | re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'), |
| 631 | re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'), |
| 632 | re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'), |
| 633 | re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*') |
| 634 | ], |
| 635 | 'test_suite_config.crypto_combinations': [ |
| 636 | 'Config: ECC: Weierstrass curves only', |
| 637 | ], |
Gilles Peskine | 150002c | 2023-11-27 18:24:45 +0100 | [diff] [blame] | 638 | 'test_suite_platform': [ |
| 639 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 640 | # component uses a sanitizer but the reference component |
| 641 | # doesn't, we have a PASS vs SKIP mismatch. |
| 642 | 'Check mbedtls_calloc overallocation', |
| 643 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 644 | # See ecp_light_only |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 645 | 'test_suite_random': [ |
| 646 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 647 | ], |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 648 | } |
| 649 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 650 | ), |
| 651 | 'analyze_driver_vs_reference_rsa': driver_vs_reference_factory('rsa', { |
Pengyu Lv | 3cd16c4 | 2023-12-06 18:17:39 +0800 | [diff] [blame] | 652 | 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto', |
| 653 | 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto', |
| 654 | 'ignored_suites': [ |
| 655 | # Modules replaced by drivers. |
| 656 | 'rsa', 'pkcs1_v15', 'pkcs1_v21', |
Pengyu Lv | 98a90c6 | 2023-12-07 17:23:25 +0800 | [diff] [blame] | 657 | # We temporarily don't care about PK stuff. |
Pengyu Lv | 3cd16c4 | 2023-12-06 18:17:39 +0800 | [diff] [blame] | 658 | 'pk', 'pkwrite', 'pkparse' |
| 659 | ], |
| 660 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 661 | 'test_suite_config': [ |
| 662 | re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'), |
| 663 | re.compile(r'.*\bMBEDTLS_GENPRIME\b.*') |
| 664 | ], |
Pengyu Lv | 3cd16c4 | 2023-12-06 18:17:39 +0800 | [diff] [blame] | 665 | 'test_suite_platform': [ |
| 666 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 667 | # component uses a sanitizer but the reference component |
| 668 | # doesn't, we have a PASS vs SKIP mismatch. |
| 669 | 'Check mbedtls_calloc overallocation', |
| 670 | ], |
| 671 | # Following tests depend on RSA_C but are not about |
| 672 | # them really, just need to know some error code is there. |
| 673 | 'test_suite_error': [ |
| 674 | 'Low and high error', |
| 675 | 'Single high error' |
| 676 | ], |
| 677 | # Constant time operations only used for PKCS1_V15 |
| 678 | 'test_suite_constant_time': [ |
| 679 | re.compile(r'mbedtls_ct_zeroize_if .*'), |
| 680 | re.compile(r'mbedtls_ct_memmove_left .*') |
| 681 | ], |
Gilles Peskine | 63072b1 | 2024-02-15 11:48:58 +0100 | [diff] [blame] | 682 | 'test_suite_psa_crypto': [ |
Gilles Peskine | 1084e8e | 2024-06-07 11:26:53 +0200 | [diff] [blame] | 683 | # We don't support generate_key_custom entry points |
Gilles Peskine | 63072b1 | 2024-02-15 11:48:58 +0100 | [diff] [blame] | 684 | # in drivers yet. |
Gilles Peskine | 1084e8e | 2024-06-07 11:26:53 +0200 | [diff] [blame] | 685 | re.compile(r'PSA generate key custom: RSA, e=.*'), |
Gilles Peskine | 63072b1 | 2024-02-15 11:48:58 +0100 | [diff] [blame] | 686 | re.compile(r'PSA generate key ext: RSA, e=.*'), |
| 687 | ], |
Pengyu Lv | 3cd16c4 | 2023-12-06 18:17:39 +0800 | [diff] [blame] | 688 | } |
| 689 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 690 | ), |
| 691 | 'analyze_block_cipher_dispatch': driver_vs_reference_factory('block_cipher_dispatch', { |
Valerio Setti | 4a8ef7c | 2023-12-19 11:16:27 +0100 | [diff] [blame] | 692 | 'component_ref': 'test_full_block_cipher_legacy_dispatch', |
Valerio Setti | 52ab8fa | 2023-12-14 18:04:04 +0100 | [diff] [blame] | 693 | 'component_driver': 'test_full_block_cipher_psa_dispatch', |
| 694 | 'ignored_suites': [ |
Valerio Setti | 4a8ef7c | 2023-12-19 11:16:27 +0100 | [diff] [blame] | 695 | # Skipped in the accelerated component |
| 696 | 'aes', 'aria', 'camellia', |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 697 | # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in |
| 698 | # order for the cipher module (actually cipher_wrapper) to work |
| 699 | # properly. However these symbols are disabled in the accelerated |
| 700 | # component so we ignore them. |
Valerio Setti | a0c9c66 | 2023-12-29 14:14:11 +0100 | [diff] [blame] | 701 | 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria', |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 702 | 'cipher.camellia', |
Valerio Setti | 52ab8fa | 2023-12-14 18:04:04 +0100 | [diff] [blame] | 703 | ], |
| 704 | 'ignored_tests': { |
Gilles Peskine | a7469d3 | 2024-05-24 09:18:25 +0200 | [diff] [blame] | 705 | 'test_suite_config': [ |
| 706 | re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'), |
| 707 | re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'), |
| 708 | ], |
Valerio Setti | a0c9c66 | 2023-12-29 14:14:11 +0100 | [diff] [blame] | 709 | 'test_suite_cmac': [ |
| 710 | # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled, |
| 711 | # but these are not available in the accelerated component. |
| 712 | 'CMAC null arguments', |
| 713 | re.compile('CMAC.* (AES|ARIA|Camellia).*'), |
| 714 | ], |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 715 | 'test_suite_cipher.padding': [ |
| 716 | # Following tests require AES_C/CAMELLIA_C to be enabled, |
| 717 | # but these are not available in the accelerated component. |
| 718 | re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'), |
Valerio Setti | 5f665c3 | 2023-12-20 09:56:05 +0100 | [diff] [blame] | 719 | ], |
Ryan Everett | afb2eee | 2024-02-08 14:31:54 +0000 | [diff] [blame] | 720 | 'test_suite_pkcs5': [ |
Ryan Everett | 67f3568 | 2024-02-09 13:02:23 +0000 | [diff] [blame] | 721 | # The AES part of PKCS#5 PBES2 is not yet supported. |
Ryan Everett | afb2eee | 2024-02-08 14:31:54 +0000 | [diff] [blame] | 722 | # The rest of PKCS#5 (PBKDF2) works, though. |
Ryan Everett | 67f3568 | 2024-02-09 13:02:23 +0000 | [diff] [blame] | 723 | re.compile(r'PBES2 .* AES-.*') |
Ryan Everett | afb2eee | 2024-02-08 14:31:54 +0000 | [diff] [blame] | 724 | ], |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 725 | 'test_suite_pkparse': [ |
| 726 | # PEM (called by pkparse) requires AES_C in order to decrypt |
| 727 | # the key, but this is not available in the accelerated |
| 728 | # component. |
| 729 | re.compile('Parse RSA Key.*(password|AES-).*'), |
Valerio Setti | 5f665c3 | 2023-12-20 09:56:05 +0100 | [diff] [blame] | 730 | ], |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 731 | 'test_suite_pem': [ |
| 732 | # Following tests require AES_C, but this is diabled in the |
| 733 | # accelerated component. |
Valerio Setti | eba4ca1 | 2024-02-19 07:42:18 +0100 | [diff] [blame] | 734 | re.compile('PEM read .*AES.*'), |
Valerio Setti | 0635cca | 2023-12-28 16:16:02 +0100 | [diff] [blame] | 735 | 'PEM read (unknown encryption algorithm)', |
Valerio Setti | 5f665c3 | 2023-12-20 09:56:05 +0100 | [diff] [blame] | 736 | ], |
| 737 | 'test_suite_error': [ |
Valerio Setti | ab0494f | 2023-12-28 13:56:13 +0100 | [diff] [blame] | 738 | # Following tests depend on AES_C but are not about them |
| 739 | # really, just need to know some error code is there. |
Valerio Setti | 5f665c3 | 2023-12-20 09:56:05 +0100 | [diff] [blame] | 740 | 'Single low error', |
| 741 | 'Low and high error', |
| 742 | ], |
| 743 | 'test_suite_version': [ |
Valerio Setti | ab0494f | 2023-12-28 13:56:13 +0100 | [diff] [blame] | 744 | # Similar to test_suite_error above. |
Valerio Setti | 5f665c3 | 2023-12-20 09:56:05 +0100 | [diff] [blame] | 745 | 'Check for MBEDTLS_AES_C when already present', |
| 746 | ], |
Valerio Setti | 52ab8fa | 2023-12-14 18:04:04 +0100 | [diff] [blame] | 747 | 'test_suite_platform': [ |
| 748 | # Incompatible with sanitizers (e.g. ASan). If the driver |
| 749 | # component uses a sanitizer but the reference component |
| 750 | # doesn't, we have a PASS vs SKIP mismatch. |
| 751 | 'Check mbedtls_calloc overallocation', |
| 752 | ], |
| 753 | } |
| 754 | } |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 755 | ), |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 756 | } |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 757 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 758 | def main(): |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 759 | main_results = Results() |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 760 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 761 | try: |
| 762 | parser = argparse.ArgumentParser(description=__doc__) |
Przemek Stekiel | 58bbc23 | 2022-10-24 08:10:10 +0200 | [diff] [blame] | 763 | parser.add_argument('outcomes', metavar='OUTCOMES.CSV', |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 764 | help='Outcome file to analyze') |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 765 | parser.add_argument('specified_tasks', default='all', nargs='?', |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 766 | help='Analysis to be done. By default, run all tasks. ' |
| 767 | 'With one or more TASK, run only those. ' |
| 768 | 'TASK can be the name of a single task or ' |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 769 | 'comma/space-separated list of tasks. ') |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 770 | parser.add_argument('--list', action='store_true', |
| 771 | help='List all available tasks and exit.') |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 772 | parser.add_argument('--require-full-coverage', action='store_true', |
| 773 | dest='full_coverage', help="Require all available " |
| 774 | "test cases to be executed and issue an error " |
| 775 | "otherwise. This flag is ignored if 'task' is " |
| 776 | "neither 'all' nor 'analyze_coverage'") |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 777 | options = parser.parse_args() |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 778 | |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 779 | if options.list: |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 780 | for task in KNOWN_TASKS: |
Valerio Setti | 5329ff0 | 2023-10-17 09:44:36 +0200 | [diff] [blame] | 781 | print(task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 782 | sys.exit(0) |
| 783 | |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 784 | if options.specified_tasks == 'all': |
| 785 | tasks_list = KNOWN_TASKS.keys() |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 786 | else: |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 787 | tasks_list = re.split(r'[, ]+', options.specified_tasks) |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 788 | for task in tasks_list: |
| 789 | if task not in KNOWN_TASKS: |
Manuel Pégourié-Gonnard | 62d6131 | 2023-10-20 10:51:57 +0200 | [diff] [blame] | 790 | sys.stderr.write('invalid task: {}\n'.format(task)) |
Valerio Setti | fb2750e | 2023-10-17 10:11:45 +0200 | [diff] [blame] | 791 | sys.exit(2) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 792 | |
Pengyu Lv | dd1d6a7 | 2023-11-27 17:57:31 +0800 | [diff] [blame] | 793 | # If the outcome file exists, parse it once and share the result |
| 794 | # among tasks to improve performance. |
Pengyu Lv | 20e3ca3 | 2023-11-28 15:30:03 +0800 | [diff] [blame] | 795 | # Otherwise, it will be generated by execute_reference_driver_tests. |
| 796 | if not os.path.exists(options.outcomes): |
| 797 | if len(tasks_list) > 1: |
| 798 | sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n") |
| 799 | sys.exit(2) |
| 800 | |
| 801 | task_name = tasks_list[0] |
| 802 | task = KNOWN_TASKS[task_name] |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 803 | if not issubclass(task, DriverVSReference): |
Pengyu Lv | 20e3ca3 | 2023-11-28 15:30:03 +0800 | [diff] [blame] | 804 | sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name)) |
| 805 | sys.exit(2) |
Pengyu Lv | 20e3ca3 | 2023-11-28 15:30:03 +0800 | [diff] [blame] | 806 | execute_reference_driver_tests(main_results, |
Gilles Peskine | 82b1672 | 2024-09-16 19:57:10 +0200 | [diff] [blame^] | 807 | task.REFERENCE, |
| 808 | task.DRIVER, |
Pengyu Lv | 20e3ca3 | 2023-11-28 15:30:03 +0800 | [diff] [blame] | 809 | options.outcomes) |
| 810 | |
| 811 | outcomes = read_outcome_file(options.outcomes) |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 812 | |
Gilles Peskine | 19ef1ae | 2024-09-16 19:12:09 +0200 | [diff] [blame] | 813 | for task_name in tasks_list: |
| 814 | task_constructor = KNOWN_TASKS[task_name] |
| 815 | if isinstance(task_constructor, dict): |
| 816 | test_function = task_constructor['test_function'] |
| 817 | test_args = task_constructor['args'] |
| 818 | test_function(main_results, outcomes, test_args) |
| 819 | else: |
| 820 | task = task_constructor(options) |
Gilles Peskine | f646dbf | 2024-09-16 19:15:29 +0200 | [diff] [blame] | 821 | main_results.new_section(task.section_name()) |
Gilles Peskine | 19ef1ae | 2024-09-16 19:12:09 +0200 | [diff] [blame] | 822 | task.run(main_results, outcomes) |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 823 | |
Valerio Setti | f6f64cf | 2023-10-17 12:28:26 +0200 | [diff] [blame] | 824 | main_results.info("Overall results: {} warnings and {} errors", |
| 825 | main_results.warning_count, main_results.error_count) |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 826 | |
Valerio Setti | 8d178be | 2023-10-17 12:23:55 +0200 | [diff] [blame] | 827 | sys.exit(0 if (main_results.error_count == 0) else 1) |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 828 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 829 | except Exception: # pylint: disable=broad-except |
| 830 | # Print the backtrace and exit explicitly with our chosen status. |
| 831 | traceback.print_exc() |
| 832 | sys.exit(120) |
| 833 | |
| 834 | if __name__ == '__main__': |
| 835 | main() |