blob: 082ed01b1569b2086bde22f6b08af9fb23080188 [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 Peskine89410332024-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',
Gilles Peskine7fbbb432024-05-22 09:35:11 +020093 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
94 check=False)
Gilles Peskine89410332024-05-21 20:26:18 +020095 if cp.returncode != 0:
96 sys.stderr.write(cp.stdout.decode('utf-8'))
Gilles Peskine7fbbb432024-05-22 09:35:11 +020097 results.error("Failed \"make generated_files\" in tests. "
98 "Coverage analysis may be incorrect.")
Gilles Peskine686c2922022-01-07 15:58:38 +010099 available = check_test_cases.collect_available_test_cases()
Pengyu Lv31a9b782023-11-23 14:15:37 +0800100 for suite_case in available:
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +0800101 hit = any(suite_case in comp_outcomes.successes or
102 suite_case in comp_outcomes.failures
103 for comp_outcomes in outcomes.values())
Pengyu Lva4428582023-11-22 19:02:15 +0800104
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +0800105 if not hit and suite_case not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100106 if full_coverage:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800107 results.error('Test case not executed: {}', suite_case)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100108 else:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800109 results.warning('Test case not executed: {}', suite_case)
Pengyu Lv5dcfd0c2023-11-29 18:03:28 +0800110 elif hit and suite_case in allow_list:
Tomás González07bdcc22023-08-11 14:59:03 +0100111 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +0100112 if full_coverage:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800113 results.error('Allow listed test case was executed: {}', suite_case)
Tomás González7ebb18f2023-08-22 09:40:23 +0100114 else:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800115 results.warning('Allow listed test case was executed: {}', suite_case)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +0200116
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800117def name_matches_pattern(name: str, str_or_re) -> bool:
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200118 """Check if name matches a pattern, that may be a string or regex.
119 - If the pattern is a string, name must be equal to match.
120 - If the pattern is a regex, name must fully match.
121 """
Manuel Pégourié-Gonnardb2695432023-10-23 09:30:40 +0200122 # The CI's python is too old for re.Pattern
123 #if isinstance(str_or_re, re.Pattern):
124 if not isinstance(str_or_re, str):
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800125 return str_or_re.fullmatch(name) is not None
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200126 else:
Manuel Pégourié-Gonnard9d9c2342023-10-26 09:37:40 +0200127 return str_or_re == name
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200128
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800129def analyze_driver_vs_reference(results: Results, outcomes: Outcomes,
130 component_ref: str, component_driver: str,
131 ignored_suites: typing.List[str], ignored_tests=None) -> None:
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800132 """Check that all tests passing in the reference component are also
133 passing in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100134 Skip:
135 - full test suites provided in ignored_suites list
136 - only some specific test inside a test suite, for which the corresponding
137 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200138 """
Pengyu Lva4428582023-11-22 19:02:15 +0800139 ref_outcomes = outcomes.get("component_" + component_ref)
140 driver_outcomes = outcomes.get("component_" + component_driver)
141
Pengyu Lv59b9efc2023-11-28 11:15:00 +0800142 if ref_outcomes is None or driver_outcomes is None:
143 results.error("required components are missing: bad outcome file?")
144 return
145
Pengyu Lv18908ec2023-11-28 12:11:52 +0800146 if not ref_outcomes.successes:
Pengyu Lva4428582023-11-22 19:02:15 +0800147 results.error("no passing test in reference component: bad outcome file?")
148 return
149
Pengyu Lv18908ec2023-11-28 12:11:52 +0800150 for suite_case in ref_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800151 # suite_case is like "test_suite_foo.bar;Description of test case"
152 (full_test_suite, test_string) = suite_case.split(';')
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100153 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200154
155 # Immediately skip fully-ignored test suites
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100156 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100157 continue
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200158
159 # For ignored test cases inside test suites, just remember and:
160 # don't issue an error if they're skipped with drivers,
161 # but issue an error if they're not (means we have a bad entry).
162 ignored = False
Gilles Peskine331d7d02024-05-24 09:18:25 +0200163 for str_or_re in (ignored_tests.get(full_test_suite, []) +
164 ignored_tests.get(test_suite, [])):
165 if name_matches_pattern(test_string, str_or_re):
166 ignored = True
Manuel Pégourié-Gonnard4da369f2023-10-18 09:40:32 +0200167
Pengyu Lv18908ec2023-11-28 12:11:52 +0800168 if not ignored and not suite_case in driver_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800169 results.error("PASS -> SKIP/FAIL: {}", suite_case)
Pengyu Lv18908ec2023-11-28 12:11:52 +0800170 if ignored and suite_case in driver_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800171 results.error("uselessly ignored: {}", suite_case)
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200172
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800173def analyze_outcomes(results: Results, outcomes: Outcomes, args) -> None:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200174 """Run all analyses on the given outcome collection."""
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100175 analyze_coverage(results, outcomes, args['allow_list'],
176 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200177
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800178def read_outcome_file(outcome_file: str) -> Outcomes:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200179 """Parse an outcome file and return an outcome collection.
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800180 """
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200181 outcomes = {}
182 with open(outcome_file, 'r', encoding='utf-8') as input_file:
183 for line in input_file:
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800184 (_platform, component, suite, case, result, _cause) = line.split(';')
Pengyu Lv451ec8a2023-11-28 17:59:05 +0800185 # Note that `component` is not unique. If a test case passes on Linux
186 # and fails on FreeBSD, it'll end up in both the successes set and
187 # the failures set.
Pengyu Lv31a9b782023-11-23 14:15:37 +0800188 suite_case = ';'.join([suite, case])
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800189 if component not in outcomes:
Pengyu Lv18908ec2023-11-28 12:11:52 +0800190 outcomes[component] = ComponentOutcomes(set(), set())
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200191 if result == 'PASS':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800192 outcomes[component].successes.add(suite_case)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200193 elif result == 'FAIL':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800194 outcomes[component].failures.add(suite_case)
Pengyu Lva4428582023-11-22 19:02:15 +0800195
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200196 return outcomes
197
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800198def do_analyze_coverage(results: Results, outcomes: Outcomes, args) -> None:
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100199 """Perform coverage analysis."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200200 results.new_section("Analyze coverage")
Valerio Setti781c2342023-10-17 12:47:35 +0200201 analyze_outcomes(results, outcomes, args)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200202
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800203def do_analyze_driver_vs_reference(results: Results, outcomes: Outcomes, args) -> None:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200204 """Perform driver vs reference analyze."""
Valerio Setti2cff8202023-10-18 14:36:47 +0200205 results.new_section("Analyze driver {} vs reference {}",
206 args['component_driver'], args['component_ref'])
Valerio Settib0c618e2023-10-16 14:19:49 +0200207
Valerio Setti3002c992023-01-18 17:28:36 +0100208 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100209
Valerio Setti781c2342023-10-17 12:47:35 +0200210 analyze_driver_vs_reference(results, outcomes,
211 args['component_ref'], args['component_driver'],
212 ignored_suites, args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200213
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100214# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200215KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200216 'analyze_coverage': {
217 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100218 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100219 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100220 # Algorithm not supported yet
221 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
222 # Algorithm not supported yet
223 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100224 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100225 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100226 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100227 },
Valerio Settia2663322023-03-24 08:20:18 +0100228 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
229 # 1. Run tests and then analysis:
230 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
231 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
232 # 2. Let this script run both automatically:
233 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200234 'analyze_driver_vs_reference_hash': {
235 'test_function': do_analyze_driver_vs_reference,
236 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100237 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
238 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100239 'ignored_suites': [
240 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100241 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200242 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100243 ],
244 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200245 'test_suite_config': [
246 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
247 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100248 'test_suite_platform': [
249 # Incompatible with sanitizers (e.g. ASan). If the driver
250 # component uses a sanitizer but the reference component
251 # doesn't, we have a PASS vs SKIP mismatch.
252 'Check mbedtls_calloc overallocation',
253 ],
Valerio Setti3002c992023-01-18 17:28:36 +0100254 }
255 }
256 },
Valerio Setti20cea942024-01-22 16:23:25 +0100257 'analyze_driver_vs_reference_hmac': {
258 'test_function': do_analyze_driver_vs_reference,
259 'args': {
260 'component_ref': 'test_psa_crypto_config_reference_hmac',
261 'component_driver': 'test_psa_crypto_config_accel_hmac',
262 'ignored_suites': [
Valerio Setticd89b0b2024-01-24 14:24:55 +0100263 # These suites require legacy hash support, which is disabled
Valerio Setti89d8a122024-01-26 15:04:05 +0100264 # in the accelerated component.
Valerio Setticd89b0b2024-01-24 14:24:55 +0100265 'shax', 'mdx',
Valerio Setti20cea942024-01-22 16:23:25 +0100266 # This suite tests builtins directly, but these are missing
267 # in the accelerated case.
268 'psa_crypto_low_hash.generated',
269 ],
270 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200271 'test_suite_config': [
272 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
273 re.compile(r'.*\bMBEDTLS_MD_C\b')
274 ],
Valerio Setti20cea942024-01-22 16:23:25 +0100275 'test_suite_md': [
276 # Builtin HMAC is not supported in the accelerate component.
277 re.compile('.*HMAC.*'),
278 # Following tests make use of functions which are not available
279 # when MD_C is disabled, as it happens in the accelerated
280 # test component.
281 re.compile('generic .* Hash file .*'),
282 'MD list',
283 ],
284 'test_suite_md.psa': [
285 # "legacy only" tests require hash algorithms to be NOT
286 # accelerated, but this of course false for the accelerated
287 # test component.
288 re.compile('PSA dispatch .* legacy only'),
289 ],
290 'test_suite_platform': [
291 # Incompatible with sanitizers (e.g. ASan). If the driver
292 # component uses a sanitizer but the reference component
293 # doesn't, we have a PASS vs SKIP mismatch.
294 'Check mbedtls_calloc overallocation',
295 ],
296 }
297 }
298 },
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100299 'analyze_driver_vs_reference_cipher_aead_cmac': {
Valerio Settib6b301f2023-10-04 12:05:05 +0200300 'test_function': do_analyze_driver_vs_reference,
301 'args': {
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100302 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac',
303 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac',
Valerio Setti507e08f2023-10-26 09:44:06 +0200304 # Modules replaced by drivers.
Valerio Settib6b301f2023-10-04 12:05:05 +0200305 'ignored_suites': [
Valerio Setti507e08f2023-10-26 09:44:06 +0200306 # low-level (block/stream) cipher modules
307 'aes', 'aria', 'camellia', 'des', 'chacha20',
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100308 # AEAD modes and CMAC
Valerio Setti507e08f2023-10-26 09:44:06 +0200309 'ccm', 'chachapoly', 'cmac', 'gcm',
310 # The Cipher abstraction layer
311 'cipher',
Valerio Settib6b301f2023-10-04 12:05:05 +0200312 ],
313 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200314 'test_suite_config': [
315 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
316 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
317 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
318 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
319 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200320 # PEM decryption is not supported so far.
321 # The rest of PEM (write, unencrypted read) works though.
Valerio Setti7448cee2023-10-04 15:46:42 +0200322 'test_suite_pem': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200323 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
Valerio Setti7448cee2023-10-04 15:46:42 +0200324 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100325 'test_suite_platform': [
326 # Incompatible with sanitizers (e.g. ASan). If the driver
327 # component uses a sanitizer but the reference component
328 # doesn't, we have a PASS vs SKIP mismatch.
329 'Check mbedtls_calloc overallocation',
330 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200331 # Following tests depend on AES_C/DES_C but are not about
332 # them really, just need to know some error code is there.
Valerio Setti7448cee2023-10-04 15:46:42 +0200333 'test_suite_error': [
334 'Low and high error',
335 'Single low error'
336 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200337 # Similar to test_suite_error above.
Valerio Setti7448cee2023-10-04 15:46:42 +0200338 'test_suite_version': [
339 'Check for MBEDTLS_AES_C when already present',
Valerio Setti93941442023-10-13 09:19:52 +0200340 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200341 # The en/decryption part of PKCS#12 is not supported so far.
342 # The rest of PKCS#12 (key derivation) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200343 'test_suite_pkcs12': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200344 re.compile(r'PBE Encrypt, .*'),
345 re.compile(r'PBE Decrypt, .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200346 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200347 # The en/decryption part of PKCS#5 is not supported so far.
348 # The rest of PKCS#5 (PBKDF2) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200349 'test_suite_pkcs5': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200350 re.compile(r'PBES2 Encrypt, .*'),
351 re.compile(r'PBES2 Decrypt .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200352 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200353 # Encrypted keys are not supported so far.
Valerio Setti5cd18f92023-10-13 15:14:07 +0200354 # pylint: disable=line-too-long
Valerio Setti93941442023-10-13 09:19:52 +0200355 'test_suite_pkparse': [
356 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
357 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
Pengyu Lva1ddcfa2023-11-28 09:46:01 +0800358 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
Valerio Setti93941442023-10-13 09:19:52 +0200359 ],
Sam Berry60255012024-06-27 14:18:22 +0100360 # Encrypted keys are not supported so far.
361 'ssl-opt': [
362 'TLS: password protected server key',
363 'TLS: password protected client key',
364 'TLS: password protected server key, two certificates',
365 ],
Valerio Settib6b301f2023-10-04 12:05:05 +0200366 }
367 }
368 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200369 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100370 'test_function': do_analyze_driver_vs_reference,
371 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200372 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
373 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100374 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200375 # Modules replaced by drivers
376 'ecdsa', 'ecdh', 'ecjpake',
Valerio Setti42d5f192023-03-20 13:54:41 +0100377 ],
378 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200379 'test_suite_config': [
380 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
381 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100382 'test_suite_platform': [
383 # Incompatible with sanitizers (e.g. ASan). If the driver
384 # component uses a sanitizer but the reference component
385 # doesn't, we have a PASS vs SKIP mismatch.
386 'Check mbedtls_calloc overallocation',
387 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200388 # This test wants a legacy function that takes f_rng, p_rng
389 # arguments, and uses legacy ECDSA for that. The test is
390 # really about the wrapper around the PSA RNG, not ECDSA.
Valerio Setti42d5f192023-03-20 13:54:41 +0100391 'test_suite_random': [
392 'PSA classic wrapper: ECDSA signature (SECP256R1)',
393 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200394 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
395 # so we must ignore disparities in the tests for which ECP_C
396 # is required.
397 'test_suite_ecp': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200398 re.compile(r'ECP check public-private .*'),
Gilles Peskine3b17ae72023-06-23 11:08:39 +0200399 re.compile(r'ECP calculate public: .*'),
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200400 re.compile(r'ECP gen keypair .*'),
401 re.compile(r'ECP point muladd .*'),
402 re.compile(r'ECP point multiplication .*'),
403 re.compile(r'ECP test vectors .*'),
Valerio Setti482a0b92023-08-18 15:55:10 +0200404 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200405 'test_suite_ssl': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200406 # This deprecated function is only present when ECP_C is On.
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200407 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
408 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200409 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100410 }
411 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200412 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200413 'test_function': do_analyze_driver_vs_reference,
414 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200415 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
416 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200417 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200418 # Modules replaced by drivers
419 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
Valerio Settie618cb02023-04-12 14:59:16 +0200420 ],
421 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200422 'test_suite_config': [
423 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
424 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
425 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100426 'test_suite_platform': [
427 # Incompatible with sanitizers (e.g. ASan). If the driver
428 # component uses a sanitizer but the reference component
429 # doesn't, we have a PASS vs SKIP mismatch.
430 'Check mbedtls_calloc overallocation',
431 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200432 # See ecp_light_only
Valerio Settie618cb02023-04-12 14:59:16 +0200433 'test_suite_random': [
434 'PSA classic wrapper: ECDSA signature (SECP256R1)',
435 ],
Valerio Settiaddeee42023-06-14 10:46:55 +0200436 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200437 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
438 # is automatically enabled in build_info.h (backward compatibility)
439 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
440 # consequence compressed points are supported in the reference
441 # component but not in the accelerated one, so they should be skipped
442 # while checking driver's coverage.
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200443 re.compile(r'Parse EC Key .*compressed\)'),
444 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Settiaddeee42023-06-14 10:46:55 +0200445 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200446 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200447 'test_suite_ssl': [
448 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
449 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200450 }
451 }
452 },
Valerio Setti307810b2023-08-15 10:12:25 +0200453 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200454 'test_function': do_analyze_driver_vs_reference,
455 'args': {
456 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
457 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
458 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200459 # Modules replaced by drivers
460 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
461 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
462 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200463 ],
464 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200465 'test_suite_config': [
466 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
467 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
468 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
469 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100470 'test_suite_platform': [
471 # Incompatible with sanitizers (e.g. ASan). If the driver
472 # component uses a sanitizer but the reference component
473 # doesn't, we have a PASS vs SKIP mismatch.
474 'Check mbedtls_calloc overallocation',
475 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200476 # See ecp_light_only
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200477 'test_suite_random': [
478 'PSA classic wrapper: ECDSA signature (SECP256R1)',
479 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200480 # See no_ecp_at_all
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200481 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200482 re.compile(r'Parse EC Key .*compressed\)'),
483 re.compile(r'Parse Public EC Key .*compressed\)'),
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200484 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200485 'test_suite_asn1parse': [
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200486 'INTEGER too large for mpi',
487 ],
488 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200489 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200490 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200491 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200492 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Settie0be95e2023-08-01 09:07:43 +0200493 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200494 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200495 'test_suite_ssl': [
496 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
497 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200498 }
499 }
500 },
Valerio Setti307810b2023-08-15 10:12:25 +0200501 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
502 'test_function': do_analyze_driver_vs_reference,
503 'args': {
504 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
505 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
506 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200507 # Modules replaced by drivers
508 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
509 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
510 'bignum.generated', 'bignum.misc',
Valerio Setti307810b2023-08-15 10:12:25 +0200511 ],
512 'ignored_tests': {
Gilles Peskine89ef2fa2024-04-30 14:25:30 +0200513 'ssl-opt': [
514 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
515 # (because it needs custom groups, which PSA does not
516 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
517 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
518 ],
Gilles Peskine331d7d02024-05-24 09:18:25 +0200519 'test_suite_config': [
520 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
521 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
522 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
523 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
524 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
525 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100526 'test_suite_platform': [
527 # Incompatible with sanitizers (e.g. ASan). If the driver
528 # component uses a sanitizer but the reference component
529 # doesn't, we have a PASS vs SKIP mismatch.
530 'Check mbedtls_calloc overallocation',
531 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200532 # See ecp_light_only
Valerio Setti307810b2023-08-15 10:12:25 +0200533 'test_suite_random': [
534 'PSA classic wrapper: ECDSA signature (SECP256R1)',
535 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200536 # See no_ecp_at_all
Valerio Setti307810b2023-08-15 10:12:25 +0200537 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200538 re.compile(r'Parse EC Key .*compressed\)'),
539 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Setti307810b2023-08-15 10:12:25 +0200540 ],
541 'test_suite_asn1parse': [
Valerio Setti307810b2023-08-15 10:12:25 +0200542 'INTEGER too large for mpi',
543 ],
544 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200545 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200546 ],
547 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200548 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200549 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200550 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200551 'test_suite_ssl': [
552 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
553 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200554 }
555 }
556 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200557 'analyze_driver_vs_reference_ffdh_alg': {
558 'test_function': do_analyze_driver_vs_reference,
559 'args': {
560 'component_ref': 'test_psa_crypto_config_reference_ffdh',
561 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200562 'ignored_suites': ['dhm'],
Gilles Peskine150002c2023-11-27 18:24:45 +0100563 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200564 'test_suite_config': [
565 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
566 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100567 'test_suite_platform': [
568 # Incompatible with sanitizers (e.g. ASan). If the driver
569 # component uses a sanitizer but the reference component
570 # doesn't, we have a PASS vs SKIP mismatch.
571 'Check mbedtls_calloc overallocation',
572 ],
573 }
Przemek Stekiel85b64422023-05-26 09:55:23 +0200574 }
575 },
Valerio Settif01d6482023-08-04 13:51:18 +0200576 'analyze_driver_vs_reference_tfm_config': {
577 'test_function': do_analyze_driver_vs_reference,
578 'args': {
579 'component_ref': 'test_tfm_config',
580 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200581 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200582 # Modules replaced by drivers
Yanray Wang57790962023-10-31 13:39:07 +0800583 'asn1parse', 'asn1write',
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200584 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
585 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
586 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200587 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200588 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200589 'test_suite_config': [
590 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
591 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
592 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
593 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
594 ],
595 'test_suite_config.crypto_combinations': [
596 'Config: ECC: Weierstrass curves only',
597 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100598 'test_suite_platform': [
599 # Incompatible with sanitizers (e.g. ASan). If the driver
600 # component uses a sanitizer but the reference component
601 # doesn't, we have a PASS vs SKIP mismatch.
602 'Check mbedtls_calloc overallocation',
603 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200604 # See ecp_light_only
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200605 'test_suite_random': [
606 'PSA classic wrapper: ECDSA signature (SECP256R1)',
607 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200608 }
609 }
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800610 },
611 'analyze_driver_vs_reference_rsa': {
612 'test_function': do_analyze_driver_vs_reference,
613 'args': {
614 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto',
615 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto',
616 'ignored_suites': [
617 # Modules replaced by drivers.
618 'rsa', 'pkcs1_v15', 'pkcs1_v21',
Pengyu Lv98a90c62023-12-07 17:23:25 +0800619 # We temporarily don't care about PK stuff.
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800620 'pk', 'pkwrite', 'pkparse'
621 ],
622 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200623 'test_suite_config': [
624 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
625 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
626 ],
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800627 'test_suite_platform': [
628 # Incompatible with sanitizers (e.g. ASan). If the driver
629 # component uses a sanitizer but the reference component
630 # doesn't, we have a PASS vs SKIP mismatch.
631 'Check mbedtls_calloc overallocation',
632 ],
633 # Following tests depend on RSA_C but are not about
634 # them really, just need to know some error code is there.
635 'test_suite_error': [
636 'Low and high error',
637 'Single high error'
638 ],
639 # Constant time operations only used for PKCS1_V15
640 'test_suite_constant_time': [
641 re.compile(r'mbedtls_ct_zeroize_if .*'),
642 re.compile(r'mbedtls_ct_memmove_left .*')
643 ],
Gilles Peskine63072b12024-02-15 11:48:58 +0100644 'test_suite_psa_crypto': [
Gilles Peskine472c10f2024-06-07 11:26:53 +0200645 # We don't support generate_key_custom entry points
Gilles Peskine63072b12024-02-15 11:48:58 +0100646 # in drivers yet.
Gilles Peskine472c10f2024-06-07 11:26:53 +0200647 re.compile(r'PSA generate key custom: RSA, e=.*'),
Gilles Peskine63072b12024-02-15 11:48:58 +0100648 re.compile(r'PSA generate key ext: RSA, e=.*'),
649 ],
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800650 }
651 }
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100652 },
653 'analyze_block_cipher_dispatch': {
654 'test_function': do_analyze_driver_vs_reference,
655 'args': {
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100656 'component_ref': 'test_full_block_cipher_legacy_dispatch',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100657 'component_driver': 'test_full_block_cipher_psa_dispatch',
658 'ignored_suites': [
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100659 # Skipped in the accelerated component
660 'aes', 'aria', 'camellia',
Valerio Setti0635cca2023-12-28 16:16:02 +0100661 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
662 # order for the cipher module (actually cipher_wrapper) to work
663 # properly. However these symbols are disabled in the accelerated
664 # component so we ignore them.
Valerio Settia0c9c662023-12-29 14:14:11 +0100665 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
Valerio Setti0635cca2023-12-28 16:16:02 +0100666 'cipher.camellia',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100667 ],
668 'ignored_tests': {
Gilles Peskine331d7d02024-05-24 09:18:25 +0200669 'test_suite_config': [
670 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
671 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
672 ],
Valerio Settia0c9c662023-12-29 14:14:11 +0100673 'test_suite_cmac': [
674 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
675 # but these are not available in the accelerated component.
676 'CMAC null arguments',
677 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
678 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100679 'test_suite_cipher.padding': [
680 # Following tests require AES_C/CAMELLIA_C to be enabled,
681 # but these are not available in the accelerated component.
682 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100683 ],
Ryan Everettafb2eee2024-02-08 14:31:54 +0000684 'test_suite_pkcs5': [
Ryan Everett67f35682024-02-09 13:02:23 +0000685 # The AES part of PKCS#5 PBES2 is not yet supported.
Ryan Everettafb2eee2024-02-08 14:31:54 +0000686 # The rest of PKCS#5 (PBKDF2) works, though.
Ryan Everett67f35682024-02-09 13:02:23 +0000687 re.compile(r'PBES2 .* AES-.*')
Ryan Everettafb2eee2024-02-08 14:31:54 +0000688 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100689 'test_suite_pkparse': [
690 # PEM (called by pkparse) requires AES_C in order to decrypt
691 # the key, but this is not available in the accelerated
692 # component.
693 re.compile('Parse RSA Key.*(password|AES-).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100694 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100695 'test_suite_pem': [
696 # Following tests require AES_C, but this is diabled in the
697 # accelerated component.
Valerio Settieba4ca12024-02-19 07:42:18 +0100698 re.compile('PEM read .*AES.*'),
Valerio Setti0635cca2023-12-28 16:16:02 +0100699 'PEM read (unknown encryption algorithm)',
Valerio Setti5f665c32023-12-20 09:56:05 +0100700 ],
701 'test_suite_error': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100702 # Following tests depend on AES_C but are not about them
703 # really, just need to know some error code is there.
Valerio Setti5f665c32023-12-20 09:56:05 +0100704 'Single low error',
705 'Low and high error',
706 ],
707 'test_suite_version': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100708 # Similar to test_suite_error above.
Valerio Setti5f665c32023-12-20 09:56:05 +0100709 'Check for MBEDTLS_AES_C when already present',
710 ],
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100711 'test_suite_platform': [
712 # Incompatible with sanitizers (e.g. ASan). If the driver
713 # component uses a sanitizer but the reference component
714 # doesn't, we have a PASS vs SKIP mismatch.
715 'Check mbedtls_calloc overallocation',
716 ],
717 }
718 }
Valerio Settif01d6482023-08-04 13:51:18 +0200719 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200720}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200721
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200722def main():
Valerio Settif075e472023-10-17 11:03:16 +0200723 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200724
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200725 try:
726 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200727 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200728 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200729 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100730 help='Analysis to be done. By default, run all tasks. '
731 'With one or more TASK, run only those. '
732 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100733 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100734 parser.add_argument('--list', action='store_true',
735 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100736 parser.add_argument('--require-full-coverage', action='store_true',
737 dest='full_coverage', help="Require all available "
738 "test cases to be executed and issue an error "
739 "otherwise. This flag is ignored if 'task' is "
740 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200741 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200742
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100743 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200744 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200745 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100746 sys.exit(0)
747
Valerio Settidfd7ca62023-10-09 16:30:11 +0200748 if options.specified_tasks == 'all':
749 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100750 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200751 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200752 for task in tasks_list:
753 if task not in KNOWN_TASKS:
Manuel Pégourié-Gonnard62d61312023-10-20 10:51:57 +0200754 sys.stderr.write('invalid task: {}\n'.format(task))
Valerio Settifb2750e2023-10-17 10:11:45 +0200755 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100756
Valerio Settidfd7ca62023-10-09 16:30:11 +0200757 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100758
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800759 # If the outcome file exists, parse it once and share the result
760 # among tasks to improve performance.
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800761 # Otherwise, it will be generated by execute_reference_driver_tests.
762 if not os.path.exists(options.outcomes):
763 if len(tasks_list) > 1:
764 sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n")
765 sys.exit(2)
766
767 task_name = tasks_list[0]
768 task = KNOWN_TASKS[task_name]
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800769 if task['test_function'] != do_analyze_driver_vs_reference: # pylint: disable=comparison-with-callable
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800770 sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
771 sys.exit(2)
772
773 execute_reference_driver_tests(main_results,
774 task['args']['component_ref'],
775 task['args']['component_driver'],
776 options.outcomes)
777
778 outcomes = read_outcome_file(options.outcomes)
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800779
Valerio Settifb2750e2023-10-17 10:11:45 +0200780 for task in tasks_list:
781 test_function = KNOWN_TASKS[task]['test_function']
782 test_args = KNOWN_TASKS[task]['args']
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800783 test_function(main_results, outcomes, test_args)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100784
Valerio Settif6f64cf2023-10-17 12:28:26 +0200785 main_results.info("Overall results: {} warnings and {} errors",
786 main_results.warning_count, main_results.error_count)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200787
Valerio Setti8d178be2023-10-17 12:23:55 +0200788 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200789
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200790 except Exception: # pylint: disable=broad-except
791 # Print the backtrace and exit explicitly with our chosen status.
792 traceback.print_exc()
793 sys.exit(120)
794
795if __name__ == '__main__':
796 main()