Skip to content

Commit 31f34e0

Browse files
ioannisgcarlescufi
authored andcommitted
tests: error_hook: fix test_catch_z_oops test case
test_catch_z_oops test case should not run in user mode, since Z_OOPS needs to be called in supervisor mode, otherwise we will be getting a reguser user memory access error that is irrelevant to the test case (and simply is triggered by Z_OOPS accessing the thread's syscall frame pointer). In addition to that, we fix the argument of Z_OOPS, because, it was triggering a null-pointer dereferencing, which results in an error thrown before Z_OOPS is even executed (if null-pointer exception is caught). We also need to generate a dummy thread->syscall_frame, that Z_OOPS implementation will access. We fix this to _image_ram_start, because this memory is always part of the image memory and is always available to supervisor mode. So, accessing it won't trigger a security fault, for example. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 3721bb6 commit 31f34e0

File tree

1 file changed

+7
-4
lines changed
  • tests/ztest/error_hook/src

1 file changed

+7
-4
lines changed

tests/ztest/error_hook/src/main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,12 @@ void test_catch_assert_in_isr(void)
275275

276276

277277
#if defined(CONFIG_USERSPACE)
278-
static void trigger_z_oops(void *a)
278+
static void trigger_z_oops(void)
279279
{
280-
Z_OOPS(*((bool *)a));
280+
/* Set up a dummy syscall frame, pointing to a valid area in memory. */
281+
_current->syscall_frame = _image_ram_start;
282+
283+
Z_OOPS(true);
281284
}
282285

283286
/**
@@ -293,7 +296,7 @@ void test_catch_z_oops(void)
293296
case_type = ZTEST_CATCH_USER_FATAL_Z_OOPS;
294297

295298
ztest_set_fault_valid(true);
296-
trigger_z_oops((void *)false);
299+
trigger_z_oops();
297300
}
298301
#endif
299302

@@ -308,7 +311,7 @@ void test_main(void)
308311
ztest_user_unit_test(test_catch_assert_fail),
309312
ztest_user_unit_test(test_catch_fatal_error),
310313
ztest_unit_test(test_catch_assert_in_isr),
311-
ztest_user_unit_test(test_catch_z_oops)
314+
ztest_unit_test(test_catch_z_oops)
312315
);
313316
ztest_run_test_suite(error_hook_tests);
314317
#else

0 commit comments

Comments
 (0)