Skip to content

Commit dbe3874

Browse files
dcpleungcarlescufi
authored andcommitted
tests: kernel/smp: wait for threads to exits between tests
This adds a bunch of k_thread_join() to make sure threads spawned for a test are no longer running between exiting that test. This prevents interference between tests if some threads are still running when assumed not. Signed-off-by: Daniel Leung <[email protected]>
1 parent c3f2da1 commit dbe3874

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/kernel/smp/src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ ZTEST(smp, test_smp_coop_threads)
144144
}
145145

146146
k_thread_abort(tid);
147+
k_thread_join(tid, K_FOREVER);
147148
zassert_true(ok, "SMP test failed");
148149
}
149150

@@ -184,6 +185,7 @@ ZTEST(smp, test_cpu_id_threads)
184185
k_sem_take(&cpuid_sema, K_FOREVER);
185186

186187
k_thread_abort(tid);
188+
k_thread_join(tid, K_FOREVER);
187189
}
188190

189191
static void thread_entry(void *p1, void *p2, void *p3)
@@ -245,6 +247,10 @@ static void abort_threads(int num)
245247
for (int i = 0; i < num; i++) {
246248
k_thread_abort(tinfo[i].tid);
247249
}
250+
251+
for (int i = 0; i < num; i++) {
252+
k_thread_join(tinfo[i].tid, K_FOREVER);
253+
}
248254
}
249255

250256
static void cleanup_resources(void)
@@ -551,6 +557,7 @@ ZTEST(smp, test_get_cpu)
551557
k_busy_wait(DELAY_US);
552558

553559
k_thread_abort(thread_id);
560+
k_thread_join(thread_id, K_FOREVER);
554561
}
555562

556563
#ifdef CONFIG_TRACE_SCHED_IPI
@@ -1005,8 +1012,10 @@ ZTEST(smp, test_smp_switch_torture)
10051012
k_sleep(K_MSEC(SLEEP_MS_LONG));
10061013

10071014
k_thread_abort(&t2);
1015+
k_thread_join(&t2, K_FOREVER);
10081016
for (uintptr_t i = 0; i < THREADS_NUM; i++) {
10091017
k_thread_abort(&tthread[i]);
1018+
k_thread_join(&tthread[i], K_FOREVER);
10101019
}
10111020
}
10121021

0 commit comments

Comments
 (0)