blob: 076a29d7385dff5f3528fd45a63b8083be4422e7 [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',
Gilles Peskine2ad2f322024-05-22 09:35:11 +020093 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
94 check=False)
Gilles Peskine78ae4f62024-05-21 20:26:18 +020095 if cp.returncode != 0:
96 sys.stderr.write(cp.stdout.decode('utf-8'))
Gilles Peskine2ad2f322024-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
Gilles Peskine82b16722024-09-16 19:57:10 +0200117IgnoreEntry = typing.Union[str, typing.Pattern]
118
119def name_matches_pattern(name: str, str_or_re: IgnoreEntry) -> bool:
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200120 """Check if name matches a pattern, that may be a string or regex.
121 - If the pattern is a string, name must be equal to match.
122 - If the pattern is a regex, name must fully match.
123 """
Manuel Pégourié-Gonnardb2695432023-10-23 09:30:40 +0200124 # The CI's python is too old for re.Pattern
125 #if isinstance(str_or_re, re.Pattern):
126 if not isinstance(str_or_re, str):
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800127 return str_or_re.fullmatch(name) is not None
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200128 else:
Manuel Pégourié-Gonnard9d9c2342023-10-26 09:37:40 +0200129 return str_or_re == name
Manuel Pégourié-Gonnard881ce012023-10-18 10:22:07 +0200130
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800131def analyze_driver_vs_reference(results: Results, outcomes: Outcomes,
132 component_ref: str, component_driver: str,
133 ignored_suites: typing.List[str], ignored_tests=None) -> None:
Sam Berrye262c232024-06-21 10:03:37 +0100134 """Check that all tests passing in the driver component are also
135 passing in the corresponding reference component.
Valerio Setti3002c992023-01-18 17:28:36 +0100136 Skip:
137 - full test suites provided in ignored_suites list
138 - only some specific test inside a test suite, for which the corresponding
139 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200140 """
Pengyu Lva4428582023-11-22 19:02:15 +0800141 ref_outcomes = outcomes.get("component_" + component_ref)
142 driver_outcomes = outcomes.get("component_" + component_driver)
143
Pengyu Lv59b9efc2023-11-28 11:15:00 +0800144 if ref_outcomes is None or driver_outcomes is None:
145 results.error("required components are missing: bad outcome file?")
146 return
147
Pengyu Lv18908ec2023-11-28 12:11:52 +0800148 if not ref_outcomes.successes:
Pengyu Lva4428582023-11-22 19:02:15 +0800149 results.error("no passing test in reference component: bad outcome file?")
150 return
151
Pengyu Lv18908ec2023-11-28 12:11:52 +0800152 for suite_case in ref_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800153 # suite_case is like "test_suite_foo.bar;Description of test case"
154 (full_test_suite, test_string) = suite_case.split(';')
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100155 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200156
157 # Immediately skip fully-ignored test suites
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100158 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100159 continue
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200160
161 # For ignored test cases inside test suites, just remember and:
162 # don't issue an error if they're skipped with drivers,
163 # but issue an error if they're not (means we have a bad entry).
164 ignored = False
Gilles Peskinea7469d32024-05-24 09:18:25 +0200165 for str_or_re in (ignored_tests.get(full_test_suite, []) +
166 ignored_tests.get(test_suite, [])):
167 if name_matches_pattern(test_string, str_or_re):
168 ignored = True
Manuel Pégourié-Gonnard4da369f2023-10-18 09:40:32 +0200169
Pengyu Lv18908ec2023-11-28 12:11:52 +0800170 if not ignored and not suite_case in driver_outcomes.successes:
Elena Uziunaitec21675e2024-09-02 15:32:07 +0100171 results.error("SKIP/FAIL -> PASS: {}", suite_case)
Pengyu Lv18908ec2023-11-28 12:11:52 +0800172 if ignored and suite_case in driver_outcomes.successes:
Pengyu Lv31a9b782023-11-23 14:15:37 +0800173 results.error("uselessly ignored: {}", suite_case)
Manuel Pégourié-Gonnard371165a2023-10-18 12:44:54 +0200174
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800175def read_outcome_file(outcome_file: str) -> Outcomes:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200176 """Parse an outcome file and return an outcome collection.
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +0800177 """
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200178 outcomes = {}
179 with open(outcome_file, 'r', encoding='utf-8') as input_file:
180 for line in input_file:
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800181 (_platform, component, suite, case, result, _cause) = line.split(';')
Pengyu Lv451ec8a2023-11-28 17:59:05 +0800182 # Note that `component` is not unique. If a test case passes on Linux
183 # and fails on FreeBSD, it'll end up in both the successes set and
184 # the failures set.
Pengyu Lv31a9b782023-11-23 14:15:37 +0800185 suite_case = ';'.join([suite, case])
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800186 if component not in outcomes:
Pengyu Lv18908ec2023-11-28 12:11:52 +0800187 outcomes[component] = ComponentOutcomes(set(), set())
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200188 if result == 'PASS':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800189 outcomes[component].successes.add(suite_case)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200190 elif result == 'FAIL':
Pengyu Lv18908ec2023-11-28 12:11:52 +0800191 outcomes[component].failures.add(suite_case)
Pengyu Lva4428582023-11-22 19:02:15 +0800192
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200193 return outcomes
194
Gilles Peskine19ef1ae2024-09-16 19:12:09 +0200195
196class Task:
197 """Base class for outcome analysis tasks."""
198
199 def __init__(self, options) -> None:
200 """Pass command line options to the tasks.
201
202 Each task decides which command line options it cares about.
203 """
204 pass
205
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200206 def section_name(self) -> str:
207 """The section name to use in results."""
208
Gilles Peskine19ef1ae2024-09-16 19:12:09 +0200209 def run(self, results: Results, outcomes: Outcomes):
210 """Run the analysis on the specified outcomes.
211
212 Signal errors via the results objects
213 """
214 raise NotImplementedError
215
216
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200217class CoverageTask(Task):
218 """Analyze test coverage."""
219
220 ALLOW_LIST = [
221 # Algorithm not supported yet
222 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
223 # Algorithm not supported yet
224 'test_suite_psa_crypto_metadata;Cipher: XTS',
225 ]
226
227 def __init__(self, options) -> None:
228 super().__init__(options)
229 self.full_coverage = options.full_coverage #type: bool
230
231 @staticmethod
232 def section_name() -> str:
233 return "Analyze coverage"
234
235 def run(self, results: Results, outcomes: Outcomes):
236 """Check that all test cases are executed at least once."""
237 analyze_coverage(results, outcomes,
238 self.ALLOW_LIST, self.full_coverage)
239
240
Gilles Peskine82b16722024-09-16 19:57:10 +0200241class DriverVSReference(Task):
242 """Compare outcomes from testing with and without a driver.
243
244 There are 2 options to use analyze_driver_vs_reference_xxx locally:
245 1. Run tests and then analysis:
246 - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
247 - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
248 2. Let this script run both automatically:
249 - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
250 """
251
252 # Override the following in child classes.
253 # Configuration name (all.sh component) used as the reference.
254 REFERENCE = ''
255 # Configuration name (all.sh component) used as the driver.
256 DRIVER = ''
257 # Ignored test suites (without the test_suite_ prefix).
258 IGNORED_SUITES = [] #type: typing.List[str]
259 # Map test suite names (with the test_suite_prefix) to a list of ignored
260 # test cases. Each element in the list can be either a string or a regex;
261 # see the `name_matches_pattern` function.
262 IGNORED_TESTS = {} #type: typing.Dict[str, typing.List[IgnoreEntry]]
263
264 def section_name(self) -> str:
265 return f"Analyze driver {self.DRIVER} vs reference {self.REFERENCE}"
266
267 def run(self, results: Results, outcomes: Outcomes) -> None:
268 """Compare driver test outcomes with reference outcomes."""
269 ignored_suites = ['test_suite_' + x for x in self.IGNORED_SUITES]
270 analyze_driver_vs_reference(results, outcomes,
271 self.REFERENCE, self.DRIVER,
272 ignored_suites, self.IGNORED_TESTS)
273
274
275def driver_vs_reference_factory(name: str,
276 args: typing.Dict[str, typing.Any]
277 ) -> typing.Type[DriverVSReference]:
278 """Build a driver-vs-reference class from dynamic data."""
279 return type('Drivervsreference_' + name,
280 (DriverVSReference,),
281 {
282 'REFERENCE': args['component_ref'],
283 'DRIVER': args['component_driver'],
284 'IGNORED_SUITES': args['ignored_suites'],
285 'IGNORED_TESTS': args['ignored_tests'],
286 })
287
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100288# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200289KNOWN_TASKS = {
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200290 'analyze_coverage': CoverageTask,
291
Gilles Peskine82b16722024-09-16 19:57:10 +0200292 'analyze_driver_vs_reference_hash': driver_vs_reference_factory('hash', {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100293 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
294 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100295 'ignored_suites': [
296 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100297 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200298 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100299 ],
300 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200301 'test_suite_config': [
302 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
303 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100304 'test_suite_platform': [
305 # Incompatible with sanitizers (e.g. ASan). If the driver
306 # component uses a sanitizer but the reference component
307 # doesn't, we have a PASS vs SKIP mismatch.
308 'Check mbedtls_calloc overallocation',
309 ],
Valerio Setti3002c992023-01-18 17:28:36 +0100310 }
311 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200312 ),
313 'analyze_driver_vs_reference_hmac': driver_vs_reference_factory('hmac', {
Valerio Setti20cea942024-01-22 16:23:25 +0100314 'component_ref': 'test_psa_crypto_config_reference_hmac',
315 'component_driver': 'test_psa_crypto_config_accel_hmac',
316 'ignored_suites': [
Valerio Setticd89b0b2024-01-24 14:24:55 +0100317 # These suites require legacy hash support, which is disabled
Valerio Setti89d8a122024-01-26 15:04:05 +0100318 # in the accelerated component.
Valerio Setticd89b0b2024-01-24 14:24:55 +0100319 'shax', 'mdx',
Valerio Setti20cea942024-01-22 16:23:25 +0100320 # This suite tests builtins directly, but these are missing
321 # in the accelerated case.
322 'psa_crypto_low_hash.generated',
323 ],
324 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200325 'test_suite_config': [
326 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
327 re.compile(r'.*\bMBEDTLS_MD_C\b')
328 ],
Valerio Setti20cea942024-01-22 16:23:25 +0100329 'test_suite_md': [
330 # Builtin HMAC is not supported in the accelerate component.
331 re.compile('.*HMAC.*'),
332 # Following tests make use of functions which are not available
333 # when MD_C is disabled, as it happens in the accelerated
334 # test component.
335 re.compile('generic .* Hash file .*'),
336 'MD list',
337 ],
338 'test_suite_md.psa': [
339 # "legacy only" tests require hash algorithms to be NOT
340 # accelerated, but this of course false for the accelerated
341 # test component.
342 re.compile('PSA dispatch .* legacy only'),
343 ],
344 'test_suite_platform': [
345 # Incompatible with sanitizers (e.g. ASan). If the driver
346 # component uses a sanitizer but the reference component
347 # doesn't, we have a PASS vs SKIP mismatch.
348 'Check mbedtls_calloc overallocation',
349 ],
350 }
351 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200352 ),
353 'analyze_driver_vs_reference_cipher_aead_cmac': driver_vs_reference_factory('cipher_aead_cmac', {
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100354 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac',
355 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac',
Valerio Setti507e08f2023-10-26 09:44:06 +0200356 # Modules replaced by drivers.
Valerio Settib6b301f2023-10-04 12:05:05 +0200357 'ignored_suites': [
Valerio Setti507e08f2023-10-26 09:44:06 +0200358 # low-level (block/stream) cipher modules
359 'aes', 'aria', 'camellia', 'des', 'chacha20',
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +0100360 # AEAD modes and CMAC
Valerio Setti507e08f2023-10-26 09:44:06 +0200361 'ccm', 'chachapoly', 'cmac', 'gcm',
362 # The Cipher abstraction layer
363 'cipher',
Valerio Settib6b301f2023-10-04 12:05:05 +0200364 ],
365 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200366 'test_suite_config': [
367 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
368 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
369 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
370 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
371 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200372 # PEM decryption is not supported so far.
373 # The rest of PEM (write, unencrypted read) works though.
Valerio Setti7448cee2023-10-04 15:46:42 +0200374 'test_suite_pem': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200375 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
Valerio Setti7448cee2023-10-04 15:46:42 +0200376 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100377 'test_suite_platform': [
378 # Incompatible with sanitizers (e.g. ASan). If the driver
379 # component uses a sanitizer but the reference component
380 # doesn't, we have a PASS vs SKIP mismatch.
381 'Check mbedtls_calloc overallocation',
382 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200383 # Following tests depend on AES_C/DES_C but are not about
384 # them really, just need to know some error code is there.
Valerio Setti7448cee2023-10-04 15:46:42 +0200385 'test_suite_error': [
386 'Low and high error',
387 'Single low error'
388 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200389 # Similar to test_suite_error above.
Valerio Setti7448cee2023-10-04 15:46:42 +0200390 'test_suite_version': [
391 'Check for MBEDTLS_AES_C when already present',
Valerio Setti93941442023-10-13 09:19:52 +0200392 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200393 # The en/decryption part of PKCS#12 is not supported so far.
394 # The rest of PKCS#12 (key derivation) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200395 'test_suite_pkcs12': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200396 re.compile(r'PBE Encrypt, .*'),
397 re.compile(r'PBE Decrypt, .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200398 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200399 # The en/decryption part of PKCS#5 is not supported so far.
400 # The rest of PKCS#5 (PBKDF2) works though.
Valerio Setti93941442023-10-13 09:19:52 +0200401 'test_suite_pkcs5': [
Manuel Pégourié-Gonnardcd84a292023-10-27 09:24:44 +0200402 re.compile(r'PBES2 Encrypt, .*'),
403 re.compile(r'PBES2 Decrypt .*'),
Valerio Setti93941442023-10-13 09:19:52 +0200404 ],
Valerio Setti507e08f2023-10-26 09:44:06 +0200405 # Encrypted keys are not supported so far.
Valerio Setti5cd18f92023-10-13 15:14:07 +0200406 # pylint: disable=line-too-long
Valerio Setti93941442023-10-13 09:19:52 +0200407 'test_suite_pkparse': [
408 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
409 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
Pengyu Lva1ddcfa2023-11-28 09:46:01 +0800410 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
Valerio Setti93941442023-10-13 09:19:52 +0200411 ],
Sam Berry4beeb0c2024-06-27 14:18:22 +0100412 # Encrypted keys are not supported so far.
413 'ssl-opt': [
414 'TLS: password protected server key',
415 'TLS: password protected client key',
416 'TLS: password protected server key, two certificates',
417 ],
Valerio Settib6b301f2023-10-04 12:05:05 +0200418 }
419 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200420 ),
421 'analyze_driver_vs_reference_ecp_light_only': driver_vs_reference_factory('ecp_light_only', {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200422 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
423 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100424 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200425 # Modules replaced by drivers
426 'ecdsa', 'ecdh', 'ecjpake',
Valerio Setti42d5f192023-03-20 13:54:41 +0100427 ],
428 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200429 'test_suite_config': [
430 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
431 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100432 'test_suite_platform': [
433 # Incompatible with sanitizers (e.g. ASan). If the driver
434 # component uses a sanitizer but the reference component
435 # doesn't, we have a PASS vs SKIP mismatch.
436 'Check mbedtls_calloc overallocation',
437 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200438 # This test wants a legacy function that takes f_rng, p_rng
439 # arguments, and uses legacy ECDSA for that. The test is
440 # really about the wrapper around the PSA RNG, not ECDSA.
Valerio Setti42d5f192023-03-20 13:54:41 +0100441 'test_suite_random': [
442 'PSA classic wrapper: ECDSA signature (SECP256R1)',
443 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200444 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
445 # so we must ignore disparities in the tests for which ECP_C
446 # is required.
447 'test_suite_ecp': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200448 re.compile(r'ECP check public-private .*'),
Gilles Peskine3b17ae72023-06-23 11:08:39 +0200449 re.compile(r'ECP calculate public: .*'),
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200450 re.compile(r'ECP gen keypair .*'),
451 re.compile(r'ECP point muladd .*'),
452 re.compile(r'ECP point multiplication .*'),
453 re.compile(r'ECP test vectors .*'),
Valerio Setti482a0b92023-08-18 15:55:10 +0200454 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200455 'test_suite_ssl': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200456 # This deprecated function is only present when ECP_C is On.
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200457 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
458 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200459 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100460 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200461 ),
462 'analyze_driver_vs_reference_no_ecp_at_all': driver_vs_reference_factory('no_ecp_at_all', {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200463 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
464 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200465 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200466 # Modules replaced by drivers
467 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
Valerio Settie618cb02023-04-12 14:59:16 +0200468 ],
469 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200470 'test_suite_config': [
471 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
472 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
473 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100474 'test_suite_platform': [
475 # Incompatible with sanitizers (e.g. ASan). If the driver
476 # component uses a sanitizer but the reference component
477 # doesn't, we have a PASS vs SKIP mismatch.
478 'Check mbedtls_calloc overallocation',
479 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200480 # See ecp_light_only
Valerio Settie618cb02023-04-12 14:59:16 +0200481 'test_suite_random': [
482 'PSA classic wrapper: ECDSA signature (SECP256R1)',
483 ],
Valerio Settiaddeee42023-06-14 10:46:55 +0200484 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200485 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
486 # is automatically enabled in build_info.h (backward compatibility)
487 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
488 # consequence compressed points are supported in the reference
489 # component but not in the accelerated one, so they should be skipped
490 # while checking driver's coverage.
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200491 re.compile(r'Parse EC Key .*compressed\)'),
492 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Settiaddeee42023-06-14 10:46:55 +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 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200498 }
499 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200500 ),
501 'analyze_driver_vs_reference_ecc_no_bignum': driver_vs_reference_factory('ecc_no_bignum', {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200502 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
503 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
504 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200505 # Modules replaced by drivers
506 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
507 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
508 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200509 ],
510 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200511 'test_suite_config': [
512 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
513 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
514 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
515 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100516 'test_suite_platform': [
517 # Incompatible with sanitizers (e.g. ASan). If the driver
518 # component uses a sanitizer but the reference component
519 # doesn't, we have a PASS vs SKIP mismatch.
520 'Check mbedtls_calloc overallocation',
521 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200522 # See ecp_light_only
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200523 'test_suite_random': [
524 'PSA classic wrapper: ECDSA signature (SECP256R1)',
525 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200526 # See no_ecp_at_all
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200527 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200528 re.compile(r'Parse EC Key .*compressed\)'),
529 re.compile(r'Parse Public EC Key .*compressed\)'),
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200530 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200531 'test_suite_asn1parse': [
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200532 'INTEGER too large for mpi',
533 ],
534 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200535 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200536 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200537 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200538 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Settie0be95e2023-08-01 09:07:43 +0200539 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200540 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200541 'test_suite_ssl': [
542 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
543 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200544 }
545 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200546 ),
547 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': driver_vs_reference_factory('ecc_ffdh_no_bignum', {
Valerio Setti307810b2023-08-15 10:12:25 +0200548 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
549 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
550 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200551 # Modules replaced by drivers
552 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
553 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
554 'bignum.generated', 'bignum.misc',
Valerio Setti307810b2023-08-15 10:12:25 +0200555 ],
556 'ignored_tests': {
Gilles Peskineff3b8212024-04-30 14:25:30 +0200557 'ssl-opt': [
558 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
559 # (because it needs custom groups, which PSA does not
560 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
561 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
562 ],
Gilles Peskinea7469d32024-05-24 09:18:25 +0200563 'test_suite_config': [
564 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
565 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
566 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
567 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
568 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
569 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100570 'test_suite_platform': [
571 # Incompatible with sanitizers (e.g. ASan). If the driver
572 # component uses a sanitizer but the reference component
573 # doesn't, we have a PASS vs SKIP mismatch.
574 'Check mbedtls_calloc overallocation',
575 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200576 # See ecp_light_only
Valerio Setti307810b2023-08-15 10:12:25 +0200577 'test_suite_random': [
578 'PSA classic wrapper: ECDSA signature (SECP256R1)',
579 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200580 # See no_ecp_at_all
Valerio Setti307810b2023-08-15 10:12:25 +0200581 'test_suite_pkparse': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200582 re.compile(r'Parse EC Key .*compressed\)'),
583 re.compile(r'Parse Public EC Key .*compressed\)'),
Valerio Setti307810b2023-08-15 10:12:25 +0200584 ],
585 'test_suite_asn1parse': [
Valerio Setti307810b2023-08-15 10:12:25 +0200586 'INTEGER too large for mpi',
587 ],
588 'test_suite_asn1write': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200589 re.compile(r'ASN.1 Write mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200590 ],
591 'test_suite_debug': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200592 re.compile(r'Debug print mbedtls_mpi.*'),
Valerio Setti307810b2023-08-15 10:12:25 +0200593 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200594 # See ecp_light_only
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200595 'test_suite_ssl': [
596 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
597 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200598 }
599 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200600 ),
601 'analyze_driver_vs_reference_ffdh_alg': driver_vs_reference_factory('ffdh_alg', {
Przemek Stekiel85b64422023-05-26 09:55:23 +0200602 'component_ref': 'test_psa_crypto_config_reference_ffdh',
603 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200604 'ignored_suites': ['dhm'],
Gilles Peskine150002c2023-11-27 18:24:45 +0100605 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200606 'test_suite_config': [
607 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
608 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100609 'test_suite_platform': [
610 # Incompatible with sanitizers (e.g. ASan). If the driver
611 # component uses a sanitizer but the reference component
612 # doesn't, we have a PASS vs SKIP mismatch.
613 'Check mbedtls_calloc overallocation',
614 ],
615 }
Przemek Stekiel85b64422023-05-26 09:55:23 +0200616 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200617 ),
618 'analyze_driver_vs_reference_tfm_config': driver_vs_reference_factory('tfm_config', {
Gilles Peskineeffa6a02024-09-14 11:35:36 +0200619 'component_ref': 'test_tfm_config_no_p256m',
Valerio Settif01d6482023-08-04 13:51:18 +0200620 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200621 'ignored_suites': [
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200622 # Modules replaced by drivers
Yanray Wang57790962023-10-31 13:39:07 +0800623 'asn1parse', 'asn1write',
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200624 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
625 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
626 'bignum.generated', 'bignum.misc',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200627 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200628 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200629 'test_suite_config': [
630 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
631 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
632 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
633 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
634 ],
635 'test_suite_config.crypto_combinations': [
636 'Config: ECC: Weierstrass curves only',
637 ],
Gilles Peskine150002c2023-11-27 18:24:45 +0100638 'test_suite_platform': [
639 # Incompatible with sanitizers (e.g. ASan). If the driver
640 # component uses a sanitizer but the reference component
641 # doesn't, we have a PASS vs SKIP mismatch.
642 'Check mbedtls_calloc overallocation',
643 ],
Manuel Pégourié-Gonnard4fd5a6a2023-10-20 10:21:09 +0200644 # See ecp_light_only
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200645 'test_suite_random': [
646 'PSA classic wrapper: ECDSA signature (SECP256R1)',
647 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200648 }
649 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200650 ),
651 'analyze_driver_vs_reference_rsa': driver_vs_reference_factory('rsa', {
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800652 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto',
653 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto',
654 'ignored_suites': [
655 # Modules replaced by drivers.
656 'rsa', 'pkcs1_v15', 'pkcs1_v21',
Pengyu Lv98a90c62023-12-07 17:23:25 +0800657 # We temporarily don't care about PK stuff.
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800658 'pk', 'pkwrite', 'pkparse'
659 ],
660 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200661 'test_suite_config': [
662 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
663 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
664 ],
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800665 'test_suite_platform': [
666 # Incompatible with sanitizers (e.g. ASan). If the driver
667 # component uses a sanitizer but the reference component
668 # doesn't, we have a PASS vs SKIP mismatch.
669 'Check mbedtls_calloc overallocation',
670 ],
671 # Following tests depend on RSA_C but are not about
672 # them really, just need to know some error code is there.
673 'test_suite_error': [
674 'Low and high error',
675 'Single high error'
676 ],
677 # Constant time operations only used for PKCS1_V15
678 'test_suite_constant_time': [
679 re.compile(r'mbedtls_ct_zeroize_if .*'),
680 re.compile(r'mbedtls_ct_memmove_left .*')
681 ],
Gilles Peskine63072b12024-02-15 11:48:58 +0100682 'test_suite_psa_crypto': [
Gilles Peskine1084e8e2024-06-07 11:26:53 +0200683 # We don't support generate_key_custom entry points
Gilles Peskine63072b12024-02-15 11:48:58 +0100684 # in drivers yet.
Gilles Peskine1084e8e2024-06-07 11:26:53 +0200685 re.compile(r'PSA generate key custom: RSA, e=.*'),
Gilles Peskine63072b12024-02-15 11:48:58 +0100686 re.compile(r'PSA generate key ext: RSA, e=.*'),
687 ],
Pengyu Lv3cd16c42023-12-06 18:17:39 +0800688 }
689 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200690 ),
691 'analyze_block_cipher_dispatch': driver_vs_reference_factory('block_cipher_dispatch', {
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100692 'component_ref': 'test_full_block_cipher_legacy_dispatch',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100693 'component_driver': 'test_full_block_cipher_psa_dispatch',
694 'ignored_suites': [
Valerio Setti4a8ef7c2023-12-19 11:16:27 +0100695 # Skipped in the accelerated component
696 'aes', 'aria', 'camellia',
Valerio Setti0635cca2023-12-28 16:16:02 +0100697 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
698 # order for the cipher module (actually cipher_wrapper) to work
699 # properly. However these symbols are disabled in the accelerated
700 # component so we ignore them.
Valerio Settia0c9c662023-12-29 14:14:11 +0100701 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
Valerio Setti0635cca2023-12-28 16:16:02 +0100702 'cipher.camellia',
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100703 ],
704 'ignored_tests': {
Gilles Peskinea7469d32024-05-24 09:18:25 +0200705 'test_suite_config': [
706 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
707 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
708 ],
Valerio Settia0c9c662023-12-29 14:14:11 +0100709 'test_suite_cmac': [
710 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
711 # but these are not available in the accelerated component.
712 'CMAC null arguments',
713 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
714 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100715 'test_suite_cipher.padding': [
716 # Following tests require AES_C/CAMELLIA_C to be enabled,
717 # but these are not available in the accelerated component.
718 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100719 ],
Ryan Everettafb2eee2024-02-08 14:31:54 +0000720 'test_suite_pkcs5': [
Ryan Everett67f35682024-02-09 13:02:23 +0000721 # The AES part of PKCS#5 PBES2 is not yet supported.
Ryan Everettafb2eee2024-02-08 14:31:54 +0000722 # The rest of PKCS#5 (PBKDF2) works, though.
Ryan Everett67f35682024-02-09 13:02:23 +0000723 re.compile(r'PBES2 .* AES-.*')
Ryan Everettafb2eee2024-02-08 14:31:54 +0000724 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100725 'test_suite_pkparse': [
726 # PEM (called by pkparse) requires AES_C in order to decrypt
727 # the key, but this is not available in the accelerated
728 # component.
729 re.compile('Parse RSA Key.*(password|AES-).*'),
Valerio Setti5f665c32023-12-20 09:56:05 +0100730 ],
Valerio Setti0635cca2023-12-28 16:16:02 +0100731 'test_suite_pem': [
732 # Following tests require AES_C, but this is diabled in the
733 # accelerated component.
Valerio Settieba4ca12024-02-19 07:42:18 +0100734 re.compile('PEM read .*AES.*'),
Valerio Setti0635cca2023-12-28 16:16:02 +0100735 'PEM read (unknown encryption algorithm)',
Valerio Setti5f665c32023-12-20 09:56:05 +0100736 ],
737 'test_suite_error': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100738 # Following tests depend on AES_C but are not about them
739 # really, just need to know some error code is there.
Valerio Setti5f665c32023-12-20 09:56:05 +0100740 'Single low error',
741 'Low and high error',
742 ],
743 'test_suite_version': [
Valerio Settiab0494f2023-12-28 13:56:13 +0100744 # Similar to test_suite_error above.
Valerio Setti5f665c32023-12-20 09:56:05 +0100745 'Check for MBEDTLS_AES_C when already present',
746 ],
Valerio Setti52ab8fa2023-12-14 18:04:04 +0100747 'test_suite_platform': [
748 # Incompatible with sanitizers (e.g. ASan). If the driver
749 # component uses a sanitizer but the reference component
750 # doesn't, we have a PASS vs SKIP mismatch.
751 'Check mbedtls_calloc overallocation',
752 ],
753 }
754 }
Gilles Peskine82b16722024-09-16 19:57:10 +0200755 ),
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200756}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200757
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200758def main():
Valerio Settif075e472023-10-17 11:03:16 +0200759 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200760
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200761 try:
762 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200763 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200764 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200765 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100766 help='Analysis to be done. By default, run all tasks. '
767 'With one or more TASK, run only those. '
768 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100769 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100770 parser.add_argument('--list', action='store_true',
771 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100772 parser.add_argument('--require-full-coverage', action='store_true',
773 dest='full_coverage', help="Require all available "
774 "test cases to be executed and issue an error "
775 "otherwise. This flag is ignored if 'task' is "
776 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200777 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200778
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100779 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200780 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200781 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100782 sys.exit(0)
783
Valerio Settidfd7ca62023-10-09 16:30:11 +0200784 if options.specified_tasks == 'all':
785 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100786 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200787 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200788 for task in tasks_list:
789 if task not in KNOWN_TASKS:
Manuel Pégourié-Gonnard62d61312023-10-20 10:51:57 +0200790 sys.stderr.write('invalid task: {}\n'.format(task))
Valerio Settifb2750e2023-10-17 10:11:45 +0200791 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100792
Pengyu Lvdd1d6a72023-11-27 17:57:31 +0800793 # If the outcome file exists, parse it once and share the result
794 # among tasks to improve performance.
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800795 # Otherwise, it will be generated by execute_reference_driver_tests.
796 if not os.path.exists(options.outcomes):
797 if len(tasks_list) > 1:
798 sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n")
799 sys.exit(2)
800
801 task_name = tasks_list[0]
802 task = KNOWN_TASKS[task_name]
Gilles Peskine82b16722024-09-16 19:57:10 +0200803 if not issubclass(task, DriverVSReference):
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800804 sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
805 sys.exit(2)
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800806 execute_reference_driver_tests(main_results,
Gilles Peskine82b16722024-09-16 19:57:10 +0200807 task.REFERENCE,
808 task.DRIVER,
Pengyu Lv20e3ca32023-11-28 15:30:03 +0800809 options.outcomes)
810
811 outcomes = read_outcome_file(options.outcomes)
Pengyu Lva6cf5d62023-11-22 11:35:21 +0800812
Gilles Peskine19ef1ae2024-09-16 19:12:09 +0200813 for task_name in tasks_list:
814 task_constructor = KNOWN_TASKS[task_name]
815 if isinstance(task_constructor, dict):
816 test_function = task_constructor['test_function']
817 test_args = task_constructor['args']
818 test_function(main_results, outcomes, test_args)
819 else:
820 task = task_constructor(options)
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200821 main_results.new_section(task.section_name())
Gilles Peskine19ef1ae2024-09-16 19:12:09 +0200822 task.run(main_results, outcomes)
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100823
Valerio Settif6f64cf2023-10-17 12:28:26 +0200824 main_results.info("Overall results: {} warnings and {} errors",
825 main_results.warning_count, main_results.error_count)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200826
Valerio Setti8d178be2023-10-17 12:23:55 +0200827 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200828
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200829 except Exception: # pylint: disable=broad-except
830 # Print the backtrace and exit explicitly with our chosen status.
831 traceback.print_exc()
832 sys.exit(120)
833
834if __name__ == '__main__':
835 main()