Core: Support regression test for IPC model

Regression tests contain library model test cases, which is not
working while TF-M runs under IPC model. Fix this problem by:
1.Make secure client service IPC compatible
2.Disable library model test cases in IPC model
3.Comment non-secure core test cases in IPC level 2 model

Change-Id: Ic7c3a336b4efe888625f904ef44cbbadc3a8d987
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/test/framework/non_secure_suites.c b/test/framework/non_secure_suites.c
index 7c442c7..1554650 100644
--- a/test/framework/non_secure_suites.c
+++ b/test/framework/non_secure_suites.c
@@ -41,6 +41,11 @@
 
     {&register_testsuite_ns_psa_ps_interface, 0, 0, 0},
 
+#ifndef TFM_PSA_API
+    /*
+     * FixMe: skip below test cases temporary since target service is not
+     * IPC compatible yet.
+     */
     /* Non-secure Audit Logging test cases */
     {&register_testsuite_ns_audit_interface, 0, 0, 0},
 
@@ -52,6 +57,7 @@
 
     /* Non-secure QCBOR library test cases */
     {&register_testsuite_ns_qcbor, 0, 0, 0},
+#endif
 
 #ifdef TFM_PARTITION_TEST_CORE
     /* Non-secure invert test cases */
@@ -62,9 +68,11 @@
 #endif /* TFM_LVL == 3 */
 
 #ifdef CORE_TEST_POSITIVE
+#if !((TFM_LVL == 2) && defined(TFM_PSA_API))
     /* Non-secure core test cases */
     {&register_testsuite_ns_core_positive, 0, 0, 0},
 #endif
+#endif
 
 #ifdef CORE_TEST_INTERACTIVE
     /* Non-secure interactive test cases */
diff --git a/test/framework/secure_suites.c b/test/framework/secure_suites.c
index 0b4c918..b7426ec 100644
--- a/test/framework/secure_suites.c
+++ b/test/framework/secure_suites.c
@@ -35,6 +35,11 @@
     {&register_testsuite_s_rollback_protection, 0, 0, 0},
 #endif
 
+#ifndef TFM_PSA_API
+    /*
+     * FixMe: since the following partitions haven't implement the IPC model,
+     * they will block the process. Skip them in IPC model.
+     */
     /* Secure Audit Logging test cases */
     {&register_testsuite_s_audit_interface, 0, 0, 0},
 
@@ -43,6 +48,7 @@
 
     /* Secure initial attestation service test cases */
     {&register_testsuite_s_attestation_interface, 0, 0, 0},
+#endif
 
 #ifdef TFM_PARTITION_TEST_CORE
     /* Secure invert test cases */
diff --git a/test/test_services/tfm_secure_client_service/manifest.yaml b/test/test_services/tfm_secure_client_service/manifest.yaml
index 1e1e95a..4f80d07 100644
--- a/test/test_services/tfm_secure_client_service/manifest.yaml
+++ b/test/test_services/tfm_secure_client_service/manifest.yaml
@@ -13,6 +13,7 @@
   "entry_point": "tfm_secure_client_service_init",
   "stack_size": "0x1000",
   "heap_size": "0x0400",
+  "tfm_partition_ipc": true,
   "mmio_regions": [
     {
       "name": "TFM_PERIPHERAL_STD_UART",
@@ -29,6 +30,16 @@
       "minor_policy": "strict"
     },
   ],
+  "services": [
+    {
+      "name": "TFM_SECURE_CLIENT_SFN_RUN_TESTS_SID",
+      "sid": "0x0000F000",
+      "signal": "TFM_SECURE_CLIENT_SFN_RUN_TESTS_SIG",
+      "non_secure_clients": "true",
+      "minor_version": 1,
+      "minor_policy": "STRICT"
+    }
+  ],
   "source_files": [
     "tfm_secure_client_service.c"
   ],
diff --git a/test/test_services/tfm_secure_client_service/tfm_sec_client_ser_sig.h b/test/test_services/tfm_secure_client_service/tfm_sec_client_ser_sig.h
new file mode 100644
index 0000000..54fa58f
--- /dev/null
+++ b/test/test_services/tfm_secure_client_service/tfm_sec_client_ser_sig.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_SEC_CLIENT_SER_SIG_H__
+#define __TFM_SEC_CLIENT_SER_SIG_H__
+
+/* FixMe: hardcode it for the tool cannot support now */
+#ifdef TFM_PSA_API
+#define TFM_SECURE_CLIENT_SFN_RUN_TESTS_SIG  (1 << (0 + 4))
+#endif /* TFM_PSA_API */
+
+#endif /* __TFM_SEC_CLIENT_SER_SIG_H__ */
diff --git a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
index 280e1af..313ca04 100644
--- a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
+++ b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
@@ -7,6 +7,11 @@
 
 #include "tfm_secure_client_service.h"
 #include "test/framework/test_framework_integ_test.h"
+#ifdef TFM_PSA_API
+#include "psa_client.h"
+#include "psa_service.h"
+#include "tfm_sec_client_ser_sig.h"
+#endif
 
 /**
  * \brief Service initialisation function. No special initialisation is
@@ -16,6 +21,28 @@
  */
 int32_t tfm_secure_client_service_init(void)
 {
+#ifdef TFM_PSA_API
+    psa_msg_t msg;
+
+    while (1) {
+        psa_wait(TFM_SECURE_CLIENT_SFN_RUN_TESTS_SIG, PSA_BLOCK);
+        psa_get(TFM_SECURE_CLIENT_SFN_RUN_TESTS_SIG, &msg);
+        switch (msg.type) {
+        case PSA_IPC_CONNECT:
+            psa_reply(msg.handle, PSA_SUCCESS);
+            break;
+        case PSA_IPC_CALL:
+            psa_reply(msg.handle, tfm_secure_client_service_sfn_run_tests());
+            break;
+        case PSA_IPC_DISCONNECT:
+            psa_reply(msg.handle, PSA_SUCCESS);
+            break;
+        default:
+            /* cannot get here? [broken SPM]. TODO*/
+            break;
+        }
+    }
+#endif
     return 0;
 }
 
diff --git a/test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.c b/test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.c
index 2b4977f..79e2840 100644
--- a/test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.c
+++ b/test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -8,9 +8,39 @@
 #include "tfm_secure_client_service_api.h"
 #include "tfm_secure_client_service_veneers.h"
 
+#ifdef TFM_PSA_API
+#include "psa_client.h"
+#include "tfm_api.h"
+
+/*
+ * Defines for SID and minor version number. These SIDs should align with the
+ * value in service manifest file.
+ */
+#define TFM_SECURE_CLIENT_SFN_RUN_TESTS_SID     (0x0000F000)
+#define TFM_SECURE_CLIENT_SFN_RUN_TESTS_MIN_VER (0x00000001)
+#endif
 
 int32_t tfm_secure_client_run_tests(void)
 {
+#ifdef TFM_PSA_API
+    psa_handle_t handle;
+    psa_status_t status;
+
+    handle = psa_connect(TFM_SECURE_CLIENT_SFN_RUN_TESTS_SID,
+                         TFM_SECURE_CLIENT_SFN_RUN_TESTS_MIN_VER);
+    if (handle <= 0) {
+        return TFM_ERROR_GENERIC;
+    }
+
+    status = psa_call(handle, NULL, 0, NULL, 0);
+    psa_close(handle);
+
+    if (status != PSA_SUCCESS) {
+        return TFM_ERROR_GENERIC;
+    }
+#else
     tfm_secure_client_service_veneer_run_tests();
+#endif
+
     return 0;
 }