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 | |
Valerio Setti | 2cff820 | 2023-10-18 14:36:47 +0200 | [diff] [blame] | 25 | def new_section(self, fmt, *args, **kwargs): |
| 26 | self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs) |
| 27 | |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 28 | def info(self, fmt, *args, **kwargs): |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 29 | self._print_line('Info: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 30 | |
| 31 | def error(self, fmt, *args, **kwargs): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 32 | self.error_count += 1 |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 33 | self._print_line('Error: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 34 | |
| 35 | def warning(self, fmt, *args, **kwargs): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 36 | self.warning_count += 1 |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 37 | self._print_line('Warning: ' + fmt, *args, **kwargs) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 38 | |
Valerio Setti | 3f33989 | 2023-10-17 10:42:11 +0200 | [diff] [blame] | 39 | @staticmethod |
Valerio Setti | 8070dbe | 2023-10-17 12:29:30 +0200 | [diff] [blame] | 40 | def _print_line(fmt, *args, **kwargs): |
Valerio Setti | 735794c | 2023-10-18 08:05:15 +0200 | [diff] [blame] | 41 | sys.stderr.write((fmt + '\n').format(*args, **kwargs)) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 42 | |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 43 | def execute_reference_driver_tests(results: Results, ref_component, driver_component, \ |
Valerio Setti | 781c234 | 2023-10-17 12:47:35 +0200 | [diff] [blame] | 44 | outcome_file): |
Valerio Setti | 22992a0 | 2023-03-29 11:15:28 +0200 | [diff] [blame] | 45 | """Run the tests specified in ref_component and driver_component. Results |
| 46 | 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] | 47 | coverage analysis""" |
| 48 | # If the outcome file already exists, we assume that the user wants to |
| 49 | # perform the comparison analysis again without repeating the tests. |
| 50 | if os.path.exists(outcome_file): |
Valerio Setti | 39d4b9d | 2023-10-18 14:30:03 +0200 | [diff] [blame] | 51 | results.info("Outcome file ({}) already exists. Tests will be skipped.", outcome_file) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 52 | return |
| 53 | |
| 54 | shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \ |
| 55 | " " + ref_component + " " + driver_component |
Valerio Setti | 39d4b9d | 2023-10-18 14:30:03 +0200 | [diff] [blame] | 56 | results.info("Running: {}", shell_command) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 57 | ret_val = subprocess.run(shell_command.split(), check=False).returncode |
| 58 | |
| 59 | if ret_val != 0: |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 60 | results.error("failed to run reference/driver components") |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 61 | |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 62 | def analyze_coverage(results, outcomes, allow_list, full_coverage): |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 63 | """Check that all available test cases are executed at least once.""" |
Gilles Peskine | 686c292 | 2022-01-07 15:58:38 +0100 | [diff] [blame] | 64 | available = check_test_cases.collect_available_test_cases() |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 65 | for suite_case in available: |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 66 | hits = 0 |
| 67 | for _comp, comp_outcomes in outcomes.items(): |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 68 | if suite_case in comp_outcomes["successes"] or \ |
| 69 | suite_case in comp_outcomes["failures"]: |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 70 | hits += 1 |
| 71 | |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 72 | if hits == 0 and suite_case not in allow_list: |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 73 | if full_coverage: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 74 | results.error('Test case not executed: {}', suite_case) |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 75 | else: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 76 | results.warning('Test case not executed: {}', suite_case) |
| 77 | elif hits != 0 and suite_case in allow_list: |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 78 | # Test Case should be removed from the allow list. |
Tomás González | 7ebb18f | 2023-08-22 09:40:23 +0100 | [diff] [blame] | 79 | if full_coverage: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 80 | results.error('Allow listed test case was executed: {}', suite_case) |
Tomás González | 7ebb18f | 2023-08-22 09:40:23 +0100 | [diff] [blame] | 81 | else: |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 82 | results.warning('Allow listed test case was executed: {}', suite_case) |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 83 | |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 84 | def name_matches_pattern(name, str_or_re): |
| 85 | """Check if name matches a pattern, that may be a string or regex. |
| 86 | - If the pattern is a string, name must be equal to match. |
| 87 | - If the pattern is a regex, name must fully match. |
| 88 | """ |
Manuel Pégourié-Gonnard | b269543 | 2023-10-23 09:30:40 +0200 | [diff] [blame] | 89 | # The CI's python is too old for re.Pattern |
| 90 | #if isinstance(str_or_re, re.Pattern): |
| 91 | if not isinstance(str_or_re, str): |
Manuel Pégourié-Gonnard | 9d9c234 | 2023-10-26 09:37:40 +0200 | [diff] [blame] | 92 | return str_or_re.fullmatch(name) |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 93 | else: |
Manuel Pégourié-Gonnard | 9d9c234 | 2023-10-26 09:37:40 +0200 | [diff] [blame] | 94 | return str_or_re == name |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 95 | |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 96 | def analyze_driver_vs_reference(results: Results, outcomes, |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 97 | component_ref, component_driver, |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 98 | ignored_suites, ignored_tests=None): |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 99 | """Check that all tests passed in the reference component are also |
| 100 | passed in the corresponding driver component. |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 101 | Skip: |
| 102 | - full test suites provided in ignored_suites list |
| 103 | - only some specific test inside a test suite, for which the corresponding |
| 104 | output string is provided |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 105 | """ |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 106 | ref_outcomes = outcomes.get("component_" + component_ref) |
| 107 | driver_outcomes = outcomes.get("component_" + component_driver) |
| 108 | |
| 109 | if ref_outcomes is None or not ref_outcomes['successes']: |
| 110 | results.error("no passing test in reference component: bad outcome file?") |
| 111 | return |
| 112 | |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 113 | for suite_case in ref_outcomes["successes"]: |
| 114 | # suite_case is like "test_suite_foo.bar;Description of test case" |
| 115 | (full_test_suite, test_string) = suite_case.split(';') |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 116 | 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] | 117 | |
| 118 | # Immediately skip fully-ignored test suites |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 119 | 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] | 120 | continue |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 121 | |
| 122 | # For ignored test cases inside test suites, just remember and: |
| 123 | # don't issue an error if they're skipped with drivers, |
| 124 | # but issue an error if they're not (means we have a bad entry). |
| 125 | ignored = False |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 126 | if full_test_suite in ignored_tests: |
Manuel Pégourié-Gonnard | d36a37f | 2023-10-26 09:41:59 +0200 | [diff] [blame] | 127 | for str_or_re in ignored_tests[test_suite]: |
Manuel Pégourié-Gonnard | 881ce01 | 2023-10-18 10:22:07 +0200 | [diff] [blame] | 128 | if name_matches_pattern(test_string, str_or_re): |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 129 | ignored = True |
Manuel Pégourié-Gonnard | 4da369f | 2023-10-18 09:40:32 +0200 | [diff] [blame] | 130 | |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 131 | if not ignored and not suite_case in driver_outcomes['successes']: |
| 132 | results.error("PASS -> SKIP/FAIL: {}", suite_case) |
| 133 | if ignored and suite_case in driver_outcomes['successes']: |
| 134 | results.error("uselessly ignored: {}", suite_case) |
Manuel Pégourié-Gonnard | 371165a | 2023-10-18 12:44:54 +0200 | [diff] [blame] | 135 | |
Valerio Setti | 781c234 | 2023-10-17 12:47:35 +0200 | [diff] [blame] | 136 | def analyze_outcomes(results: Results, outcomes, args): |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 137 | """Run all analyses on the given outcome collection.""" |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 138 | analyze_coverage(results, outcomes, args['allow_list'], |
| 139 | args['full_coverage']) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 140 | |
| 141 | def read_outcome_file(outcome_file): |
| 142 | """Parse an outcome file and return an outcome collection. |
| 143 | |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 144 | An outcome collection is a dictionary presentation of the outcome file: |
| 145 | ``` |
| 146 | outcomes = { |
| 147 | "<config>": { |
| 148 | "successes": frozenset(["<suite_case>", ... ]), |
| 149 | "failures": frozenset(["<suite_case>", ...]) |
| 150 | } |
| 151 | ... |
| 152 | } |
| 153 | suite_case = "<suite>;<case>" |
| 154 | ``` |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 155 | """ |
| 156 | outcomes = {} |
| 157 | with open(outcome_file, 'r', encoding='utf-8') as input_file: |
| 158 | for line in input_file: |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 159 | (_platform, config, suite, case, result, _cause) = line.split(';') |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 160 | suite_case = ';'.join([suite, case]) |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 161 | if config not in outcomes: |
| 162 | outcomes[config] = {"successes":[], "failures":[]} |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 163 | if result == 'PASS': |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 164 | outcomes[config]['successes'].append(suite_case) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 165 | elif result == 'FAIL': |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 166 | outcomes[config]['failures'].append(suite_case) |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 167 | |
Pengyu Lv | 31a9b78 | 2023-11-23 14:15:37 +0800 | [diff] [blame^] | 168 | # Convert `list` to `frozenset` to improve search performance |
Pengyu Lv | a442858 | 2023-11-22 19:02:15 +0800 | [diff] [blame] | 169 | for config in outcomes: |
| 170 | outcomes[config]['successes'] = frozenset(outcomes[config]['successes']) |
| 171 | outcomes[config]['failures'] = frozenset(outcomes[config]['failures']) |
| 172 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 173 | return outcomes |
| 174 | |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 175 | def do_analyze_coverage(results: Results, outcomes_or_file, args): |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 176 | """Perform coverage analysis.""" |
Valerio Setti | 2cff820 | 2023-10-18 14:36:47 +0200 | [diff] [blame] | 177 | results.new_section("Analyze coverage") |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 178 | outcomes = read_outcome_file(outcomes_or_file) \ |
| 179 | if isinstance(outcomes_or_file, str) else outcomes_or_file |
Valerio Setti | 781c234 | 2023-10-17 12:47:35 +0200 | [diff] [blame] | 180 | analyze_outcomes(results, outcomes, args) |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 181 | |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 182 | def do_analyze_driver_vs_reference(results: Results, outcomes_or_file, args): |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 183 | """Perform driver vs reference analyze.""" |
Valerio Setti | 2cff820 | 2023-10-18 14:36:47 +0200 | [diff] [blame] | 184 | results.new_section("Analyze driver {} vs reference {}", |
| 185 | args['component_driver'], args['component_ref']) |
Valerio Setti | b0c618e | 2023-10-16 14:19:49 +0200 | [diff] [blame] | 186 | |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 187 | ignored_suites = ['test_suite_' + x for x in args['ignored_suites']] |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 188 | |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 189 | if isinstance(outcomes_or_file, str): |
| 190 | execute_reference_driver_tests(results, args['component_ref'], \ |
| 191 | args['component_driver'], outcomes_or_file) |
| 192 | outcomes = read_outcome_file(outcomes_or_file) |
| 193 | else: |
| 194 | outcomes = outcomes_or_file |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 195 | |
Valerio Setti | 781c234 | 2023-10-17 12:47:35 +0200 | [diff] [blame] | 196 | analyze_driver_vs_reference(results, outcomes, |
| 197 | args['component_ref'], args['component_driver'], |
| 198 | ignored_suites, args['ignored_tests']) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 199 | |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 200 | # 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] | 201 | KNOWN_TASKS = { |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 202 | 'analyze_coverage': { |
| 203 | 'test_function': do_analyze_coverage, |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 204 | 'args': { |
Tomás González | 358c6c6 | 2023-08-14 15:43:46 +0100 | [diff] [blame] | 205 | 'allow_list': [ |
Tomás González | 5022311 | 2023-08-22 09:52:06 +0100 | [diff] [blame] | 206 | # Algorithm not supported yet |
| 207 | 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA', |
| 208 | # Algorithm not supported yet |
| 209 | 'test_suite_psa_crypto_metadata;Cipher: XTS', |
Tomás González | d43cab3 | 2023-08-24 09:12:40 +0100 | [diff] [blame] | 210 | ], |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 211 | 'full_coverage': False, |
Tomás González | 07bdcc2 | 2023-08-11 14:59:03 +0100 | [diff] [blame] | 212 | } |
Tomás González | d43cab3 | 2023-08-24 09:12:40 +0100 | [diff] [blame] | 213 | }, |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 214 | # There are 2 options to use analyze_driver_vs_reference_xxx locally: |
| 215 | # 1. Run tests and then analysis: |
| 216 | # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver> |
| 217 | # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
| 218 | # 2. Let this script run both automatically: |
| 219 | # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 220 | 'analyze_driver_vs_reference_hash': { |
| 221 | 'test_function': do_analyze_driver_vs_reference, |
| 222 | 'args': { |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 223 | 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa', |
| 224 | 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa', |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 225 | 'ignored_suites': [ |
| 226 | 'shax', 'mdx', # the software implementations that are being excluded |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 227 | 'md.psa', # purposefully depends on whether drivers are present |
Gilles Peskine | 35b49c4 | 2023-10-04 12:28:41 +0200 | [diff] [blame] | 228 | 'psa_crypto_low_hash.generated', # testing the builtins |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 229 | ], |
| 230 | 'ignored_tests': { |
| 231 | } |
| 232 | } |
| 233 | }, |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 234 | 'analyze_driver_vs_reference_cipher_aead': { |
| 235 | 'test_function': do_analyze_driver_vs_reference, |
| 236 | 'args': { |
| 237 | 'component_ref': 'test_psa_crypto_config_reference_cipher_aead', |
| 238 | 'component_driver': 'test_psa_crypto_config_accel_cipher_aead', |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 239 | # Modules replaced by drivers. |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 240 | 'ignored_suites': [ |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 241 | # low-level (block/stream) cipher modules |
| 242 | 'aes', 'aria', 'camellia', 'des', 'chacha20', |
| 243 | # AEAD modes |
| 244 | 'ccm', 'chachapoly', 'cmac', 'gcm', |
| 245 | # The Cipher abstraction layer |
| 246 | 'cipher', |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 247 | ], |
| 248 | 'ignored_tests': { |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 249 | # PEM decryption is not supported so far. |
| 250 | # The rest of PEM (write, unencrypted read) works though. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 251 | 'test_suite_pem': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 252 | re.compile(r'PEM read .*(AES|DES|\bencrypt).*'), |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 253 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 254 | # Following tests depend on AES_C/DES_C but are not about |
| 255 | # them really, just need to know some error code is there. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 256 | 'test_suite_error': [ |
| 257 | 'Low and high error', |
| 258 | 'Single low error' |
| 259 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 260 | # Similar to test_suite_error above. |
Valerio Setti | 7448cee | 2023-10-04 15:46:42 +0200 | [diff] [blame] | 261 | 'test_suite_version': [ |
| 262 | 'Check for MBEDTLS_AES_C when already present', |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 263 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 264 | # The en/decryption part of PKCS#12 is not supported so far. |
| 265 | # The rest of PKCS#12 (key derivation) works though. |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 266 | 'test_suite_pkcs12': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 267 | re.compile(r'PBE Encrypt, .*'), |
| 268 | re.compile(r'PBE Decrypt, .*'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 269 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 270 | # The en/decryption part of PKCS#5 is not supported so far. |
| 271 | # The rest of PKCS#5 (PBKDF2) works though. |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 272 | 'test_suite_pkcs5': [ |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 273 | re.compile(r'PBES2 Encrypt, .*'), |
| 274 | re.compile(r'PBES2 Decrypt .*'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 275 | ], |
Valerio Setti | 507e08f | 2023-10-26 09:44:06 +0200 | [diff] [blame] | 276 | # Encrypted keys are not supported so far. |
Valerio Setti | 5cd18f9 | 2023-10-13 15:14:07 +0200 | [diff] [blame] | 277 | # pylint: disable=line-too-long |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 278 | 'test_suite_pkparse': [ |
| 279 | 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)', |
| 280 | 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)', |
Manuel Pégourié-Gonnard | cd84a29 | 2023-10-27 09:24:44 +0200 | [diff] [blame] | 281 | re.compile(r'Parse RSA Key .*\(PKCS#8 encrypted .*\)'), |
Valerio Setti | 9394144 | 2023-10-13 09:19:52 +0200 | [diff] [blame] | 282 | ], |
Valerio Setti | b6b301f | 2023-10-04 12:05:05 +0200 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 286 | 'analyze_driver_vs_reference_ecp_light_only': { |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 287 | 'test_function': do_analyze_driver_vs_reference, |
| 288 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 289 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', |
| 290 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 291 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 292 | # Modules replaced by drivers |
| 293 | 'ecdsa', 'ecdh', 'ecjpake', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 294 | ], |
| 295 | 'ignored_tests': { |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 296 | # This test wants a legacy function that takes f_rng, p_rng |
| 297 | # arguments, and uses legacy ECDSA for that. The test is |
| 298 | # really about the wrapper around the PSA RNG, not ECDSA. |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 299 | 'test_suite_random': [ |
| 300 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 301 | ], |
Valerio Setti | 0c477d3 | 2023-04-07 15:54:20 +0200 | [diff] [blame] | 302 | # In the accelerated test ECP_C is not set (only ECP_LIGHT is) |
| 303 | # so we must ignore disparities in the tests for which ECP_C |
| 304 | # is required. |
| 305 | 'test_suite_ecp': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 306 | re.compile(r'ECP check public-private .*'), |
| 307 | re.compile(r'ECP gen keypair .*'), |
| 308 | re.compile(r'ECP point muladd .*'), |
| 309 | re.compile(r'ECP point multiplication .*'), |
| 310 | re.compile(r'ECP test vectors .*'), |
Valerio Setti | 482a0b9 | 2023-08-18 15:55:10 +0200 | [diff] [blame] | 311 | ], |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 312 | 'test_suite_ssl': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 313 | # 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] | 314 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 315 | ], |
Valerio Setti | 5f54020 | 2023-06-30 17:20:49 +0200 | [diff] [blame] | 316 | } |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 317 | } |
| 318 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 319 | 'analyze_driver_vs_reference_no_ecp_at_all': { |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 320 | 'test_function': do_analyze_driver_vs_reference, |
| 321 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 322 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all', |
| 323 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all', |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 324 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 325 | # Modules replaced by drivers |
| 326 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 327 | ], |
| 328 | 'ignored_tests': { |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 329 | # See ecp_light_only |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 330 | 'test_suite_random': [ |
| 331 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 332 | ], |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 333 | 'test_suite_pkparse': [ |
Valerio Setti | 5bd2523 | 2023-06-19 19:32:14 +0200 | [diff] [blame] | 334 | # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED |
| 335 | # is automatically enabled in build_info.h (backward compatibility) |
| 336 | # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a |
| 337 | # consequence compressed points are supported in the reference |
| 338 | # component but not in the accelerated one, so they should be skipped |
| 339 | # while checking driver's coverage. |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 340 | re.compile(r'Parse EC Key .*compressed\)'), |
| 341 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 342 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 343 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 344 | 'test_suite_ssl': [ |
| 345 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 346 | ], |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | }, |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 350 | 'analyze_driver_vs_reference_ecc_no_bignum': { |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 351 | 'test_function': do_analyze_driver_vs_reference, |
| 352 | 'args': { |
| 353 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum', |
| 354 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum', |
| 355 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 356 | # Modules replaced by drivers |
| 357 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
| 358 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 359 | 'bignum.generated', 'bignum.misc', |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 360 | ], |
| 361 | 'ignored_tests': { |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 362 | # See ecp_light_only |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 363 | 'test_suite_random': [ |
| 364 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 365 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 366 | # See no_ecp_at_all |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 367 | 'test_suite_pkparse': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 368 | re.compile(r'Parse EC Key .*compressed\)'), |
| 369 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 370 | ], |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 371 | 'test_suite_asn1parse': [ |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 372 | 'INTEGER too large for mpi', |
| 373 | ], |
| 374 | 'test_suite_asn1write': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 375 | re.compile(r'ASN.1 Write mpi.*'), |
Valerio Setti | 9b3dbcc | 2023-07-26 18:00:31 +0200 | [diff] [blame] | 376 | ], |
Valerio Setti | e0be95e | 2023-08-01 09:07:43 +0200 | [diff] [blame] | 377 | 'test_suite_debug': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 378 | re.compile(r'Debug print mbedtls_mpi.*'), |
Valerio Setti | e0be95e | 2023-08-01 09:07:43 +0200 | [diff] [blame] | 379 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 380 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 381 | 'test_suite_ssl': [ |
| 382 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 383 | ], |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | }, |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 387 | 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': { |
| 388 | 'test_function': do_analyze_driver_vs_reference, |
| 389 | 'args': { |
| 390 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum', |
| 391 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum', |
| 392 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 393 | # Modules replaced by drivers |
| 394 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm', |
| 395 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 396 | 'bignum.generated', 'bignum.misc', |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 397 | ], |
| 398 | 'ignored_tests': { |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 399 | # See ecp_light_only |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 400 | 'test_suite_random': [ |
| 401 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 402 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 403 | # See no_ecp_at_all |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 404 | 'test_suite_pkparse': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 405 | re.compile(r'Parse EC Key .*compressed\)'), |
| 406 | re.compile(r'Parse Public EC Key .*compressed\)'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 407 | ], |
| 408 | 'test_suite_asn1parse': [ |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 409 | 'INTEGER too large for mpi', |
| 410 | ], |
| 411 | 'test_suite_asn1write': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 412 | re.compile(r'ASN.1 Write mpi.*'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 413 | ], |
| 414 | 'test_suite_debug': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 415 | re.compile(r'Debug print mbedtls_mpi.*'), |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 416 | ], |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 417 | # See ecp_light_only |
Manuel Pégourié-Gonnard | f07ce3b | 2023-09-22 11:53:41 +0200 | [diff] [blame] | 418 | 'test_suite_ssl': [ |
| 419 | 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', |
| 420 | ], |
Valerio Setti | 307810b | 2023-08-15 10:12:25 +0200 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | }, |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 424 | 'analyze_driver_vs_reference_ffdh_alg': { |
| 425 | 'test_function': do_analyze_driver_vs_reference, |
| 426 | 'args': { |
| 427 | 'component_ref': 'test_psa_crypto_config_reference_ffdh', |
| 428 | 'component_driver': 'test_psa_crypto_config_accel_ffdh', |
Przemek Stekiel | 84f4ff1 | 2023-07-04 12:35:31 +0200 | [diff] [blame] | 429 | 'ignored_suites': ['dhm'], |
Przemek Stekiel | 565353e | 2023-07-05 11:07:07 +0200 | [diff] [blame] | 430 | 'ignored_tests': {} |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 431 | } |
| 432 | }, |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 433 | 'analyze_driver_vs_reference_tfm_config': { |
| 434 | 'test_function': do_analyze_driver_vs_reference, |
| 435 | 'args': { |
| 436 | 'component_ref': 'test_tfm_config', |
| 437 | 'component_driver': 'test_tfm_config_p256m_driver_accel_ec', |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 438 | 'ignored_suites': [ |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 439 | # Modules replaced by drivers |
Yanray Wang | 5779096 | 2023-10-31 13:39:07 +0800 | [diff] [blame] | 440 | 'asn1parse', 'asn1write', |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 441 | 'ecp', 'ecdsa', 'ecdh', 'ecjpake', |
| 442 | 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', |
| 443 | 'bignum.generated', 'bignum.misc', |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 444 | ], |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 445 | 'ignored_tests': { |
Manuel Pégourié-Gonnard | 4fd5a6a | 2023-10-20 10:21:09 +0200 | [diff] [blame] | 446 | # See ecp_light_only |
Manuel Pégourié-Gonnard | e9d9797 | 2023-08-08 18:34:47 +0200 | [diff] [blame] | 447 | 'test_suite_random': [ |
| 448 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 449 | ], |
Valerio Setti | f01d648 | 2023-08-04 13:51:18 +0200 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | } |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 453 | } |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 454 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 455 | def main(): |
Valerio Setti | f075e47 | 2023-10-17 11:03:16 +0200 | [diff] [blame] | 456 | main_results = Results() |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 457 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 458 | try: |
| 459 | parser = argparse.ArgumentParser(description=__doc__) |
Przemek Stekiel | 58bbc23 | 2022-10-24 08:10:10 +0200 | [diff] [blame] | 460 | parser.add_argument('outcomes', metavar='OUTCOMES.CSV', |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 461 | help='Outcome file to analyze') |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 462 | parser.add_argument('specified_tasks', default='all', nargs='?', |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 463 | help='Analysis to be done. By default, run all tasks. ' |
| 464 | 'With one or more TASK, run only those. ' |
| 465 | 'TASK can be the name of a single task or ' |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 466 | 'comma/space-separated list of tasks. ') |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 467 | parser.add_argument('--list', action='store_true', |
| 468 | help='List all available tasks and exit.') |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 469 | parser.add_argument('--require-full-coverage', action='store_true', |
| 470 | dest='full_coverage', help="Require all available " |
| 471 | "test cases to be executed and issue an error " |
| 472 | "otherwise. This flag is ignored if 'task' is " |
| 473 | "neither 'all' nor 'analyze_coverage'") |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 474 | options = parser.parse_args() |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 475 | |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 476 | if options.list: |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 477 | for task in KNOWN_TASKS: |
Valerio Setti | 5329ff0 | 2023-10-17 09:44:36 +0200 | [diff] [blame] | 478 | print(task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 479 | sys.exit(0) |
| 480 | |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 481 | if options.specified_tasks == 'all': |
| 482 | tasks_list = KNOWN_TASKS.keys() |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 483 | else: |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 484 | tasks_list = re.split(r'[, ]+', options.specified_tasks) |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 485 | for task in tasks_list: |
| 486 | if task not in KNOWN_TASKS: |
Manuel Pégourié-Gonnard | 62d6131 | 2023-10-20 10:51:57 +0200 | [diff] [blame] | 487 | sys.stderr.write('invalid task: {}\n'.format(task)) |
Valerio Setti | fb2750e | 2023-10-17 10:11:45 +0200 | [diff] [blame] | 488 | sys.exit(2) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 489 | |
Valerio Setti | dfd7ca6 | 2023-10-09 16:30:11 +0200 | [diff] [blame] | 490 | KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 491 | |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 492 | # If the outcome file already exists, we assume that the user wants to |
| 493 | # perform the comparison. |
| 494 | # Share the contents among tasks to improve performance. |
| 495 | if os.path.exists(options.outcomes): |
| 496 | main_results.info("Read outcome file from {}.", options.outcomes) |
| 497 | outcomes_or_file = read_outcome_file(options.outcomes) |
| 498 | else: |
| 499 | outcomes_or_file = options.outcomes |
| 500 | |
Valerio Setti | fb2750e | 2023-10-17 10:11:45 +0200 | [diff] [blame] | 501 | for task in tasks_list: |
| 502 | test_function = KNOWN_TASKS[task]['test_function'] |
| 503 | test_args = KNOWN_TASKS[task]['args'] |
Pengyu Lv | a6cf5d6 | 2023-11-22 11:35:21 +0800 | [diff] [blame] | 504 | test_function(main_results, outcomes_or_file, test_args) |
Tomás González | b401e11 | 2023-08-11 15:22:04 +0100 | [diff] [blame] | 505 | |
Valerio Setti | f6f64cf | 2023-10-17 12:28:26 +0200 | [diff] [blame] | 506 | main_results.info("Overall results: {} warnings and {} errors", |
| 507 | main_results.warning_count, main_results.error_count) |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 508 | |
Valerio Setti | 8d178be | 2023-10-17 12:23:55 +0200 | [diff] [blame] | 509 | sys.exit(0 if (main_results.error_count == 0) else 1) |
Valerio Setti | aaef0bc | 2023-10-10 09:42:13 +0200 | [diff] [blame] | 510 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 511 | except Exception: # pylint: disable=broad-except |
| 512 | # Print the backtrace and exit explicitly with our chosen status. |
| 513 | traceback.print_exc() |
| 514 | sys.exit(120) |
| 515 | |
| 516 | if __name__ == '__main__': |
| 517 | main() |