Add psa arch test components
In preparation for running PSA arch tests against TS service
providers, add an external component for the arch tests and add
deployments for building the different test suites.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Change-Id: Ifcc746b1d3c876734b711cb48547c56a5b1856c3
diff --git a/components/app/arch-test-runner/arch_test_runner.c b/components/app/arch-test-runner/arch_test_runner.c
new file mode 100644
index 0000000..be80214
--- /dev/null
+++ b/components/app/arch-test-runner/arch_test_runner.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdint.h>
+#include <psa/crypto.h>
+#include <service_locator.h>
+
+int32_t val_entry(void);
+
+int main(int argc, char *argv[])
+{
+ int rval = -1;
+
+ psa_crypto_init();
+ service_locator_init();
+
+ rval = val_entry();
+
+ return rval;
+}
diff --git a/components/app/arch-test-runner/component.cmake b/components/app/arch-test-runner/component.cmake
new file mode 100644
index 0000000..3f99593
--- /dev/null
+++ b/components/app/arch-test-runner/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/arch_test_runner.c"
+ )
diff --git a/deployments/ts-arch-test/crypto/arm-linux/CMakeLists.txt b/deployments/ts-arch-test/crypto/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..8d58643
--- /dev/null
+++ b/deployments/ts-arch-test/crypto/arm-linux/CMakeLists.txt
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the ts-arch-test deployment for arm-linux
+#
+# Used for building and running psa arch tests on an Arm based Linux device
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/arm-linux/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(ts-arch-test)
+target_include_directories(ts-arch-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# ts-arch-test/crypto
+#-------------------------------------------------------------------------------
+include(../crypto-arch-test.cmake REQUIRED)
diff --git a/deployments/ts-arch-test/crypto/crypto-arch-test.cmake b/deployments/ts-arch-test/crypto/crypto-arch-test.cmake
new file mode 100644
index 0000000..93ade3b
--- /dev/null
+++ b/deployments/ts-arch-test/crypto/crypto-arch-test.cmake
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Define test suite to build. Used by the psa_arch_tests external component
+# to configure what test suite gets built.
+#-------------------------------------------------------------------------------
+set(TS_ARCH_TEST_SUITE CRYPTO CACHE STRING "Arch test suite")
+
+#-------------------------------------------------------------------------------
+# Crypto specific components
+#
+#-------------------------------------------------------------------------------
+
+# Configuration for mbedcrypto
+set(MBEDTLS_USER_CONFIG_FILE
+ "${TS_ROOT}/components/service/crypto/client/cpp/config_mbedtls_user.h"
+ CACHE STRING "Configuration file for mbedcrypto")
+
+# Mbed TLS provides libmbedcrypto
+include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake)
+target_link_libraries(ts-arch-test PRIVATE mbedcrypto)
+
+# Export psa crypto API
+list(APPEND PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS ${PSA_CRYPTO_API_INCLUDE})
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# ts-arch-test
+#-------------------------------------------------------------------------------
+include(../../ts-arch-test.cmake REQUIRED)
diff --git a/deployments/ts-arch-test/crypto/linux-pc/CMakeLists.txt b/deployments/ts-arch-test/crypto/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..f5b286e
--- /dev/null
+++ b/deployments/ts-arch-test/crypto/linux-pc/CMakeLists.txt
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the ts-arch-test deployment for linux-pc
+#
+# Used for building and running psa arch tests in a native PC enviroment.
+# Tests can be run by running the built executable called "ts-arch-test"
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(ts-arch-test)
+target_include_directories(ts-arch-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# ts-arch-test/crypto
+#-------------------------------------------------------------------------------
+include(../crypto-arch-test.cmake REQUIRED)
diff --git a/deployments/ts-arch-test/initial_attestation/iat-arch-test.cmake b/deployments/ts-arch-test/initial_attestation/iat-arch-test.cmake
new file mode 100644
index 0000000..c672b4c
--- /dev/null
+++ b/deployments/ts-arch-test/initial_attestation/iat-arch-test.cmake
@@ -0,0 +1,41 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Define test suite to build. Used by the psa_arch_tests external component
+# to configure what test suite gets built.
+#-------------------------------------------------------------------------------
+set(TS_ARCH_TEST_SUITE INITIAL_ATTESTATION CACHE STRING "Arch test suite")
+
+#-------------------------------------------------------------------------------
+# Add attestation specific components.
+#
+#-------------------------------------------------------------------------------
+add_components(
+ TARGET "ts-arch-test"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/service/attestation/include"
+)
+
+# Configuration for mbedcrypto
+set(MBEDTLS_USER_CONFIG_FILE
+ "${TS_ROOT}/components/service/crypto/client/cpp/config_mbedtls_user.h"
+ CACHE STRING "Configuration file for mbedcrypto")
+
+# Mbed TLS provides libmbedcrypto
+include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake)
+target_link_libraries(ts-arch-test PRIVATE mbedcrypto)
+
+# Export psa crypto API
+list(APPEND PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS ${PSA_CRYPTO_API_INCLUDE})
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# ts-arch-test
+#-------------------------------------------------------------------------------
+include(../../ts-arch-test.cmake REQUIRED)
diff --git a/deployments/ts-arch-test/initial_attestation/linux-pc/CMakeLists.txt b/deployments/ts-arch-test/initial_attestation/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..7b0922d
--- /dev/null
+++ b/deployments/ts-arch-test/initial_attestation/linux-pc/CMakeLists.txt
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the ts-arch-test deployment for linux-pc
+#
+# Used for building and running psa arch tests in a native PC enviroment.
+# Tests can be run by running the built executable called "ts-arch-test"
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(ts-arch-test)
+target_include_directories(ts-arch-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# ts-arch-test/initial_attestation
+#-------------------------------------------------------------------------------
+include(../iat-arch-test.cmake REQUIRED)
diff --git a/deployments/ts-arch-test/ts-arch-test.cmake b/deployments/ts-arch-test/ts-arch-test.cmake
new file mode 100644
index 0000000..9c2e778
--- /dev/null
+++ b/deployments/ts-arch-test/ts-arch-test.cmake
@@ -0,0 +1,56 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# The base build file shared between deployments of 'ts-arch-test' for
+# different environments. Used for running PSA arch tests.
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Use libts for locating and accessing services. An appropriate version of
+# libts will be imported for the enviroment in which service tests are
+# deployed.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/deployments/libts/libts-import.cmake)
+target_link_libraries(ts-arch-test PRIVATE libts)
+
+#-------------------------------------------------------------------------------
+# Components that are common accross all deployments
+#
+#-------------------------------------------------------------------------------
+add_components(
+ TARGET "ts-arch-test"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/app/arch-test-runner"
+ "components/service/common/include"
+)
+
+#-------------------------------------------------------------------------------
+# Export project header paths for arch tests
+#
+#-------------------------------------------------------------------------------
+get_target_property(_include_paths ts-arch-test INCLUDE_DIRECTORIES)
+list(APPEND PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS ${_include_paths})
+
+#-------------------------------------------------------------------------------
+# Components used from external projects
+#
+#-------------------------------------------------------------------------------
+
+# psa-arch-tests
+include(${TS_ROOT}/external/psa_arch_tests/psa_arch_tests.cmake)
+target_link_libraries(ts-arch-test PRIVATE val_nspe test_combine pal_nspe)
+
+#-------------------------------------------------------------------------------
+# Define install content.
+#
+#-------------------------------------------------------------------------------
+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+endif()
+install(TARGETS ts-arch-test RUNTIME DESTINATION ${TS_ENV}/bin)
diff --git a/external/psa_arch_tests/psa_arch_tests.cmake b/external/psa_arch_tests/psa_arch_tests.cmake
new file mode 100644
index 0000000..2d94640
--- /dev/null
+++ b/external/psa_arch_tests/psa_arch_tests.cmake
@@ -0,0 +1,102 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# Determine the number of processes to run while running parallel builds.
+# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
+if(NOT DEFINED PROCESSOR_COUNT)
+ include(ProcessorCount)
+ ProcessorCount(PROCESSOR_COUNT)
+ set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.")
+endif()
+
+set(PSA_ARCH_TESTS_URL "https://github.com/ARM-software/psa-arch-tests.git" CACHE STRING "psa-arch-tests repository URL")
+set(PSA_ARCH_TESTS_REFSPEC "master" CACHE STRING "psa-arch-tests git refspec")
+set(PSA_ARCH_TESTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/psa-arch-tests_install" CACHE PATH "psa-arch-tests installation directory")
+set(PSA_ARCH_TESTS_PACKAGE_PATH "${PSA_ARCH_TESTS_INSTALL_PATH}/libpsa-arch-tests/cmake" CACHE PATH "psa-arch-tests CMake package directory")
+
+include(FetchContent)
+
+# Checking git
+find_program(GIT_COMMAND "git")
+if (NOT GIT_COMMAND)
+ message(FATAL_ERROR "Please install git")
+endif()
+
+# Fetching psa-arch-tests
+FetchContent_Declare(
+ psa-arch-tests
+ GIT_REPOSITORY ${PSA_ARCH_TESTS_URL}
+ GIT_TAG ${PSA_ARCH_TESTS_REFSPEC}
+ GIT_SHALLOW TRUE
+)
+
+# FetchContent_GetProperties exports psa-arch-tests_SOURCE_DIR and psa-arch-tests_BINARY_DIR variables
+FetchContent_GetProperties(psa-arch-tests)
+if(NOT psa-arch-tests_POPULATED)
+ message(STATUS "Fetching psa-arch-tests")
+ FetchContent_Populate(psa-arch-tests)
+endif()
+
+# Ensure list of include paths is separated correctly
+string(REPLACE ";" "\\;" PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS "${PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS}")
+
+# Configure the psa-arch-test library
+if(NOT CMAKE_CROSSCOMPILING)
+ execute_process(COMMAND
+ ${CMAKE_COMMAND}
+ -DTOOLCHAIN=GCC_LINUX
+ -DCOMPILER_NAME=gcc
+ -DPSA_INCLUDE_PATHS=${PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS}
+ -DSUITE=${TS_ARCH_TEST_SUITE}
+ -DCMAKE_VERBOSE_MAKEFILE=OFF
+ -DTARGET=tgt_dev_apis_linux
+ -GUnix\ Makefiles
+ ${psa-arch-tests_SOURCE_DIR}/api-tests
+ WORKING_DIRECTORY
+ ${psa-arch-tests_BINARY_DIR}
+ RESULT_VARIABLE _exec_error
+ )
+else()
+execute_process(COMMAND
+ ${CMAKE_COMMAND}
+ -DCROSS_COMPILE=aarch64-linux-gnu
+ -DTOOLCHAIN=GNUARM
+ -DCPU_ARCH=armv8a
+ -DPSA_INCLUDE_PATHS=${PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS}
+ -DSUITE=${TS_ARCH_TEST_SUITE}
+ -DCMAKE_VERBOSE_MAKEFILE=OFF
+ -DTARGET=tgt_dev_apis_linux
+ -GUnix\ Makefiles
+ ${psa-arch-tests_SOURCE_DIR}/api-tests
+ WORKING_DIRECTORY
+ ${psa-arch-tests_BINARY_DIR}
+ RESULT_VARIABLE _exec_error
+ )
+endif()
+
+# Build the library
+if (_exec_error)
+ message(FATAL_ERROR "Configuration step of psa-arch-tests runtime failed with ${_exec_error}.")
+endif()
+
+execute_process(COMMAND
+ ${CMAKE_COMMAND} --build ${psa-arch-tests_BINARY_DIR} --parallel ${PROCESSOR_COUNT}
+ RESULT_VARIABLE _exec_error
+ )
+if (_exec_error)
+ message(FATAL_ERROR "Build step of psa-arch-tests runtime failed with ${_exec_error}.")
+endif()
+
+# Create targets for generated libraries
+add_library(test_combine STATIC IMPORTED)
+set_property(TARGET test_combine PROPERTY IMPORTED_LOCATION "${psa-arch-tests_BINARY_DIR}/dev_apis/crypto/test_combine${CMAKE_STATIC_LIBRARY_SUFFIX}")
+
+add_library(val_nspe STATIC IMPORTED)
+set_property(TARGET val_nspe PROPERTY IMPORTED_LOCATION "${psa-arch-tests_BINARY_DIR}/val/val_nspe${CMAKE_STATIC_LIBRARY_SUFFIX}")
+
+add_library(pal_nspe STATIC IMPORTED)
+set_property(TARGET pal_nspe PROPERTY IMPORTED_LOCATION "${psa-arch-tests_BINARY_DIR}/platform/pal_nspe${CMAKE_STATIC_LIBRARY_SUFFIX}")
diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
index 5c86866..adfd233 100644
--- a/tools/b-test/test_data.yaml
+++ b/tools/b-test/test_data.yaml
@@ -37,6 +37,21 @@
- "-GUnix Makefiles"
- "-DSP_DEV_KIT_DIR=$SP_DEV_KIT_DIR"
- "-DCMAKE_VERBOSE_MAKEFILE=y"
+ - name: "ts-arch-test-crypto-pc-linux"
+ src: "$TS_ROOT/deployments/ts-arch-test/crypto/linux-pc"
+ os_id : "GNU/Linux"
+ params:
+ - "-GUnix Makefiles"
+ - name: "ts-arch-test-crypto-arm-linux"
+ src: "$TS_ROOT/deployments/ts-arch-test/crypto/arm-linux"
+ os_id : "GNU/Linux"
+ params:
+ - "-GUnix Makefiles"
+ - name: "ts-arch-test-initial_attestation-pc-linux"
+ src: "$TS_ROOT/deployments/ts-arch-test/initial_attestation/linux-pc"
+ os_id : "GNU/Linux"
+ params:
+ - "-GUnix Makefiles"
- name: "se-proxy-optee-arm"
src: "$TS_ROOT/deployments/se-proxy/opteesp"
params: