Skip to content

Commit 3c456fc

Browse files
Andrew Boieandrewboie
authored andcommitted
tests: mem_protect: fix corruption issue
This test has a problem, specifically in the scenario for test_mem_domain_remove_partitions. A low priority thread (10) is created which is expected to produce an exception. Then the following happens: - The thread indeed crashes and ends up in the custom fatal error handler, on the stack used for exceptions - The call to ztest_test_pass() is made - ztest_test_pass() gives the test_end_signal semaphore - We then context switch to the ztest main thread which is higher priority, leaving the thread that crashed context switched out *on the exception stack* - More tests are run, and some of them also produce exceptions - Eventually we do a sleep and the original crashed thread is swapped in again - Since several other exceptions have taken place on the exception stack since then, resuming context results in an unexpected error, causing the test to fail Only seems to affect arches that have a dedicated stack for exceptions, like x86_64. For now, increase the priority of the child thread so it's cleaned up immediately. Longer-term, this all needs to be re-thought in the test case to make this less fragile. Signed-off-by: Andrew Boie <[email protected]>
1 parent d27acb9 commit 3c456fc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tests/kernel/mem_protect/mem_protect/src/mem_domain.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static inline void set_valid_fault_value(int test_case_number)
9191
/* Userspace function */
9292
void mem_domain_for_user(void *tc_number, void *p2, void *p3)
9393
{
94-
set_valid_fault_value((uintptr_t)tc_number);
94+
set_valid_fault_value((int)tc_number);
9595

9696
mem_domain_buf[0] = 10U;
9797
if (valid_fault == false) {
@@ -523,7 +523,7 @@ void test_mem_domain_remove_partitions(void *p1, void *p2, void *p3)
523523
MEM_DOMAIN_STACK_SIZE,
524524
mem_domain_test_6_1,
525525
NULL, NULL, NULL,
526-
10, K_USER | K_INHERIT_PERMS, K_NO_WAIT);
526+
-1, K_USER | K_INHERIT_PERMS, K_NO_WAIT);
527527

528528

529529
k_sem_take(&sync_sem, K_MSEC(100));
@@ -536,7 +536,7 @@ void test_mem_domain_remove_partitions(void *p1, void *p2, void *p3)
536536
MEM_DOMAIN_STACK_SIZE,
537537
mem_domain_test_6_2,
538538
NULL, NULL, NULL,
539-
10, K_USER | K_INHERIT_PERMS, K_NO_WAIT);
539+
-1, K_USER | K_INHERIT_PERMS, K_NO_WAIT);
540540

541541
k_sem_take(&sync_sem, SYNC_SEM_TIMEOUT);
542542

0 commit comments

Comments
 (0)