test(memory sharing): donate consecutively same memory
TFTF attempts to donate the same memory address consecutively.
The added test validates that such attempt fails, from NWd
targetting the SP receiver to the first donate, as well as
another SP.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Iee55ebea54beab2499b38372aa2579024237da5f
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
index ce9c81f..9418b57 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
@@ -24,6 +24,7 @@
/* Memory section to be used for memory share operations */
static __aligned(PAGE_SIZE) uint8_t share_page[PAGE_SIZE];
+static __aligned(PAGE_SIZE) uint8_t consecutive_donate_page[PAGE_SIZE];
static bool check_written_words(uint32_t *ptr, uint32_t word, uint32_t wcount)
{
@@ -222,6 +223,44 @@
constituents_count);
}
+test_result_t test_consecutive_donate(void)
+{
+ struct ffa_memory_region_constituent constituents[] = {
+ {(void *)consecutive_donate_page, 1, 0}
+ };
+ const uint32_t constituents_count = sizeof(constituents) /
+ sizeof(struct ffa_memory_region_constituent);
+
+ CHECK_SPMC_TESTING_SETUP(1, 1, expected_sp_uuids);
+
+ test_result_t ret = test_memory_send_sp(FFA_MEM_DONATE_SMC32, SP_ID(1),
+ constituents,
+ constituents_count);
+
+ if (ret != TEST_RESULT_SUCCESS) {
+ ERROR("Failed at first attempting of sharing.\n");
+ return TEST_RESULT_FAIL;
+ }
+
+ if (!test_memory_send_expect_denied(FFA_MEM_DONATE_SMC32,
+ consecutive_donate_page,
+ SP_ID(1))) {
+ ERROR("Memory was successfully donated again from the NWd, to "
+ "the same borrower.\n");
+ return TEST_RESULT_FAIL;
+ }
+
+ if (!test_memory_send_expect_denied(FFA_MEM_DONATE_SMC32,
+ consecutive_donate_page,
+ SP_ID(2))) {
+ ERROR("Memory was successfully donated again from the NWd, to "
+ "another borrower.\n");
+ return TEST_RESULT_FAIL;
+ }
+
+ return TEST_RESULT_SUCCESS;
+}
+
/*
* Test requests a memory send operation between cactus SPs.
* Cactus SP should reply to TFTF on whether the test succeeded or not.
diff --git a/tftf/tests/tests-spm.xml b/tftf/tests/tests-spm.xml
index b8861d3..6c701ce 100644
--- a/tftf/tests/tests-spm.xml
+++ b/tftf/tests/tests-spm.xml
@@ -94,6 +94,8 @@
function="test_req_mem_lend_sp_to_vm" />
<testcase name="Share forbidden memory with SP"
function="test_share_forbidden_ranges" />
+ <testcase name="Donate consecutively"
+ function="test_consecutive_donate" />
</testsuite>
<testsuite name="SIMD,SVE Registers context"