2020-06-25 18:36:28 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""Analyze the test outcomes from a full CI run.
|
|
|
|
|
|
|
|
This script can also run on outcomes from a partial run, but the results are
|
|
|
|
less likely to be useful.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
import traceback
|
2022-11-17 11:50:23 +01:00
|
|
|
import re
|
2023-03-24 08:20:18 +01:00
|
|
|
import subprocess
|
|
|
|
import os
|
2020-06-25 18:36:28 +02:00
|
|
|
|
2020-06-25 18:37:43 +02:00
|
|
|
import check_test_cases
|
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
class Results:
|
|
|
|
"""Process analysis results."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.error_count = 0
|
|
|
|
self.warning_count = 0
|
|
|
|
|
2023-10-18 14:36:47 +02:00
|
|
|
def new_section(self, fmt, *args, **kwargs):
|
|
|
|
self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs)
|
|
|
|
|
2023-10-10 09:42:13 +02:00
|
|
|
def info(self, fmt, *args, **kwargs):
|
2023-10-17 12:29:30 +02:00
|
|
|
self._print_line('Info: ' + fmt, *args, **kwargs)
|
2020-06-25 18:36:28 +02:00
|
|
|
|
|
|
|
def error(self, fmt, *args, **kwargs):
|
|
|
|
self.error_count += 1
|
2023-10-17 12:29:30 +02:00
|
|
|
self._print_line('Error: ' + fmt, *args, **kwargs)
|
2020-06-25 18:36:28 +02:00
|
|
|
|
|
|
|
def warning(self, fmt, *args, **kwargs):
|
|
|
|
self.warning_count += 1
|
2023-10-17 12:29:30 +02:00
|
|
|
self._print_line('Warning: ' + fmt, *args, **kwargs)
|
2020-06-25 18:36:28 +02:00
|
|
|
|
2023-10-17 10:42:11 +02:00
|
|
|
@staticmethod
|
2023-10-17 12:29:30 +02:00
|
|
|
def _print_line(fmt, *args, **kwargs):
|
2023-10-18 08:05:15 +02:00
|
|
|
sys.stderr.write((fmt + '\n').format(*args, **kwargs))
|
2020-06-25 18:36:28 +02:00
|
|
|
|
2023-10-17 11:03:16 +02:00
|
|
|
def execute_reference_driver_tests(results: Results, ref_component, driver_component, \
|
2023-10-17 12:47:35 +02:00
|
|
|
outcome_file):
|
2023-03-29 11:15:28 +02:00
|
|
|
"""Run the tests specified in ref_component and driver_component. Results
|
|
|
|
are stored in the output_file and they will be used for the following
|
2023-03-24 08:20:18 +01:00
|
|
|
coverage analysis"""
|
|
|
|
# If the outcome file already exists, we assume that the user wants to
|
|
|
|
# perform the comparison analysis again without repeating the tests.
|
|
|
|
if os.path.exists(outcome_file):
|
2023-10-18 14:30:03 +02:00
|
|
|
results.info("Outcome file ({}) already exists. Tests will be skipped.", outcome_file)
|
2023-03-24 08:20:18 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
|
|
|
|
" " + ref_component + " " + driver_component
|
2023-10-18 14:30:03 +02:00
|
|
|
results.info("Running: {}", shell_command)
|
2023-03-24 08:20:18 +01:00
|
|
|
ret_val = subprocess.run(shell_command.split(), check=False).returncode
|
|
|
|
|
|
|
|
if ret_val != 0:
|
2023-10-17 11:03:16 +02:00
|
|
|
results.error("failed to run reference/driver components")
|
2023-03-24 08:20:18 +01:00
|
|
|
|
2023-08-11 16:22:04 +02:00
|
|
|
def analyze_coverage(results, outcomes, allow_list, full_coverage):
|
2020-06-25 18:37:43 +02:00
|
|
|
"""Check that all available test cases are executed at least once."""
|
2022-01-07 15:58:38 +01:00
|
|
|
available = check_test_cases.collect_available_test_cases()
|
2023-11-23 07:15:37 +01:00
|
|
|
for suite_case in available:
|
2023-11-22 12:02:15 +01:00
|
|
|
hits = 0
|
2023-11-27 10:57:31 +01:00
|
|
|
for comp_outcomes in outcomes.values():
|
2023-11-23 07:15:37 +01:00
|
|
|
if suite_case in comp_outcomes["successes"] or \
|
|
|
|
suite_case in comp_outcomes["failures"]:
|
2023-11-22 12:02:15 +01:00
|
|
|
hits += 1
|
2023-11-28 03:56:29 +01:00
|
|
|
break
|
2023-11-22 12:02:15 +01:00
|
|
|
|
2023-11-23 07:15:37 +01:00
|
|
|
if hits == 0 and suite_case not in allow_list:
|
2023-08-11 16:22:04 +02:00
|
|
|
if full_coverage:
|
2023-11-23 07:15:37 +01:00
|
|
|
results.error('Test case not executed: {}', suite_case)
|
2023-08-11 16:22:04 +02:00
|
|
|
else:
|
2023-11-23 07:15:37 +01:00
|
|
|
results.warning('Test case not executed: {}', suite_case)
|
|
|
|
elif hits != 0 and suite_case in allow_list:
|
2023-08-11 15:59:03 +02:00
|
|
|
# Test Case should be removed from the allow list.
|
2023-08-22 10:40:23 +02:00
|
|
|
if full_coverage:
|
2023-11-23 07:15:37 +01:00
|
|
|
results.error('Allow listed test case was executed: {}', suite_case)
|
2023-08-22 10:40:23 +02:00
|
|
|
else:
|
2023-11-23 07:15:37 +01:00
|
|
|
results.warning('Allow listed test case was executed: {}', suite_case)
|
2020-06-25 18:37:43 +02:00
|
|
|
|
2023-10-18 10:22:07 +02:00
|
|
|
def name_matches_pattern(name, str_or_re):
|
|
|
|
"""Check if name matches a pattern, that may be a string or regex.
|
|
|
|
- If the pattern is a string, name must be equal to match.
|
|
|
|
- If the pattern is a regex, name must fully match.
|
|
|
|
"""
|
2023-10-23 09:30:40 +02:00
|
|
|
# The CI's python is too old for re.Pattern
|
|
|
|
#if isinstance(str_or_re, re.Pattern):
|
|
|
|
if not isinstance(str_or_re, str):
|
2023-10-26 09:37:40 +02:00
|
|
|
return str_or_re.fullmatch(name)
|
2023-10-18 10:22:07 +02:00
|
|
|
else:
|
2023-10-26 09:37:40 +02:00
|
|
|
return str_or_re == name
|
2023-10-18 10:22:07 +02:00
|
|
|
|
2023-10-17 11:03:16 +02:00
|
|
|
def analyze_driver_vs_reference(results: Results, outcomes,
|
2023-10-10 09:42:13 +02:00
|
|
|
component_ref, component_driver,
|
2023-10-18 10:22:07 +02:00
|
|
|
ignored_suites, ignored_tests=None):
|
2023-11-27 10:57:31 +01:00
|
|
|
"""Check that all tests passing in the reference component are also
|
|
|
|
passing in the corresponding driver component.
|
2023-01-18 17:28:36 +01:00
|
|
|
Skip:
|
|
|
|
- full test suites provided in ignored_suites list
|
|
|
|
- only some specific test inside a test suite, for which the corresponding
|
|
|
|
output string is provided
|
2022-10-21 13:42:08 +02:00
|
|
|
"""
|
2023-11-22 12:02:15 +01:00
|
|
|
ref_outcomes = outcomes.get("component_" + component_ref)
|
|
|
|
driver_outcomes = outcomes.get("component_" + component_driver)
|
|
|
|
|
2023-11-28 04:15:00 +01:00
|
|
|
if ref_outcomes is None or driver_outcomes is None:
|
|
|
|
results.error("required components are missing: bad outcome file?")
|
|
|
|
return
|
|
|
|
|
|
|
|
if not ref_outcomes['successes']:
|
2023-11-22 12:02:15 +01:00
|
|
|
results.error("no passing test in reference component: bad outcome file?")
|
|
|
|
return
|
|
|
|
|
2023-11-23 07:15:37 +01:00
|
|
|
for suite_case in ref_outcomes["successes"]:
|
|
|
|
# suite_case is like "test_suite_foo.bar;Description of test case"
|
|
|
|
(full_test_suite, test_string) = suite_case.split(';')
|
2023-02-02 11:33:31 +01:00
|
|
|
test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
|
2023-10-18 12:44:54 +02:00
|
|
|
|
|
|
|
# Immediately skip fully-ignored test suites
|
2023-03-17 15:13:08 +01:00
|
|
|
if test_suite in ignored_suites or full_test_suite in ignored_suites:
|
2023-02-02 11:33:31 +01:00
|
|
|
continue
|
2023-10-18 12:44:54 +02:00
|
|
|
|
|
|
|
# For ignored test cases inside test suites, just remember and:
|
|
|
|
# don't issue an error if they're skipped with drivers,
|
|
|
|
# but issue an error if they're not (means we have a bad entry).
|
|
|
|
ignored = False
|
2023-10-18 10:22:07 +02:00
|
|
|
if full_test_suite in ignored_tests:
|
2023-10-26 09:41:59 +02:00
|
|
|
for str_or_re in ignored_tests[test_suite]:
|
2023-10-18 10:22:07 +02:00
|
|
|
if name_matches_pattern(test_string, str_or_re):
|
2023-10-18 12:44:54 +02:00
|
|
|
ignored = True
|
2023-10-18 09:40:32 +02:00
|
|
|
|
2023-11-23 07:15:37 +01:00
|
|
|
if not ignored and not suite_case in driver_outcomes['successes']:
|
|
|
|
results.error("PASS -> SKIP/FAIL: {}", suite_case)
|
|
|
|
if ignored and suite_case in driver_outcomes['successes']:
|
|
|
|
results.error("uselessly ignored: {}", suite_case)
|
2023-10-18 12:44:54 +02:00
|
|
|
|
2023-10-17 12:47:35 +02:00
|
|
|
def analyze_outcomes(results: Results, outcomes, args):
|
2020-06-25 18:36:28 +02:00
|
|
|
"""Run all analyses on the given outcome collection."""
|
2023-08-11 16:22:04 +02:00
|
|
|
analyze_coverage(results, outcomes, args['allow_list'],
|
|
|
|
args['full_coverage'])
|
2020-06-25 18:36:28 +02:00
|
|
|
|
|
|
|
def read_outcome_file(outcome_file):
|
|
|
|
"""Parse an outcome file and return an outcome collection.
|
|
|
|
|
2023-11-23 07:15:37 +01:00
|
|
|
An outcome collection is a dictionary presentation of the outcome file:
|
|
|
|
```
|
|
|
|
outcomes = {
|
2023-11-27 10:57:31 +01:00
|
|
|
"<component>": {
|
2023-11-23 07:15:37 +01:00
|
|
|
"successes": frozenset(["<suite_case>", ... ]),
|
|
|
|
"failures": frozenset(["<suite_case>", ...])
|
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
suite_case = "<suite>;<case>"
|
|
|
|
```
|
2020-06-25 18:36:28 +02:00
|
|
|
"""
|
|
|
|
outcomes = {}
|
|
|
|
with open(outcome_file, 'r', encoding='utf-8') as input_file:
|
|
|
|
for line in input_file:
|
2023-11-27 10:57:31 +01:00
|
|
|
(_platform, component, suite, case, result, _cause) = line.split(';')
|
2023-11-23 07:15:37 +01:00
|
|
|
suite_case = ';'.join([suite, case])
|
2023-11-27 10:57:31 +01:00
|
|
|
if component not in outcomes:
|
2023-11-28 04:35:19 +01:00
|
|
|
outcomes[component] = {"successes":set(), "failures":set()}
|
2020-06-25 18:36:28 +02:00
|
|
|
if result == 'PASS':
|
2023-11-28 04:35:19 +01:00
|
|
|
outcomes[component]['successes'].add(suite_case)
|
2020-06-25 18:36:28 +02:00
|
|
|
elif result == 'FAIL':
|
2023-11-28 04:35:19 +01:00
|
|
|
outcomes[component]['failures'].add(suite_case)
|
2023-11-22 12:02:15 +01:00
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
return outcomes
|
|
|
|
|
2023-11-22 04:35:21 +01:00
|
|
|
def do_analyze_coverage(results: Results, outcomes_or_file, args):
|
2022-11-09 10:50:29 +01:00
|
|
|
"""Perform coverage analysis."""
|
2023-10-18 14:36:47 +02:00
|
|
|
results.new_section("Analyze coverage")
|
2023-11-22 04:35:21 +01:00
|
|
|
outcomes = read_outcome_file(outcomes_or_file) \
|
|
|
|
if isinstance(outcomes_or_file, str) else outcomes_or_file
|
2023-10-17 12:47:35 +02:00
|
|
|
analyze_outcomes(results, outcomes, args)
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2023-11-22 04:35:21 +01:00
|
|
|
def do_analyze_driver_vs_reference(results: Results, outcomes_or_file, args):
|
2022-10-21 13:42:08 +02:00
|
|
|
"""Perform driver vs reference analyze."""
|
2023-10-18 14:36:47 +02:00
|
|
|
results.new_section("Analyze driver {} vs reference {}",
|
|
|
|
args['component_driver'], args['component_ref'])
|
2023-10-16 14:19:49 +02:00
|
|
|
|
2023-01-18 17:28:36 +01:00
|
|
|
ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
|
2022-11-09 12:07:29 +01:00
|
|
|
|
2023-11-22 04:35:21 +01:00
|
|
|
if isinstance(outcomes_or_file, str):
|
|
|
|
execute_reference_driver_tests(results, args['component_ref'], \
|
|
|
|
args['component_driver'], outcomes_or_file)
|
|
|
|
outcomes = read_outcome_file(outcomes_or_file)
|
|
|
|
else:
|
|
|
|
outcomes = outcomes_or_file
|
2023-10-10 09:42:13 +02:00
|
|
|
|
2023-10-17 12:47:35 +02:00
|
|
|
analyze_driver_vs_reference(results, outcomes,
|
|
|
|
args['component_ref'], args['component_driver'],
|
|
|
|
ignored_suites, args['ignored_tests'])
|
2020-06-25 18:36:28 +02:00
|
|
|
|
2022-11-09 10:50:29 +01:00
|
|
|
# List of tasks with a function that can handle this task and additional arguments if required
|
2023-10-09 16:30:11 +02:00
|
|
|
KNOWN_TASKS = {
|
2022-10-26 16:11:26 +02:00
|
|
|
'analyze_coverage': {
|
|
|
|
'test_function': do_analyze_coverage,
|
2023-08-11 15:59:03 +02:00
|
|
|
'args': {
|
2023-08-14 16:43:46 +02:00
|
|
|
'allow_list': [
|
2023-08-22 10:52:06 +02:00
|
|
|
# Algorithm not supported yet
|
|
|
|
'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
|
|
|
|
# Algorithm not supported yet
|
|
|
|
'test_suite_psa_crypto_metadata;Cipher: XTS',
|
2023-08-24 10:12:40 +02:00
|
|
|
],
|
2023-08-11 16:22:04 +02:00
|
|
|
'full_coverage': False,
|
2023-08-11 15:59:03 +02:00
|
|
|
}
|
2023-08-24 10:12:40 +02:00
|
|
|
},
|
2023-03-24 08:20:18 +01:00
|
|
|
# There are 2 options to use analyze_driver_vs_reference_xxx locally:
|
|
|
|
# 1. Run tests and then analysis:
|
|
|
|
# - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
|
|
|
|
# - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
|
|
|
|
# 2. Let this script run both automatically:
|
|
|
|
# - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
|
2022-10-26 16:11:26 +02:00
|
|
|
'analyze_driver_vs_reference_hash': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
2022-11-09 12:07:29 +01:00
|
|
|
'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
|
2022-12-29 12:29:09 +01:00
|
|
|
'ignored_suites': [
|
|
|
|
'shax', 'mdx', # the software implementations that are being excluded
|
2023-03-17 15:13:08 +01:00
|
|
|
'md.psa', # purposefully depends on whether drivers are present
|
2023-10-04 12:28:41 +02:00
|
|
|
'psa_crypto_low_hash.generated', # testing the builtins
|
2023-01-18 17:28:36 +01:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-10-04 12:05:05 +02:00
|
|
|
'analyze_driver_vs_reference_cipher_aead': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
|
|
|
'component_ref': 'test_psa_crypto_config_reference_cipher_aead',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_cipher_aead',
|
2023-10-26 09:44:06 +02:00
|
|
|
# Modules replaced by drivers.
|
2023-10-04 12:05:05 +02:00
|
|
|
'ignored_suites': [
|
2023-10-26 09:44:06 +02:00
|
|
|
# low-level (block/stream) cipher modules
|
|
|
|
'aes', 'aria', 'camellia', 'des', 'chacha20',
|
|
|
|
# AEAD modes
|
|
|
|
'ccm', 'chachapoly', 'cmac', 'gcm',
|
|
|
|
# The Cipher abstraction layer
|
|
|
|
'cipher',
|
2023-10-04 12:05:05 +02:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
2023-10-26 09:44:06 +02:00
|
|
|
# PEM decryption is not supported so far.
|
|
|
|
# The rest of PEM (write, unencrypted read) works though.
|
2023-10-04 15:46:42 +02:00
|
|
|
'test_suite_pem': [
|
2023-10-27 09:24:44 +02:00
|
|
|
re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
|
2023-10-04 15:46:42 +02:00
|
|
|
],
|
2023-10-26 09:44:06 +02:00
|
|
|
# Following tests depend on AES_C/DES_C but are not about
|
|
|
|
# them really, just need to know some error code is there.
|
2023-10-04 15:46:42 +02:00
|
|
|
'test_suite_error': [
|
|
|
|
'Low and high error',
|
|
|
|
'Single low error'
|
|
|
|
],
|
2023-10-26 09:44:06 +02:00
|
|
|
# Similar to test_suite_error above.
|
2023-10-04 15:46:42 +02:00
|
|
|
'test_suite_version': [
|
|
|
|
'Check for MBEDTLS_AES_C when already present',
|
2023-10-13 09:19:52 +02:00
|
|
|
],
|
2023-10-26 09:44:06 +02:00
|
|
|
# The en/decryption part of PKCS#12 is not supported so far.
|
|
|
|
# The rest of PKCS#12 (key derivation) works though.
|
2023-10-13 09:19:52 +02:00
|
|
|
'test_suite_pkcs12': [
|
2023-10-27 09:24:44 +02:00
|
|
|
re.compile(r'PBE Encrypt, .*'),
|
|
|
|
re.compile(r'PBE Decrypt, .*'),
|
2023-10-13 09:19:52 +02:00
|
|
|
],
|
2023-10-26 09:44:06 +02:00
|
|
|
# The en/decryption part of PKCS#5 is not supported so far.
|
|
|
|
# The rest of PKCS#5 (PBKDF2) works though.
|
2023-10-13 09:19:52 +02:00
|
|
|
'test_suite_pkcs5': [
|
2023-10-27 09:24:44 +02:00
|
|
|
re.compile(r'PBES2 Encrypt, .*'),
|
|
|
|
re.compile(r'PBES2 Decrypt .*'),
|
2023-10-13 09:19:52 +02:00
|
|
|
],
|
2023-10-26 09:44:06 +02:00
|
|
|
# Encrypted keys are not supported so far.
|
2023-10-13 15:14:07 +02:00
|
|
|
# pylint: disable=line-too-long
|
2023-10-13 09:19:52 +02:00
|
|
|
'test_suite_pkparse': [
|
|
|
|
'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
|
|
|
|
'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
|
2023-10-27 09:24:44 +02:00
|
|
|
re.compile(r'Parse RSA Key .*\(PKCS#8 encrypted .*\)'),
|
2023-10-13 09:19:52 +02:00
|
|
|
],
|
2023-01-18 17:28:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-06-14 10:33:10 +02:00
|
|
|
'analyze_driver_vs_reference_ecp_light_only': {
|
2023-03-20 13:54:41 +01:00
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
2023-06-14 10:33:10 +02:00
|
|
|
'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
|
2023-03-20 13:54:41 +01:00
|
|
|
'ignored_suites': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# Modules replaced by drivers
|
|
|
|
'ecdsa', 'ecdh', 'ecjpake',
|
2023-03-20 13:54:41 +01:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
2023-10-20 10:21:09 +02:00
|
|
|
# This test wants a legacy function that takes f_rng, p_rng
|
|
|
|
# arguments, and uses legacy ECDSA for that. The test is
|
|
|
|
# really about the wrapper around the PSA RNG, not ECDSA.
|
2023-03-20 13:54:41 +01:00
|
|
|
'test_suite_random': [
|
|
|
|
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
|
|
|
],
|
2023-04-07 15:54:20 +02:00
|
|
|
# In the accelerated test ECP_C is not set (only ECP_LIGHT is)
|
|
|
|
# so we must ignore disparities in the tests for which ECP_C
|
|
|
|
# is required.
|
|
|
|
'test_suite_ecp': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'ECP check public-private .*'),
|
|
|
|
re.compile(r'ECP gen keypair .*'),
|
|
|
|
re.compile(r'ECP point muladd .*'),
|
|
|
|
re.compile(r'ECP point multiplication .*'),
|
|
|
|
re.compile(r'ECP test vectors .*'),
|
2023-08-18 15:55:10 +02:00
|
|
|
],
|
2023-09-22 11:53:41 +02:00
|
|
|
'test_suite_ssl': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# This deprecated function is only present when ECP_C is On.
|
2023-09-22 11:53:41 +02:00
|
|
|
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
|
|
|
|
],
|
2023-06-30 17:20:49 +02:00
|
|
|
}
|
2023-03-20 13:54:41 +01:00
|
|
|
}
|
|
|
|
},
|
2023-06-14 10:33:10 +02:00
|
|
|
'analyze_driver_vs_reference_no_ecp_at_all': {
|
2023-04-12 14:59:16 +02:00
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
2023-06-14 10:33:10 +02:00
|
|
|
'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
|
2023-04-12 14:59:16 +02:00
|
|
|
'ignored_suites': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# Modules replaced by drivers
|
|
|
|
'ecp', 'ecdsa', 'ecdh', 'ecjpake',
|
2023-04-12 14:59:16 +02:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-04-12 14:59:16 +02:00
|
|
|
'test_suite_random': [
|
|
|
|
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
|
|
|
],
|
2023-06-14 10:46:55 +02:00
|
|
|
'test_suite_pkparse': [
|
2023-06-19 19:32:14 +02:00
|
|
|
# When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
|
|
|
|
# is automatically enabled in build_info.h (backward compatibility)
|
|
|
|
# even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
|
|
|
|
# consequence compressed points are supported in the reference
|
|
|
|
# component but not in the accelerated one, so they should be skipped
|
|
|
|
# while checking driver's coverage.
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'Parse EC Key .*compressed\)'),
|
|
|
|
re.compile(r'Parse Public EC Key .*compressed\)'),
|
2023-06-12 17:51:33 +02:00
|
|
|
],
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-09-22 11:53:41 +02:00
|
|
|
'test_suite_ssl': [
|
|
|
|
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
|
|
|
|
],
|
2023-06-12 17:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-08-15 10:12:25 +02:00
|
|
|
'analyze_driver_vs_reference_ecc_no_bignum': {
|
2023-06-12 17:51:33 +02:00
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
|
|
|
'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
|
|
|
|
'ignored_suites': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# Modules replaced by drivers
|
|
|
|
'ecp', 'ecdsa', 'ecdh', 'ecjpake',
|
|
|
|
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
|
|
|
|
'bignum.generated', 'bignum.misc',
|
2023-06-12 17:51:33 +02:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-06-12 17:51:33 +02:00
|
|
|
'test_suite_random': [
|
|
|
|
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
|
|
|
],
|
2023-10-20 10:21:09 +02:00
|
|
|
# See no_ecp_at_all
|
2023-08-15 10:12:25 +02:00
|
|
|
'test_suite_pkparse': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'Parse EC Key .*compressed\)'),
|
|
|
|
re.compile(r'Parse Public EC Key .*compressed\)'),
|
2023-08-15 10:12:25 +02:00
|
|
|
],
|
|
|
|
'test_suite_asn1parse': [
|
|
|
|
'INTEGER too large for mpi',
|
|
|
|
],
|
|
|
|
'test_suite_asn1write': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'ASN.1 Write mpi.*'),
|
2023-08-15 10:12:25 +02:00
|
|
|
],
|
|
|
|
'test_suite_debug': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'Debug print mbedtls_mpi.*'),
|
2023-08-15 10:12:25 +02:00
|
|
|
],
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-09-22 11:53:41 +02:00
|
|
|
'test_suite_ssl': [
|
|
|
|
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
|
|
|
|
],
|
2023-08-15 10:12:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
|
|
|
'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
|
|
|
|
'ignored_suites': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# Modules replaced by drivers
|
|
|
|
'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
|
|
|
|
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
|
|
|
|
'bignum.generated', 'bignum.misc',
|
2023-08-15 10:12:25 +02:00
|
|
|
],
|
|
|
|
'ignored_tests': {
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-08-15 10:12:25 +02:00
|
|
|
'test_suite_random': [
|
|
|
|
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
|
|
|
],
|
2023-10-20 10:21:09 +02:00
|
|
|
# See no_ecp_at_all
|
2023-06-12 17:51:33 +02:00
|
|
|
'test_suite_pkparse': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'Parse EC Key .*compressed\)'),
|
|
|
|
re.compile(r'Parse Public EC Key .*compressed\)'),
|
2023-06-14 10:46:55 +02:00
|
|
|
],
|
2023-07-26 18:00:31 +02:00
|
|
|
'test_suite_asn1parse': [
|
|
|
|
'INTEGER too large for mpi',
|
|
|
|
],
|
|
|
|
'test_suite_asn1write': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'ASN.1 Write mpi.*'),
|
2023-07-26 18:00:31 +02:00
|
|
|
],
|
2023-08-01 09:07:43 +02:00
|
|
|
'test_suite_debug': [
|
2023-10-20 10:21:09 +02:00
|
|
|
re.compile(r'Debug print mbedtls_mpi.*'),
|
2023-08-01 09:07:43 +02:00
|
|
|
],
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-09-22 11:53:41 +02:00
|
|
|
'test_suite_ssl': [
|
|
|
|
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
|
|
|
|
],
|
2023-04-12 14:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-05-26 09:55:23 +02:00
|
|
|
'analyze_driver_vs_reference_ffdh_alg': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
|
|
|
'component_ref': 'test_psa_crypto_config_reference_ffdh',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_ffdh',
|
2023-07-04 12:35:31 +02:00
|
|
|
'ignored_suites': ['dhm'],
|
2023-07-05 11:07:07 +02:00
|
|
|
'ignored_tests': {}
|
2023-05-26 09:55:23 +02:00
|
|
|
}
|
|
|
|
},
|
2023-08-04 13:51:18 +02:00
|
|
|
'analyze_driver_vs_reference_tfm_config': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
|
|
|
'component_ref': 'test_tfm_config',
|
|
|
|
'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
|
2023-08-08 18:34:47 +02:00
|
|
|
'ignored_suites': [
|
2023-10-20 10:21:09 +02:00
|
|
|
# Modules replaced by drivers
|
2023-10-31 06:39:07 +01:00
|
|
|
'asn1parse', 'asn1write',
|
2023-10-20 10:21:09 +02:00
|
|
|
'ecp', 'ecdsa', 'ecdh', 'ecjpake',
|
|
|
|
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
|
|
|
|
'bignum.generated', 'bignum.misc',
|
2023-08-08 18:34:47 +02:00
|
|
|
],
|
2023-08-04 13:51:18 +02:00
|
|
|
'ignored_tests': {
|
2023-10-20 10:21:09 +02:00
|
|
|
# See ecp_light_only
|
2023-08-08 18:34:47 +02:00
|
|
|
'test_suite_random': [
|
|
|
|
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
|
|
|
],
|
2023-08-04 13:51:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-26 16:11:26 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
def main():
|
2023-10-17 11:03:16 +02:00
|
|
|
main_results = Results()
|
2023-10-10 09:42:13 +02:00
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
try:
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
2022-10-24 08:10:10 +02:00
|
|
|
parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
|
2020-06-25 18:36:28 +02:00
|
|
|
help='Outcome file to analyze')
|
2023-10-09 16:30:11 +02:00
|
|
|
parser.add_argument('specified_tasks', default='all', nargs='?',
|
2022-11-09 13:54:49 +01:00
|
|
|
help='Analysis to be done. By default, run all tasks. '
|
|
|
|
'With one or more TASK, run only those. '
|
|
|
|
'TASK can be the name of a single task or '
|
2022-11-17 11:50:23 +01:00
|
|
|
'comma/space-separated list of tasks. ')
|
2022-11-09 13:54:49 +01:00
|
|
|
parser.add_argument('--list', action='store_true',
|
|
|
|
help='List all available tasks and exit.')
|
2023-08-11 16:22:04 +02:00
|
|
|
parser.add_argument('--require-full-coverage', action='store_true',
|
|
|
|
dest='full_coverage', help="Require all available "
|
|
|
|
"test cases to be executed and issue an error "
|
|
|
|
"otherwise. This flag is ignored if 'task' is "
|
|
|
|
"neither 'all' nor 'analyze_coverage'")
|
2020-06-25 18:36:28 +02:00
|
|
|
options = parser.parse_args()
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2022-11-09 13:54:49 +01:00
|
|
|
if options.list:
|
2023-10-09 16:30:11 +02:00
|
|
|
for task in KNOWN_TASKS:
|
2023-10-17 09:44:36 +02:00
|
|
|
print(task)
|
2022-11-09 13:54:49 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2023-10-09 16:30:11 +02:00
|
|
|
if options.specified_tasks == 'all':
|
|
|
|
tasks_list = KNOWN_TASKS.keys()
|
2022-11-09 13:54:49 +01:00
|
|
|
else:
|
2023-10-09 16:30:11 +02:00
|
|
|
tasks_list = re.split(r'[, ]+', options.specified_tasks)
|
|
|
|
for task in tasks_list:
|
|
|
|
if task not in KNOWN_TASKS:
|
2023-10-20 10:51:57 +02:00
|
|
|
sys.stderr.write('invalid task: {}\n'.format(task))
|
2023-10-17 10:11:45 +02:00
|
|
|
sys.exit(2)
|
2022-11-09 13:54:49 +01:00
|
|
|
|
2023-10-09 16:30:11 +02:00
|
|
|
KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
|
2022-11-09 13:54:49 +01:00
|
|
|
|
2023-11-27 10:57:31 +01:00
|
|
|
# If the outcome file exists, parse it once and share the result
|
|
|
|
# among tasks to improve performance.
|
|
|
|
# Otherwise, it will be generated by do_analyze_driver_vs_reference.
|
2023-11-22 04:35:21 +01:00
|
|
|
if os.path.exists(options.outcomes):
|
|
|
|
main_results.info("Read outcome file from {}.", options.outcomes)
|
|
|
|
outcomes_or_file = read_outcome_file(options.outcomes)
|
|
|
|
else:
|
|
|
|
outcomes_or_file = options.outcomes
|
|
|
|
|
2023-10-17 10:11:45 +02:00
|
|
|
for task in tasks_list:
|
|
|
|
test_function = KNOWN_TASKS[task]['test_function']
|
|
|
|
test_args = KNOWN_TASKS[task]['args']
|
2023-11-22 04:35:21 +01:00
|
|
|
test_function(main_results, outcomes_or_file, test_args)
|
2022-11-09 13:54:49 +01:00
|
|
|
|
2023-10-17 12:28:26 +02:00
|
|
|
main_results.info("Overall results: {} warnings and {} errors",
|
|
|
|
main_results.warning_count, main_results.error_count)
|
2023-08-11 16:22:04 +02:00
|
|
|
|
2023-10-17 12:23:55 +02:00
|
|
|
sys.exit(0 if (main_results.error_count == 0) else 1)
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
except Exception: # pylint: disable=broad-except
|
|
|
|
# Print the backtrace and exit explicitly with our chosen status.
|
|
|
|
traceback.print_exc()
|
|
|
|
sys.exit(120)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|