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 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 21 | #pylint: disable=too-many-branches,too-many-statements |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 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 |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 33 | try: |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 34 | os.chdir(psa_arch_tests_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 35 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 36 | subprocess.check_call(['git', 'init']) |
| 37 | subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF]) |
| 38 | subprocess.check_call(['git', 'checkout', 'FETCH_HEAD']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 39 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 40 | build_dir = 'api-tests/build' |
| 41 | try: |
| 42 | shutil.rmtree(build_dir) |
| 43 | except FileNotFoundError: |
| 44 | pass |
| 45 | os.mkdir(build_dir) |
| 46 | os.chdir(build_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 47 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 48 | #pylint: disable=bad-continuation |
| 49 | subprocess.check_call([ |
| 50 | 'cmake', '..', |
| 51 | '-GUnix Makefiles', |
| 52 | '-DTARGET=tgt_dev_apis_stdc', |
| 53 | '-DTOOLCHAIN=HOST_GCC', |
| 54 | '-DSUITE=CRYPTO', |
| 55 | '-DPSA_CRYPTO_LIB_FILENAME={}/library/libmbedcrypto.a'.format(mbedtls_dir), |
| 56 | '-DPSA_INCLUDE_PATHS={}/include'.format(mbedtls_dir) |
| 57 | ]) |
| 58 | subprocess.check_call(['cmake', '--build', '.']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 59 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 60 | proc = subprocess.Popen(['./psa-arch-tests-crypto'], |
| 61 | bufsize=1, stdout=subprocess.PIPE, universal_newlines=True) |
| 62 | |
| 63 | test_re = re.compile( |
| 64 | '^TEST: (?P<test_num>[0-9]*)|' |
| 65 | '^TEST RESULT: (?P<test_result>FAILED|PASSED)' |
| 66 | ) |
| 67 | test = -1 |
| 68 | unexpected_successes = set(EXPECTED_FAILURES) |
| 69 | expected_failures = [] |
| 70 | unexpected_failures = [] |
| 71 | for line in proc.stdout: |
| 72 | print(line, end='') |
| 73 | match = test_re.match(line) |
| 74 | if match is not None: |
| 75 | groupdict = match.groupdict() |
| 76 | test_num = groupdict['test_num'] |
| 77 | if test_num is not None: |
| 78 | test = int(test_num) |
| 79 | elif groupdict['test_result'] == 'FAILED': |
| 80 | try: |
| 81 | unexpected_successes.remove(test) |
| 82 | expected_failures.append(test) |
| 83 | print('Expected failure, ignoring') |
| 84 | except KeyError: |
| 85 | unexpected_failures.append(test) |
| 86 | print('ERROR: Unexpected failure') |
| 87 | elif test in unexpected_successes: |
| 88 | print('ERROR: Unexpected success') |
| 89 | proc.wait() |
| 90 | |
| 91 | print() |
| 92 | print('***** test_psa_compliance.py report ******') |
| 93 | print() |
| 94 | print('Expected failures:', ', '.join(str(i) for i in expected_failures)) |
| 95 | print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures)) |
| 96 | print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes))) |
| 97 | print() |
| 98 | if unexpected_successes or unexpected_failures: |
| 99 | if unexpected_successes: |
| 100 | print('Unexpected successes encountered.') |
| 101 | print('Please remove the corresponding tests from ' |
| 102 | 'EXPECTED_FAILURES in tests/scripts/compliance_test.py') |
| 103 | print() |
| 104 | print('FAILED') |
| 105 | return 1 |
| 106 | else: |
| 107 | shutil.rmtree(psa_arch_tests_dir) |
| 108 | print('SUCCESS') |
| 109 | return 0 |
| 110 | finally: |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 111 | os.chdir(mbedtls_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 112 | |
| 113 | if __name__ == '__main__': |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame^] | 114 | sys.exit(main()) |