2021-10-19 15:05:36 +02:00
|
|
|
#!/usr/bin/env python3
|
2021-12-21 06:14:10 +01:00
|
|
|
"""Run the PSA Crypto API compliance test suite.
|
2021-11-02 13:41:14 +01:00
|
|
|
Clone the repo and check out the commit specified by PSA_ARCH_TEST_REPO and PSA_ARCH_TEST_REF,
|
2023-08-29 11:32:26 +02:00
|
|
|
then compile and run the test suite. The clone is stored at <repository root>/psa-arch-tests.
|
2023-10-09 10:25:45 +02:00
|
|
|
Known defects in either the test suite or mbedtls / TF-PSA-Crypto - identified by their test
|
2023-08-29 11:32:26 +02:00
|
|
|
number - are ignored, while unexpected failures AND successes are reported as errors, to help
|
|
|
|
keep the list of known defects as up to date as possible.
|
2021-11-02 13:41:14 +01:00
|
|
|
"""
|
2021-11-02 14:01:08 +01:00
|
|
|
|
|
|
|
# Copyright The Mbed TLS Contributors
|
2023-11-02 20:47:20 +01:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2021-11-02 14:01:08 +01:00
|
|
|
|
2023-08-17 19:08:24 +02:00
|
|
|
import argparse
|
2021-10-19 15:05:36 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2023-08-29 18:36:35 +02:00
|
|
|
from typing import List
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2023-07-19 12:43:27 +02:00
|
|
|
#pylint: disable=unused-import
|
2023-07-18 18:39:35 +02:00
|
|
|
import scripts_path
|
|
|
|
from mbedtls_dev import build_tree
|
|
|
|
|
2023-10-09 10:25:45 +02:00
|
|
|
# PSA Compliance tests we expect to fail due to known defects in Mbed TLS /
|
|
|
|
# TF-PSA-Crypto (or the test suite).
|
2021-11-09 21:30:43 +01:00
|
|
|
# The test numbers correspond to the numbers used by the console output of the test suite.
|
|
|
|
# Test number 2xx corresponds to the files in the folder
|
|
|
|
# psa-arch-tests/api-tests/dev_apis/crypto/test_c0xx
|
2021-10-19 15:05:36 +02:00
|
|
|
EXPECTED_FAILURES = {
|
2021-11-09 21:30:43 +01:00
|
|
|
# psa_hash_suspend() and psa_hash_resume() are not supported.
|
|
|
|
# - Tracked in issue #3274
|
|
|
|
262, 263
|
2021-10-19 15:05:36 +02:00
|
|
|
}
|
2021-11-09 17:33:57 +01:00
|
|
|
|
|
|
|
# We currently use a fork of ARM-software/psa-arch-tests, with a couple of downstream patches
|
2023-10-06 18:07:24 +02:00
|
|
|
# that allow it to build with Mbed TLS 3, and fixes a couple of issues in the compliance test suite.
|
2021-11-09 17:33:57 +01:00
|
|
|
# These fixes allow the tests numbered 216, 248 and 249 to complete successfully.
|
|
|
|
#
|
|
|
|
# Once all the fixes are upstreamed, this fork should be replaced with an upstream commit/tag.
|
2021-11-09 22:13:46 +01:00
|
|
|
# - Tracked in issue #5145
|
2021-11-09 17:33:57 +01:00
|
|
|
#
|
|
|
|
# Web URL: https://github.com/bensze01/psa-arch-tests/tree/fixes-for-mbedtls-3
|
|
|
|
PSA_ARCH_TESTS_REPO = 'https://github.com/bensze01/psa-arch-tests.git'
|
2022-05-17 17:23:09 +02:00
|
|
|
PSA_ARCH_TESTS_REF = 'fix-pr-5736'
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2023-07-19 12:43:27 +02:00
|
|
|
#pylint: disable=too-many-branches,too-many-statements,too-many-locals
|
2023-08-17 19:08:24 +02:00
|
|
|
def main(library_build_dir: str):
|
2023-08-29 11:27:13 +02:00
|
|
|
root_dir = os.getcwd()
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2023-11-24 12:41:23 +01:00
|
|
|
in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir)
|
|
|
|
|
2023-11-30 14:56:09 +01:00
|
|
|
crypto_name = build_tree.crypto_library_filename(root_dir)
|
2023-12-02 00:47:59 +01:00
|
|
|
library_subdir = build_tree.crypto_core_directory(root_dir, relative=True)
|
2023-08-29 14:56:17 +02:00
|
|
|
|
|
|
|
crypto_lib_filename = (library_build_dir + '/' +
|
|
|
|
library_subdir + '/' +
|
|
|
|
'lib' + crypto_name + '.a')
|
2023-08-29 11:25:26 +02:00
|
|
|
|
|
|
|
if not os.path.exists(crypto_lib_filename):
|
2023-08-29 11:37:29 +02:00
|
|
|
#pylint: disable=bad-continuation
|
2023-08-17 19:08:24 +02:00
|
|
|
subprocess.check_call([
|
|
|
|
'cmake', '.',
|
|
|
|
'-GUnix Makefiles',
|
2023-08-29 15:57:23 +02:00
|
|
|
'-B' + library_build_dir
|
2023-08-17 19:08:24 +02:00
|
|
|
])
|
2023-08-29 14:56:17 +02:00
|
|
|
subprocess.check_call(['cmake', '--build', library_build_dir,
|
2023-08-30 10:46:20 +02:00
|
|
|
'--target', crypto_name])
|
2021-10-19 15:05:36 +02:00
|
|
|
|
|
|
|
psa_arch_tests_dir = 'psa-arch-tests'
|
2021-11-02 14:06:40 +01:00
|
|
|
os.makedirs(psa_arch_tests_dir, exist_ok=True)
|
2021-11-02 13:48:39 +01:00
|
|
|
try:
|
|
|
|
os.chdir(psa_arch_tests_dir)
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2021-11-03 11:32:51 +01:00
|
|
|
# Reuse existing local clone
|
2021-11-02 13:48:39 +01:00
|
|
|
subprocess.check_call(['git', 'init'])
|
|
|
|
subprocess.check_call(['git', 'fetch', PSA_ARCH_TESTS_REPO, PSA_ARCH_TESTS_REF])
|
|
|
|
subprocess.check_call(['git', 'checkout', 'FETCH_HEAD'])
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
build_dir = 'api-tests/build'
|
|
|
|
try:
|
|
|
|
shutil.rmtree(build_dir)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
os.mkdir(build_dir)
|
|
|
|
os.chdir(build_dir)
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2023-08-29 11:27:13 +02:00
|
|
|
extra_includes = (';{}/drivers/builtin/include'.format(root_dir)
|
2023-10-09 10:25:45 +02:00
|
|
|
if in_tf_psa_crypto_repo else '')
|
2023-07-18 18:39:35 +02:00
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
#pylint: disable=bad-continuation
|
|
|
|
subprocess.check_call([
|
|
|
|
'cmake', '..',
|
|
|
|
'-GUnix Makefiles',
|
|
|
|
'-DTARGET=tgt_dev_apis_stdc',
|
|
|
|
'-DTOOLCHAIN=HOST_GCC',
|
|
|
|
'-DSUITE=CRYPTO',
|
2023-08-29 11:27:13 +02:00
|
|
|
'-DPSA_CRYPTO_LIB_FILENAME={}/{}'.format(root_dir,
|
2023-08-23 17:21:40 +02:00
|
|
|
crypto_lib_filename),
|
2023-08-29 11:27:13 +02:00
|
|
|
('-DPSA_INCLUDE_PATHS={}/include' + extra_includes).format(root_dir)
|
2021-11-02 13:48:39 +01:00
|
|
|
])
|
|
|
|
subprocess.check_call(['cmake', '--build', '.'])
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
proc = subprocess.Popen(['./psa-arch-tests-crypto'],
|
|
|
|
bufsize=1, stdout=subprocess.PIPE, universal_newlines=True)
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
test_re = re.compile(
|
|
|
|
'^TEST: (?P<test_num>[0-9]*)|'
|
|
|
|
'^TEST RESULT: (?P<test_result>FAILED|PASSED)'
|
|
|
|
)
|
|
|
|
test = -1
|
|
|
|
unexpected_successes = set(EXPECTED_FAILURES)
|
2023-08-29 17:21:15 +02:00
|
|
|
expected_failures = [] # type: List[int]
|
|
|
|
unexpected_failures = [] # type: List[int]
|
|
|
|
if proc.stdout is None:
|
|
|
|
return 1
|
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
for line in proc.stdout:
|
|
|
|
print(line, end='')
|
|
|
|
match = test_re.match(line)
|
|
|
|
if match is not None:
|
|
|
|
groupdict = match.groupdict()
|
|
|
|
test_num = groupdict['test_num']
|
|
|
|
if test_num is not None:
|
|
|
|
test = int(test_num)
|
|
|
|
elif groupdict['test_result'] == 'FAILED':
|
|
|
|
try:
|
|
|
|
unexpected_successes.remove(test)
|
|
|
|
expected_failures.append(test)
|
|
|
|
print('Expected failure, ignoring')
|
|
|
|
except KeyError:
|
|
|
|
unexpected_failures.append(test)
|
|
|
|
print('ERROR: Unexpected failure')
|
|
|
|
elif test in unexpected_successes:
|
|
|
|
print('ERROR: Unexpected success')
|
|
|
|
proc.wait()
|
2021-10-19 15:05:36 +02:00
|
|
|
|
2021-11-02 13:48:39 +01:00
|
|
|
print()
|
|
|
|
print('***** test_psa_compliance.py report ******')
|
|
|
|
print()
|
|
|
|
print('Expected failures:', ', '.join(str(i) for i in expected_failures))
|
|
|
|
print('Unexpected failures:', ', '.join(str(i) for i in unexpected_failures))
|
|
|
|
print('Unexpected successes:', ', '.join(str(i) for i in sorted(unexpected_successes)))
|
|
|
|
print()
|
|
|
|
if unexpected_successes or unexpected_failures:
|
|
|
|
if unexpected_successes:
|
|
|
|
print('Unexpected successes encountered.')
|
|
|
|
print('Please remove the corresponding tests from '
|
|
|
|
'EXPECTED_FAILURES in tests/scripts/compliance_test.py')
|
|
|
|
print()
|
|
|
|
print('FAILED')
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
print('SUCCESS')
|
|
|
|
return 0
|
|
|
|
finally:
|
2023-08-29 11:27:13 +02:00
|
|
|
os.chdir(root_dir)
|
2021-10-19 15:05:36 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-08-29 15:12:53 +02:00
|
|
|
BUILD_DIR = 'out_of_source_build'
|
2023-08-17 19:08:24 +02:00
|
|
|
|
2023-08-29 19:20:01 +02:00
|
|
|
# pylint: disable=invalid-name
|
2023-08-17 19:08:24 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--build-dir', nargs=1,
|
2023-10-09 10:25:45 +02:00
|
|
|
help='path to Mbed TLS / TF-PSA-Crypto build directory')
|
2023-08-17 19:08:24 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.build_dir is not None:
|
2023-08-29 15:12:53 +02:00
|
|
|
BUILD_DIR = args.build_dir[0]
|
2023-08-17 19:08:24 +02:00
|
|
|
|
2023-08-29 15:12:53 +02:00
|
|
|
sys.exit(main(BUILD_DIR))
|