Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion boards/arm/mps2/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
27 changes: 27 additions & 0 deletions tests/arch/arm/arm_user_stack_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/arch/arm/arm_user_stack_test/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
common:
tags:
- arm
timeout: 120
tests:
arch.arm.user.stack:
filter: CONFIG_CPU_CORTEX_M
Expand Down
Loading