1a8e1175bSopenharmony_ci#!/usr/bin/env python3 2a8e1175bSopenharmony_ci 3a8e1175bSopenharmony_ci"""Analyze the test outcomes from a full CI run. 4a8e1175bSopenharmony_ci 5a8e1175bSopenharmony_ciThis script can also run on outcomes from a partial run, but the results are 6a8e1175bSopenharmony_ciless likely to be useful. 7a8e1175bSopenharmony_ci""" 8a8e1175bSopenharmony_ci 9a8e1175bSopenharmony_ciimport argparse 10a8e1175bSopenharmony_ciimport sys 11a8e1175bSopenharmony_ciimport traceback 12a8e1175bSopenharmony_ciimport re 13a8e1175bSopenharmony_ciimport subprocess 14a8e1175bSopenharmony_ciimport os 15a8e1175bSopenharmony_ciimport typing 16a8e1175bSopenharmony_ci 17a8e1175bSopenharmony_ciimport check_test_cases 18a8e1175bSopenharmony_ci 19a8e1175bSopenharmony_ci 20a8e1175bSopenharmony_ci# `ComponentOutcomes` is a named tuple which is defined as: 21a8e1175bSopenharmony_ci# ComponentOutcomes( 22a8e1175bSopenharmony_ci# successes = { 23a8e1175bSopenharmony_ci# "<suite_case>", 24a8e1175bSopenharmony_ci# ... 25a8e1175bSopenharmony_ci# }, 26a8e1175bSopenharmony_ci# failures = { 27a8e1175bSopenharmony_ci# "<suite_case>", 28a8e1175bSopenharmony_ci# ... 29a8e1175bSopenharmony_ci# } 30a8e1175bSopenharmony_ci# ) 31a8e1175bSopenharmony_ci# suite_case = "<suite>;<case>" 32a8e1175bSopenharmony_ciComponentOutcomes = typing.NamedTuple('ComponentOutcomes', 33a8e1175bSopenharmony_ci [('successes', typing.Set[str]), 34a8e1175bSopenharmony_ci ('failures', typing.Set[str])]) 35a8e1175bSopenharmony_ci 36a8e1175bSopenharmony_ci# `Outcomes` is a representation of the outcomes file, 37a8e1175bSopenharmony_ci# which defined as: 38a8e1175bSopenharmony_ci# Outcomes = { 39a8e1175bSopenharmony_ci# "<component>": ComponentOutcomes, 40a8e1175bSopenharmony_ci# ... 41a8e1175bSopenharmony_ci# } 42a8e1175bSopenharmony_ciOutcomes = typing.Dict[str, ComponentOutcomes] 43a8e1175bSopenharmony_ci 44a8e1175bSopenharmony_ci 45a8e1175bSopenharmony_ciclass Results: 46a8e1175bSopenharmony_ci """Process analysis results.""" 47a8e1175bSopenharmony_ci 48a8e1175bSopenharmony_ci def __init__(self): 49a8e1175bSopenharmony_ci self.error_count = 0 50a8e1175bSopenharmony_ci self.warning_count = 0 51a8e1175bSopenharmony_ci 52a8e1175bSopenharmony_ci def new_section(self, fmt, *args, **kwargs): 53a8e1175bSopenharmony_ci self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs) 54a8e1175bSopenharmony_ci 55a8e1175bSopenharmony_ci def info(self, fmt, *args, **kwargs): 56a8e1175bSopenharmony_ci self._print_line('Info: ' + fmt, *args, **kwargs) 57a8e1175bSopenharmony_ci 58a8e1175bSopenharmony_ci def error(self, fmt, *args, **kwargs): 59a8e1175bSopenharmony_ci self.error_count += 1 60a8e1175bSopenharmony_ci self._print_line('Error: ' + fmt, *args, **kwargs) 61a8e1175bSopenharmony_ci 62a8e1175bSopenharmony_ci def warning(self, fmt, *args, **kwargs): 63a8e1175bSopenharmony_ci self.warning_count += 1 64a8e1175bSopenharmony_ci self._print_line('Warning: ' + fmt, *args, **kwargs) 65a8e1175bSopenharmony_ci 66a8e1175bSopenharmony_ci @staticmethod 67a8e1175bSopenharmony_ci def _print_line(fmt, *args, **kwargs): 68a8e1175bSopenharmony_ci sys.stderr.write((fmt + '\n').format(*args, **kwargs)) 69a8e1175bSopenharmony_ci 70a8e1175bSopenharmony_cidef execute_reference_driver_tests(results: Results, ref_component: str, driver_component: str, \ 71a8e1175bSopenharmony_ci outcome_file: str) -> None: 72a8e1175bSopenharmony_ci """Run the tests specified in ref_component and driver_component. Results 73a8e1175bSopenharmony_ci are stored in the output_file and they will be used for the following 74a8e1175bSopenharmony_ci coverage analysis""" 75a8e1175bSopenharmony_ci results.new_section("Test {} and {}", ref_component, driver_component) 76a8e1175bSopenharmony_ci 77a8e1175bSopenharmony_ci shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \ 78a8e1175bSopenharmony_ci " " + ref_component + " " + driver_component 79a8e1175bSopenharmony_ci results.info("Running: {}", shell_command) 80a8e1175bSopenharmony_ci ret_val = subprocess.run(shell_command.split(), check=False).returncode 81a8e1175bSopenharmony_ci 82a8e1175bSopenharmony_ci if ret_val != 0: 83a8e1175bSopenharmony_ci results.error("failed to run reference/driver components") 84a8e1175bSopenharmony_ci 85a8e1175bSopenharmony_cidef analyze_coverage(results: Results, outcomes: Outcomes, 86a8e1175bSopenharmony_ci allow_list: typing.List[str], full_coverage: bool) -> None: 87a8e1175bSopenharmony_ci """Check that all available test cases are executed at least once.""" 88a8e1175bSopenharmony_ci available = check_test_cases.collect_available_test_cases() 89a8e1175bSopenharmony_ci for suite_case in available: 90a8e1175bSopenharmony_ci hit = any(suite_case in comp_outcomes.successes or 91a8e1175bSopenharmony_ci suite_case in comp_outcomes.failures 92a8e1175bSopenharmony_ci for comp_outcomes in outcomes.values()) 93a8e1175bSopenharmony_ci 94a8e1175bSopenharmony_ci if not hit and suite_case not in allow_list: 95a8e1175bSopenharmony_ci if full_coverage: 96a8e1175bSopenharmony_ci results.error('Test case not executed: {}', suite_case) 97a8e1175bSopenharmony_ci else: 98a8e1175bSopenharmony_ci results.warning('Test case not executed: {}', suite_case) 99a8e1175bSopenharmony_ci elif hit and suite_case in allow_list: 100a8e1175bSopenharmony_ci # Test Case should be removed from the allow list. 101a8e1175bSopenharmony_ci if full_coverage: 102a8e1175bSopenharmony_ci results.error('Allow listed test case was executed: {}', suite_case) 103a8e1175bSopenharmony_ci else: 104a8e1175bSopenharmony_ci results.warning('Allow listed test case was executed: {}', suite_case) 105a8e1175bSopenharmony_ci 106a8e1175bSopenharmony_cidef name_matches_pattern(name: str, str_or_re) -> bool: 107a8e1175bSopenharmony_ci """Check if name matches a pattern, that may be a string or regex. 108a8e1175bSopenharmony_ci - If the pattern is a string, name must be equal to match. 109a8e1175bSopenharmony_ci - If the pattern is a regex, name must fully match. 110a8e1175bSopenharmony_ci """ 111a8e1175bSopenharmony_ci # The CI's python is too old for re.Pattern 112a8e1175bSopenharmony_ci #if isinstance(str_or_re, re.Pattern): 113a8e1175bSopenharmony_ci if not isinstance(str_or_re, str): 114a8e1175bSopenharmony_ci return str_or_re.fullmatch(name) is not None 115a8e1175bSopenharmony_ci else: 116a8e1175bSopenharmony_ci return str_or_re == name 117a8e1175bSopenharmony_ci 118a8e1175bSopenharmony_cidef analyze_driver_vs_reference(results: Results, outcomes: Outcomes, 119a8e1175bSopenharmony_ci component_ref: str, component_driver: str, 120a8e1175bSopenharmony_ci ignored_suites: typing.List[str], ignored_tests=None) -> None: 121a8e1175bSopenharmony_ci """Check that all tests passing in the reference component are also 122a8e1175bSopenharmony_ci passing in the corresponding driver component. 123a8e1175bSopenharmony_ci Skip: 124a8e1175bSopenharmony_ci - full test suites provided in ignored_suites list 125a8e1175bSopenharmony_ci - only some specific test inside a test suite, for which the corresponding 126a8e1175bSopenharmony_ci output string is provided 127a8e1175bSopenharmony_ci """ 128a8e1175bSopenharmony_ci ref_outcomes = outcomes.get("component_" + component_ref) 129a8e1175bSopenharmony_ci driver_outcomes = outcomes.get("component_" + component_driver) 130a8e1175bSopenharmony_ci 131a8e1175bSopenharmony_ci if ref_outcomes is None or driver_outcomes is None: 132a8e1175bSopenharmony_ci results.error("required components are missing: bad outcome file?") 133a8e1175bSopenharmony_ci return 134a8e1175bSopenharmony_ci 135a8e1175bSopenharmony_ci if not ref_outcomes.successes: 136a8e1175bSopenharmony_ci results.error("no passing test in reference component: bad outcome file?") 137a8e1175bSopenharmony_ci return 138a8e1175bSopenharmony_ci 139a8e1175bSopenharmony_ci for suite_case in ref_outcomes.successes: 140a8e1175bSopenharmony_ci # suite_case is like "test_suite_foo.bar;Description of test case" 141a8e1175bSopenharmony_ci (full_test_suite, test_string) = suite_case.split(';') 142a8e1175bSopenharmony_ci test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name 143a8e1175bSopenharmony_ci 144a8e1175bSopenharmony_ci # Immediately skip fully-ignored test suites 145a8e1175bSopenharmony_ci if test_suite in ignored_suites or full_test_suite in ignored_suites: 146a8e1175bSopenharmony_ci continue 147a8e1175bSopenharmony_ci 148a8e1175bSopenharmony_ci # For ignored test cases inside test suites, just remember and: 149a8e1175bSopenharmony_ci # don't issue an error if they're skipped with drivers, 150a8e1175bSopenharmony_ci # but issue an error if they're not (means we have a bad entry). 151a8e1175bSopenharmony_ci ignored = False 152a8e1175bSopenharmony_ci if full_test_suite in ignored_tests: 153a8e1175bSopenharmony_ci for str_or_re in ignored_tests[full_test_suite]: 154a8e1175bSopenharmony_ci if name_matches_pattern(test_string, str_or_re): 155a8e1175bSopenharmony_ci ignored = True 156a8e1175bSopenharmony_ci 157a8e1175bSopenharmony_ci if not ignored and not suite_case in driver_outcomes.successes: 158a8e1175bSopenharmony_ci results.error("PASS -> SKIP/FAIL: {}", suite_case) 159a8e1175bSopenharmony_ci if ignored and suite_case in driver_outcomes.successes: 160a8e1175bSopenharmony_ci results.error("uselessly ignored: {}", suite_case) 161a8e1175bSopenharmony_ci 162a8e1175bSopenharmony_cidef analyze_outcomes(results: Results, outcomes: Outcomes, args) -> None: 163a8e1175bSopenharmony_ci """Run all analyses on the given outcome collection.""" 164a8e1175bSopenharmony_ci analyze_coverage(results, outcomes, args['allow_list'], 165a8e1175bSopenharmony_ci args['full_coverage']) 166a8e1175bSopenharmony_ci 167a8e1175bSopenharmony_cidef read_outcome_file(outcome_file: str) -> Outcomes: 168a8e1175bSopenharmony_ci """Parse an outcome file and return an outcome collection. 169a8e1175bSopenharmony_ci """ 170a8e1175bSopenharmony_ci outcomes = {} 171a8e1175bSopenharmony_ci with open(outcome_file, 'r', encoding='utf-8') as input_file: 172a8e1175bSopenharmony_ci for line in input_file: 173a8e1175bSopenharmony_ci (_platform, component, suite, case, result, _cause) = line.split(';') 174a8e1175bSopenharmony_ci # Note that `component` is not unique. If a test case passes on Linux 175a8e1175bSopenharmony_ci # and fails on FreeBSD, it'll end up in both the successes set and 176a8e1175bSopenharmony_ci # the failures set. 177a8e1175bSopenharmony_ci suite_case = ';'.join([suite, case]) 178a8e1175bSopenharmony_ci if component not in outcomes: 179a8e1175bSopenharmony_ci outcomes[component] = ComponentOutcomes(set(), set()) 180a8e1175bSopenharmony_ci if result == 'PASS': 181a8e1175bSopenharmony_ci outcomes[component].successes.add(suite_case) 182a8e1175bSopenharmony_ci elif result == 'FAIL': 183a8e1175bSopenharmony_ci outcomes[component].failures.add(suite_case) 184a8e1175bSopenharmony_ci 185a8e1175bSopenharmony_ci return outcomes 186a8e1175bSopenharmony_ci 187a8e1175bSopenharmony_cidef do_analyze_coverage(results: Results, outcomes: Outcomes, args) -> None: 188a8e1175bSopenharmony_ci """Perform coverage analysis.""" 189a8e1175bSopenharmony_ci results.new_section("Analyze coverage") 190a8e1175bSopenharmony_ci analyze_outcomes(results, outcomes, args) 191a8e1175bSopenharmony_ci 192a8e1175bSopenharmony_cidef do_analyze_driver_vs_reference(results: Results, outcomes: Outcomes, args) -> None: 193a8e1175bSopenharmony_ci """Perform driver vs reference analyze.""" 194a8e1175bSopenharmony_ci results.new_section("Analyze driver {} vs reference {}", 195a8e1175bSopenharmony_ci args['component_driver'], args['component_ref']) 196a8e1175bSopenharmony_ci 197a8e1175bSopenharmony_ci ignored_suites = ['test_suite_' + x for x in args['ignored_suites']] 198a8e1175bSopenharmony_ci 199a8e1175bSopenharmony_ci analyze_driver_vs_reference(results, outcomes, 200a8e1175bSopenharmony_ci args['component_ref'], args['component_driver'], 201a8e1175bSopenharmony_ci ignored_suites, args['ignored_tests']) 202a8e1175bSopenharmony_ci 203a8e1175bSopenharmony_ci# List of tasks with a function that can handle this task and additional arguments if required 204a8e1175bSopenharmony_ciKNOWN_TASKS = { 205a8e1175bSopenharmony_ci 'analyze_coverage': { 206a8e1175bSopenharmony_ci 'test_function': do_analyze_coverage, 207a8e1175bSopenharmony_ci 'args': { 208a8e1175bSopenharmony_ci 'allow_list': [ 209a8e1175bSopenharmony_ci # Algorithm not supported yet 210a8e1175bSopenharmony_ci 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA', 211a8e1175bSopenharmony_ci # Algorithm not supported yet 212a8e1175bSopenharmony_ci 'test_suite_psa_crypto_metadata;Cipher: XTS', 213a8e1175bSopenharmony_ci ], 214a8e1175bSopenharmony_ci 'full_coverage': False, 215a8e1175bSopenharmony_ci } 216a8e1175bSopenharmony_ci }, 217a8e1175bSopenharmony_ci # There are 2 options to use analyze_driver_vs_reference_xxx locally: 218a8e1175bSopenharmony_ci # 1. Run tests and then analysis: 219a8e1175bSopenharmony_ci # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver> 220a8e1175bSopenharmony_ci # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx 221a8e1175bSopenharmony_ci # 2. Let this script run both automatically: 222a8e1175bSopenharmony_ci # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx 223a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_hash': { 224a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 225a8e1175bSopenharmony_ci 'args': { 226a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa', 227a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa', 228a8e1175bSopenharmony_ci 'ignored_suites': [ 229a8e1175bSopenharmony_ci 'shax', 'mdx', # the software implementations that are being excluded 230a8e1175bSopenharmony_ci 'md.psa', # purposefully depends on whether drivers are present 231a8e1175bSopenharmony_ci 'psa_crypto_low_hash.generated', # testing the builtins 232a8e1175bSopenharmony_ci ], 233a8e1175bSopenharmony_ci 'ignored_tests': { 234a8e1175bSopenharmony_ci 'test_suite_platform': [ 235a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 236a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 237a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 238a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 239a8e1175bSopenharmony_ci ], 240a8e1175bSopenharmony_ci } 241a8e1175bSopenharmony_ci } 242a8e1175bSopenharmony_ci }, 243a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_hmac': { 244a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 245a8e1175bSopenharmony_ci 'args': { 246a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_hmac', 247a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_hmac', 248a8e1175bSopenharmony_ci 'ignored_suites': [ 249a8e1175bSopenharmony_ci # These suites require legacy hash support, which is disabled 250a8e1175bSopenharmony_ci # in the accelerated component. 251a8e1175bSopenharmony_ci 'shax', 'mdx', 252a8e1175bSopenharmony_ci # This suite tests builtins directly, but these are missing 253a8e1175bSopenharmony_ci # in the accelerated case. 254a8e1175bSopenharmony_ci 'psa_crypto_low_hash.generated', 255a8e1175bSopenharmony_ci ], 256a8e1175bSopenharmony_ci 'ignored_tests': { 257a8e1175bSopenharmony_ci 'test_suite_md': [ 258a8e1175bSopenharmony_ci # Builtin HMAC is not supported in the accelerate component. 259a8e1175bSopenharmony_ci re.compile('.*HMAC.*'), 260a8e1175bSopenharmony_ci # Following tests make use of functions which are not available 261a8e1175bSopenharmony_ci # when MD_C is disabled, as it happens in the accelerated 262a8e1175bSopenharmony_ci # test component. 263a8e1175bSopenharmony_ci re.compile('generic .* Hash file .*'), 264a8e1175bSopenharmony_ci 'MD list', 265a8e1175bSopenharmony_ci ], 266a8e1175bSopenharmony_ci 'test_suite_md.psa': [ 267a8e1175bSopenharmony_ci # "legacy only" tests require hash algorithms to be NOT 268a8e1175bSopenharmony_ci # accelerated, but this of course false for the accelerated 269a8e1175bSopenharmony_ci # test component. 270a8e1175bSopenharmony_ci re.compile('PSA dispatch .* legacy only'), 271a8e1175bSopenharmony_ci ], 272a8e1175bSopenharmony_ci 'test_suite_platform': [ 273a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 274a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 275a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 276a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 277a8e1175bSopenharmony_ci ], 278a8e1175bSopenharmony_ci } 279a8e1175bSopenharmony_ci } 280a8e1175bSopenharmony_ci }, 281a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_cipher_aead_cmac': { 282a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 283a8e1175bSopenharmony_ci 'args': { 284a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac', 285a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac', 286a8e1175bSopenharmony_ci # Modules replaced by drivers. 287a8e1175bSopenharmony_ci 'ignored_suites': [ 288a8e1175bSopenharmony_ci # low-level (block/stream) cipher modules 289a8e1175bSopenharmony_ci 'aes', 'aria', 'camellia', 'des', 'chacha20', 290a8e1175bSopenharmony_ci # AEAD modes and CMAC 291a8e1175bSopenharmony_ci 'ccm', 'chachapoly', 'cmac', 'gcm', 292a8e1175bSopenharmony_ci # The Cipher abstraction layer 293a8e1175bSopenharmony_ci 'cipher', 294a8e1175bSopenharmony_ci ], 295a8e1175bSopenharmony_ci 'ignored_tests': { 296a8e1175bSopenharmony_ci # PEM decryption is not supported so far. 297a8e1175bSopenharmony_ci # The rest of PEM (write, unencrypted read) works though. 298a8e1175bSopenharmony_ci 'test_suite_pem': [ 299a8e1175bSopenharmony_ci re.compile(r'PEM read .*(AES|DES|\bencrypt).*'), 300a8e1175bSopenharmony_ci ], 301a8e1175bSopenharmony_ci 'test_suite_platform': [ 302a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 303a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 304a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 305a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 306a8e1175bSopenharmony_ci ], 307a8e1175bSopenharmony_ci # Following tests depend on AES_C/DES_C but are not about 308a8e1175bSopenharmony_ci # them really, just need to know some error code is there. 309a8e1175bSopenharmony_ci 'test_suite_error': [ 310a8e1175bSopenharmony_ci 'Low and high error', 311a8e1175bSopenharmony_ci 'Single low error' 312a8e1175bSopenharmony_ci ], 313a8e1175bSopenharmony_ci # Similar to test_suite_error above. 314a8e1175bSopenharmony_ci 'test_suite_version': [ 315a8e1175bSopenharmony_ci 'Check for MBEDTLS_AES_C when already present', 316a8e1175bSopenharmony_ci ], 317a8e1175bSopenharmony_ci # The en/decryption part of PKCS#12 is not supported so far. 318a8e1175bSopenharmony_ci # The rest of PKCS#12 (key derivation) works though. 319a8e1175bSopenharmony_ci 'test_suite_pkcs12': [ 320a8e1175bSopenharmony_ci re.compile(r'PBE Encrypt, .*'), 321a8e1175bSopenharmony_ci re.compile(r'PBE Decrypt, .*'), 322a8e1175bSopenharmony_ci ], 323a8e1175bSopenharmony_ci # The en/decryption part of PKCS#5 is not supported so far. 324a8e1175bSopenharmony_ci # The rest of PKCS#5 (PBKDF2) works though. 325a8e1175bSopenharmony_ci 'test_suite_pkcs5': [ 326a8e1175bSopenharmony_ci re.compile(r'PBES2 Encrypt, .*'), 327a8e1175bSopenharmony_ci re.compile(r'PBES2 Decrypt .*'), 328a8e1175bSopenharmony_ci ], 329a8e1175bSopenharmony_ci # Encrypted keys are not supported so far. 330a8e1175bSopenharmony_ci # pylint: disable=line-too-long 331a8e1175bSopenharmony_ci 'test_suite_pkparse': [ 332a8e1175bSopenharmony_ci 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)', 333a8e1175bSopenharmony_ci 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)', 334a8e1175bSopenharmony_ci re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'), 335a8e1175bSopenharmony_ci ], 336a8e1175bSopenharmony_ci } 337a8e1175bSopenharmony_ci } 338a8e1175bSopenharmony_ci }, 339a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_ecp_light_only': { 340a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 341a8e1175bSopenharmony_ci 'args': { 342a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', 343a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', 344a8e1175bSopenharmony_ci 'ignored_suites': [ 345a8e1175bSopenharmony_ci # Modules replaced by drivers 346a8e1175bSopenharmony_ci 'ecdsa', 'ecdh', 'ecjpake', 347a8e1175bSopenharmony_ci ], 348a8e1175bSopenharmony_ci 'ignored_tests': { 349a8e1175bSopenharmony_ci 'test_suite_platform': [ 350a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 351a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 352a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 353a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 354a8e1175bSopenharmony_ci ], 355a8e1175bSopenharmony_ci # This test wants a legacy function that takes f_rng, p_rng 356a8e1175bSopenharmony_ci # arguments, and uses legacy ECDSA for that. The test is 357a8e1175bSopenharmony_ci # really about the wrapper around the PSA RNG, not ECDSA. 358a8e1175bSopenharmony_ci 'test_suite_random': [ 359a8e1175bSopenharmony_ci 'PSA classic wrapper: ECDSA signature (SECP256R1)', 360a8e1175bSopenharmony_ci ], 361a8e1175bSopenharmony_ci # In the accelerated test ECP_C is not set (only ECP_LIGHT is) 362a8e1175bSopenharmony_ci # so we must ignore disparities in the tests for which ECP_C 363a8e1175bSopenharmony_ci # is required. 364a8e1175bSopenharmony_ci 'test_suite_ecp': [ 365a8e1175bSopenharmony_ci re.compile(r'ECP check public-private .*'), 366a8e1175bSopenharmony_ci re.compile(r'ECP calculate public: .*'), 367a8e1175bSopenharmony_ci re.compile(r'ECP gen keypair .*'), 368a8e1175bSopenharmony_ci re.compile(r'ECP point muladd .*'), 369a8e1175bSopenharmony_ci re.compile(r'ECP point multiplication .*'), 370a8e1175bSopenharmony_ci re.compile(r'ECP test vectors .*'), 371a8e1175bSopenharmony_ci ], 372a8e1175bSopenharmony_ci 'test_suite_ssl': [ 373a8e1175bSopenharmony_ci # This deprecated function is only present when ECP_C is On. 374a8e1175bSopenharmony_ci 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 375a8e1175bSopenharmony_ci ], 376a8e1175bSopenharmony_ci } 377a8e1175bSopenharmony_ci } 378a8e1175bSopenharmony_ci }, 379a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_no_ecp_at_all': { 380a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 381a8e1175bSopenharmony_ci 'args': { 382a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all', 383a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all', 384a8e1175bSopenharmony_ci 'ignored_suites': [ 385a8e1175bSopenharmony_ci # Modules replaced by drivers 386a8e1175bSopenharmony_ci 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 387a8e1175bSopenharmony_ci ], 388a8e1175bSopenharmony_ci 'ignored_tests': { 389a8e1175bSopenharmony_ci 'test_suite_platform': [ 390a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 391a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 392a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 393a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 394a8e1175bSopenharmony_ci ], 395a8e1175bSopenharmony_ci # See ecp_light_only 396a8e1175bSopenharmony_ci 'test_suite_random': [ 397a8e1175bSopenharmony_ci 'PSA classic wrapper: ECDSA signature (SECP256R1)', 398a8e1175bSopenharmony_ci ], 399a8e1175bSopenharmony_ci 'test_suite_pkparse': [ 400a8e1175bSopenharmony_ci # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED 401a8e1175bSopenharmony_ci # is automatically enabled in build_info.h (backward compatibility) 402a8e1175bSopenharmony_ci # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a 403a8e1175bSopenharmony_ci # consequence compressed points are supported in the reference 404a8e1175bSopenharmony_ci # component but not in the accelerated one, so they should be skipped 405a8e1175bSopenharmony_ci # while checking driver's coverage. 406a8e1175bSopenharmony_ci re.compile(r'Parse EC Key .*compressed\)'), 407a8e1175bSopenharmony_ci re.compile(r'Parse Public EC Key .*compressed\)'), 408a8e1175bSopenharmony_ci ], 409a8e1175bSopenharmony_ci # See ecp_light_only 410a8e1175bSopenharmony_ci 'test_suite_ssl': [ 411a8e1175bSopenharmony_ci 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 412a8e1175bSopenharmony_ci ], 413a8e1175bSopenharmony_ci } 414a8e1175bSopenharmony_ci } 415a8e1175bSopenharmony_ci }, 416a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_ecc_no_bignum': { 417a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 418a8e1175bSopenharmony_ci 'args': { 419a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum', 420a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum', 421a8e1175bSopenharmony_ci 'ignored_suites': [ 422a8e1175bSopenharmony_ci # Modules replaced by drivers 423a8e1175bSopenharmony_ci 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 424a8e1175bSopenharmony_ci 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 425a8e1175bSopenharmony_ci 'bignum.generated', 'bignum.misc', 426a8e1175bSopenharmony_ci ], 427a8e1175bSopenharmony_ci 'ignored_tests': { 428a8e1175bSopenharmony_ci 'test_suite_platform': [ 429a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 430a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 431a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 432a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 433a8e1175bSopenharmony_ci ], 434a8e1175bSopenharmony_ci # See ecp_light_only 435a8e1175bSopenharmony_ci 'test_suite_random': [ 436a8e1175bSopenharmony_ci 'PSA classic wrapper: ECDSA signature (SECP256R1)', 437a8e1175bSopenharmony_ci ], 438a8e1175bSopenharmony_ci # See no_ecp_at_all 439a8e1175bSopenharmony_ci 'test_suite_pkparse': [ 440a8e1175bSopenharmony_ci re.compile(r'Parse EC Key .*compressed\)'), 441a8e1175bSopenharmony_ci re.compile(r'Parse Public EC Key .*compressed\)'), 442a8e1175bSopenharmony_ci ], 443a8e1175bSopenharmony_ci 'test_suite_asn1parse': [ 444a8e1175bSopenharmony_ci 'INTEGER too large for mpi', 445a8e1175bSopenharmony_ci ], 446a8e1175bSopenharmony_ci 'test_suite_asn1write': [ 447a8e1175bSopenharmony_ci re.compile(r'ASN.1 Write mpi.*'), 448a8e1175bSopenharmony_ci ], 449a8e1175bSopenharmony_ci 'test_suite_debug': [ 450a8e1175bSopenharmony_ci re.compile(r'Debug print mbedtls_mpi.*'), 451a8e1175bSopenharmony_ci ], 452a8e1175bSopenharmony_ci # See ecp_light_only 453a8e1175bSopenharmony_ci 'test_suite_ssl': [ 454a8e1175bSopenharmony_ci 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 455a8e1175bSopenharmony_ci ], 456a8e1175bSopenharmony_ci } 457a8e1175bSopenharmony_ci } 458a8e1175bSopenharmony_ci }, 459a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': { 460a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 461a8e1175bSopenharmony_ci 'args': { 462a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum', 463a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum', 464a8e1175bSopenharmony_ci 'ignored_suites': [ 465a8e1175bSopenharmony_ci # Modules replaced by drivers 466a8e1175bSopenharmony_ci 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm', 467a8e1175bSopenharmony_ci 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 468a8e1175bSopenharmony_ci 'bignum.generated', 'bignum.misc', 469a8e1175bSopenharmony_ci ], 470a8e1175bSopenharmony_ci 'ignored_tests': { 471a8e1175bSopenharmony_ci 'test_suite_platform': [ 472a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 473a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 474a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 475a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 476a8e1175bSopenharmony_ci ], 477a8e1175bSopenharmony_ci # See ecp_light_only 478a8e1175bSopenharmony_ci 'test_suite_random': [ 479a8e1175bSopenharmony_ci 'PSA classic wrapper: ECDSA signature (SECP256R1)', 480a8e1175bSopenharmony_ci ], 481a8e1175bSopenharmony_ci # See no_ecp_at_all 482a8e1175bSopenharmony_ci 'test_suite_pkparse': [ 483a8e1175bSopenharmony_ci re.compile(r'Parse EC Key .*compressed\)'), 484a8e1175bSopenharmony_ci re.compile(r'Parse Public EC Key .*compressed\)'), 485a8e1175bSopenharmony_ci ], 486a8e1175bSopenharmony_ci 'test_suite_asn1parse': [ 487a8e1175bSopenharmony_ci 'INTEGER too large for mpi', 488a8e1175bSopenharmony_ci ], 489a8e1175bSopenharmony_ci 'test_suite_asn1write': [ 490a8e1175bSopenharmony_ci re.compile(r'ASN.1 Write mpi.*'), 491a8e1175bSopenharmony_ci ], 492a8e1175bSopenharmony_ci 'test_suite_debug': [ 493a8e1175bSopenharmony_ci re.compile(r'Debug print mbedtls_mpi.*'), 494a8e1175bSopenharmony_ci ], 495a8e1175bSopenharmony_ci # See ecp_light_only 496a8e1175bSopenharmony_ci 'test_suite_ssl': [ 497a8e1175bSopenharmony_ci 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 498a8e1175bSopenharmony_ci ], 499a8e1175bSopenharmony_ci } 500a8e1175bSopenharmony_ci } 501a8e1175bSopenharmony_ci }, 502a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_ffdh_alg': { 503a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 504a8e1175bSopenharmony_ci 'args': { 505a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_ffdh', 506a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_ffdh', 507a8e1175bSopenharmony_ci 'ignored_suites': ['dhm'], 508a8e1175bSopenharmony_ci 'ignored_tests': { 509a8e1175bSopenharmony_ci 'test_suite_platform': [ 510a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 511a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 512a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 513a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 514a8e1175bSopenharmony_ci ], 515a8e1175bSopenharmony_ci } 516a8e1175bSopenharmony_ci } 517a8e1175bSopenharmony_ci }, 518a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_tfm_config': { 519a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 520a8e1175bSopenharmony_ci 'args': { 521a8e1175bSopenharmony_ci 'component_ref': 'test_tfm_config', 522a8e1175bSopenharmony_ci 'component_driver': 'test_tfm_config_p256m_driver_accel_ec', 523a8e1175bSopenharmony_ci 'ignored_suites': [ 524a8e1175bSopenharmony_ci # Modules replaced by drivers 525a8e1175bSopenharmony_ci 'asn1parse', 'asn1write', 526a8e1175bSopenharmony_ci 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 527a8e1175bSopenharmony_ci 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 528a8e1175bSopenharmony_ci 'bignum.generated', 'bignum.misc', 529a8e1175bSopenharmony_ci ], 530a8e1175bSopenharmony_ci 'ignored_tests': { 531a8e1175bSopenharmony_ci 'test_suite_platform': [ 532a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 533a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 534a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 535a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 536a8e1175bSopenharmony_ci ], 537a8e1175bSopenharmony_ci # See ecp_light_only 538a8e1175bSopenharmony_ci 'test_suite_random': [ 539a8e1175bSopenharmony_ci 'PSA classic wrapper: ECDSA signature (SECP256R1)', 540a8e1175bSopenharmony_ci ], 541a8e1175bSopenharmony_ci } 542a8e1175bSopenharmony_ci } 543a8e1175bSopenharmony_ci }, 544a8e1175bSopenharmony_ci 'analyze_driver_vs_reference_rsa': { 545a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 546a8e1175bSopenharmony_ci 'args': { 547a8e1175bSopenharmony_ci 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto', 548a8e1175bSopenharmony_ci 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto', 549a8e1175bSopenharmony_ci 'ignored_suites': [ 550a8e1175bSopenharmony_ci # Modules replaced by drivers. 551a8e1175bSopenharmony_ci 'rsa', 'pkcs1_v15', 'pkcs1_v21', 552a8e1175bSopenharmony_ci # We temporarily don't care about PK stuff. 553a8e1175bSopenharmony_ci 'pk', 'pkwrite', 'pkparse' 554a8e1175bSopenharmony_ci ], 555a8e1175bSopenharmony_ci 'ignored_tests': { 556a8e1175bSopenharmony_ci 'test_suite_platform': [ 557a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 558a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 559a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 560a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 561a8e1175bSopenharmony_ci ], 562a8e1175bSopenharmony_ci # Following tests depend on RSA_C but are not about 563a8e1175bSopenharmony_ci # them really, just need to know some error code is there. 564a8e1175bSopenharmony_ci 'test_suite_error': [ 565a8e1175bSopenharmony_ci 'Low and high error', 566a8e1175bSopenharmony_ci 'Single high error' 567a8e1175bSopenharmony_ci ], 568a8e1175bSopenharmony_ci # Constant time operations only used for PKCS1_V15 569a8e1175bSopenharmony_ci 'test_suite_constant_time': [ 570a8e1175bSopenharmony_ci re.compile(r'mbedtls_ct_zeroize_if .*'), 571a8e1175bSopenharmony_ci re.compile(r'mbedtls_ct_memmove_left .*') 572a8e1175bSopenharmony_ci ], 573a8e1175bSopenharmony_ci 'test_suite_psa_crypto': [ 574a8e1175bSopenharmony_ci # We don't support generate_key_ext entry points 575a8e1175bSopenharmony_ci # in drivers yet. 576a8e1175bSopenharmony_ci re.compile(r'PSA generate key ext: RSA, e=.*'), 577a8e1175bSopenharmony_ci ], 578a8e1175bSopenharmony_ci } 579a8e1175bSopenharmony_ci } 580a8e1175bSopenharmony_ci }, 581a8e1175bSopenharmony_ci 'analyze_block_cipher_dispatch': { 582a8e1175bSopenharmony_ci 'test_function': do_analyze_driver_vs_reference, 583a8e1175bSopenharmony_ci 'args': { 584a8e1175bSopenharmony_ci 'component_ref': 'test_full_block_cipher_legacy_dispatch', 585a8e1175bSopenharmony_ci 'component_driver': 'test_full_block_cipher_psa_dispatch', 586a8e1175bSopenharmony_ci 'ignored_suites': [ 587a8e1175bSopenharmony_ci # Skipped in the accelerated component 588a8e1175bSopenharmony_ci 'aes', 'aria', 'camellia', 589a8e1175bSopenharmony_ci # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in 590a8e1175bSopenharmony_ci # order for the cipher module (actually cipher_wrapper) to work 591a8e1175bSopenharmony_ci # properly. However these symbols are disabled in the accelerated 592a8e1175bSopenharmony_ci # component so we ignore them. 593a8e1175bSopenharmony_ci 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria', 594a8e1175bSopenharmony_ci 'cipher.camellia', 595a8e1175bSopenharmony_ci ], 596a8e1175bSopenharmony_ci 'ignored_tests': { 597a8e1175bSopenharmony_ci 'test_suite_cmac': [ 598a8e1175bSopenharmony_ci # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled, 599a8e1175bSopenharmony_ci # but these are not available in the accelerated component. 600a8e1175bSopenharmony_ci 'CMAC null arguments', 601a8e1175bSopenharmony_ci re.compile('CMAC.* (AES|ARIA|Camellia).*'), 602a8e1175bSopenharmony_ci ], 603a8e1175bSopenharmony_ci 'test_suite_cipher.padding': [ 604a8e1175bSopenharmony_ci # Following tests require AES_C/CAMELLIA_C to be enabled, 605a8e1175bSopenharmony_ci # but these are not available in the accelerated component. 606a8e1175bSopenharmony_ci re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'), 607a8e1175bSopenharmony_ci ], 608a8e1175bSopenharmony_ci 'test_suite_pkcs5': [ 609a8e1175bSopenharmony_ci # The AES part of PKCS#5 PBES2 is not yet supported. 610a8e1175bSopenharmony_ci # The rest of PKCS#5 (PBKDF2) works, though. 611a8e1175bSopenharmony_ci re.compile(r'PBES2 .* AES-.*') 612a8e1175bSopenharmony_ci ], 613a8e1175bSopenharmony_ci 'test_suite_pkparse': [ 614a8e1175bSopenharmony_ci # PEM (called by pkparse) requires AES_C in order to decrypt 615a8e1175bSopenharmony_ci # the key, but this is not available in the accelerated 616a8e1175bSopenharmony_ci # component. 617a8e1175bSopenharmony_ci re.compile('Parse RSA Key.*(password|AES-).*'), 618a8e1175bSopenharmony_ci ], 619a8e1175bSopenharmony_ci 'test_suite_pem': [ 620a8e1175bSopenharmony_ci # Following tests require AES_C, but this is diabled in the 621a8e1175bSopenharmony_ci # accelerated component. 622a8e1175bSopenharmony_ci re.compile('PEM read .*AES.*'), 623a8e1175bSopenharmony_ci 'PEM read (unknown encryption algorithm)', 624a8e1175bSopenharmony_ci ], 625a8e1175bSopenharmony_ci 'test_suite_error': [ 626a8e1175bSopenharmony_ci # Following tests depend on AES_C but are not about them 627a8e1175bSopenharmony_ci # really, just need to know some error code is there. 628a8e1175bSopenharmony_ci 'Single low error', 629a8e1175bSopenharmony_ci 'Low and high error', 630a8e1175bSopenharmony_ci ], 631a8e1175bSopenharmony_ci 'test_suite_version': [ 632a8e1175bSopenharmony_ci # Similar to test_suite_error above. 633a8e1175bSopenharmony_ci 'Check for MBEDTLS_AES_C when already present', 634a8e1175bSopenharmony_ci ], 635a8e1175bSopenharmony_ci 'test_suite_platform': [ 636a8e1175bSopenharmony_ci # Incompatible with sanitizers (e.g. ASan). If the driver 637a8e1175bSopenharmony_ci # component uses a sanitizer but the reference component 638a8e1175bSopenharmony_ci # doesn't, we have a PASS vs SKIP mismatch. 639a8e1175bSopenharmony_ci 'Check mbedtls_calloc overallocation', 640a8e1175bSopenharmony_ci ], 641a8e1175bSopenharmony_ci } 642a8e1175bSopenharmony_ci } 643a8e1175bSopenharmony_ci } 644a8e1175bSopenharmony_ci} 645a8e1175bSopenharmony_ci 646a8e1175bSopenharmony_cidef main(): 647a8e1175bSopenharmony_ci main_results = Results() 648a8e1175bSopenharmony_ci 649a8e1175bSopenharmony_ci try: 650a8e1175bSopenharmony_ci parser = argparse.ArgumentParser(description=__doc__) 651a8e1175bSopenharmony_ci parser.add_argument('outcomes', metavar='OUTCOMES.CSV', 652a8e1175bSopenharmony_ci help='Outcome file to analyze') 653a8e1175bSopenharmony_ci parser.add_argument('specified_tasks', default='all', nargs='?', 654a8e1175bSopenharmony_ci help='Analysis to be done. By default, run all tasks. ' 655a8e1175bSopenharmony_ci 'With one or more TASK, run only those. ' 656a8e1175bSopenharmony_ci 'TASK can be the name of a single task or ' 657a8e1175bSopenharmony_ci 'comma/space-separated list of tasks. ') 658a8e1175bSopenharmony_ci parser.add_argument('--list', action='store_true', 659a8e1175bSopenharmony_ci help='List all available tasks and exit.') 660a8e1175bSopenharmony_ci parser.add_argument('--require-full-coverage', action='store_true', 661a8e1175bSopenharmony_ci dest='full_coverage', help="Require all available " 662a8e1175bSopenharmony_ci "test cases to be executed and issue an error " 663a8e1175bSopenharmony_ci "otherwise. This flag is ignored if 'task' is " 664a8e1175bSopenharmony_ci "neither 'all' nor 'analyze_coverage'") 665a8e1175bSopenharmony_ci options = parser.parse_args() 666a8e1175bSopenharmony_ci 667a8e1175bSopenharmony_ci if options.list: 668a8e1175bSopenharmony_ci for task in KNOWN_TASKS: 669a8e1175bSopenharmony_ci print(task) 670a8e1175bSopenharmony_ci sys.exit(0) 671a8e1175bSopenharmony_ci 672a8e1175bSopenharmony_ci if options.specified_tasks == 'all': 673a8e1175bSopenharmony_ci tasks_list = KNOWN_TASKS.keys() 674a8e1175bSopenharmony_ci else: 675a8e1175bSopenharmony_ci tasks_list = re.split(r'[, ]+', options.specified_tasks) 676a8e1175bSopenharmony_ci for task in tasks_list: 677a8e1175bSopenharmony_ci if task not in KNOWN_TASKS: 678a8e1175bSopenharmony_ci sys.stderr.write('invalid task: {}\n'.format(task)) 679a8e1175bSopenharmony_ci sys.exit(2) 680a8e1175bSopenharmony_ci 681a8e1175bSopenharmony_ci KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage 682a8e1175bSopenharmony_ci 683a8e1175bSopenharmony_ci # If the outcome file exists, parse it once and share the result 684a8e1175bSopenharmony_ci # among tasks to improve performance. 685a8e1175bSopenharmony_ci # Otherwise, it will be generated by execute_reference_driver_tests. 686a8e1175bSopenharmony_ci if not os.path.exists(options.outcomes): 687a8e1175bSopenharmony_ci if len(tasks_list) > 1: 688a8e1175bSopenharmony_ci sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n") 689a8e1175bSopenharmony_ci sys.exit(2) 690a8e1175bSopenharmony_ci 691a8e1175bSopenharmony_ci task_name = tasks_list[0] 692a8e1175bSopenharmony_ci task = KNOWN_TASKS[task_name] 693a8e1175bSopenharmony_ci if task['test_function'] != do_analyze_driver_vs_reference: # pylint: disable=comparison-with-callable 694a8e1175bSopenharmony_ci sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name)) 695a8e1175bSopenharmony_ci sys.exit(2) 696a8e1175bSopenharmony_ci 697a8e1175bSopenharmony_ci execute_reference_driver_tests(main_results, 698a8e1175bSopenharmony_ci task['args']['component_ref'], 699a8e1175bSopenharmony_ci task['args']['component_driver'], 700a8e1175bSopenharmony_ci options.outcomes) 701a8e1175bSopenharmony_ci 702a8e1175bSopenharmony_ci outcomes = read_outcome_file(options.outcomes) 703a8e1175bSopenharmony_ci 704a8e1175bSopenharmony_ci for task in tasks_list: 705a8e1175bSopenharmony_ci test_function = KNOWN_TASKS[task]['test_function'] 706a8e1175bSopenharmony_ci test_args = KNOWN_TASKS[task]['args'] 707a8e1175bSopenharmony_ci test_function(main_results, outcomes, test_args) 708a8e1175bSopenharmony_ci 709a8e1175bSopenharmony_ci main_results.info("Overall results: {} warnings and {} errors", 710a8e1175bSopenharmony_ci main_results.warning_count, main_results.error_count) 711a8e1175bSopenharmony_ci 712a8e1175bSopenharmony_ci sys.exit(0 if (main_results.error_count == 0) else 1) 713a8e1175bSopenharmony_ci 714a8e1175bSopenharmony_ci except Exception: # pylint: disable=broad-except 715a8e1175bSopenharmony_ci # Print the backtrace and exit explicitly with our chosen status. 716a8e1175bSopenharmony_ci traceback.print_exc() 717a8e1175bSopenharmony_ci sys.exit(120) 718a8e1175bSopenharmony_ci 719a8e1175bSopenharmony_ciif __name__ == '__main__': 720a8e1175bSopenharmony_ci main() 721