App: Combine the test threads together

This patch combines the test threads together to simplify
the codes and always build a test thread to output the EOT.

This also makes the output of EOT apply to non-test.

Change-Id: I4143dd9d59d663b432c599d36cddd26747d910af
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 144fc4c..76e1a7e 100755
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -268,31 +268,33 @@
 
 ############################# Test integration #################################
 
-add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
+add_library(tfm_test_app STATIC EXCLUDE_FROM_ALL)
 
-target_sources(tfm_ns_integration_test
+target_sources(tfm_test_app
     PRIVATE
-        tfm_integ_test.c
+        test_app.c
 )
 
-target_include_directories(tfm_ns_integration_test
+target_include_directories(tfm_test_app
     PUBLIC
         .
 )
 
-target_link_libraries(tfm_ns_integration_test
+target_link_libraries(tfm_test_app
     PRIVATE
         $<$<BOOL:${TEST_FRAMEWORK_NS}>:tfm_ns_tests>
-        $<$<BOOL:${TEST_FRAMEWORK_S}>:tfm_ns_interface>
-        $<$<BOOL:${TEST_FRAMEWORK_S}>:tfm_api_ns>
+        $<$<BOOL:${TEST_PSA_API}>:val_nspe>
+        $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
+        $<$<BOOL:${TEST_PSA_API}>:test_combine>
         tfm_log
 )
 
-target_compile_definitions(tfm_ns_integration_test
-    PUBLIC
+target_compile_definitions(tfm_test_app
+    PRIVATE
         $<$<BOOL:${TEST_FRAMEWORK_NS}>:TEST_FRAMEWORK_NS>
         $<$<BOOL:${TEST_FRAMEWORK_S}>:TEST_FRAMEWORK_S>
         $<$<BOOL:${TFM_LIB_MODEL}>:TFM_LIB_MODEL>
+        $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
 )
 
 ############################# TFM NS app #######################################
@@ -302,26 +304,17 @@
 target_sources(tfm_ns
     PRIVATE
         main_ns.c
-        $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
 )
 
 target_link_libraries(tfm_ns
     PRIVATE
         platform_ns
         CMSIS_5_tfm_ns
-        $<$<OR:$<BOOL:${TEST_FRAMEWORK_NS}>,$<BOOL:${TEST_FRAMEWORK_S}>>:tfm_ns_integration_test>
-        $<$<BOOL:${TEST_PSA_API}>:val_nspe>
-        $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
-        $<$<BOOL:${TEST_PSA_API}>:test_combine>
+        tfm_test_app
         tfm_api_ns
         tfm_log
 )
 
-target_compile_definitions(tfm_ns
-    PUBLIC
-    $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
-)
-
 set_target_properties(tfm_ns PROPERTIES
     SUFFIX ".axf"
     RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
diff --git a/app/main_ns.c b/app/main_ns.c
index e9ab48d..8189142 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -10,12 +10,7 @@
 #include "cmsis_compiler.h"
 #include "tfm_ns_interface.h"
 #include "tfm_nsid_manager.h"
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
-#include "tfm_integ_test.h"
-#endif
-#ifdef PSA_API_TEST_NS
-#include "psa_api_test.h"
-#endif
+#include "test_app.h"
 #include "tfm_plat_ns.h"
 #include "driver/Driver_USART.h"
 #include "device_cfg.h"
@@ -52,14 +47,16 @@
 /**
  * \brief List of RTOS thread attributes
  */
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
- || defined(PSA_API_TEST_NS)
 static const osThreadAttr_t thread_attr = {
     .name = "test_thread",
     .stack_size = 4096U,
     .tz_module = ((TZ_ModuleId_t)TFM_DEFAULT_NSID)
 };
-#endif
+/**
+ * \brief Static globals to hold RTOS related quantities,
+ *        main thread
+ */
+static osThreadFunc_t thread_func = test_app;
 
 #ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD
 static osThreadFunc_t mailbox_thread_func = tfm_ns_mailbox_thread_runner;
@@ -69,15 +66,6 @@
 };
 #endif
 
-/**
- * \brief Static globals to hold RTOS related quantities,
- *        main thread
- */
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
- || 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;
 
@@ -178,16 +166,7 @@
     (void) osThreadNew(mailbox_thread_func, NULL, &mailbox_thread_attr);
 #endif
 
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
-    thread_func = test_app;
-#elif defined(PSA_API_TEST_NS)
-    thread_func = psa_api_test;
-#endif
-
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
- || defined(PSA_API_TEST_NS)
     (void) osThreadNew(thread_func, NULL, &thread_attr);
-#endif
 
     LOG_MSG("Non-Secure system starting...\r\n");
     (void) osKernelStart();
diff --git a/app/psa_api_test.c b/app/psa_api_test.c
deleted file mode 100644
index 8f9624b..0000000
--- a/app/psa_api_test.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "psa_api_test.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);
-
-    val_entry();
-
-    for (;;) {
-    }
-}
diff --git a/app/psa_api_test.h b/app/psa_api_test.h
deleted file mode 100644
index 5423b15..0000000
--- a/app/psa_api_test.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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/test_app.c
similarity index 79%
rename from app/tfm_integ_test.c
rename to app/test_app.c
index 0430837..93cbd54 100644
--- a/app/tfm_integ_test.c
+++ b/app/test_app.c
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-#include "tfm_integ_test.h"
+#include "test_app.h"
 #include "tfm_log.h"
 
 #ifdef TEST_FRAMEWORK_NS
@@ -18,7 +18,14 @@
 #include "tfm_secure_client_service_api.h"
 #endif
 
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
+#if PSA_API_TEST_NS
+/**
+ * \brief This symbol is the entry point provided by the PSA API compliance
+ *        test libraries
+ */
+extern void val_entry(void);
+#endif
+
 /**
  * \brief Services test thread
  *
@@ -36,13 +43,19 @@
      * 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
+
+#ifdef PSA_API_TEST_NS
+    val_entry();
+#endif
+
     /* Output EOT char for test environments like FVP. */
     LOG_MSG("\x04");
+
     /* End of test */
     for (;;) {
     }
 }
-#endif /* TEST_FRAMEWORK_NS OR TEST_FRAMEWORK_S */
diff --git a/app/test_app.h b/app/test_app.h
new file mode 100644
index 0000000..d60827c
--- /dev/null
+++ b/app/test_app.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_TEST_APP_H__
+#define __TFM_TEST_APP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Simple macro to mark UNUSED variables
+ *
+ */
+#define UNUSED_VARIABLE(X) ((void)(X))
+
+/**
+ * \brief Main test application for the RTX-TFM core
+ *        integration tests
+ *
+ */
+void test_app(void *argument);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_TEST_APP_H__ */
diff --git a/app/tfm_integ_test.h b/app/tfm_integ_test.h
deleted file mode 100644
index f793ced..0000000
--- a/app/tfm_integ_test.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __TFM_INTEG_TEST_H__
-#define __TFM_INTEG_TEST_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * \brief Simple macro to mark UNUSED variables
- *
- */
-#define UNUSED_VARIABLE(X) ((void)(X))
-
-#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
-/**
- * \brief Main test application for the RTX-TFM core
- *        integration tests
- *
- */
-void test_app(void *argument);
-#endif /* TEST_FRAMEWORK_NS || TEST_FRAMEWORK_S */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TFM_INTEG_TEST_H__ */
diff --git a/test/secure_fw/suites/core/CMakeLists.txt b/test/secure_fw/suites/core/CMakeLists.txt
index ffb73a7..cf5eec5 100644
--- a/test/secure_fw/suites/core/CMakeLists.txt
+++ b/test/secure_fw/suites/core/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -36,7 +36,6 @@
 target_link_libraries(tfm_test_suite_core_ns
     PRIVATE
         tfm_test_framework_ns
-        tfm_ns_integration_test
         CMSIS_5_tfm_ns
         tfm_partition_defs
         platform_ns