Test/App: Add the original test and app codes from tf-m

The version of the tf-m is:
ac9ccf207e153726b8dc1f5569f702f56d94297f

Change-Id: I445ada360540da55bbe74b3e7aa8d622e8fda501
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
new file mode 100644
index 0000000..2039a6a
--- /dev/null
+++ b/app/CMakeLists.txt
@@ -0,0 +1,435 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_minimum_required(VERSION 3.7)
+
+set(TFM_BUILD_IN_SPE OFF)
+
+#Tell cmake where our modules can be found
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
+
+set(APP_DIR ${CMAKE_CURRENT_LIST_DIR})
+get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE)
+set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface)
+
+#Include common stuff to control cmake.
+include("Common/BuildSys")
+
+#Start an embedded project.
+embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake")
+project(tfm_ns LANGUAGES ASM C)
+embedded_project_fixup()
+
+#Include BL2 bootloader related functions
+set(MCUBOOT_DIR "${TFM_ROOT_DIR}/bl2/ext/mcuboot")
+include("${MCUBOOT_DIR}/MCUBoot.cmake")
+
+#CMSIS
+get_filename_component(CMSIS_DIR ${TFM_ROOT_DIR}/../tf-m-tests/CMSIS ABSOLUTE)
+
+if(NOT EXISTS ${CMSIS_DIR})
+	message(FATAL_ERROR "Missing CMSIS. Please clone the tf-m-tests repo.")
+endif()
+
+if (NOT DEFINED BL2)
+	message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
+endif ()
+
+if (NOT DEFINED TFM_PARTITION_AUDIT_LOG)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PARTITION_PLATFORM)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PLATFORM is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PROTECTED_STORAGE is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PARTITION_CRYPTO)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.")
+endif()
+
+if (NOT DEFINED TFM_PSA_API)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined.")
+endif()
+
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/app ABSOLUTE)
+
+set(NS_APP_SRC "${CMSIS_DIR}/RTOS2/RTX/Config/RTX_Config.c"
+	"${CMSIS_DIR}/RTOS2/RTX/Source/rtx_lib.c"
+	"${APP_DIR}/main_ns.c"
+	"${APP_DIR}/tfm_integ_test.c"
+	"${APP_DIR}/os_wrapper_cmsis_rtos_v2.c"
+	"${TFM_ROOT_DIR}/interface/src/log/tfm_log_raw.c"
+	)
+
+if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY)
+	list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_interface.c")
+endif()
+
+if (TFM_PARTITION_AUDIT_LOG)
+	if (TFM_PSA_API)
+		message(FATAL_ERROR "Audit log has not been supported in IPC model yet.")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_audit_func_api.c")
+	endif()
+endif()
+
+if (TFM_PARTITION_PLATFORM)
+	if (TFM_PSA_API)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_ipc_api.c")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_func_api.c")
+	endif()
+endif()
+
+if (TFM_PARTITION_PROTECTED_STORAGE)
+	if (TFM_PSA_API)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ps_ipc_api.c")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ps_func_api.c")
+	endif()
+endif()
+
+if (TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
+	if (TFM_PSA_API)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_ipc_api.c")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_func_api.c")
+	endif()
+endif()
+
+if (TFM_PARTITION_CRYPTO)
+	if (TFM_PSA_API)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_ipc_api.c")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_func_api.c")
+	endif()
+endif()
+
+if (TFM_PARTITION_INITIAL_ATTESTATION)
+	if (TFM_PSA_API)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_ipc_api.c")
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_func_api.c")
+	endif()
+endif()
+
+if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
+elseif (TFM_NS_CLIENT_IDENTIFICATION)
+	list(APPEND NS_APP_SRC
+		"${INTERFACE_DIR}/src/tfm_nspm_svc_handler.c"
+		"${INTERFACE_DIR}/src/tfm_nspm_api.c"
+		)
+endif()
+
+if (PSA_API_TEST_NS)
+	list(APPEND NS_APP_SRC "${APP_DIR}/psa_api_test.c")
+endif()
+
+if (TFM_PSA_API)
+	if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY)
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_mailbox.c"
+			"${INTERFACE_DIR}/src/tfm_multi_core_api.c"
+			"${INTERFACE_DIR}/src/tfm_multi_core_psa_ns_api.c"
+			)
+
+		if (TFM_MULTI_CORE_TEST)
+			add_definitions(-DTFM_MULTI_CORE_TEST)
+		endif()
+	else()
+		list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_psa_ns_api.c")
+	endif()
+endif()
+
+set(BUILD_CMSIS_CORE On)
+set(BUILD_RETARGET On)
+set(BUILD_NATIVE_DRIVERS On)
+set(BUILD_TIME On)
+set(BUILD_STARTUP On)
+set(BUILD_TARGET_CFG Off)
+set(BUILD_TARGET_HARDWARE_KEYS Off)
+set(BUILD_TARGET_NV_COUNTERS Off)
+set(BUILD_CMSIS_DRIVERS On)
+set(BUILD_UART_STDOUT On)
+set(BUILD_FLASH Off)
+if(CORE_TEST_POSITIVE)
+	set(BUILD_PLAT_TEST On)
+	set(BUILD_TIME On)
+else()
+	set(BUILD_PLAT_TEST Off)
+	set(BUILD_TIME Off)
+endif()
+if(NOT DEFINED PLATFORM_CMAKE_FILE)
+	message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
+elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
+	message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
+else()
+	include(${PLATFORM_CMAKE_FILE})
+endif()
+
+if(NOT DEFINED NS_SCATTER_FILE_NAME)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
+endif()
+embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH  "${NS_SCATTER_FILE_NAME}")
+
+#Create an object library to avoid compiling all source files twice, when two executables
+#with different memory map need to be linked(BL2 non-swapping)
+set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
+add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
+
+#Set common compiler flags
+config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
+
+#Set macro definitions
+set(TARGET_COMPILE_DEFINITIONS __thumb2__ __DOMAIN_NS=1 DOMAIN_NS=__DOMAIN_NS)
+target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE ${TARGET_COMPILE_DEFINITIONS})
+
+#Set include directories.
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/RTX/Include ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/Include ABSOLUTE APPEND)
+embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/RTX/Config  ABSOLUTE APPEND)
+
+if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
+	message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
+elseif (TFM_NS_CLIENT_IDENTIFICATION)
+	target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION)
+endif()
+
+add_subdirectory(${TEST_DIR} ${CMAKE_BINARY_DIR}/test/non_secure_test)
+
+# For the non-swapping BL2 configuration two executables need to be built.
+# One can be executed from the primary slot flash partition and other from the
+# secondary slot. Only the linking phase is different. This function captures
+# common settings and eliminates copy-paste.
+function(set_up_app_build)
+	set( _OPTIONS_ARGS)                                                            #Option (on/off) arguments (e.g. IGNORE_CASE)
+	set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
+	set( _MULTI_VALUE_ARGS LINK_DEFINES)                                           #List arguments (e.g. LANGUAGES C ASM CXX)
+	cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
+
+	if (NOT DEFINED _MY_PARAMS_NS_TARGET)
+		message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_S_TARGET)
+		message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_FULL_BIN)
+		message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
+		message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.")
+	endif()
+
+	if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
+		message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.")
+	endif()
+
+	set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX})
+	set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
+	set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX})
+	set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX})
+	set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
+
+	#Create linker target: add object library to executable
+	add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
+
+	#Set common linker flags
+	config_setting_shared_linker_flags(${EXE_NAME})
+
+	#Set individual linker flags per linker target/executable
+	foreach(flag ${_MY_PARAMS_LINK_DEFINES})
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
+	endforeach(flag)
+
+	embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}")
+
+	#Add the RTX library
+	if(NOT DEFINED RTX_LIB_PATH)
+		message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
+	endif()
+
+	#Add the PSA API compliance test libraries
+	if(PSA_API_TEST_NS)
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/val/val_nspe.a")
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/platform/pal_nspe.a")
+	endif()
+	if(PSA_API_TEST_NS AND (PSA_API_TEST_INTERNAL_TRUSTED_STORAGE OR PSA_API_TEST_PROTECTED_STORAGE OR PSA_API_TEST_STORAGE))
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/storage/test_combine.a")
+	endif()
+	if(PSA_API_TEST_NS AND PSA_API_TEST_CRYPTO)
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/crypto/test_combine.a")
+	endif()
+	if(PSA_API_TEST_NS AND PSA_API_TEST_INITIAL_ATTESTATION)
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/initial_attestation/test_combine.a")
+	endif()
+	if(PSA_API_TEST_NS AND PSA_API_TEST_IPC)
+		target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/ff/ipc/test_combine.a")
+	endif()
+
+	if(NOT DEFINED PLATFORM_LINK_INCLUDES)
+		message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
+	endif()
+	embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
+
+	#Generate binary file from axf
+	compiler_generate_binary_output(${EXE_NAME})
+
+	#Generate intel hex file from axf
+	compiler_generate_hex_output(${EXE_NAME})
+
+	#Generate elf file from axf
+	compiler_generate_elf_output(${EXE_NAME})
+
+	#Generate MCUBoot compatible payload
+	if (BL2)
+		mcuboot_create_boot_payload(S_BIN    ${S_BIN}
+									NS_BIN   ${EXE_NAME}
+									FULL_BIN ${FULL_NAME}
+									SIGN_BIN ${SIGN_NAME}
+									POSTFIX  ${_MY_PARAMS_POSTFIX})
+	endif()
+
+	if (NOT DEFINED TFM_PARTITION_TEST_CORE)
+		message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
+	elseif (TFM_PARTITION_TEST_CORE)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
+	endif()
+
+	if (NOT DEFINED TFM_PARTITION_TEST_CORE_IPC)
+		message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE_IPC is undefined.")
+	elseif (TFM_PARTITION_TEST_CORE_IPC)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE_IPC")
+	endif()
+
+	if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
+		message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
+	elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
+	endif()
+
+	if (NOT DEFINED TEST_FRAMEWORK_S)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
+	elseif (TEST_FRAMEWORK_S)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S")
+	endif()
+
+	if (NOT DEFINED TEST_FRAMEWORK_NS)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
+	elseif (TEST_FRAMEWORK_NS)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS")
+	endif()
+
+	#Set BL2 specific settings.
+	if (BL2)
+		#Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2" "MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}")
+	endif()
+
+	#We depend on the non secure tests. See if the library target is available.
+	if(TARGET tfm_non_secure_tests)
+		#If yes, then use the library.
+		target_link_libraries(${EXE_NAME} tfm_non_secure_tests)
+		#Ensure library is built first.
+		add_dependencies(${EXE_NAME} tfm_non_secure_tests)
+	endif()
+
+	target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}")
+
+	#Ensure secure_fw is built before our executable.
+	add_dependencies(${EXE_NAME} ${S_BIN})
+
+	if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY)
+		if (NOT DEFINED S_VENEER_PATH)
+			if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../secure_fw)
+				set (S_VENEER_PATH "${CMAKE_CURRENT_BINARY_DIR}/../secure_fw")
+			else()
+				message(FATAL_ERROR "No valid path for S_VENEER_PATH, secure_fw is built?")
+			endif()
+		endif()
+
+		#Add the veneers to the executable.
+		set(S_VENEER_FILE "${S_VENEER_PATH}/${VENEER_NAME}")
+		set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
+	endif()
+
+	#Collect executables to common location: build/install/outputs/
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.hex
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.elf
+			DESTINATION outputs/${TARGET_PLATFORM}/)
+
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.hex
+				  ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.elf
+			DESTINATION outputs/fvp/)
+endfunction()
+
+if (LINK_TO_BOTH_MEMORY_REGION)
+	#Link to primary memory region
+	set_up_app_build(NS_TARGET     ${PROJECT_NAME}
+					 S_TARGET      tfm_s
+					 FULL_BIN      tfm_full
+					 SIGN_BIN      tfm_sign
+					 VENEER_NAME   s_veneers)
+
+	#Link to secondary memory region(add extra linker flag)
+	set_up_app_build(NS_TARGET     ${PROJECT_NAME}
+					 LINK_DEFINES  "LINK_TO_SECONDARY_PARTITION"
+					 S_TARGET      tfm_s
+					 FULL_BIN      tfm_full
+					 SIGN_BIN      tfm_sign
+					 VENEER_NAME   s_veneers
+					 POSTFIX       "_1")
+else()
+	#Link to primary memory region only
+	set_up_app_build(NS_TARGET     ${PROJECT_NAME}
+					 S_TARGET      tfm_s
+					 FULL_BIN      tfm_full
+					 SIGN_BIN      tfm_sign
+					 VENEER_NAME   s_veneers)
+endif()
+
+#If the tfm_non_secure_tests target is not available
+if(NOT TARGET tfm_non_secure_tests)
+	#Add the test source to the build.
+	#As of today since secure_fw is built as a sub-project this code will never execute.
+	option(ENABLE_PROTECTED_STORAGE_SERVICE_TESTS "" TRUE)
+	include(${TEST_DIR}/CMakeLists.inc)
+	target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
+endif()
+
+#Finally let CMake system apply changes after the whole project is defined.
+if (TARGET ${PROJECT_NAME})
+	embedded_project_end(${PROJECT_NAME})
+endif()
+
+if (TARGET ${PROJECT_NAME}_1)
+	embedded_project_end(${PROJECT_NAME}_1)
+endif()
+
+embedded_project_end(${PROJECT_OBJ_LIB})
diff --git a/app/main_ns.c b/app/main_ns.c
new file mode 100644
index 0000000..fc874bd
--- /dev/null
+++ b/app/main_ns.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_api.h"
+#include "cmsis_os2.h"
+#include "tfm_integ_test.h"
+#include "tfm_ns_svc.h"
+#include "tfm_ns_interface.h"
+#ifdef TEST_FRAMEWORK_NS
+#include "test/framework/test_framework_integ_test.h"
+#endif
+#ifdef PSA_API_TEST_NS
+#include "psa_api_test.h"
+#endif
+#include "target_cfg.h"
+#include "tfm_plat_ns.h"
+#include "Driver_USART.h"
+#include "device_cfg.h"
+#ifdef TFM_MULTI_CORE_TOPOLOGY
+#include "tfm_multi_core_api.h"
+#include "tfm_ns_mailbox.h"
+#endif
+#include "log/tfm_assert.h"
+#include "log/tfm_log.h"
+#include "uart_stdout.h"
+#include "region.h"
+
+/**
+ * \brief Modified table template for user defined SVC functions
+ *
+ * \details RTX has a weak definition of osRtxUserSVC, which
+ *          is overridden here
+ */
+#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004))
+/* Workaround needed for a bug in Armclang 6.11, more details at:
+ * http://www.keil.com/support/docs/4089.htm
+ */
+__attribute__((section(".gnu.linkonce")))
+#endif
+extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
+       void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
+  (void *)USER_SVC_COUNT,
+
+#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
+
+    /* SVC API for Services */
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
+    LIST_SVC_NSPM
+#endif
+
+#undef X
+
+/*
+ * (void *)user_function1,
+ *  ...
+ */
+};
+
+/**
+ * \brief List of RTOS thread attributes
+ */
+#if defined(TEST_FRAMEWORK_NS) || defined(PSA_API_TEST_NS)
+static uint64_t test_app_stack[(4u * 1024u) / (sizeof(uint64_t))]; /* 4KB */
+static const osThreadAttr_t thread_attr = {
+    .name = "test_thread",
+    .stack_mem = test_app_stack,
+    .stack_size = sizeof(test_app_stack),
+};
+#endif
+
+/**
+ * \brief Static globals to hold RTOS related quantities,
+ *        main thread
+ */
+#if defined(TEST_FRAMEWORK_NS) || defined(PSA_API_TEST_NS)
+static osThreadFunc_t thread_func;
+#endif
+
+#ifdef TFM_MULTI_CORE_TOPOLOGY
+static struct ns_mailbox_queue_t ns_mailbox_queue;
+
+static void tfm_ns_multi_core_boot(void)
+{
+    int32_t ret;
+
+    LOG_MSG("Non-secure code running on non-secure core.");
+
+    if (tfm_ns_wait_for_s_cpu_ready()) {
+        LOG_MSG("Error sync'ing with secure core.");
+
+        /* Avoid undefined behavior after multi-core sync-up failed */
+        for (;;) {
+        }
+    }
+
+    ret = tfm_ns_mailbox_init(&ns_mailbox_queue);
+    if (ret != MAILBOX_SUCCESS) {
+        LOG_MSG("Non-secure mailbox initialization failed.");
+
+        /* Avoid undefined behavior after NS mailbox initialization failed */
+        for (;;) {
+        }
+    }
+}
+#endif
+
+/**
+ * \brief Platform peripherals and devices initialization.
+ *        Can be overridden for platform specific initialization.
+ *
+ * \return  ARM_DRIVER_OK if the initialization succeeds
+ */
+__WEAK int32_t tfm_ns_platform_init(void)
+{
+    stdio_init();
+
+    return ARM_DRIVER_OK;
+}
+
+/**
+ * \brief Platform peripherals and devices de-initialization.
+ *        Can be overridden for platform specific initialization.
+ *
+ * \return  ARM_DRIVER_OK if the de-initialization succeeds
+ */
+__WEAK int32_t tfm_ns_platform_uninit(void)
+{
+    stdio_uninit();
+
+    return ARM_DRIVER_OK;
+}
+
+/**
+ * \brief main() function
+ */
+#ifndef __GNUC__
+__attribute__((noreturn))
+#endif
+int main(void)
+{
+#if defined(__ARM_ARCH_8_1M_MAIN__) || defined(__ARM_ARCH_8M_MAIN__)
+    /* Set Main Stack Pointer limit */
+    REGION_DECLARE(Image$$, ARM_LIB_STACK_MSP, $$ZI$$Base);
+    __set_MSPLIM((uint32_t)&REGION_NAME(Image$$, ARM_LIB_STACK_MSP,
+                                        $$ZI$$Base));
+#endif
+
+    if (tfm_ns_platform_init() != ARM_DRIVER_OK) {
+        /* Avoid undefined behavior if platform init failed */
+        while(1);
+    }
+
+#ifdef TFM_MULTI_CORE_TOPOLOGY
+    tfm_ns_multi_core_boot();
+#endif
+
+    (void) osKernelInitialize();
+
+    /* Initialize the TFM NS interface */
+    tfm_ns_interface_init();
+
+#if defined(TEST_FRAMEWORK_NS)
+    thread_func = test_app;
+#elif defined(PSA_API_TEST_NS)
+    thread_func = psa_api_test;
+#endif
+
+#if defined(TEST_FRAMEWORK_NS) || defined(PSA_API_TEST_NS)
+    (void) osThreadNew(thread_func, NULL, &thread_attr);
+#endif
+
+    LOG_MSG("Non-Secure system starting...\r\n");
+    (void) osKernelStart();
+
+    /* Reached only in case of error */
+    for (;;) {
+    }
+}
diff --git a/app/os_wrapper_cmsis_rtos_v2.c b/app/os_wrapper_cmsis_rtos_v2.c
new file mode 100644
index 0000000..9892290
--- /dev/null
+++ b/app/os_wrapper_cmsis_rtos_v2.c
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "os_wrapper/thread.h"
+#include "os_wrapper/mutex.h"
+#include "os_wrapper/semaphore.h"
+
+#include <string.h>
+#include "cmsis_os2.h"
+
+/* This is an example OS abstraction layer for CMSIS-RTOSv2 */
+
+void *os_wrapper_thread_new(const char *name, int32_t stack_size,
+                            os_wrapper_thread_func func, void *arg,
+                            uint32_t priority)
+{
+    osThreadAttr_t task_attribs = {.tz_module = 1};
+
+    /* By default, the thread starts as osThreadDetached */
+    if (stack_size != OS_WRAPPER_DEFAULT_STACK_SIZE) {
+        task_attribs.stack_size = stack_size;
+    }
+    task_attribs.name = name;
+    task_attribs.priority = (osPriority_t) priority;
+
+    return (void *)osThreadNew(func, arg, &task_attribs);
+}
+
+void *os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
+                                  const char *name)
+{
+    osSemaphoreAttr_t sema_attrib = {0};
+
+    sema_attrib.name = name;
+
+    return (void *)osSemaphoreNew(max_count, initial_count, &sema_attrib);
+}
+
+uint32_t os_wrapper_semaphore_acquire(void *handle, uint32_t timeout)
+{
+    osStatus_t status;
+
+    status = osSemaphoreAcquire((osSemaphoreId_t)handle,
+                                (timeout == OS_WRAPPER_WAIT_FOREVER) ?
+                                osWaitForever : timeout);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_semaphore_release(void *handle)
+{
+    osStatus_t status;
+
+    status = osSemaphoreRelease((osSemaphoreId_t)handle);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_semaphore_delete(void *handle)
+{
+    osStatus_t status;
+
+    status = osSemaphoreDelete((osSemaphoreId_t)handle);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+void *os_wrapper_mutex_create(void)
+{
+    const osMutexAttr_t attr = {
+        .name = NULL,
+        .attr_bits = osMutexPrioInherit, /* Priority inheritance is recommended
+                                          * to enable if it is supported.
+                                          * For recursive mutex and the ability
+                                          * of auto release when owner being
+                                          * terminated is not required.
+                                          */
+        .cb_mem = NULL,
+        .cb_size = 0U
+    };
+
+    return (void *)osMutexNew(&attr);
+}
+
+uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout)
+{
+    osStatus_t status = osOK;
+
+    if (!handle) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    status = osMutexAcquire((osMutexId_t)handle,
+                            (timeout == OS_WRAPPER_WAIT_FOREVER) ?
+                             osWaitForever : timeout);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_mutex_release(void *handle)
+{
+    osStatus_t status = osOK;
+
+    if (!handle) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    status = osMutexRelease((osMutexId_t)handle);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_mutex_delete(void *handle)
+{
+    osStatus_t status = osOK;
+
+    if (!handle) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    status = osMutexDelete((osMutexId_t)handle);
+    if (status != osOK) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+void *os_wrapper_thread_get_handle(void)
+{
+    return (void *)osThreadGetId();
+}
+
+uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority)
+{
+    osPriority_t prio;
+
+    prio = osThreadGetPriority((osThreadId_t)handle);
+    if (prio == osPriorityError) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    *priority = (uint32_t)prio;
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+void os_wrapper_thread_exit(void)
+{
+    osThreadExit();
+}
+
+uint32_t os_wrapper_thread_set_flag(void *handle, uint32_t flags)
+{
+    uint32_t ret;
+
+    ret = osThreadFlagsSet((osThreadId_t)handle, flags);
+    if (ret & osFlagsError) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+/*
+ * According to the description of CMSIS-RTOS v2 Thread Flags,
+ * osThreadFlagsSet() can be called inside Interrupt Service Routine.
+ */
+uint32_t os_wrapper_thread_set_flag_isr(void *handle, uint32_t flags)
+{
+    uint32_t ret;
+
+    ret = osThreadFlagsSet((osThreadId_t)handle, flags);
+    if (ret & osFlagsError) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_thread_wait_flag(uint32_t flags, uint32_t timeout)
+{
+    uint32_t ret;
+
+    ret = osThreadFlagsWait(flags, osFlagsWaitAll,
+                            (timeout == OS_WRAPPER_WAIT_FOREVER) ?
+                            osWaitForever : timeout);
+    if (ret & osFlagsError) {
+        return OS_WRAPPER_ERROR;
+    }
+
+    return OS_WRAPPER_SUCCESS;
+}
+
+uint32_t os_wrapper_get_tick(void)
+{
+    return osKernelGetTickCount();
+}
diff --git a/app/psa_api_test.c b/app/psa_api_test.c
new file mode 100644
index 0000000..3a6cc53
--- /dev/null
+++ b/app/psa_api_test.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "psa_api_test.h"
+#include "tfm_nspm_api.h"
+#include "tfm_integ_test.h"
+
+/**
+ * \brief This symbol is the entry point provided by the PSA API compliance
+ *        test libraries
+ */
+extern void val_entry(void);
+
+__attribute__((noreturn))
+void psa_api_test(void *arg)
+{
+    UNUSED_VARIABLE(arg);
+
+#ifdef TFM_NS_CLIENT_IDENTIFICATION
+    tfm_nspm_register_client_id();
+#endif /* TFM_NS_CLIENT_IDENTIFICATION */
+
+    val_entry();
+
+    for (;;) {
+    }
+}
diff --git a/app/psa_api_test.h b/app/psa_api_test.h
new file mode 100644
index 0000000..5423b15
--- /dev/null
+++ b/app/psa_api_test.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __PSA_API_TEST_H__
+#define __PSA_API_TEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Main test application for the PSA API compliance tests
+ *
+ */
+void psa_api_test(void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PSA_API_TEST_H__ */
diff --git a/app/tfm_integ_test.c b/app/tfm_integ_test.c
new file mode 100644
index 0000000..32cb674
--- /dev/null
+++ b/app/tfm_integ_test.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_integ_test.h"
+
+#ifdef TEST_FRAMEWORK_NS
+#include "test/framework/test_framework_integ_test.h"
+#endif
+
+#ifdef TEST_FRAMEWORK_S
+#include \
+  "test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.h"
+#endif
+
+#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
+/**
+ * \brief Services test thread
+ *
+ */
+__attribute__((noreturn))
+void test_app(void *argument)
+{
+    UNUSED_VARIABLE(argument);
+
+#ifdef TEST_FRAMEWORK_S
+    /* FIXME: The non-secure audit log test currently relies on the fact that
+     * the audit log secure test is run first. However the Non-secure tests
+     * represent simpler and more common test cases which would make more sense
+     * to be run first. Therefore if this dependency is removed the execution
+     * order of these test classes should be reversed. */
+    tfm_secure_client_run_tests();
+#endif
+#ifdef TEST_FRAMEWORK_NS
+    tfm_non_secure_client_run_tests();
+#endif
+    /* End of test */
+    for (;;) {
+    }
+}
+#endif /* TEST_FRAMEWORK_NS OR TEST_FRAMEWORK_S */
diff --git a/app/tfm_integ_test.h b/app/tfm_integ_test.h
new file mode 100644
index 0000000..778f2ae
--- /dev/null
+++ b/app/tfm_integ_test.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stdio.h>
+#include "cmsis_compiler.h"
+
+#ifndef __TFM_INTEG_TEST_H__
+#define __TFM_INTEG_TEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Avoids the semihosting issue */
+#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+__asm("  .global __ARM_use_no_argv\n");
+#endif
+
+/**
+ * \brief Simple macro to mark UNUSED variables
+ *
+ */
+#define UNUSED_VARIABLE(X) ((void)(X))
+
+#ifdef TEST_FRAMEWORK_NS
+/**
+ * \brief Main test application for the RTX-TFM core
+ *        integration tests
+ *
+ */
+void test_app(void *argument);
+#endif /* TEST_FRAMEWORK_NS */
+
+/**
+ * \brief Execute the interactive test cases (button push)
+ *
+ */
+void execute_ns_interactive_tests(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_INTEG_TEST_H__ */