blob: 41003d80da0b265e1b90f5af537139ef6e08836a [file] [log] [blame]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02001#!/usr/bin/env python3
Bence Szépkúti449781f2021-11-02 13:41:14 +01002"""Run the PSA Cryto API compliance test suite.
3Clone the repo and check out the commit specified by PSA_ARCH_TEST_REPO and PSA_ARCH_TEST_REF,
4then complie and run the test suite.
5Known defects in either the test suite or mbedtls - identified by their test number - are ignored,
6while unexpected failures AND successes are reported as errors,
7to help keep the list of known defects as up to date as possible.
8"""
Bence Szépkúti80b31c52021-10-19 15:05:36 +02009import os
10import re
11import shutil
12import subprocess
13import sys
14
15EXPECTED_FAILURES = {
16 216, 221, 224, 225, 248, 249, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263
17}
18PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git'
19PSA_ARCH_TESTS_REF = 'crypto1.0-3.0'
20
21#pylint: disable=too-many-statements
22def main():
23 mbedtls_dir = os.getcwd()
24
Bence Szépkútica9236b2021-10-25 19:29:07 +020025 if not os.path.exists('library/libmbedcrypto.a'):
26 subprocess.check_call(['make', '-C', 'library', 'libmbedcrypto.a'])
Bence Szépkúti80b31c52021-10-19 15:05:36 +020027
28 psa_arch_tests_dir = 'psa-arch-tests'
29 try:
30 os.mkdir(psa_arch_tests_dir)
31 except FileExistsError:
32 pass
33 os.chdir(psa_arch_tests_dir)
34
35 subprocess.check_call(['git', 'init'])
36 subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF])
37 subprocess.check_call(['git', 'checkout', 'FETCH_HEAD'])
38
39 build_dir = 'api-tests/build'
40 try:
41 shutil.rmtree(build_dir)
42 except FileNotFoundError:
43 pass
44 os.mkdir(build_dir)
45 os.chdir(build_dir)
46
47 #pylint: disable=bad-continuation
48 subprocess.check_call([
49 'cmake', '..', '-GUnix Makefiles',
50 '-DTARGET=tgt_dev_apis_stdc',
51 '-DTOOLCHAIN=HOST_GCC',
52 '-DSUITE=CRYPTO',
53 '-DPSA_CRYPTO_LIB_FILENAME={}/library/libmbedcrypto.a'.format(mbedtls_dir),
54 '-DPSA_INCLUDE_PATHS={}/include'.format(mbedtls_dir)
55 ])
56 subprocess.check_call(['cmake', '--build', '.'])
57
58 proc = subprocess.Popen(['./psa-arch-tests-crypto'],
59 bufsize=1, stdout=subprocess.PIPE, universal_newlines=True)
60
Bence Szépkúti83aa6042021-10-29 12:06:19 +020061 test_re = re.compile(
62 '^TEST: (?P<test_num>[0-9]*)|'
63 '^TEST RESULT: (?P<test_result>FAILED|PASSED)'
64 )
Bence Szépkúti80b31c52021-10-19 15:05:36 +020065 test = -1
66 unexpected_successes = set(EXPECTED_FAILURES)
67 expected_failures = []
68 unexpected_failures = []
69 for line in proc.stdout:
Bence Szépkútic2bac002021-10-25 20:58:14 +020070 print(line, end='')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020071 match = test_re.match(line)
72 if match is not None:
Bence Szépkúti83aa6042021-10-29 12:06:19 +020073 groupdict = match.groupdict()
74 test_num = groupdict['test_num']
75 if test_num is not None:
76 test = int(test_num)
77 elif groupdict['test_result'] == 'FAILED':
Bence Szépkúti80b31c52021-10-19 15:05:36 +020078 try:
79 unexpected_successes.remove(test)
80 expected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020081 print('Expected failure, ignoring')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020082 except KeyError:
83 unexpected_failures.append(test)
Bence Szépkútid2ea2c02021-10-25 20:58:14 +020084 print('ERROR: Unexpected failure')
85 elif test in unexpected_successes:
86 print('ERROR: Unexpected success')
Bence Szépkúti80b31c52021-10-19 15:05:36 +020087 proc.wait()
88
89 print()
90 print('***** test_psa_compliance.py report ******')
91 print()
92 print('Expected failures:', ', '.join(str(i) for i in expected_failures))
93 print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures))
94 print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes)))
95 print()
96 if unexpected_successes or unexpected_failures:
97 if unexpected_successes:
98 print('Unexpected successes encountered.')
Bence Szépkúti449781f2021-11-02 13:41:14 +010099 print('Please remove the corresponding tests from '
100 'EXPECTED_FAILURES in tests/scripts/compliance_test.py')
Bence Szépkúti80b31c52021-10-19 15:05:36 +0200101 print()
102 print('FAILED')
103 sys.exit(1)
104 else:
105 os.chdir(mbedtls_dir)
106 shutil.rmtree(psa_arch_tests_dir)
107 print('SUCCESS')
108
109if __name__ == '__main__':
110 main()