Test: Convert TFM_IPC_ISOLATION_2_TEST_READ_ONLY_MEM to positive test
Call tfm_hal_memory_has_access API to convert the negative test case
TFM_IPC_ISOLATION_2_TEST_READ_ONLY_MEM into positive test case.
This test only enabled when isolation level greater than 1.
Change-Id: I7c358b86c484c74858fc0b1c7280df47966f6672
Signed-off-by: Shawn Shan <Shawn.Shan@arm.com>
diff --git a/test/suites/ipc/non_secure/ipc_ns_interface_testsuite.c b/test/suites/ipc/non_secure/ipc_ns_interface_testsuite.c
index c352a62..4d8ea59 100644
--- a/test/suites/ipc/non_secure/ipc_ns_interface_testsuite.c
+++ b/test/suites/ipc/non_secure/ipc_ns_interface_testsuite.c
@@ -255,6 +255,7 @@
static void tfm_ipc_test_1007(struct test_result_t *ret)
{
psa_handle_t handle;
+ psa_status_t status;
int test_result;
struct psa_outvec outvecs[1] = {{&test_result, sizeof(test_result)}};
@@ -268,10 +269,13 @@
return;
}
- psa_call(handle, PSA_IPC_CALL, NULL, 0, outvecs, 1);
+ status = psa_call(handle, PSA_IPC_CALL, NULL, 0, outvecs, 1);
+ if (status == PSA_SUCCESS) {
+ ret->val = TEST_PASSED;
+ } else {
+ ret->val = TEST_FAILED;
+ }
- /* The system should panic in psa_call. If runs here, the test fails. */
- ret->val = TEST_FAILED;
psa_close(handle);
}
#endif
diff --git a/test/test_services/tfm_ipc_service/CMakeLists.txt b/test/test_services/tfm_ipc_service/CMakeLists.txt
index e0dac7a..db4a127 100644
--- a/test/test_services/tfm_ipc_service/CMakeLists.txt
+++ b/test/test_services/tfm_ipc_service/CMakeLists.txt
@@ -44,4 +44,5 @@
target_compile_definitions(tfm_partition_defs
INTERFACE
TFM_PARTITION_TEST_CORE_IPC
+ $<$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>:TFM_IPC_ISOLATION_2_TEST_READ_ONLY_MEM>
)
diff --git a/test/test_services/tfm_ipc_service/tfm_ipc_service_test.c b/test/test_services/tfm_ipc_service/tfm_ipc_service_test.c
index 09f37d3..e558513 100644
--- a/test/test_services/tfm_ipc_service/tfm_ipc_service_test.c
+++ b/test/test_services/tfm_ipc_service/tfm_ipc_service_test.c
@@ -6,13 +6,13 @@
*/
#include <assert.h>
-#include <stdio.h>
#include <stdbool.h>
#include "psa/client.h"
#include "psa/service.h"
-#include "tfm_secure_api.h"
-#include "tfm_api.h"
#include "psa_manifest/tfm_ipc_service_test.h"
+#include "tfm_api.h"
+#include "tfm_hal_isolation.h"
+#include "tfm_secure_api.h"
#define IPC_SERVICE_BUFFER_LEN 32
@@ -131,7 +131,7 @@
psa_msg_t msg;
psa_status_t r;
char rec_data;
- uint32_t rec_buf;
+ uint32_t rec_buf, attr = 0;
psa_get(IPC_SERVICE_TEST_PSA_ACCESS_APP_READ_ONLY_MEM_SIGNAL, &msg);
switch (msg.type) {
@@ -160,11 +160,14 @@
psa_reply(msg.handle, -1);
break;
}
-
- /* Write the char type read only memory. */
- *((char *)rec_buf) = 'B';
+ attr |= (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE
+ | TFM_HAL_ACCESS_UNPRIVILEGED);
+ if (tfm_hal_memory_has_access((uintptr_t)rec_buf, 4, attr) !=
+ TFM_HAL_ERROR_MEM_FAULT) {
+ psa_reply(msg.handle, PSA_ERROR_GENERIC_ERROR);
+ break;
+ }
}
-
psa_reply(msg.handle, PSA_SUCCESS);
break;
case PSA_IPC_DISCONNECT: