blob: 9c13d8c040cbfa261b8d35dee5fcd6295472bedb [file] [log] [blame]
Gilles Peskine15c2cbf2020-06-25 18:36:28 +02001#!/usr/bin/env python3
2
3"""Analyze the test outcomes from a full CI run.
4
5This script can also run on outcomes from a partial run, but the results are
6less likely to be useful.
7"""
8
9import argparse
10import sys
11import traceback
Przemek Stekiel85c54ea2022-11-17 11:50:23 +010012import re
Valerio Settia2663322023-03-24 08:20:18 +010013import subprocess
14import os
Pengyu Lv18908ec2023-11-28 12:11:52 +080015import typing
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020016
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020017import check_test_cases
18
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080019
Pengyu Lv550cd6f2023-11-29 09:17:59 +080020# `ComponentOutcomes` is a named tuple which is defined as:
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080021# ComponentOutcomes(
22# successes = {
23# "<suite_case>",
24# ...
25# },
26# failures = {
27# "<suite_case>",
28# ...
29# }
30# )
31# suite_case = "<suite>;<case>"
Pengyu Lv18908ec2023-11-28 12:11:52 +080032ComponentOutcomes = typing.NamedTuple('ComponentOutcomes',
33 [('successes', typing.Set[str]),
34 ('failures', typing.Set[str])])
35
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080036# `Outcomes` is a representation of the outcomes file,
37# which defined as:
38# Outcomes = {
39# "<component>": ComponentOutcomes,
40# ...
41# }
42Outcomes = typing.Dict[str, ComponentOutcomes]
43
44
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020045class Results:
46 """Process analysis results."""
47
48 def __init__(self):
49 self.error_count = 0
50 self.warning_count = 0
51
Valerio Setti2cff8202023-10-18 14:36:47 +020052 def new_section(self, fmt, *args, **kwargs):
53 self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs)
54
Valerio Settiaaef0bc2023-10-10 09:42:13 +020055 def info(self, fmt, *args, **kwargs):
Valerio Setti8070dbe2023-10-17 12:29:30 +020056 self._print_line('Info: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020057
58 def error(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020059 self.error_count += 1
Valerio Setti8070dbe2023-10-17 12:29:30 +020060 self._print_line('Error: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020061
62 def warning(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020063 self.warning_count += 1
Valerio Setti8070dbe2023-10-17 12:29:30 +020064 self._print_line('Warning: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020065
Valerio Setti3f339892023-10-17 10:42:11 +020066 @staticmethod
Valerio Setti8070dbe2023-10-17 12:29:30 +020067 def _print_line(fmt, *args, **kwargs):
Valerio Setti735794c2023-10-18 08:05:15 +020068 sys.stderr.write((fmt + '\n').format(*args, **kwargs))
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020069
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080070def execute_reference_driver_tests(results: Results, ref_component: str, driver_component: str, \
71 outcome_file: str) -> None:
Valerio Setti22992a02023-03-29 11:15:28 +020072 """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 Settia2663322023-03-24 08:20:18 +010074 coverage analysis"""
Pengyu Lv20e3ca32023-11-28 15:30:03 +080075 results.new_section("Test {} and {}", ref_component, driver_component)
Valerio Settia2663322023-03-24 08:20:18 +010076
77 shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
78 " " + ref_component + " " + driver_component
Valerio Setti39d4b9d2023-10-18 14:30:03 +020079 results.info("Running: {}", shell_command)
Valerio Settia2663322023-03-24 08:20:18 +010080 ret_val = subprocess.run(shell_command.split(), check=False).returncode
81
82 if ret_val != 0:
Valerio Settif075e472023-10-17 11:03:16 +020083 results.error("failed to run reference/driver components")
Valerio Settia2663322023-03-24 08:20:18 +010084
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080085def analyze_coverage(results: Results, outcomes: Outcomes,
86 allow_list: typing.List[str], full_coverage: bool) -> None:
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020087 """Check that all available test cases are executed at least once."""
Gilles Peskine78ae4f62024-05-21 20:26:18 +020088 # 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',
93 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
94 if cp.returncode != 0:
95 sys.stderr.write(cp.stdout.decode('utf-8'))
96 results.error("Failed \"make generated_files\" in tests. Coverage analysis may be incorrect.")
Gilles Peskine686c2922022-01-07 15:58:38 +010097 available = check_test_cases.collect_available_test_cases()
Pengyu Lv31a9b782023-11-23 14:15:37 +080098 for suite_case in available:
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +080099 hit = any(suite_case in comp_outcomes.successes or
100 suite_case in comp_outcomes.failures
101 for comp_outcomes in outcomes.values())
Pengyu Lva4428582023-11-22 19:02:15 +0800102
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +0800103 if not hit and suite_case not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100104 if full_coverage:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800105 results.error('Test case not executed: {}', suite_case)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100106 else:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800107 results.warning('Test case not executed: {}', suite_case)
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +0800108 elif hit and suite_case in allow_list:
Tomás González07bdcc22023-08-11 14:59:03 +0100109 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +0100110 if full_coverage:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800111 results.error('Allow listed test case was executed: {}', suite_case)
Tomás González7ebb18f2023-08-22 09:40:23 +0100112 else:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800113 results.warning('Allow listed test case was executed: {}', suite_case)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +0200114
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800115def name_matches_pattern(name: str, str_or_re) -> bool:
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200116 """Check if name matches a pattern, that may be a string or regex.
117 - If the pattern is a string, name must be equal to match.
118 - If the pattern is a regex, name must fully match.
119 """
Manuel Pégourié-Gonnardb2695432023-10-23 09:30:40 +0200120 # The CI's python is too old for re.Pattern
121 #if isinstance(str_or_re, re.Pattern):
122 if not isinstance(str_or_re, str):
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800123 return str_or_re.fullmatch(name) is not None
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200124 else:
Manuel Pégourié-Gonnard9d9c2342023-10-26 09:37:40 +0200125 return str_or_re == name
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200126
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800127def analyze_driver_vs_reference(results: Results, outcomes: Outcomes,
128 component_ref: str, component_driver: str,
129 ignored_suites: typing.List[str], ignored_tests=None) -> None:
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800130 """Check that all tests passing in the reference component are also
131 passing in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100132 Skip:
133 - full test suites provided in ignored_suites list
134 - only some specific test inside a test suite, for which the corresponding
135 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200136 """
Pengyu Lva4428582023-11-22 19:02:15 +0800137 ref_outcomes = outcomes.get("component_" + component_ref)
138 driver_outcomes = outcomes.get("component_" + component_driver)
139
Pengyu Lv59b9efc2023-11-28 11:15:00 +0800140 if ref_outcomes is None or driver_outcomes is None:
141 results.error("required components are missing: bad outcome file?")
142 return
143
Pengyu Lv18908ec2023-11-28 12:11:52 +0800144 if not ref_outcomes.successes:
Pengyu Lva4428582023-11-22 19:02:15 +0800145 results.error("no passing test in reference component: bad outcome file?")
146 return
147
Pengyu Lv18908ec2023-11-28 12:11:52 +0800148 for suite_case in ref_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800149 # suite_case is like "test_suite_foo.bar;Description of test case"
150 (full_test_suite, test_string) = suite_case.split(';')
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100151 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200152
153 # Immediately skip fully-ignored test suites
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100154 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100155 continue
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200156
157 # For ignored test cases inside test suites, just remember and:
158 # don't issue an error if they're skipped with drivers,
159 # but issue an error if they're not (means we have a bad entry).
160 ignored = False
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200161 if full_test_suite in ignored_tests:
Valerio Setti9afa3292023-12-20 09:55:28 +0100162 for str_or_re in ignored_tests[full_test_suite]:
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200163 if name_matches_pattern(test_string, str_or_re):
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200164 ignored = True
Manuel Pégourié-Gonnard4da369f2023-10-18 09:40:32 +0200165
Pengyu Lv18908ec2023-11-28 12:11:52 +0800166 if not ignored and not suite_case in driver_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800167 results.error("PASS -> SKIP/FAIL: {}", suite_case)
Pengyu Lv18908ec2023-11-28 12:11:52 +0800168 if ignored and suite_case in driver_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800169 results.error("uselessly ignored: {}", suite_case)
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200170
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800171def analyze_outcomes(results: Results, outcomes: Outcomes, args) -> None:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200172 """Run all analyses on the given outcome collection."""
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100173 analyze_coverage(results, outcomes, args['allow_list'],
174 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200175
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800176def read_outcome_file(outcome_file: str) -> Outcomes:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200177 """Parse an outcome file and return an outcome collection.
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800178 """
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200179 outcomes = {}
180 with open(outcome_file, 'r', encoding='utf-8') as input_file:
181 for line in input_file:
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800182 (_platform, component, suite, case, result, _cause) = line.split(';')
Pengyu Lv451ec8a2023-11-28 17:59:05 +0800183 # Note that `component` is not unique. If a test case passes on Linux
184 # and fails on FreeBSD, it'll end up in both the successes set and
185 # the failures set.
Pengyu Lv31a9b782023-11-23 14:15:37 +0800186 suite_case = ';'.join([suite, case])
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800187 if component not in outcomes:
Pengyu Lv18908ec2023-11-28 12:11:52 +0800188 outcomes[component] = ComponentOutcomes(set(), set())
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200189 if result == 'PASS':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800190 outcomes[component].successes.add(suite_case)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200191 elif result == 'FAIL':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800192 outcomes[component].failures.add(suite_case)
Pengyu Lva4428582023-11-22 19:02:15 +0800193
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200194 return outcomes
195
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800196def do_analyze_coverage(results: Results, outcomes: Outcomes, args) -> None:
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100197 """Perform coverage analysis."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200198 results.new_section("Analyze coverage")
Valerio Setti781c2342023-10-17 12:47:35 +0200199 analyze_outcomes(results, outcomes, args)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200200
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800201def do_analyze_driver_vs_reference(results: Results, outcomes: Outcomes, args) -> None:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200202 """Perform driver vs reference analyze."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200203 results.new_section("Analyze driver {} vs reference {}",
204 args['component_driver'], args['component_ref'])
Valerio Settib0c618e2023-10-16 14:19:49 +0200205
Valerio Setti3002c992023-01-18 17:28:36 +0100206 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100207
Valerio Setti781c2342023-10-17 12:47:35 +0200208 analyze_driver_vs_reference(results, outcomes,
209 args['component_ref'], args['component_driver'],
210 ignored_suites, args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200211
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100212# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200213KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200214 'analyze_coverage': {
215 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100216 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100217 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100218 # Algorithm not supported yet
219 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
220 # Algorithm not supported yet
221 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100222 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100223 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100224 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100225 },
Valerio Settia2663322023-03-24 08:20:18 +0100226 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
227 # 1. Run tests and then analysis:
228 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
229 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
230 # 2. Let this script run both automatically:
231 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200232 'analyze_driver_vs_reference_hash': {
233 'test_function': do_analyze_driver_vs_reference,
234 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100235 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
236 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100237 'ignored_suites': [
238 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100239 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200240 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100241 ],
242 'ignored_tests': {
Gilles Peskine150002c2023-11-27 18:24:45 +0100243 'test_suite_platform': [
244 # Incompatible with sanitizers (e.g. ASan). If the driver
245 # component uses a sanitizer but the reference component
246 # doesn't, we have a PASS vs SKIP mismatch.
247 'Check mbedtls_calloc overallocation',
248 ],
Valerio Setti3002c992023-01-18 17:28:36 +0100249 }
250 }
251 },
Valerio Setti20cea942024-01-22 16:23:25 +0100252 'analyze_driver_vs_reference_hmac': {
253 'test_function': do_analyze_driver_vs_reference,
254 'args': {
255 'component_ref': 'test_psa_crypto_config_reference_hmac',
256 'component_driver': 'test_psa_crypto_config_accel_hmac',
257 'ignored_suites': [
Valerio Setticd89b0b2024-01-24 14:24:55 +0100258 # These suites require legacy hash support, which is disabled
Valerio Setti89d8a122024-01-26 15:04:05 +0100259 # in the accelerated component.
Valerio Setticd89b0b2024-01-24 14:24:55 +0100260 'shax', 'mdx',
Valerio Setti20cea942024-01-22 16:23:25 +0100261 # This suite tests builtins directly, but these are missing
262 # in the accelerated case.
263 'psa_crypto_low_hash.generated',
264 ],
265 'ignored_tests': {
266 'test_suite_md': [
267 # Builtin HMAC is not supported in the accelerate component.
268 re.compile('.*HMAC.*'),
269 # Following tests make use of functions which are not available
270 # when MD_C is disabled, as it happens in the accelerated
271 # test component.
272 re.compile('generic .* Hash file .*'),
273 'MD list',
274 ],
275 'test_suite_md.psa': [
276 # "legacy only" tests require hash algorithms to be NOT
277 # accelerated, but this of course false for the accelerated
278 # test component.
279 re.compile('PSA dispatch .* legacy only'),
280 ],
281 'test_suite_platform': [
282 # Incompatible with sanitizers (e.g. ASan). If the driver
283 # component uses a sanitizer but the reference component
284 # doesn't, we have a PASS vs SKIP mismatch.
285 'Check mbedtls_calloc overallocation',
286 ],
287 }
288 }
289 },
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100290 'analyze_driver_vs_reference_cipher_aead_cmac': {
Valerio Settib6b301f2023-10-04 12:05:05 +0200291 'test_function': do_analyze_driver_vs_reference,
292 'args': {
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100293 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac',
294 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac',
Valerio Setti507e08f2023-10-26 09:44:06 +0200295 # Modules replaced by drivers.
Valerio Settib6b301f2023-10-04 12:05:05 +0200296 'ignored_suites': [
Valerio Setti507e08f2023-10-26 09:44:06 +0200297 # low-level (block/stream) cipher modules
298 'aes', 'aria', 'camellia', 'des', 'chacha20',
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100299 # AEAD modes and CMAC
Valerio Setti507e08f2023-10-26 09:44:06 +0200300 'ccm', 'chachapoly', 'cmac', 'gcm',
301 # The Cipher abstraction layer
302 'cipher',
Valerio Settib6b301f2023-10-04 12:05:05 +0200303 ],
304 'ignored_tests': {
Valerio Setti507e08f2023-10-26 09:44:06 +0200305 # PEM decryption is not supported so far.
306 # The rest of PEM (write, unencrypted read) works though.
Valerio Setti7448cee2023-10-04 15:46:42 +0200307 'test_suite_pem': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200308 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
Valerio Setti7448cee2023-10-04 15:46:42 +0200309 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100310 'test_suite_platform': [
311 # Incompatible with sanitizers (e.g. ASan). If the driver
312 # component uses a sanitizer but the reference component
313 # doesn't, we have a PASS vs SKIP mismatch.
314 'Check mbedtls_calloc overallocation',
315 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200316 # Following tests depend on AES_C/DES_C but are not about
317 # them really, just need to know some error code is there.
Valerio Setti7448cee2023-10-04 15:46:42 +0200318 'test_suite_error': [
319 'Low and high error',
320 'Single low error'
321 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200322 # Similar to test_suite_error above.
Valerio Setti7448cee2023-10-04 15:46:42 +0200323 'test_suite_version': [
324 'Check for MBEDTLS_AES_C when already present',
Valerio Setti93941442023-10-13 09:19:52 +0200325 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200326 # The en/decryption part of PKCS#12 is not supported so far.
327 # The rest of PKCS#12 (key derivation) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200328 'test_suite_pkcs12': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200329 re.compile(r'PBE Encrypt, .*'),
330 re.compile(r'PBE Decrypt, .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200331 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200332 # The en/decryption part of PKCS#5 is not supported so far.
333 # The rest of PKCS#5 (PBKDF2) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200334 'test_suite_pkcs5': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200335 re.compile(r'PBES2 Encrypt, .*'),
336 re.compile(r'PBES2 Decrypt .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200337 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200338 # Encrypted keys are not supported so far.
Valerio Setti5cd18f92023-10-13 15:14:07 +0200339 # pylint: disable=line-too-long
Valerio Setti93941442023-10-13 09:19:52 +0200340 'test_suite_pkparse': [
341 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
342 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
Pengyu Lva1ddcfa2023-11-28 09:46:01 +0800343 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
Valerio Setti93941442023-10-13 09:19:52 +0200344 ],
Valerio Settib6b301f2023-10-04 12:05:05 +0200345 }
346 }
347 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200348 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100349 'test_function': do_analyze_driver_vs_reference,
350 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200351 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
352 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100353 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200354 # Modules replaced by drivers
355 'ecdsa', 'ecdh', 'ecjpake',
Valerio Setti42d5f192023-03-20 13:54:41 +0100356 ],
357 'ignored_tests': {
Gilles Peskine150002c2023-11-27 18:24:45 +0100358 'test_suite_platform': [
359 # Incompatible with sanitizers (e.g. ASan). If the driver
360 # component uses a sanitizer but the reference component
361 # doesn't, we have a PASS vs SKIP mismatch.
362 'Check mbedtls_calloc overallocation',
363 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200364 # This test wants a legacy function that takes f_rng, p_rng
365 # arguments, and uses legacy ECDSA for that. The test is
366 # really about the wrapper around the PSA RNG, not ECDSA.
Valerio Setti42d5f192023-03-20 13:54:41 +0100367 'test_suite_random': [
368 'PSA classic wrapper: ECDSA signature (SECP256R1)',
369 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200370 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
371 # so we must ignore disparities in the tests for which ECP_C
372 # is required.
373 'test_suite_ecp': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200374 re.compile(r'ECP check public-private .*'),
Gilles Peskine3b17ae72023-06-23 11:08:39 +0200375 re.compile(r'ECP calculate public: .*'),
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200376 re.compile(r'ECP gen keypair .*'),
377 re.compile(r'ECP point muladd .*'),
378 re.compile(r'ECP point multiplication .*'),
379 re.compile(r'ECP test vectors .*'),
Valerio Setti482a0b92023-08-18 15:55:10 +0200380 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200381 'test_suite_ssl': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200382 # This deprecated function is only present when ECP_C is On.
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200383 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
384 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200385 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100386 }
387 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200388 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200389 'test_function': do_analyze_driver_vs_reference,
390 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200391 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
392 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200393 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200394 # Modules replaced by drivers
395 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
Valerio Settie618cb02023-04-12 14:59:16 +0200396 ],
397 'ignored_tests': {
Gilles Peskine150002c2023-11-27 18:24:45 +0100398 'test_suite_platform': [
399 # Incompatible with sanitizers (e.g. ASan). If the driver
400 # component uses a sanitizer but the reference component
401 # doesn't, we have a PASS vs SKIP mismatch.
402 'Check mbedtls_calloc overallocation',
403 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200404 # See ecp_light_only
Valerio Settie618cb02023-04-12 14:59:16 +0200405 'test_suite_random': [
406 'PSA classic wrapper: ECDSA signature (SECP256R1)',
407 ],
Valerio Settiaddeee42023-06-14 10:46:55 +0200408 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200409 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
410 # is automatically enabled in build_info.h (backward compatibility)
411 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
412 # consequence compressed points are supported in the reference
413 # component but not in the accelerated one, so they should be skipped
414 # while checking driver's coverage.
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200415 re.compile(r'Parse EC Key .*compressed\)'),
416 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Settiaddeee42023-06-14 10:46:55 +0200417 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200418 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200419 'test_suite_ssl': [
420 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
421 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200422 }
423 }
424 },
Valerio Setti307810b2023-08-15 10:12:25 +0200425 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200426 'test_function': do_analyze_driver_vs_reference,
427 'args': {
428 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
429 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
430 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200431 # Modules replaced by drivers
432 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
433 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
434 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200435 ],
436 'ignored_tests': {
Gilles Peskine150002c2023-11-27 18:24:45 +0100437 'test_suite_platform': [
438 # Incompatible with sanitizers (e.g. ASan). If the driver
439 # component uses a sanitizer but the reference component
440 # doesn't, we have a PASS vs SKIP mismatch.
441 'Check mbedtls_calloc overallocation',
442 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200443 # See ecp_light_only
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200444 'test_suite_random': [
445 'PSA classic wrapper: ECDSA signature (SECP256R1)',
446 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200447 # See no_ecp_at_all
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200448 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200449 re.compile(r'Parse EC Key .*compressed\)'),
450 re.compile(r'Parse Public EC Key .*compressed\)'),
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200451 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200452 'test_suite_asn1parse': [
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200453 'INTEGER too large for mpi',
454 ],
455 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200456 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200457 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200458 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200459 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Settie0be95e2023-08-01 09:07:43 +0200460 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200461 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200462 'test_suite_ssl': [
463 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
464 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200465 }
466 }
467 },
Valerio Setti307810b2023-08-15 10:12:25 +0200468 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
469 'test_function': do_analyze_driver_vs_reference,
470 'args': {
471 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
472 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
473 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200474 # Modules replaced by drivers
475 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
476 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
477 'bignum.generated', 'bignum.misc',
Valerio Setti307810b2023-08-15 10:12:25 +0200478 ],
479 'ignored_tests': {
Gilles Peskineff3b8212024-04-30 14:25:30 +0200480 'ssl-opt': [
481 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
482 # (because it needs custom groups, which PSA does not
483 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
484 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
485 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100486 'test_suite_platform': [
487 # Incompatible with sanitizers (e.g. ASan). If the driver
488 # component uses a sanitizer but the reference component
489 # doesn't, we have a PASS vs SKIP mismatch.
490 'Check mbedtls_calloc overallocation',
491 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200492 # See ecp_light_only
Valerio Setti307810b2023-08-15 10:12:25 +0200493 'test_suite_random': [
494 'PSA classic wrapper: ECDSA signature (SECP256R1)',
495 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200496 # See no_ecp_at_all
Valerio Setti307810b2023-08-15 10:12:25 +0200497 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200498 re.compile(r'Parse EC Key .*compressed\)'),
499 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Setti307810b2023-08-15 10:12:25 +0200500 ],
501 'test_suite_asn1parse': [
Valerio Setti307810b2023-08-15 10:12:25 +0200502 'INTEGER too large for mpi',
503 ],
504 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200505 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200506 ],
507 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200508 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200509 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200510 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200511 'test_suite_ssl': [
512 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
513 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200514 }
515 }
516 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200517 'analyze_driver_vs_reference_ffdh_alg': {
518 'test_function': do_analyze_driver_vs_reference,
519 'args': {
520 'component_ref': 'test_psa_crypto_config_reference_ffdh',
521 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200522 'ignored_suites': ['dhm'],
Gilles Peskine150002c2023-11-27 18:24:45 +0100523 'ignored_tests': {
524 'test_suite_platform': [
525 # Incompatible with sanitizers (e.g. ASan). If the driver
526 # component uses a sanitizer but the reference component
527 # doesn't, we have a PASS vs SKIP mismatch.
528 'Check mbedtls_calloc overallocation',
529 ],
530 }
Przemek Stekiel85b64422023-05-26 09:55:23 +0200531 }
532 },
Valerio Settif01d6482023-08-04 13:51:18 +0200533 'analyze_driver_vs_reference_tfm_config': {
534 'test_function': do_analyze_driver_vs_reference,
535 'args': {
536 'component_ref': 'test_tfm_config',
537 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200538 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200539 # Modules replaced by drivers
Yanray Wang57790962023-10-31 13:39:07 +0800540 'asn1parse', 'asn1write',
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200541 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
542 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
543 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200544 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200545 'ignored_tests': {
Gilles Peskine150002c2023-11-27 18:24:45 +0100546 'test_suite_platform': [
547 # Incompatible with sanitizers (e.g. ASan). If the driver
548 # component uses a sanitizer but the reference component
549 # doesn't, we have a PASS vs SKIP mismatch.
550 'Check mbedtls_calloc overallocation',
551 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200552 # See ecp_light_only
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200553 'test_suite_random': [
554 'PSA classic wrapper: ECDSA signature (SECP256R1)',
555 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200556 }
557 }
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800558 },
559 'analyze_driver_vs_reference_rsa': {
560 'test_function': do_analyze_driver_vs_reference,
561 'args': {
562 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto',
563 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto',
564 'ignored_suites': [
565 # Modules replaced by drivers.
566 'rsa', 'pkcs1_v15', 'pkcs1_v21',
Pengyu Lv98a90c62023-12-07 17:23:25 +0800567 # We temporarily don't care about PK stuff.
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800568 'pk', 'pkwrite', 'pkparse'
569 ],
570 'ignored_tests': {
571 'test_suite_platform': [
572 # Incompatible with sanitizers (e.g. ASan). If the driver
573 # component uses a sanitizer but the reference component
574 # doesn't, we have a PASS vs SKIP mismatch.
575 'Check mbedtls_calloc overallocation',
576 ],
577 # Following tests depend on RSA_C but are not about
578 # them really, just need to know some error code is there.
579 'test_suite_error': [
580 'Low and high error',
581 'Single high error'
582 ],
583 # Constant time operations only used for PKCS1_V15
584 'test_suite_constant_time': [
585 re.compile(r'mbedtls_ct_zeroize_if .*'),
586 re.compile(r'mbedtls_ct_memmove_left .*')
587 ],
Gilles Peskine63072b12024-02-15 11:48:58 +0100588 'test_suite_psa_crypto': [
589 # We don't support generate_key_ext entry points
590 # in drivers yet.
591 re.compile(r'PSA generate key ext: RSA, e=.*'),
592 ],
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800593 }
594 }
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100595 },
596 'analyze_block_cipher_dispatch': {
597 'test_function': do_analyze_driver_vs_reference,
598 'args': {
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100599 'component_ref': 'test_full_block_cipher_legacy_dispatch',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100600 'component_driver': 'test_full_block_cipher_psa_dispatch',
601 'ignored_suites': [
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100602 # Skipped in the accelerated component
603 'aes', 'aria', 'camellia',
Valerio Setti0635cca2023-12-28 16:16:02 +0100604 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
605 # order for the cipher module (actually cipher_wrapper) to work
606 # properly. However these symbols are disabled in the accelerated
607 # component so we ignore them.
Valerio Settia0c9c662023-12-29 14:14:11 +0100608 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
Valerio Setti0635cca2023-12-28 16:16:02 +0100609 'cipher.camellia',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100610 ],
611 'ignored_tests': {
Valerio Settia0c9c662023-12-29 14:14:11 +0100612 'test_suite_cmac': [
613 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
614 # but these are not available in the accelerated component.
615 'CMAC null arguments',
616 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
617 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100618 'test_suite_cipher.padding': [
619 # Following tests require AES_C/CAMELLIA_C to be enabled,
620 # but these are not available in the accelerated component.
621 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100622 ],
Ryan Everettafb2eee2024-02-08 14:31:54 +0000623 'test_suite_pkcs5': [
Ryan Everett67f35682024-02-09 13:02:23 +0000624 # The AES part of PKCS#5 PBES2 is not yet supported.
Ryan Everettafb2eee2024-02-08 14:31:54 +0000625 # The rest of PKCS#5 (PBKDF2) works, though.
Ryan Everett67f35682024-02-09 13:02:23 +0000626 re.compile(r'PBES2 .* AES-.*')
Ryan Everettafb2eee2024-02-08 14:31:54 +0000627 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100628 'test_suite_pkparse': [
629 # PEM (called by pkparse) requires AES_C in order to decrypt
630 # the key, but this is not available in the accelerated
631 # component.
632 re.compile('Parse RSA Key.*(password|AES-).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100633 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100634 'test_suite_pem': [
635 # Following tests require AES_C, but this is diabled in the
636 # accelerated component.
Valerio Settieba4ca12024-02-19 07:42:18 +0100637 re.compile('PEM read .*AES.*'),
Valerio Setti0635cca2023-12-28 16:16:02 +0100638 'PEM read (unknown encryption algorithm)',
Valerio Setti5f665c32023-12-20 09:56:05 +0100639 ],
640 'test_suite_error': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100641 # Following tests depend on AES_C but are not about them
642 # really, just need to know some error code is there.
Valerio Setti5f665c32023-12-20 09:56:05 +0100643 'Single low error',
644 'Low and high error',
645 ],
646 'test_suite_version': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100647 # Similar to test_suite_error above.
Valerio Setti5f665c32023-12-20 09:56:05 +0100648 'Check for MBEDTLS_AES_C when already present',
649 ],
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100650 'test_suite_platform': [
651 # Incompatible with sanitizers (e.g. ASan). If the driver
652 # component uses a sanitizer but the reference component
653 # doesn't, we have a PASS vs SKIP mismatch.
654 'Check mbedtls_calloc overallocation',
655 ],
656 }
657 }
Valerio Settif01d6482023-08-04 13:51:18 +0200658 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200659}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200660
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200661def main():
Valerio Settif075e472023-10-17 11:03:16 +0200662 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200663
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200664 try:
665 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200666 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200667 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200668 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100669 help='Analysis to be done. By default, run all tasks. '
670 'With one or more TASK, run only those. '
671 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100672 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100673 parser.add_argument('--list', action='store_true',
674 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100675 parser.add_argument('--require-full-coverage', action='store_true',
676 dest='full_coverage', help="Require all available "
677 "test cases to be executed and issue an error "
678 "otherwise. This flag is ignored if 'task' is "
679 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200680 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200681
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100682 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200683 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200684 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100685 sys.exit(0)
686
Valerio Settidfd7ca62023-10-09 16:30:11 +0200687 if options.specified_tasks == 'all':
688 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100689 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200690 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200691 for task in tasks_list:
692 if task not in KNOWN_TASKS:
Manuel Pégourié-Gonnard62d61312023-10-20 10:51:57 +0200693 sys.stderr.write('invalid task: {}\n'.format(task))
Valerio Settifb2750e2023-10-17 10:11:45 +0200694 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100695
Valerio Settidfd7ca62023-10-09 16:30:11 +0200696 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100697
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800698 # If the outcome file exists, parse it once and share the result
699 # among tasks to improve performance.
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800700 # Otherwise, it will be generated by execute_reference_driver_tests.
701 if not os.path.exists(options.outcomes):
702 if len(tasks_list) > 1:
703 sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n")
704 sys.exit(2)
705
706 task_name = tasks_list[0]
707 task = KNOWN_TASKS[task_name]
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800708 if task['test_function'] != do_analyze_driver_vs_reference: # pylint: disable=comparison-with-callable
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800709 sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
710 sys.exit(2)
711
712 execute_reference_driver_tests(main_results,
713 task['args']['component_ref'],
714 task['args']['component_driver'],
715 options.outcomes)
716
717 outcomes = read_outcome_file(options.outcomes)
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800718
Valerio Settifb2750e2023-10-17 10:11:45 +0200719 for task in tasks_list:
720 test_function = KNOWN_TASKS[task]['test_function']
721 test_args = KNOWN_TASKS[task]['args']
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800722 test_function(main_results, outcomes, test_args)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100723
Valerio Settif6f64cf2023-10-17 12:28:26 +0200724 main_results.info("Overall results: {} warnings and {} errors",
725 main_results.warning_count, main_results.error_count)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200726
Valerio Setti8d178be2023-10-17 12:23:55 +0200727 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200728
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200729 except Exception: # pylint: disable=broad-except
730 # Print the backtrace and exit explicitly with our chosen status.
731 traceback.print_exc()
732 sys.exit(120)
733
734if __name__ == '__main__':
735 main()