Bence Szépkúti | 9f84911 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | #pylint: disable=missing-module-docstring |
| 3 | import os |
| 4 | import re |
| 5 | import shutil |
| 6 | import subprocess |
| 7 | import sys |
| 8 | |
| 9 | EXPECTED_FAILURES = { |
| 10 | 216, 221, 224, 225, 248, 249, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263 |
| 11 | } |
| 12 | PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git' |
| 13 | PSA_ARCH_TESTS_REF = 'crypto1.0-3.0' |
| 14 | |
| 15 | #pylint: disable=too-many-statements |
| 16 | def main(): |
| 17 | mbedtls_dir = os.getcwd() |
| 18 | |
Bence Szépkúti | ab796e6 | 2021-10-25 19:29:07 +0200 | [diff] [blame^] | 19 | if not os.path.exists('library/libmbedcrypto.a'): |
| 20 | subprocess.check_call(['make', '-C', 'library', 'libmbedcrypto.a']) |
Bence Szépkúti | 9f84911 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 21 | |
| 22 | psa_arch_tests_dir = 'psa-arch-tests' |
| 23 | try: |
| 24 | os.mkdir(psa_arch_tests_dir) |
| 25 | except FileExistsError: |
| 26 | pass |
| 27 | os.chdir(psa_arch_tests_dir) |
| 28 | |
| 29 | subprocess.check_call(['git', 'init']) |
| 30 | subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF]) |
| 31 | subprocess.check_call(['git', 'checkout', 'FETCH_HEAD']) |
| 32 | |
| 33 | build_dir = 'api-tests/build' |
| 34 | try: |
| 35 | shutil.rmtree(build_dir) |
| 36 | except FileNotFoundError: |
| 37 | pass |
| 38 | os.mkdir(build_dir) |
| 39 | os.chdir(build_dir) |
| 40 | |
| 41 | #pylint: disable=bad-continuation |
| 42 | subprocess.check_call([ |
| 43 | 'cmake', '..', '-GUnix Makefiles', |
| 44 | '-DTARGET=tgt_dev_apis_stdc', |
| 45 | '-DTOOLCHAIN=HOST_GCC', |
| 46 | '-DSUITE=CRYPTO', |
| 47 | '-DPSA_CRYPTO_LIB_FILENAME={}/library/libmbedcrypto.a'.format(mbedtls_dir), |
| 48 | '-DPSA_INCLUDE_PATHS={}/include'.format(mbedtls_dir) |
| 49 | ]) |
| 50 | subprocess.check_call(['cmake', '--build', '.']) |
| 51 | |
| 52 | proc = subprocess.Popen(['./psa-arch-tests-crypto'], |
| 53 | bufsize=1, stdout=subprocess.PIPE, universal_newlines=True) |
| 54 | |
| 55 | test_re = re.compile('^TEST(?:: ([0-9]*)| RESULT: FAILED)') |
| 56 | test = -1 |
| 57 | unexpected_successes = set(EXPECTED_FAILURES) |
| 58 | expected_failures = [] |
| 59 | unexpected_failures = [] |
| 60 | for line in proc.stdout: |
| 61 | print(line[:-1]) |
| 62 | match = test_re.match(line) |
| 63 | if match is not None: |
| 64 | if match.group(1) is not None: |
| 65 | test = int(match.group(1)) |
| 66 | else: |
| 67 | try: |
| 68 | unexpected_successes.remove(test) |
| 69 | expected_failures.append(test) |
| 70 | except KeyError: |
| 71 | unexpected_failures.append(test) |
| 72 | proc.wait() |
| 73 | |
| 74 | print() |
| 75 | print('***** test_psa_compliance.py report ******') |
| 76 | print() |
| 77 | print('Expected failures:', ', '.join(str(i) for i in expected_failures)) |
| 78 | print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures)) |
| 79 | print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes))) |
| 80 | print() |
| 81 | if unexpected_successes or unexpected_failures: |
| 82 | if unexpected_successes: |
| 83 | print('Unexpected successes encountered.') |
| 84 | #pylint: disable=line-too-long |
| 85 | print('Please remove the corresponding tests from EXPECTED_FAILURES in tests/scripts/compliance_test.py') |
| 86 | print() |
| 87 | print('FAILED') |
| 88 | sys.exit(1) |
| 89 | else: |
| 90 | os.chdir(mbedtls_dir) |
| 91 | shutil.rmtree(psa_arch_tests_dir) |
| 92 | print('SUCCESS') |
| 93 | |
| 94 | if __name__ == '__main__': |
| 95 | main() |