Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Bence Szépkúti | 449781f | 2021-11-02 13:41:14 +0100 | [diff] [blame^] | 2 | """Run the PSA Cryto API compliance test suite. |
| 3 | Clone the repo and check out the commit specified by PSA_ARCH_TEST_REPO and PSA_ARCH_TEST_REF, |
| 4 | then complie and run the test suite. |
| 5 | Known defects in either the test suite or mbedtls - identified by their test number - are ignored, |
| 6 | while unexpected failures AND successes are reported as errors, |
| 7 | to help keep the list of known defects as up to date as possible. |
| 8 | """ |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 9 | import os |
| 10 | import re |
| 11 | import shutil |
| 12 | import subprocess |
| 13 | import sys |
| 14 | |
| 15 | EXPECTED_FAILURES = { |
| 16 | 216, 221, 224, 225, 248, 249, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263 |
| 17 | } |
| 18 | PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git' |
| 19 | PSA_ARCH_TESTS_REF = 'crypto1.0-3.0' |
| 20 | |
| 21 | #pylint: disable=too-many-statements |
| 22 | def main(): |
| 23 | mbedtls_dir = os.getcwd() |
| 24 | |
Bence Szépkúti | ca9236b | 2021-10-25 19:29:07 +0200 | [diff] [blame] | 25 | if not os.path.exists('library/libmbedcrypto.a'): |
| 26 | subprocess.check_call(['make', '-C', 'library', 'libmbedcrypto.a']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 27 | |
| 28 | psa_arch_tests_dir = 'psa-arch-tests' |
| 29 | try: |
| 30 | os.mkdir(psa_arch_tests_dir) |
| 31 | except FileExistsError: |
| 32 | pass |
| 33 | os.chdir(psa_arch_tests_dir) |
| 34 | |
| 35 | subprocess.check_call(['git', 'init']) |
| 36 | subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF]) |
| 37 | subprocess.check_call(['git', 'checkout', 'FETCH_HEAD']) |
| 38 | |
| 39 | build_dir = 'api-tests/build' |
| 40 | try: |
| 41 | shutil.rmtree(build_dir) |
| 42 | except FileNotFoundError: |
| 43 | pass |
| 44 | os.mkdir(build_dir) |
| 45 | os.chdir(build_dir) |
| 46 | |
| 47 | #pylint: disable=bad-continuation |
| 48 | subprocess.check_call([ |
| 49 | 'cmake', '..', '-GUnix Makefiles', |
| 50 | '-DTARGET=tgt_dev_apis_stdc', |
| 51 | '-DTOOLCHAIN=HOST_GCC', |
| 52 | '-DSUITE=CRYPTO', |
| 53 | '-DPSA_CRYPTO_LIB_FILENAME={}/library/libmbedcrypto.a'.format(mbedtls_dir), |
| 54 | '-DPSA_INCLUDE_PATHS={}/include'.format(mbedtls_dir) |
| 55 | ]) |
| 56 | subprocess.check_call(['cmake', '--build', '.']) |
| 57 | |
| 58 | proc = subprocess.Popen(['./psa-arch-tests-crypto'], |
| 59 | bufsize=1, stdout=subprocess.PIPE, universal_newlines=True) |
| 60 | |
Bence Szépkúti | 83aa604 | 2021-10-29 12:06:19 +0200 | [diff] [blame] | 61 | test_re = re.compile( |
| 62 | '^TEST: (?P<test_num>[0-9]*)|' |
| 63 | '^TEST RESULT: (?P<test_result>FAILED|PASSED)' |
| 64 | ) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 65 | test = -1 |
| 66 | unexpected_successes = set(EXPECTED_FAILURES) |
| 67 | expected_failures = [] |
| 68 | unexpected_failures = [] |
| 69 | for line in proc.stdout: |
Bence Szépkúti | c2bac00 | 2021-10-25 20:58:14 +0200 | [diff] [blame] | 70 | print(line, end='') |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 71 | match = test_re.match(line) |
| 72 | if match is not None: |
Bence Szépkúti | 83aa604 | 2021-10-29 12:06:19 +0200 | [diff] [blame] | 73 | groupdict = match.groupdict() |
| 74 | test_num = groupdict['test_num'] |
| 75 | if test_num is not None: |
| 76 | test = int(test_num) |
| 77 | elif groupdict['test_result'] == 'FAILED': |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 78 | try: |
| 79 | unexpected_successes.remove(test) |
| 80 | expected_failures.append(test) |
Bence Szépkúti | d2ea2c0 | 2021-10-25 20:58:14 +0200 | [diff] [blame] | 81 | print('Expected failure, ignoring') |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 82 | except KeyError: |
| 83 | unexpected_failures.append(test) |
Bence Szépkúti | d2ea2c0 | 2021-10-25 20:58:14 +0200 | [diff] [blame] | 84 | print('ERROR: Unexpected failure') |
| 85 | elif test in unexpected_successes: |
| 86 | print('ERROR: Unexpected success') |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 87 | proc.wait() |
| 88 | |
| 89 | print() |
| 90 | print('***** test_psa_compliance.py report ******') |
| 91 | print() |
| 92 | print('Expected failures:', ', '.join(str(i) for i in expected_failures)) |
| 93 | print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures)) |
| 94 | print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes))) |
| 95 | print() |
| 96 | if unexpected_successes or unexpected_failures: |
| 97 | if unexpected_successes: |
| 98 | print('Unexpected successes encountered.') |
Bence Szépkúti | 449781f | 2021-11-02 13:41:14 +0100 | [diff] [blame^] | 99 | print('Please remove the corresponding tests from ' |
| 100 | 'EXPECTED_FAILURES in tests/scripts/compliance_test.py') |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 101 | print() |
| 102 | print('FAILED') |
| 103 | sys.exit(1) |
| 104 | else: |
| 105 | os.chdir(mbedtls_dir) |
| 106 | shutil.rmtree(psa_arch_tests_dir) |
| 107 | print('SUCCESS') |
| 108 | |
| 109 | if __name__ == '__main__': |
| 110 | main() |