tests_reg: Add tests for mm-iovecs with stateful services

The tests enable connection-based testing of MMIO vectors

Signed-off-by: Umair Khan <umair.khan@arm.com>
Change-Id: I063604240f4dcf1fdc1b79d73a257cbac820e862
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 b41d4c5..81a038a 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
@@ -32,6 +32,12 @@
 static void tfm_ipc_test_1014(struct test_result_t *ret);
 
 static void tfm_ipc_test_1015(struct test_result_t *ret);
+
+static void tfm_ipc_test_1019(struct test_result_t *ret);
+
+static void tfm_ipc_test_1020(struct test_result_t *ret);
+
+static void tfm_ipc_test_1021(struct test_result_t *ret);
 #endif
 
 static void tfm_ipc_test_1016(struct test_result_t *ret);
@@ -60,6 +66,12 @@
      "Mapping output vectors and unmapping them"},
     {&tfm_ipc_test_1015, "TFM_NS_IPC_TEST_1015",
      "Mapping output vectors and not unmapping them"},
+    {&tfm_ipc_test_1019, "TFM_NS_IPC_TEST_1019",
+     "Testing connection based mapping and unmapping of input vectors"},
+    {&tfm_ipc_test_1020, "TFM_NS_IPC_TEST_1020",
+     "Testing connection based mapping and unmapping of output vectors"},
+    {&tfm_ipc_test_1021, "TFM_NS_IPC_TEST_1021",
+     "Testing connection based mapping of output vectors without unmapping them"},
 #endif
 
     {&tfm_ipc_test_1016, "TFM_NS_IPC_TEST_1016",
@@ -357,4 +369,70 @@
     outvec_map_only_test(ret, IPC_SERVICE_TEST_MMIOVEC_HANDLE);
 }
 
+/**
+ * \brief Connection-based test for mapping input vectors and unmapping them.
+ *
+ * \note Test psa_map_invec() and psa_unmap_invec() functionality.
+ */
+static void tfm_ipc_test_1019(struct test_result_t *ret)
+{
+    psa_handle_t handle;
+    ret->val = TEST_FAILED;
+
+    handle = psa_connect(IPC_SERVICE_TEST_MMIOVEC_STATEFUL_SID,
+                         IPC_SERVICE_TEST_MMIOVEC_STATEFUL_VERSION);
+
+    if (handle > 0) {
+        invec_map_unmap_test(ret, handle);
+        psa_close(handle);
+        ret->val = TEST_PASSED;
+    } else {
+        TEST_FAIL("Connection to the service failed!\r\n");
+    }
+}
+
+/**
+ * \brief Connection-based test for mapping output vectors and unmapping them.
+ *
+ * \note Test psa_map_outvec() and psa_unmap_outvec() functionality.
+ */
+static void tfm_ipc_test_1020(struct test_result_t *ret)
+{
+    psa_handle_t handle;
+    ret->val = TEST_FAILED;
+
+    handle = psa_connect(IPC_SERVICE_TEST_MMIOVEC_STATEFUL_SID,
+                         IPC_SERVICE_TEST_MMIOVEC_STATEFUL_VERSION);
+
+    if (handle > 0) {
+        outvec_map_unmap_test(ret, handle);
+        psa_close(handle);
+        ret->val = TEST_PASSED;
+    } else {
+        TEST_FAIL("Connection to the service failed!\r\n");
+    }
+}
+
+/**
+ * \brief Connection-based test for mapping of output vectors without unmapping them.
+ *
+ * \note RoT services map outvecs and does not unmap outvecs, the service caller
+ *       should get a zero out length.
+ */
+static void tfm_ipc_test_1021(struct test_result_t *ret)
+{
+    psa_handle_t handle;
+    ret->val = TEST_FAILED;
+
+    handle = psa_connect(IPC_SERVICE_TEST_MMIOVEC_STATEFUL_SID,
+                         IPC_SERVICE_TEST_MMIOVEC_STATEFUL_VERSION);
+
+    if (handle > 0) {
+        outvec_map_only_test(ret, handle);
+        psa_close(handle);
+        ret->val = TEST_PASSED;
+    } else {
+        TEST_FAIL("Connection to the service failed!\r\n");
+    }
+}
 #endif
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 aaef76d..48ac612 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
@@ -235,19 +235,27 @@
 
 #if PSA_FRAMEWORK_HAS_MM_IOVEC
 
-static void ipc_service_mmiovec_test_handle(void)
+static void ipc_service_mmiovec_test_handle(uint32_t signals)
 {
-    psa_status_t status;
+    psa_status_t status = TFM_MMIOVEC_TEST_ERROR;
     psa_msg_t msg;
 
     /* Retrieve the message corresponding to the MMIO test service signal */
-    status = psa_get(IPC_SERVICE_TEST_MMIOVEC_SIGNAL, &msg);
+    status = psa_get(signals, &msg);
     if (status != PSA_SUCCESS) {
         psa_panic();
     }
 
     /* Decode the message */
     switch (msg.type) {
+    case PSA_IPC_CONNECT:
+    case PSA_IPC_DISCONNECT:
+
+        /* Only entertain cases when the call is from a connection-based test context */
+        if (signal & IPC_SERVICE_TEST_MMIOVEC_STATEFUL_SIGNAL) {
+            status = PSA_SUCCESS;
+        }
+        break;
     case INVEC_MAP_AND_UNMAP:
         status = test_service_mmiovec_invec(&msg);
         break;
@@ -417,8 +425,9 @@
         } else if (signals & IPC_SERVICE_TEST_STATELESS_ROT_SIGNAL) {
             ipc_service_stateless_rot();
 #if PSA_FRAMEWORK_HAS_MM_IOVEC
-        } else if (signals & IPC_SERVICE_TEST_MMIOVEC_SIGNAL) {
-            ipc_service_mmiovec_test_handle();
+        } else if ((signals & IPC_SERVICE_TEST_MMIOVEC_SIGNAL) ||
+                   (signals & IPC_SERVICE_TEST_MMIOVEC_STATEFUL_SIGNAL)) {
+            ipc_service_mmiovec_test_handle(signals);
 #endif
         } else if (signals & IPC_SERVICE_TEST_CLIENT_ID_TRANSLATE_SIGNAL) {
             ipc_service_client_id_translate();
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 0b234bb..5042c01 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
@@ -97,5 +97,14 @@
       "version": 1,
       "version_policy": "STRICT"
     },
+    {
+      "name": "IPC_SERVICE_TEST_MMIOVEC_STATEFUL",
+      "sid": "0x0000F090",
+      "non_secure_clients": true,
+      "connection_based": true,
+      "mm_iovec": "enable",
+      "version": 1,
+      "version_policy": "STRICT"
+    },
   ]
 }