Enable libpsa in psa-api-tests
Refactor psa-api-test deployments to use libpsa.
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
Change-Id: If7f8fdbd48ce082a810983bf0696c791db185a9c
diff --git a/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt b/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt
index 2ef6303..8e72bc4 100644
--- a/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt
+++ b/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt
@@ -18,6 +18,14 @@
add_executable(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(TRACE_PREFIX "PSACRYPTO" CACHE STRING "Trace prefix")
+add_components(TARGET ${PROJECT_NAME}
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/common/trace"
+ "environments/arm-linux"
+)
+
#-------------------------------------------------------------------------------
# Extend with components that are common across all deployments of
# psa-api-test/crypto
diff --git a/deployments/psa-api-test/crypto/crypto-api-test.cmake b/deployments/psa-api-test/crypto/crypto-api-test.cmake
index 9cc97e3..8d4f5e1 100644
--- a/deployments/psa-api-test/crypto/crypto-api-test.cmake
+++ b/deployments/psa-api-test/crypto/crypto-api-test.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -29,16 +29,15 @@
# Crypto specific components
#
#-------------------------------------------------------------------------------
-add_components(
- TARGET "${PROJECT_NAME}"
- BASE_DIR ${TS_ROOT}
- COMPONENTS
- "components/service/crypto/include"
- "components/service/crypto/client/psa"
+target_sources(${PROJECT_NAME} PRIVATE
+ ${TS_ROOT}/deployments/psa-api-test/crypto/crypto.c
)
-target_sources(${PROJECT_NAME} PRIVATE
- ${TS_ROOT}/deployments/psa-api-test/crypto/crypto_locator.c
+add_components(TARGET ${PROJECT_NAME}
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/service/common/include"
+ "components/service/crypto/include"
)
#-------------------------------------------------------------------------------
diff --git a/deployments/psa-api-test/crypto/crypto.c b/deployments/psa-api-test/crypto/crypto.c
new file mode 100644
index 0000000..9cbc67b
--- /dev/null
+++ b/deployments/psa-api-test/crypto/crypto.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "../psa_api_test_common.h"
+#include "libpsa.h"
+#include "trace.h"
+
+psa_status_t test_setup(const char *service_name_crypto, const char *service_name_iat,
+ const char *service_name_ps, const char *service_name_its)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+
+ if (!service_name_crypto)
+ service_name_crypto = "sn:trustedfirmware.org:crypto:0";
+
+ psa_status = libpsa_init_crypto_context(service_name_crypto);
+ if (psa_status) {
+ EMSG("libpsa_init_crypto_context failed: %d\n", psa_status);
+ return psa_status;
+ }
+
+ psa_status = psa_crypto_init();
+ if (psa_status) {
+ EMSG("psa_crypto_init failed: %d\n", psa_status);
+ return psa_status;
+ }
+
+ return PSA_SUCCESS;
+}
+
+void test_teardown(void)
+{
+ libpsa_deinit_crypto_context();
+}
diff --git a/deployments/psa-api-test/crypto/crypto_locator.c b/deployments/psa-api-test/crypto/crypto_locator.c
deleted file mode 100644
index c57a501..0000000
--- a/deployments/psa-api-test/crypto/crypto_locator.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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/crypto/client/psa/psa_crypto_client.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
-#include "../service_under_test.h"
-
-/* RPC context */
-static struct rpc_caller_session *session = NULL;
-static struct service_context *attestation_service_context = NULL;
-
-int locate_service_under_test(void)
-{
- int status = -1;
-
- if (!session && !attestation_service_context) {
-
- service_locator_init();
-
- attestation_service_context =
- service_locator_query("sn:trustedfirmware.org:crypto:0");
-
- if (attestation_service_context) {
-
- session = service_context_open(attestation_service_context);
-
- if (session) {
-
- psa_crypto_client_init(session);
-
- status = 0;
- }
- else {
-
- status = -1;
- relinquish_service_under_test();
- }
- }
- }
-
- return status;
-}
-
-int relinquish_service_under_test(void)
-{
- psa_crypto_client_deinit();
-
- if (attestation_service_context && session) {
-
- service_context_close(attestation_service_context, session);
- session = NULL;
- }
-
- if (attestation_service_context) {
-
- service_context_relinquish(attestation_service_context);
- attestation_service_context = NULL;
- }
-
- return 0;
-}
diff --git a/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt b/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt
index b99604a..d9ad385 100644
--- a/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt
+++ b/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt
@@ -20,6 +20,12 @@
add_executable(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(TRACE_PREFIX "PSACRYPTO" CACHE STRING "Trace prefix")
+add_components(TARGET ${PROJECT_NAME}
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS "environments/linux-pc"
+)
+
#-------------------------------------------------------------------------------
# Extend with components that are common across all deployments of
# psa-api-test/crypto