Add test for multiple SPs with the same UUID

Add a new test SP which is used to test when multiple SPs have
the same FF-A UUID. This change carries the following modifications to
the spm-test deployments:
  - introduce a new UUID which identifies the SP binary (like a file
    name)
  - ensure the binary UUID is used in output file names if set in the
    opteesp deployments
  - adds a new deployment to have two SPs with matching FF-A UUID
  - refactor tests to check if SPMC allows discovering SPs with matching
    FF-A UUID.

Change-Id: Icb82a67adf51cfdd2b20a21ecfe7ad2fa39c88a3
Signed-off-by: Jelle Sels <jelle.sels@arm.com>
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/components/service/spm_test/sp.c b/components/service/spm_test/sp.c
index 30ddea7..5bbc545 100644
--- a/components/service/spm_test/sp.c
+++ b/components/service/spm_test/sp.c
@@ -159,51 +159,73 @@
 	return false;
 }
 
+static bool ffa_partition_info_get_process(sp_result result, uint32_t count,
+					struct sp_partition_info *partitions)
+{
+	uint32_t i = 0;
+
+	if (result != SP_RESULT_OK) {
+		if (result == FFA_NOT_SUPPORTED) {
+			IMSG("ffa_partition_info_get(): not supported\n");
+			return false;
+		}
+		EMSG("ffa_partition_info_get(): unknown error %"PRId32"\n", result);
+		return false;
+	}
+	IMSG("ffa_partition_info_get(): count=%"PRIu32"\n", count);
+
+	for (i = 0; i < count; i++) {
+		IMSG("partition #%u: ID=%u, execution_count=%u  \
+		      direct request = %c, send direcy request = %c, \
+		      indirect request = %c\n",
+		      i, partitions[i].partition_id,
+		      partitions[i].execution_context_count,
+		      partitions[i].supports_direct_requests ? '1' : '0',
+		      partitions[i].can_send_direct_requests ? '1' : '0',
+		      partitions[i].supports_indirect_requests ? '1' : '0'
+		      );
+	}
+
+	IMSG("Testing ffa_rx_release()\n");
+
+	result = ffa_rx_release();
+	if (result == FFA_OK) {
+		IMSG("ffa_rx_release(): success\n");
+		return true;
+	} else if (result == FFA_NOT_SUPPORTED) {
+		IMSG("ffa_rx_release(): not supported\n");
+		return false;
+	}
+
+	EMSG("ffa_rx_release(): unknown error %"PRId32"\n", result);
+	return false;
+}
+
 static bool test_ffa_partition_info_get(void)
 {
-	sp_result result  = SP_RESULT_OK;
+	sp_result result = SP_RESULT_OK;
 	struct sp_partition_info partitions[10] = {0};
-	uint32_t i = 0;
 	uint32_t count = 10;
+	struct sp_uuid uuid = {.uuid = {0x23, 0xeb, 0x01, 0x00, 0xe3, 0x2a,
+					0x44, 0x97, 0x90, 0x52, 0x2f, 0x11,
+					0xe5, 0x84, 0xaf, 0xa6}};
 
 	IMSG("Testing ffa_partition_info_get(nil)\n");
 
 	result = sp_discovery_partition_info_get_all(partitions, &count);
-	if (result == SP_RESULT_OK) {
-
-		IMSG("ffa_partition_info_get(): count=%"PRIu32"\n", count);
-
-		for (i = 0; i < count; i++) {
-			IMSG("partition #%u: ID=%u, execution_count=%u  \
-			      direct request = %c, send direcy request = %c, \
-			      indirect request = %c\n",
-			      i, partitions[i].partition_id,
-			      partitions[i].execution_context_count,
-			      partitions[i].supports_direct_requests ? '1': '0',
-			      partitions[i].can_send_direct_requests ? '1': '0',
-			      partitions[i].supports_indirect_requests ? '1':
-			      '0'
-			      );
-		}
-
-		IMSG("Testing ffa_rx_release()\n");
-
-		result = ffa_rx_release();
-		if (result == FFA_OK) {
-			IMSG("ffa_rx_release(): success\n");
-			return true;
-		} else if (result == FFA_NOT_SUPPORTED) {
-			IMSG("ffa_rx_release(): not supported\n");
-			return false;
-		}
-		EMSG("ffa_rx_release(): unknown error %"PRId32"\n", result);
+	if (!ffa_partition_info_get_process(result, count, partitions))
 		return false;
-	} else if (result == FFA_NOT_SUPPORTED) {
-		IMSG("ffa_partition_info_get(): not supported\n");
+	result = sp_discovery_partition_info_get(&uuid,
+		   partitions,
+		   &count);
+
+	if (!ffa_partition_info_get_process(result, count, partitions))
+		return false;
+	if (count < 2) {
+		EMSG("ffa_partition_info_get(): Returned not enough SPs count=%"PRIu32"\n", count);
 		return false;
 	}
-	EMSG("ffa_partition_info_get(): unknown error %"PRId32"\n", result);
-	return false;
+	return true;
 }
 
 static bool test_ffa_rxtx_unmap()
@@ -757,6 +779,7 @@
 
 	test_ffa_rxtx_map();
 	/* End of boot phase */
+	test_ffa_partition_info_get();
 	ffa_msg_wait(&msg);
 
 	while (1) {
diff --git a/components/service/spm_test/spm_test.cmake b/components/service/spm_test/spm_test.cmake
index 666429b..e77dbf9 100644
--- a/components/service/spm_test/spm_test.cmake
+++ b/components/service/spm_test/spm_test.cmake
@@ -77,6 +77,7 @@
 include(${TS_ROOT}/tools/cmake/common/ExportSp.cmake)
 export_sp(
 	SP_UUID_CANON ${SP_UUID_CANON}
+	SP_BIN_UUID_CANON ${SP_BIN_UUID_CANON}
 	SP_UUID_LE ${SP_UUID_LE}
 	SP_NAME "spm-test${SP_NUMBER}"
 	MK_IN ${TS_ROOT}/environments/opteesp/sp.mk.in
diff --git a/deployments/spm-test1/opteesp/CMakeLists.txt b/deployments/spm-test1/opteesp/CMakeLists.txt
index 7a2d614..b21bcf9 100644
--- a/deployments/spm-test1/opteesp/CMakeLists.txt
+++ b/deployments/spm-test1/opteesp/CMakeLists.txt
@@ -12,6 +12,7 @@
 project(trusted-services LANGUAGES C ASM)
 add_executable(spm-test1)
 
+set(SP_BIN_UUID_CANON "5c9edbc3-7b3a-4367-9f83-7c191ae86a37")
 set(SP_UUID_CANON "5c9edbc3-7b3a-4367-9f83-7c191ae86a37")
 set(SP_NUMBER 1)
 include(${TS_ROOT}/components/service/spm_test/spm_test.cmake)
diff --git a/deployments/spm-test2/opteesp/CMakeLists.txt b/deployments/spm-test2/opteesp/CMakeLists.txt
index a3c3408..7942d50 100644
--- a/deployments/spm-test2/opteesp/CMakeLists.txt
+++ b/deployments/spm-test2/opteesp/CMakeLists.txt
@@ -12,6 +12,7 @@
 project(trusted-services LANGUAGES C ASM)
 add_executable(spm-test2)
 
+set(SP_BIN_UUID_CANON "7817164c-c40c-4d1a-867a-9bb2278cf41a")
 set(SP_UUID_CANON "7817164c-c40c-4d1a-867a-9bb2278cf41a")
 set(SP_NUMBER 2)
 include(${TS_ROOT}/components/service/spm_test/spm_test.cmake)
diff --git a/deployments/spm-test3/opteesp/CMakeLists.txt b/deployments/spm-test3/opteesp/CMakeLists.txt
index f756bb7..d0e198c 100644
--- a/deployments/spm-test3/opteesp/CMakeLists.txt
+++ b/deployments/spm-test3/opteesp/CMakeLists.txt
@@ -12,6 +12,7 @@
 project(trusted-services LANGUAGES C ASM)
 add_executable(spm-test3)
 
+set(SP_BIN_UUID_CANON "23eb0100-e32a-4497-9052-2f11e584afa6")
 set(SP_UUID_CANON "23eb0100-e32a-4497-9052-2f11e584afa6")
 set(SP_NUMBER 3)
 include(${TS_ROOT}/components/service/spm_test/spm_test.cmake)
diff --git a/deployments/spm-test4/opteesp/CMakeLists.txt b/deployments/spm-test4/opteesp/CMakeLists.txt
new file mode 100644
index 0000000..7197aa7
--- /dev/null
+++ b/deployments/spm-test4/opteesp/CMakeLists.txt
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
+set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.")
+include(../../deployment.cmake REQUIRED)
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+
+project(trusted-services LANGUAGES C ASM)
+add_executable(spm-test4)
+
+set(SP_BIN_UUID_CANON "423762ed-7772-406f-99d8-0c27da0abbf8")
+set(SP_UUID_CANON "23eb0100-e32a-4497-9052-2f11e584afa6")
+set(SP_NUMBER 4)
+include(${TS_ROOT}/components/service/spm_test/spm_test.cmake)
+#-------------------------------------------------------------------------------
+#  Components that are spm-test specific to deployment in the opteesp
+#  environment.
+#-------------------------------------------------------------------------------
+add_components(TARGET "spm-test${SP_NUMBER}"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/common/fdt"
+		"components/common/trace"
+		"components/common/utils"
+		"components/config/loader/sp"
+		"components/messaging/ffa/libsp"
+		"environments/opteesp"
+)
diff --git a/deployments/spm-test4/opteesp/default_spm_test4.dts.in b/deployments/spm-test4/opteesp/default_spm_test4.dts.in
new file mode 100644
index 0000000..fffc31f
--- /dev/null
+++ b/deployments/spm-test4/opteesp/default_spm_test4.dts.in
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+@DTS_TAG@
+
+@DTS_NODE@ {
+	compatible = "arm,ffa-manifest-1.0";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+
+	/* Properties */
+	description = "SPMC test SP4";
+	uuid = <@EXPORT_SP_UUID_DT@>;
+	execution-ctx-count = <1>;
+	exception-level = <1>; /* S-EL0 */
+	execution-state = <0>; /* AARCH64 */
+	xlat-granule = <0>; /* 4KiB */
+	messaging-method = <3>; /* Direct messaging only */
+	ns-interrupts-action = <2>; /* Non-secure interrupts are signaled */
+	elf-format = <1>;
+};
diff --git a/environments/opteesp/component.cmake b/environments/opteesp/component.cmake
index ec0cf34..526d8c8 100644
--- a/environments/opteesp/component.cmake
+++ b/environments/opteesp/component.cmake
@@ -12,7 +12,12 @@
 	endif()
 endforeach()
 
-ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_UUID_CANON}" )
+# Ensure elf output naming is symbolize.py compatible.
+# If binary UUID is not defined, fall back to using the SP UUID value.
+if (NOT SP_BIN_UUID_CANON)
+	set(SP_BIN_UUID_CANON "${SP_UUID_CANON}")
+endif()
+ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_BIN_UUID_CANON}" )
 
 target_sources(${TGT} PRIVATE
 	"${CMAKE_CURRENT_LIST_DIR}/optee_sp_header.c"
diff --git a/environments/sp/component.cmake b/environments/sp/component.cmake
index 2a4a502..3f3b0b4 100644
--- a/environments/sp/component.cmake
+++ b/environments/sp/component.cmake
@@ -12,7 +12,12 @@
 	endif()
 endforeach()
 
-ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_UUID_CANON}" )
+# Ensure elf output naming is symbolize.py compatible.
+# If binary UUID is not defined, fall back to using the SP UUID value.
+if (NOT SP_BIN_UUID_CANON)
+	set(SP_BIN_UUID_CANON "${SP_UUID_CANON}")
+endif()
+ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_BIN_UUID_CANON}" )
 
 target_sources(${TGT} PRIVATE
 	"${CMAKE_CURRENT_LIST_DIR}/entry.S"
diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
index 5908388..fd08e1a 100644
--- a/tools/b-test/test_data.yaml
+++ b/tools/b-test/test_data.yaml
@@ -211,6 +211,10 @@
       src: "$TS_ROOT/deployments/spm-test3/opteesp"
       params:
             - "-GUnix Makefiles"
+    - name: "spm-test4-opteesp"
+      src: "$TS_ROOT/deployments/spm-test4/opteesp"
+      params:
+            - "-GUnix Makefiles"
     - name: "ts-demo-arm-linux"
       src: "$TS_ROOT/deployments/ts-demo/arm-linux"
       os_id : "GNU/Linux"