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 | 67fb314 | 2021-11-02 14:01:08 +0100 | [diff] [blame] | 9 | |
| 10 | # Copyright The Mbed TLS Contributors |
| 11 | # SPDX-License-Identifier: Apache-2.0 |
| 12 | # |
| 13 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 14 | # not use this file except in compliance with the License. |
| 15 | # You may obtain a copy of the License at |
| 16 | # |
| 17 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | # |
| 19 | # Unless required by applicable law or agreed to in writing, software |
| 20 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 21 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | # See the License for the specific language governing permissions and |
| 23 | # limitations under the License. |
| 24 | |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 25 | import os |
| 26 | import re |
| 27 | import shutil |
| 28 | import subprocess |
| 29 | import sys |
| 30 | |
| 31 | EXPECTED_FAILURES = { |
| 32 | 216, 221, 224, 225, 248, 249, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263 |
| 33 | } |
| 34 | PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git' |
| 35 | PSA_ARCH_TESTS_REF = 'crypto1.0-3.0' |
| 36 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 37 | #pylint: disable=too-many-branches,too-many-statements |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 38 | def main(): |
| 39 | mbedtls_dir = os.getcwd() |
| 40 | |
Bence Szépkúti | ca9236b | 2021-10-25 19:29:07 +0200 | [diff] [blame] | 41 | if not os.path.exists('library/libmbedcrypto.a'): |
| 42 | subprocess.check_call(['make', '-C', 'library', 'libmbedcrypto.a']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 43 | |
| 44 | psa_arch_tests_dir = 'psa-arch-tests' |
Bence Szépkúti | c63d160 | 2021-11-02 14:06:40 +0100 | [diff] [blame^] | 45 | os.makedirs(psa_arch_tests_dir, exist_ok=True) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 46 | try: |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 47 | os.chdir(psa_arch_tests_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 48 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 49 | subprocess.check_call(['git', 'init']) |
| 50 | subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF]) |
| 51 | subprocess.check_call(['git', 'checkout', 'FETCH_HEAD']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 52 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 53 | build_dir = 'api-tests/build' |
| 54 | try: |
| 55 | shutil.rmtree(build_dir) |
| 56 | except FileNotFoundError: |
| 57 | pass |
| 58 | os.mkdir(build_dir) |
| 59 | os.chdir(build_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 60 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 61 | #pylint: disable=bad-continuation |
| 62 | subprocess.check_call([ |
| 63 | 'cmake', '..', |
| 64 | '-GUnix Makefiles', |
| 65 | '-DTARGET=tgt_dev_apis_stdc', |
| 66 | '-DTOOLCHAIN=HOST_GCC', |
| 67 | '-DSUITE=CRYPTO', |
| 68 | '-DPSA_CRYPTO_LIB_FILENAME={}/library/libmbedcrypto.a'.format(mbedtls_dir), |
| 69 | '-DPSA_INCLUDE_PATHS={}/include'.format(mbedtls_dir) |
| 70 | ]) |
| 71 | subprocess.check_call(['cmake', '--build', '.']) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 72 | |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 73 | proc = subprocess.Popen(['./psa-arch-tests-crypto'], |
| 74 | bufsize=1, stdout=subprocess.PIPE, universal_newlines=True) |
| 75 | |
| 76 | test_re = re.compile( |
| 77 | '^TEST: (?P<test_num>[0-9]*)|' |
| 78 | '^TEST RESULT: (?P<test_result>FAILED|PASSED)' |
| 79 | ) |
| 80 | test = -1 |
| 81 | unexpected_successes = set(EXPECTED_FAILURES) |
| 82 | expected_failures = [] |
| 83 | unexpected_failures = [] |
| 84 | for line in proc.stdout: |
| 85 | print(line, end='') |
| 86 | match = test_re.match(line) |
| 87 | if match is not None: |
| 88 | groupdict = match.groupdict() |
| 89 | test_num = groupdict['test_num'] |
| 90 | if test_num is not None: |
| 91 | test = int(test_num) |
| 92 | elif groupdict['test_result'] == 'FAILED': |
| 93 | try: |
| 94 | unexpected_successes.remove(test) |
| 95 | expected_failures.append(test) |
| 96 | print('Expected failure, ignoring') |
| 97 | except KeyError: |
| 98 | unexpected_failures.append(test) |
| 99 | print('ERROR: Unexpected failure') |
| 100 | elif test in unexpected_successes: |
| 101 | print('ERROR: Unexpected success') |
| 102 | proc.wait() |
| 103 | |
| 104 | print() |
| 105 | print('***** test_psa_compliance.py report ******') |
| 106 | print() |
| 107 | print('Expected failures:', ', '.join(str(i) for i in expected_failures)) |
| 108 | print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures)) |
| 109 | print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes))) |
| 110 | print() |
| 111 | if unexpected_successes or unexpected_failures: |
| 112 | if unexpected_successes: |
| 113 | print('Unexpected successes encountered.') |
| 114 | print('Please remove the corresponding tests from ' |
| 115 | 'EXPECTED_FAILURES in tests/scripts/compliance_test.py') |
| 116 | print() |
| 117 | print('FAILED') |
| 118 | return 1 |
| 119 | else: |
| 120 | shutil.rmtree(psa_arch_tests_dir) |
| 121 | print('SUCCESS') |
| 122 | return 0 |
| 123 | finally: |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 124 | os.chdir(mbedtls_dir) |
Bence Szépkúti | 80b31c5 | 2021-10-19 15:05:36 +0200 | [diff] [blame] | 125 | |
| 126 | if __name__ == '__main__': |
Bence Szépkúti | 34b5f56 | 2021-11-02 13:48:39 +0100 | [diff] [blame] | 127 | sys.exit(main()) |