Add secure storage PSA API test deployments
Adds build files and test suite specific initialisation for building
and running PSA API tests against secure storage service providers.
Tests may be run in a native PC environment or from Linux userspace
on an Arm based Linux platform.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I58596bd176f3987c026da7c80a5d330b90763848
diff --git a/deployments/psa-api-test/internal_trusted_storage/arm-linux/CMakeLists.txt b/deployments/psa-api-test/internal_trusted_storage/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..27e511a
--- /dev/null
+++ b/deployments/psa-api-test/internal_trusted_storage/arm-linux/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)
+include(../../psa-api-test-config.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the psa-api-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(psa-api-test)
+target_include_directories(psa-api-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test/internal_trusted_storage
+#-------------------------------------------------------------------------------
+include(../its-api-test.cmake REQUIRED)
diff --git a/deployments/psa-api-test/internal_trusted_storage/its-api-test.cmake b/deployments/psa-api-test/internal_trusted_storage/its-api-test.cmake
new file mode 100644
index 0000000..ea6f381
--- /dev/null
+++ b/deployments/psa-api-test/internal_trusted_storage/its-api-test.cmake
@@ -0,0 +1,42 @@
+#-------------------------------------------------------------------------------
+# 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 INTERNAL_TRUSTED_STORAGE CACHE STRING "Arch test suite")
+
+#-------------------------------------------------------------------------------
+# The arch test build system puts its build output under a test suite specific
+# subdirectory. The subdirectory name is different from the test suite name
+# so an additional define is needed to obtain the built library.
+#-------------------------------------------------------------------------------
+set(TS_ARCH_TEST_BUILD_SUBDIR storage CACHE STRING "Arch test build subdirectory")
+
+#-------------------------------------------------------------------------------
+# Crypto specific components
+#
+#-------------------------------------------------------------------------------
+add_components(
+ TARGET "psa-api-test"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/service/secure_storage/include"
+ "components/service/secure_storage/frontend/psa/its"
+ "components/service/secure_storage/backend/secure_storage_client"
+)
+
+target_sources(psa-api-test PRIVATE
+ ${TS_ROOT}/deployments/psa-api-test/internal_trusted_storage/its_locator.c
+)
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test
+#-------------------------------------------------------------------------------
+include(../../psa-api-test.cmake REQUIRED)
diff --git a/deployments/psa-api-test/internal_trusted_storage/its_locator.c b/deployments/psa-api-test/internal_trusted_storage/its_locator.c
new file mode 100644
index 0000000..e100328
--- /dev/null
+++ b/deployments/psa-api-test/internal_trusted_storage/its_locator.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <service_locator.h>
+#include <service/secure_storage/frontend/psa/its/its_frontend.h>
+#include <service/secure_storage/backend/secure_storage_client/secure_storage_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
+#include "../service_under_test.h"
+
+/* RPC context */
+static rpc_session_handle session_handle = NULL;
+static struct service_context *ps_service_context = NULL;
+static struct secure_storage_client storage_client;
+
+int locate_service_under_test(struct logging_caller *call_logger)
+{
+ int status = -1;
+
+ if (!session_handle && !ps_service_context) {
+
+ struct rpc_caller *caller;
+
+ ps_service_context =
+ service_locator_query("sn:trustedfirmware.org:internal-trusted-storage:0", &status);
+
+ if (ps_service_context) {
+
+ session_handle =
+ service_context_open(ps_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
+
+ if (session_handle) {
+
+ struct storage_backend *storage_backend = NULL;
+ status = -1;
+
+ if (call_logger) {
+
+ storage_backend = secure_storage_client_init(&storage_client,
+ logging_caller_attach(call_logger, caller));
+ }
+ else {
+
+ storage_backend = secure_storage_client_init(&storage_client, caller);
+ }
+
+ if (storage_backend) {
+
+ psa_its_frontend_init(storage_backend);
+ status = 0;
+ }
+ }
+
+ if (status < 0) relinquish_service_under_test();
+ }
+ }
+
+ return status;
+}
+
+void relinquish_service_under_test(void)
+{
+ psa_its_frontend_init(NULL);
+ secure_storage_client_deinit(&storage_client);
+
+ if (ps_service_context && session_handle) {
+
+ service_context_close(ps_service_context, session_handle);
+ session_handle = NULL;
+ }
+
+ if (ps_service_context) {
+
+ service_context_relinquish(ps_service_context);
+ ps_service_context = NULL;
+ }
+}
diff --git a/deployments/psa-api-test/internal_trusted_storage/linux-pc/CMakeLists.txt b/deployments/psa-api-test/internal_trusted_storage/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..941d47f
--- /dev/null
+++ b/deployments/psa-api-test/internal_trusted_storage/linux-pc/CMakeLists.txt
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------------------------
+# 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)
+include(../../psa-api-test-config.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the psa-api-test/internal_trusted_storage
+# 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 "psa-api-test"
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(psa-api-test)
+target_include_directories(psa-api-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test/internal_trusted_storage
+#-------------------------------------------------------------------------------
+include(../its-api-test.cmake REQUIRED)