diff --git a/boards/arm/mps2/Kconfig.defconfig b/boards/arm/mps2/Kconfig.defconfig index 367e09c2a9a17..b6c51af651c41 100644 --- a/boards/arm/mps2/Kconfig.defconfig +++ b/boards/arm/mps2/Kconfig.defconfig @@ -33,7 +33,7 @@ config TEST_EXTRA_STACK_SIZE endif # COVERAGE_GCOV -endif +endif # BOARD_MPS2_AN383 || BOARD_MPS2_AN385 || BOARD_MPS2_AN386 || BOARD_MPS2_AN500 if BOARD_MPS2_AN521_CPU0 || BOARD_MPS2_AN521_CPU0_NS || BOARD_MPS2_AN521_CPU1 @@ -58,4 +58,11 @@ config UART_INTERRUPT_DRIVEN endif # SERIAL +endif # BOARD_MPS2_AN521_CPU0 || BOARD_MPS2_AN521_CPU0_NS || BOARD_MPS2_AN521_CPU1 + +if QEMU_TARGET + +config ISR_STACK_SIZE + default 4096 + endif diff --git a/tests/arch/arm/arm_user_stack_test/src/main.c b/tests/arch/arm/arm_user_stack_test/src/main.c index ee7e1ed90bbc1..71d9316aec358 100644 --- a/tests/arch/arm/arm_user_stack_test/src/main.c +++ b/tests/arch/arm/arm_user_stack_test/src/main.c @@ -23,8 +23,13 @@ volatile int *const attack_sp = &attack_stack[128]; const int sysno = K_SYSCALL_K_UPTIME_TICKS; k_tid_t low_tid, hi_tid; +struct k_timer timer; +volatile ZTEST_BMEM uint64_t hi_thread_runs, test_completed; + void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *pEsf) { + test_completed = 1; + k_timer_stop(&timer); ztest_test_pass(); k_thread_abort(low_tid); @@ -37,6 +42,24 @@ void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *pEsf) } } +static void timeout_handler(struct k_timer *timer) +{ + if (!test_completed) { + + printf("hi_thread_runs: %lld\n", hi_thread_runs); + /* the timer times out after 120s, + * by then hi_fn would have ran multiple times so + * compare against a random number like 1000 to make sure that + * hi_fn actually ran for a while + */ + if (hi_thread_runs > 1000) { + ztest_test_pass(); + } else { + ztest_test_fail(); + } + } +} + void attack_entry(void) { printf("Call %s from %s\n", __func__, k_is_user_context() ? "user" : "kernel"); @@ -79,11 +102,15 @@ void hi_fn(void *arg1, void *arg2, void *arg3) while (1) { attack_sp[-2] = (int)attack_entry; k_msleep(1); + hi_thread_runs++; } } ZTEST(arm_user_stack_test, test_arm_user_stack_corruption) { + k_timer_init(&timer, timeout_handler, NULL); + k_timer_start(&timer, K_SECONDS(120), K_NO_WAIT); + low_tid = k_thread_create(&th0, stk0, K_THREAD_STACK_SIZEOF(stk0), low_fn, NULL, NULL, NULL, 2, #ifdef CONFIG_FPU_SHARING diff --git a/tests/arch/arm/arm_user_stack_test/testcase.yaml b/tests/arch/arm/arm_user_stack_test/testcase.yaml index 49cd8fd3a00e8..0d7bafb8fa124 100644 --- a/tests/arch/arm/arm_user_stack_test/testcase.yaml +++ b/tests/arch/arm/arm_user_stack_test/testcase.yaml @@ -1,6 +1,7 @@ common: tags: - arm + timeout: 120 tests: arch.arm.user.stack: filter: CONFIG_CPU_CORTEX_M