refactor(spm): helper functions for SPM's MP tests

Factored out code to power on cpus from direct messaging test, and
placed in a helper function. To be used to test other multicore
functionality.
The function expects the cpu on handler to be implemented in the scope
of the functionality to be tested.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Ic0074dc85e0a906bae9d7b8cc071aff476f94de5
diff --git a/tftf/tests/common/test_helpers.c b/tftf/tests/common/test_helpers.c
index fffad67..80497bd 100644
--- a/tftf/tests/common/test_helpers.c
+++ b/tftf/tests/common/test_helpers.c
@@ -176,3 +176,46 @@
 
 	return TEST_RESULT_SUCCESS;
 }
+
+test_result_t spm_run_multi_core_test(uintptr_t cpu_on_handler,
+				      event_t *cpu_done)
+{
+	unsigned int lead_mpid = read_mpidr_el1() & MPID_MASK;
+	unsigned int core_pos, cpu_node, mpidr;
+	int32_t ret;
+
+	VERBOSE("Powering on all cpus.\n");
+
+	for (unsigned int i = 0U; i < PLATFORM_CORE_COUNT; i++) {
+		tftf_init_event(&cpu_done[i]);
+	}
+
+	for_each_cpu(cpu_node) {
+		mpidr = tftf_get_mpidr_from_node(cpu_node);
+		if (mpidr == lead_mpid) {
+			continue;
+		}
+
+		ret = tftf_cpu_on(mpidr, cpu_on_handler, 0U);
+		if (ret != 0) {
+			ERROR("tftf_cpu_on mpidr 0x%x returns %d\n",
+			      mpidr, ret);
+		}
+	}
+
+	VERBOSE("Waiting secondary CPUs to turn off ...\n");
+
+	for_each_cpu(cpu_node) {
+		mpidr = tftf_get_mpidr_from_node(cpu_node);
+		if (mpidr == lead_mpid) {
+			continue;
+		}
+
+		core_pos = platform_get_core_pos(mpidr);
+		tftf_wait_for_event(&cpu_done[core_pos]);
+	}
+
+	VERBOSE("Done exiting.\n");
+
+	return TEST_RESULT_SUCCESS;
+}