blob: aa0a480e5cf138fb46b700893775c7243201c5a4 [file] [log] [blame]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02001#!/usr/bin/env python3
2#pylint: disable=missing-module-docstring
3import os
4import re
5import shutil
6import subprocess
7import sys
8
9EXPECTED_FAILURES = {
10 216, 221, 224, 225, 248, 249, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263
11}
12PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git'
13PSA_ARCH_TESTS_REF = 'crypto1.0-3.0'
14
15#pylint: disable=too-many-statements
16def main():
17 mbedtls_dir = os.getcwd()
18
Bence Szépkútica9236b2021-10-25 19:29:07 +020019 if not os.path.exists('library/libmbedcrypto.a'):
20 subprocess.check_call(['make', '-C', 'library', 'libmbedcrypto.a'])
Bence Szépkúti80b31c52021-10-19 15:05:36 +020021
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
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020055 test_re = re.compile('^TEST(?:: ([0-9]*)| RESULT: (FAILED|PASSED))')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020056 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))
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020066 elif match.group(2) == 'FAILED':
Bence Szépkúti80b31c52021-10-19 15:05:36 +020067 try:
68 unexpected_successes.remove(test)
69 expected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020070 print('Expected failure, ignoring')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020071 except KeyError:
72 unexpected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020073 print('ERROR: Unexpected failure')
74 elif test in unexpected_successes:
75 print('ERROR: Unexpected success')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020076 proc.wait()
77
78 print()
79 print('***** test_psa_compliance.py report ******')
80 print()
81 print('Expected failures:', ', '.join(str(i) for i in expected_failures))
82 print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures))
83 print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes)))
84 print()
85 if unexpected_successes or unexpected_failures:
86 if unexpected_successes:
87 print('Unexpected successes encountered.')
88 #pylint: disable=line-too-long
89 print('Please remove the corresponding tests from EXPECTED_FAILURES in tests/scripts/compliance_test.py')
90 print()
91 print('FAILED')
92 sys.exit(1)
93 else:
94 os.chdir(mbedtls_dir)
95 shutil.rmtree(psa_arch_tests_dir)
96 print('SUCCESS')
97
98if __name__ == '__main__':
99 main()