tests_reg: Add test for refused connection in IPC-NS

Add tfm_ipc_test_1018 test case to check the correct PSA_ERROR
returned value from a RoT which refuses a connection.

Signed-off-by: Nicola Mazzucato <nicola.mazzucato@arm.com>
Change-Id: If38dfb05aaa4642abe36a8e14f1b4009779ff1da
(cherry picked from commit 98d7c3cb640cd2e01570c896a4edcf5cf4dbc3c9)
diff --git a/tests_reg/test/secure_fw/suites/spm/ipc/non_secure/ipc_ns_interface_testsuite.c b/tests_reg/test/secure_fw/suites/spm/ipc/non_secure/ipc_ns_interface_testsuite.c
index 47a104f..ab96a26 100644
--- a/tests_reg/test/secure_fw/suites/spm/ipc/non_secure/ipc_ns_interface_testsuite.c
+++ b/tests_reg/test/secure_fw/suites/spm/ipc/non_secure/ipc_ns_interface_testsuite.c
@@ -36,6 +36,8 @@
 
 static void tfm_ipc_test_1016(struct test_result_t *ret);
 
+static void tfm_ipc_test_1018(struct test_result_t *ret);
+
 static struct test_t ipc_veneers_tests[] = {
     {&tfm_ipc_test_1001, "TFM_NS_IPC_TEST_1001",
      "Get PSA framework version"},
@@ -60,6 +62,8 @@
 
     {&tfm_ipc_test_1016, "TFM_NS_IPC_TEST_1016",
      "Testing Client-Id Translation"},
+    {&tfm_ipc_test_1018, "TFM_NS_IPC_TEST_1018",
+     "Testing Refused connection"},
 };
 
 void register_testsuite_ns_ipc_interface(struct test_suite_t *p_test_suite)
@@ -209,6 +213,21 @@
     psa_close(handle);
 }
 
+static void tfm_ipc_test_1018(struct test_result_t *ret)
+{
+    psa_handle_t handle;
+
+    handle = psa_connect(IPC_SERVICE_TEST_CONNECTION_REFUSED_SID,
+                         IPC_SERVICE_TEST_CONNECTION_REFUSED_VERSION);
+    if (handle != PSA_ERROR_CONNECTION_REFUSED) {
+        TEST_FAIL("The RoT Service was expected to refuse the connection!\r\n");
+        ret->val = TEST_FAILED;
+        return;
+    }
+
+    ret->val = TEST_PASSED;
+}
+
 #if PSA_FRAMEWORK_HAS_MM_IOVEC
 
 /**
diff --git a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
index c23aeda..6babde5 100644
--- a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
+++ b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
@@ -294,6 +294,27 @@
     psa_reply(msg.handle, status);
 }
 
+static void ipc_service_connection_refused(void)
+{
+    psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
+    psa_msg_t msg;
+
+    status = psa_get(IPC_SERVICE_TEST_CONNECTION_REFUSED_SIGNAL, &msg);
+    if (status != PSA_SUCCESS) {
+        psa_panic();
+    }
+
+    switch (msg.type) {
+    case PSA_IPC_CONNECT:
+        break;
+    default:
+        tfm_abort();
+        break;
+    }
+
+    psa_reply(msg.handle, PSA_ERROR_CONNECTION_REFUSED);
+}
+
 /* Test thread */
 void ipc_service_test_main(void *param)
 {
@@ -325,6 +346,8 @@
 #endif
         } else if (signals & IPC_SERVICE_TEST_CLIENT_ID_TRANSLATE_SIGNAL) {
             ipc_service_client_id_translate();
+        } else if (signals & IPC_SERVICE_TEST_CONNECTION_REFUSED_SIGNAL) {
+            ipc_service_connection_refused();
         } else {
             /* Should not come here */
             tfm_abort();
diff --git a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.yaml b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.yaml
index e512d15..a22b918 100644
--- a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.yaml
+++ b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.yaml
@@ -81,5 +81,13 @@
       "version": 1,
       "version_policy": "STRICT"
     },
+    {
+      "name": "IPC_SERVICE_TEST_CONNECTION_REFUSED",
+      "sid": "0x0000F089",
+      "non_secure_clients": true,
+      "connection_based": true,
+      "version": 1,
+      "version_policy": "STRICT"
+    },
   ]
 }