feat(invalid-access): dynamically map/unmap test region
Invalid-access test suites are negative tests which tries to access
memory address from a world which does not have privilege. This causes
a memory fault which is caught by tftf framework.
Dynamically map/unmap these addresses during the test
Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: Icb5d77d15ef4c4c352f6c646d756315a75b129cd
diff --git a/tftf/tests/misc_tests/test_invalid_access.c b/tftf/tests/misc_tests/test_invalid_access.c
index 18b68fb..1e584af 100644
--- a/tftf/tests/misc_tests/test_invalid_access.c
+++ b/tftf/tests/misc_tests/test_invalid_access.c
@@ -17,6 +17,8 @@
#include <lib/aarch64/arch_features.h>
#include <runtime_services/realm_payload/realm_payload_test.h>
#include <tftf_lib.h>
+#include <xlat_tables_v2.h>
+
#include <platform_def.h>
/*
@@ -69,15 +71,26 @@
VERBOSE("Attempt to access el3 memory (0x%lx)\n", test_address);
+ sync_exception_triggered = false;
data_abort_triggered = false;
+
+ int rc = mmap_add_dynamic_region(test_address, test_address, PAGE_SIZE,
+ MT_MEMORY | MT_RW | MT_NS);
+ if (rc != 0) {
+ tftf_testcase_printf("%d: mmap_add_dynamic_region() = %d\n", __LINE__, rc);
+ return TEST_RESULT_FAIL;
+ }
+
register_custom_sync_exception_handler(data_abort_handler);
- dsbsy();
-
*((volatile uint64_t *)test_address);
-
- dsbsy();
unregister_custom_sync_exception_handler();
+ rc = mmap_remove_dynamic_region(test_address, PAGE_SIZE);
+ if (rc != 0) {
+ tftf_testcase_printf("%d: mmap_remove_dynamic_region() = %d\n", __LINE__, rc);
+ return TEST_RESULT_FAIL;
+ }
+
if (sync_exception_triggered == false) {
tftf_testcase_printf("No sync exception while accessing (0x%lx)\n", test_address);
return TEST_RESULT_SKIPPED;