blob: dfd23938a287a37df2af3432b89871e184f7e9ce [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úti83aa6042021-10-29 12:06:19 +020055 test_re = re.compile(
56 '^TEST: (?P<test_num>[0-9]*)|'
57 '^TEST RESULT: (?P<test_result>FAILED|PASSED)'
58 )
Bence Szépkúti80b31c52021-10-19 15:05:36 +020059 test = -1
60 unexpected_successes = set(EXPECTED_FAILURES)
61 expected_failures = []
62 unexpected_failures = []
63 for line in proc.stdout:
Bence Szépkútic2bac002021-10-25 20:58:14 +020064 print(line, end='')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020065 match = test_re.match(line)
66 if match is not None:
Bence Szépkúti83aa6042021-10-29 12:06:19 +020067 groupdict = match.groupdict()
68 test_num = groupdict['test_num']
69 if test_num is not None:
70 test = int(test_num)
71 elif groupdict['test_result'] == 'FAILED':
Bence Szépkúti80b31c52021-10-19 15:05:36 +020072 try:
73 unexpected_successes.remove(test)
74 expected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020075 print('Expected failure, ignoring')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020076 except KeyError:
77 unexpected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020078 print('ERROR: Unexpected failure')
79 elif test in unexpected_successes:
80 print('ERROR: Unexpected success')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020081 proc.wait()
82
83 print()
84 print('***** test_psa_compliance.py report ******')
85 print()
86 print('Expected failures:', ', '.join(str(i) for i in expected_failures))
87 print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures))
88 print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes)))
89 print()
90 if unexpected_successes or unexpected_failures:
91 if unexpected_successes:
92 print('Unexpected successes encountered.')
93 #pylint: disable=line-too-long
94 print('Please remove the corresponding tests from EXPECTED_FAILURES in tests/scripts/compliance_test.py')
95 print()
96 print('FAILED')
97 sys.exit(1)
98 else:
99 os.chdir(mbedtls_dir)
100 shutil.rmtree(psa_arch_tests_dir)
101 print('SUCCESS')
102
103if __name__ == '__main__':
104 main()