fix(memory share): reclaim and check memory

If the test relates with FFA_MEM_DONATE do not reclaim or check memory.
The memory is owned by the receiver, and is not accessible to sender.

If operation is lend/share, TFTF should reclaim memory contents first,
and then validate that the SP's access to memory. This is to avoid
fault on lend, as lender doesn't have access to memory until after
the reclaim.

Change-Id: I548b5cf2ac5c2774123f438a02565723470b4d85
Signed-off-by: J-Alves <joao.alves@arm.com>
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 60e6a1b..f047dd4 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
@@ -172,16 +172,22 @@
 		return TEST_RESULT_FAIL;
 	}
 
-	/* Check that borrower used the memory as expected for this test. */
-	if (!check_written_words(ptr, mem_func, nr_words_to_write)) {
-		ERROR("Words written to shared memory, not as expected.\n");
-		return TEST_RESULT_FAIL;
-	}
+	if (mem_func != FFA_MEM_DONATE_SMC32) {
 
-	if (mem_func != FFA_MEM_DONATE_SMC32 &&
-	    is_ffa_call_error(ffa_mem_reclaim(handle, 0))) {
+		/* Reclaim memory entirely before checking its state. */
+		if (is_ffa_call_error(ffa_mem_reclaim(handle, 0))) {
 			tftf_testcase_printf("Couldn't reclaim memory\n");
 			return TEST_RESULT_FAIL;
+		}
+
+		/*
+		 * Check that borrower used the memory as expected for this
+		 * test.
+		 */
+		if (!check_written_words(ptr, mem_func, nr_words_to_write)) {
+			ERROR("Fail because of state of memory.\n");
+			return TEST_RESULT_FAIL;
+		}
 	}
 
 	return TEST_RESULT_SUCCESS;