test(rme): rxtx buffers are in the realm PAS

Added a test for which the SPMC attempts to use the RXTX
buffers, in an RME enabled platform and in which the buffers
were changed to realm PAS.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Idb29f8687fbe5885c00e61155a5ebbdd8908d688
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_exceptions.c b/tftf/tests/runtime_services/secure_service/test_ffa_exceptions.c
index 0a345d4..bd0df07 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_exceptions.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_exceptions.c
@@ -7,6 +7,7 @@
 #include <arch_helpers.h>
 #include <cactus_test_cmds.h>
 #include "ffa_helpers.h"
+#include "tftf_lib.h"
 #include <debug.h>
 #include <ffa_endpoints.h>
 #include <ffa_svc.h>
@@ -115,3 +116,55 @@
 
 	return host_cmp_result();
 }
+
+/**
+ * Map the NS RXTX buffers to the SPM, invoke the TRP delegation
+ * service to change the RX buffer PAS to realm, invoke the
+ * FFA_PARTITON_INFO_GET interface, such that SPM does NS access
+ * to realm region and triggers GPF.
+ */
+test_result_t test_ffa_rxtx_to_realm_pas(void)
+{
+	struct mailbox_buffers mb;
+	u_register_t retmm;
+	struct ffa_value ret;
+
+	GET_TFTF_MAILBOX(mb);
+
+	if (get_armv9_2_feat_rme_support() == 0U) {
+		return TEST_RESULT_SKIPPED;
+	}
+
+	/* Delegate the shared page to Realm. */
+	retmm = host_rmi_granule_delegate((u_register_t)mb.recv);
+	if (retmm != 0UL) {
+		ERROR("Granule delegate failed, ret=0x%lx\n", retmm);
+		return TEST_RESULT_FAIL;
+	}
+
+	ret = ffa_partition_info_get((struct ffa_uuid){{0}});
+
+	if (!is_expected_ffa_error(ret, FFA_ERROR_ABORTED)) {
+		ERROR("FFA_PARTITON_INFO_GET should terminate with"
+		       "FFA_ERROR_ABORTED\n");
+		return TEST_RESULT_FAIL;
+	}
+
+	/* Undelegate the shared page. */
+	retmm = host_rmi_granule_undelegate((u_register_t)mb.recv);
+	if (retmm != 0UL) {
+		ERROR("Granule undelegate failed, ret=0x%lx\n", retmm);
+		return TEST_RESULT_FAIL;
+	}
+
+	ret = ffa_partition_info_get((struct ffa_uuid){{0}});
+
+	if (is_ffa_call_error(ret)) {
+		ERROR("FFA_PARTITON_INFO_GET should succeed.\n");
+		return TEST_RESULT_FAIL;
+	}
+
+	ffa_rx_release();
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-memory-access.mk b/tftf/tests/tests-memory-access.mk
index 13b2241..82ea094 100644
--- a/tftf/tests/tests-memory-access.mk
+++ b/tftf/tests/tests-memory-access.mk
@@ -27,4 +27,5 @@
 		test_ffa_memory_sharing.c				\
 		test_ffa_setup_and_discovery.c				\
 		spm_test_helpers.c					\
+		test_ffa_exceptions.c					\
 )
diff --git a/tftf/tests/tests-memory-access.xml b/tftf/tests/tests-memory-access.xml
index 4318cc9..fa8a8a4 100644
--- a/tftf/tests/tests-memory-access.xml
+++ b/tftf/tests/tests-memory-access.xml
@@ -57,6 +57,8 @@
                 function="test_ffa_mem_send_sp_realm_memory" />
       <testcase name="FF-A memory share fail realm memory other constituent"
                 function="test_ffa_mem_lend_sp_realm_memory_separate_constituent" />
+      <testcase name="FF-A partition info get after NWd RX is in realm PAS"
+                function="test_ffa_rxtx_to_realm_pas" />
   </testsuite>
 
 </testsuites>