Test: Abstract SFN backend tests

This patch abstracts the SFN backend test for adding Secure
tests later.

Change-Id: I8816cfc913bd5fb8f5ff3d15315bd3ff90b6e9a5
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
diff --git a/test/secure_fw/suites/spm/sfn/CMakeLists.txt b/test/secure_fw/suites/spm/sfn/CMakeLists.txt
index fc80377..b5acfc1 100644
--- a/test/secure_fw/suites/spm/sfn/CMakeLists.txt
+++ b/test/secure_fw/suites/spm/sfn/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2021, Arm Limited. All rights reserved.
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -15,6 +15,7 @@
     target_sources(tfm_test_suite_sfn_ns
         PRIVATE
             non_secure/sfn_backend_ns_testsuite.c
+            sfn_backend_tests.c
             ${CMAKE_CURRENT_SOURCE_DIR}/../common/suites/client_api_tests.c
             $<$<BOOL:${PSA_FRAMEWORK_HAS_MM_IOVEC}>:
                 ${CMAKE_CURRENT_SOURCE_DIR}/../common/suites/mmiovec_test.c>
diff --git a/test/secure_fw/suites/spm/sfn/non_secure/sfn_backend_ns_testsuite.c b/test/secure_fw/suites/spm/sfn/non_secure/sfn_backend_ns_testsuite.c
index fd499ae..242c601 100644
--- a/test/secure_fw/suites/spm/sfn/non_secure/sfn_backend_ns_testsuite.c
+++ b/test/secure_fw/suites/spm/sfn/non_secure/sfn_backend_ns_testsuite.c
@@ -5,30 +5,14 @@
  *
  */
 
-#include <stdio.h>
-#include <string.h>
+#include <stdint.h>
+
 #include "sfn_ns_tests.h"
-#include "psa/client.h"
+#include "../sfn_backend_tests.h"
+
 #include "psa/framework_feature.h"
-#include "test_framework_helpers.h"
-#include "psa_manifest/sid.h"
-#include "client_api_tests.h"
-#if PSA_FRAMEWORK_HAS_MM_IOVEC
-#include "mmiovec_test.h"
-#endif
 
-/* List of tests */
-static void tfm_sfn_test_1001(struct test_result_t *ret);
-static void tfm_sfn_test_1002(struct test_result_t *ret);
-static void tfm_sfn_test_1003(struct test_result_t *ret);
-static void tfm_sfn_test_1004(struct test_result_t *ret);
-#if PSA_FRAMEWORK_HAS_MM_IOVEC
-static void tfm_sfn_test_1005(struct test_result_t *ret);
-static void tfm_sfn_test_1006(struct test_result_t *ret);
-static void tfm_sfn_test_1007(struct test_result_t *ret);
-#endif
-
-static struct test_t sfn_veneers_tests[] = {
+static struct test_t sfn_backend_ns_tests[] = {
     {&tfm_sfn_test_1001, "TFM_NS_SFN_TEST_1001",
      "Get PSA framework version"},
     {&tfm_sfn_test_1002, "TFM_NS_SFN_TEST_1002",
@@ -51,94 +35,8 @@
 {
     uint32_t list_size;
 
-    list_size = (sizeof(sfn_veneers_tests) / sizeof(sfn_veneers_tests[0]));
+    list_size = (sizeof(sfn_backend_ns_tests) / sizeof(sfn_backend_ns_tests[0]));
 
-    set_testsuite("SFN non-secure interface test (TFM_NS_SFN_TEST_1XXX)",
-                  sfn_veneers_tests, list_size, p_test_suite);
+    set_testsuite("SFN Backend NS test (TFM_NS_SFN_TEST_1XXX)",
+                  sfn_backend_ns_tests, list_size, p_test_suite);
 }
-
-/**
- * \brief Retrieve the version of the PSA Framework API.
- */
-static void tfm_sfn_test_1001(struct test_result_t *ret)
-{
-    psa_framework_version_test(ret);
-}
-
-/**
- * \brief Retrieve the version of an RoT Service.
- */
-static void tfm_sfn_test_1002(struct test_result_t *ret)
-{
-    psa_version_test(SFN_TEST_STATELESS_SID, ret);
-}
-
-/**
- * \brief Request a connection-based RoT Service
- */
-static void tfm_sfn_test_1003(struct test_result_t *ret)
-{
-    psa_handle_t handle;
-
-    handle = psa_connect(SFN_TEST_CONNECTION_BASED_SID,
-                         SFN_TEST_CONNECTION_BASED_VERSION);
-    if (!PSA_HANDLE_IS_VALID(handle)) {
-        TEST_FAIL("Connecting to a connection-based service fails.\r\n");
-        return;
-    }
-
-    request_rot_service_test(handle, ret);
-
-    psa_close(handle);
-}
-
-/**
- * \brief Request a stateless RoT Service
- */
-static void tfm_sfn_test_1004(struct test_result_t *ret)
-{
-    psa_handle_t handle;
-
-    /* Connecting to a stateless service should fail. */
-    handle = psa_connect(SFN_TEST_STATELESS_SID, SFN_TEST_STATELESS_VERSION);
-    if (PSA_HANDLE_IS_VALID(handle)) {
-        TEST_FAIL("Connecting to a stateless service should not succeed.\r\n");
-        return;
-    }
-
-    request_rot_service_test(SFN_TEST_STATELESS_HANDLE, ret);
-}
-
-#if PSA_FRAMEWORK_HAS_MM_IOVEC
-/**
- * \brief Mapping input vectors and unmapping them.
- *
- * \note Test psa_map_invec() and psa_unmap_invec() functionality.
- */
-static void tfm_sfn_test_1005(struct test_result_t *ret)
-{
-    invec_map_unmap_test(ret, SFN_TEST_STATELESS_HANDLE);
-}
-
-/**
- * \brief Mapping output vectors and unmapping them.
- *
- * \note Test psa_map_outvec() and psa_unmap_outvec() functionality.
- */
-static void tfm_sfn_test_1006(struct test_result_t *ret)
-{
-    outvec_map_unmap_test(ret, SFN_TEST_STATELESS_HANDLE);
-}
-
-/**
- * \brief Mapping output vectors and not unmapping them.
- *
- * \note RoT services map outvecs and does not unmap outvecs, the service caller
- *       should get a zero out length.
- */
-static void tfm_sfn_test_1007(struct test_result_t *ret)
-{
-    outvec_map_only_test(ret, SFN_TEST_STATELESS_HANDLE);
-}
-
-#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
diff --git a/test/secure_fw/suites/spm/sfn/sfn_backend_tests.c b/test/secure_fw/suites/spm/sfn/sfn_backend_tests.c
new file mode 100644
index 0000000..fc316b5
--- /dev/null
+++ b/test/secure_fw/suites/spm/sfn/sfn_backend_tests.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "sfn_backend_tests.h"
+#include "client_api_tests.h"
+#if PSA_FRAMEWORK_HAS_MM_IOVEC
+#include "mmiovec_test.h"
+#endif
+
+#include "psa/client.h"
+#include "psa/framework_feature.h"
+#include "psa_manifest/sid.h"
+
+void tfm_sfn_test_1001(struct test_result_t *ret)
+{
+    psa_framework_version_test(ret);
+}
+
+void tfm_sfn_test_1002(struct test_result_t *ret)
+{
+    psa_version_test(SFN_TEST_STATELESS_SID, ret);
+}
+
+void tfm_sfn_test_1003(struct test_result_t *ret)
+{
+    psa_handle_t handle;
+
+    handle = psa_connect(SFN_TEST_CONNECTION_BASED_SID,
+                         SFN_TEST_CONNECTION_BASED_VERSION);
+    if (!PSA_HANDLE_IS_VALID(handle)) {
+        TEST_FAIL("Connecting to a connection-based service fails.\r\n");
+        return;
+    }
+
+    request_rot_service_test(handle, ret);
+
+    psa_close(handle);
+}
+
+void tfm_sfn_test_1004(struct test_result_t *ret)
+{
+#if DOMAIN_NS == 1
+    psa_handle_t handle;
+
+    /*
+     * Connecting to a stateless service should return PROGRAMMER ERROR to NS
+     * client and panic for Secure clients.
+     * So this test code is only enabled for NS test.
+     */
+    handle = psa_connect(SFN_TEST_STATELESS_SID, SFN_TEST_STATELESS_VERSION);
+    if (PSA_HANDLE_IS_VALID(handle)) {
+        TEST_FAIL("Connecting to a stateless service should not succeed.\r\n");
+        return;
+    }
+#endif
+
+    request_rot_service_test(SFN_TEST_STATELESS_HANDLE, ret);
+}
+
+#if PSA_FRAMEWORK_HAS_MM_IOVEC
+void tfm_sfn_test_1005(struct test_result_t *ret)
+{
+    invec_map_unmap_test(ret, SFN_TEST_STATELESS_HANDLE);
+}
+
+void tfm_sfn_test_1006(struct test_result_t *ret)
+{
+    outvec_map_unmap_test(ret, SFN_TEST_STATELESS_HANDLE);
+}
+
+void tfm_sfn_test_1007(struct test_result_t *ret)
+{
+    outvec_map_only_test(ret, SFN_TEST_STATELESS_HANDLE);
+}
+
+#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
diff --git a/test/secure_fw/suites/spm/sfn/sfn_backend_tests.h b/test/secure_fw/suites/spm/sfn/sfn_backend_tests.h
new file mode 100644
index 0000000..5af344a
--- /dev/null
+++ b/test/secure_fw/suites/spm/sfn/sfn_backend_tests.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "psa/framework_feature.h"
+#include "test_framework.h"
+
+/**
+ * \brief Retrieve the version of the PSA Framework API.
+ */
+void tfm_sfn_test_1001(struct test_result_t *ret);
+
+/**
+ * \brief Retrieve the version of an RoT Service.
+ */
+void tfm_sfn_test_1002(struct test_result_t *ret);
+
+/**
+ * \brief Request a connection-based RoT Service
+ */
+void tfm_sfn_test_1003(struct test_result_t *ret);
+
+/**
+ * \brief Request a stateless RoT Service
+ */
+void tfm_sfn_test_1004(struct test_result_t *ret);
+
+#if PSA_FRAMEWORK_HAS_MM_IOVEC
+/**
+ * \brief Mapping input vectors and unmapping them.
+ *
+ * \note Test psa_map_invec() and psa_unmap_invec() functionality.
+ */
+void tfm_sfn_test_1005(struct test_result_t *ret);
+
+/**
+ * \brief Mapping output vectors and unmapping them.
+ *
+ * \note Test psa_map_outvec() and psa_unmap_outvec() functionality.
+ */
+void tfm_sfn_test_1006(struct test_result_t *ret);
+
+/**
+ * \brief Mapping output vectors and not unmapping them.
+ *
+ * \note RoT services map outvecs and does not unmap outvecs, the service caller
+ *       should get a zero out length.
+ */
+void tfm_sfn_test_1007(struct test_result_t *ret);
+
+#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */