Add test_runner service
This is a new service with client and provider that can be
used for running tests in a secure processing environment
and retrieving the results. The test_runner provider allows
for arbitrary test farmework backends. The goal is to
have a cpputest backend. In this commit, a mock backend
is included for testing the service itself. The service
has its own access protocol defined under the protocols
top-level directory.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: If4e965c110763bd805abbdcb87e7e03cd76248b2
diff --git a/deployments/env-test/opteesp/.gitignore b/deployments/env-test/opteesp/.gitignore
new file mode 100644
index 0000000..378eac2
--- /dev/null
+++ b/deployments/env-test/opteesp/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/deployments/env-test/opteesp/CMakeLists.txt b/deployments/env-test/opteesp/CMakeLists.txt
new file mode 100644
index 0000000..125485d
--- /dev/null
+++ b/deployments/env-test/opteesp/CMakeLists.txt
@@ -0,0 +1,129 @@
+#-------------------------------------------------------------------------------
+# 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 env-test deployment for opteesp
+#
+# Builds the test_runner service provider for running in an SEL0 secure partition
+# hosted by OPTEE in the role of SPM. Environment tests are added and CppUnit
+# test cases.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+project(trusted-services LANGUAGES C CXX ASM)
+add_executable(env_test)
+target_include_directories(env_test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(SP_UUID "33c75baf-ac6a-4fe4-8ac7-e9909bee2d17")
+
+
+# Include SP DEV KIT interface
+set(SP_DEV_KIT_INC_DIR ${CMAKE_CURRENT_LIST_DIR})
+list(APPEND CMAKE_MODULE_PATH "${TS_ROOT}/external/Spdevkit")
+find_package(Spdevkit REQUIRED)
+sp_dev_kit_configure_linking(TARGET env_test DEFINES ARM64=1)
+target_link_libraries(env_test PRIVATE ${SP_DEV_KIT_LIBRARIES})
+
+#-------------------------------------------------------------------------------
+# Components that are env_testecific to deployment in the opteesp
+# environment.
+#-------------------------------------------------------------------------------
+add_components(TARGET "env_test"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/common/tlv"
+ "components/config/ramstore"
+ "components/messaging/ffa/libsp"
+ "components/rpc/ffarpc/endpoint"
+ "components/rpc/common/interface"
+ "components/service/common"
+ "components/service/common/provider"
+ "components/service/test_runner/provider"
+ "components/service/test_runner/provider/serializer/packed-c"
+ "components/service/test_runner/provider/backend/mock"
+ "protocols/rpc/common/packed-c"
+ "environments/opteesp"
+)
+
+target_sources(env_test PRIVATE
+ env_test.c
+ env_test_config.c
+)
+
+#-------------------------------------------------------------------------------
+# Use the selected platform to provide drivers needed by the deployment
+#
+#-------------------------------------------------------------------------------
+# temporarily force platform - remove when external builder updated
+set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Overridden" FORCE)
+
+add_platform(TARGET "env_test")
+
+#-------------------------------------------------------------------------------
+# Components used from external projects
+#
+#-------------------------------------------------------------------------------
+
+if(CMAKE_CROSSCOMPILING)
+ target_link_libraries(env_test PRIVATE stdc++ gcc m)
+endif()
+
+#################################################################
+
+target_compile_definitions(env_test PRIVATE
+ ARM64=1
+)
+
+target_include_directories(env_test PRIVATE
+ ${TS_ROOT}
+ ${TS_ROOT}/components
+ ${TS_ROOT}/deployments/env-test/opteesp
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ target_compile_options(env_test PRIVATE
+ -fdiagnostics-show-option
+ -fpic
+ -gdwarf-2
+ -mstrict-align
+ -O0
+ $<$<COMPILE_LANGUAGE:C>:-std=gnu99>
+ $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
+ )
+
+ # Options for GCC that control linking
+ target_link_options(env_test PRIVATE
+ -e __sp_entry
+ -fno-lto
+ -nostdlib
+ -pie
+ -zmax-page-size=4096
+ )
+ # Options directly for LD, these are not understood by GCC
+ target_link_options(env_test PRIVATE
+ -Wl,--as-needed
+ -Wl,--sort-section=alignment
+ # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
+ )
+endif()
+
+compiler_generate_stripped_elf(TARGET env_test NAME "${SP_UUID}.stripped.elf" RES STRIPPED_ELF)
+
+######################################## install
+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()
+#TODO: api headers
+install(TARGETS env_test
+ PUBLIC_HEADER DESTINATION include
+ RUNTIME DESTINATION bin
+ )
+install(FILES ${STRIPPED_ELF} DESTINATION bin)
+
+set(EXPORT_SP_NAME "env-test")
+set(EXPORT_SP_UUID ${SP_UUID})
+include(${TS_ROOT}/environments/opteesp/ExportSp.cmake)
diff --git a/deployments/env-test/opteesp/env_test.c b/deployments/env-test/opteesp/env_test.c
new file mode 100644
index 0000000..0bb523f
--- /dev/null
+++ b/deployments/env-test/opteesp/env_test.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ */
+
+#include <rpc/ffarpc/caller/sp/ffarpc_caller.h>
+#include <rpc/ffarpc/endpoint/ffarpc_call_ep.h>
+#include <service/test_runner/provider/test_runner_provider.h>
+#include <service/test_runner/provider/serializer/packed-c/packedc_test_runner_provider_serializer.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <ffa_api.h>
+#include <sp_api.h>
+#include <sp_rxtx.h>
+#include <trace.h>
+#include "env_test_config.h"
+
+
+uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */
+
+
+static int sp_init(uint16_t *own_sp_id);
+
+void __noreturn sp_main(struct ffa_init_info *init_info)
+{
+ struct test_runner_provider test_runner_provider;
+ struct ffa_call_ep ffarpc_call_ep;
+ struct rpc_interface *test_runner_iface;
+ struct ffarpc_caller ffarpc_caller;
+ struct ffa_direct_msg req_msg;
+
+ /* Boot */
+ (void) init_info;
+
+ if (sp_init(&own_id) != 0) goto fatal_error;
+
+ load_sp_config(init_info);
+
+ /* Initialize the test_runner service */
+ test_runner_iface = test_runner_provider_init(&test_runner_provider);
+
+ test_runner_provider_register_serializer(&test_runner_provider,
+ TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance());
+
+ ffa_call_ep_init(&ffarpc_call_ep, test_runner_iface);
+
+ /* End of boot phase */
+ ffa_msg_wait(&req_msg);
+
+ while (1) {
+ if (req_msg.function_id == FFA_MSG_SEND_DIRECT_REQ_32) {
+
+ struct ffa_direct_msg resp_msg;
+
+ ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg);
+
+ ffa_msg_send_direct_resp(req_msg.destination_id,
+ req_msg.source_id, resp_msg.args[0], resp_msg.args[1],
+ resp_msg.args[2], resp_msg.args[3], resp_msg.args[4],
+ &req_msg);
+ }
+ }
+
+fatal_error:
+ /* SP is not viable */
+ EMSG("environment-test SP error");
+ while (1) {}
+}
+
+void sp_interrupt_handler(uint32_t interrupt_id)
+{
+ (void)interrupt_id;
+}
+
+static int sp_init(uint16_t *own_sp_id)
+{
+ int status = -1;
+ ffa_result ffa_res;
+ sp_result sp_res;
+ static uint8_t tx_buffer[4096] __aligned(4096);
+ static uint8_t rx_buffer[4096] __aligned(4096);
+
+ sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
+ if (sp_res == SP_RESULT_OK) {
+ ffa_res = ffa_id_get(own_sp_id);
+ if (ffa_res == FFA_OK) {
+ status = 0;
+ }
+ }
+
+ return status;
+}
diff --git a/deployments/env-test/opteesp/env_test.h b/deployments/env-test/opteesp/env_test.h
new file mode 100644
index 0000000..0f4c8b7
--- /dev/null
+++ b/deployments/env-test/opteesp/env_test.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ENV_TEST_SP_H
+#define ENV_TEST_SP_H
+
+#define ENV_TEST_SP_UUID \
+ {0x33c75baf, 0xac6a, 0x4fe4, \
+ {0x8a, 0xc7, 0xe9, 0x90, 0x9b, 0xee, 0x2d, 0x17}}
+
+#define ENV_TEST_SP_UUID_BYTES \
+ {0x33, 0xc7, 0x5b, 0xaf, 0xac, 0x6a, 0x4f, 0xef, \
+ 0x8a, 0xcy, 0xe9, 0x90, 0x9b, 0xee, 0x2d, 0x17}
+
+#endif /* ENV_TEST_SP_H */
diff --git a/deployments/env-test/opteesp/env_test_config.c b/deployments/env-test/opteesp/env_test_config.c
new file mode 100644
index 0000000..14a1e53
--- /dev/null
+++ b/deployments/env-test/opteesp/env_test_config.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ */
+
+#include <config/ramstore/config_ramstore.h>
+#include "env_test_config.h"
+
+
+void load_sp_config(struct ffa_init_info *init_info)
+{
+ config_ramstore_init();
+
+ /* Load deployment specific configuration */
+ (void)init_info;
+}
\ No newline at end of file
diff --git a/deployments/env-test/opteesp/env_test_config.h b/deployments/env-test/opteesp/env_test_config.h
new file mode 100644
index 0000000..8ed4a7e
--- /dev/null
+++ b/deployments/env-test/opteesp/env_test_config.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ENV_TEST_CONFIG_H
+#define ENV_TEST_CONFIG_H
+
+#include <ffa_api.h>
+
+/**
+ * Loads the SP specific configuration passed as SP initialization parameters.
+ */
+void load_sp_config(struct ffa_init_info *init_info);
+
+
+#endif /* ENV_TEST_CONFIG_H */
diff --git a/deployments/env-test/opteesp/optee_sp_user_defines.h b/deployments/env-test/opteesp/optee_sp_user_defines.h
new file mode 100644
index 0000000..a524a6e
--- /dev/null
+++ b/deployments/env-test/opteesp/optee_sp_user_defines.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef SP_HEADER_DEFINES_H
+#define SP_HEADER_DEFINES_H
+
+/* To get UUID definition */
+#include "env_test.h"
+
+#define OPTEE_SP_UUID ENV_TEST_SP_UUID
+#define OPTEE_SP_FLAGS 0
+
+/* Provisioned stack size */
+#define OPTEE_SP_STACK_SIZE (64 * 1024)
+
+/* Provisioned heap size */
+#define OPTEE_SP_HEAP_SIZE (32 * 1024)
+
+#endif /* SP_HEADER_DEFINES_H */