Skip to content

Commit

Permalink
tests: kernel/msgq_api: add k_thread_join after k_thread_abort
Browse files Browse the repository at this point in the history
On SMP systems, threads going through k_thread_abort() may still
be running while the test moves on to the next one. This creates
some interferences and may result in the next test failing. So
add k_thread_join() after k_thread_abort() to make sure those
threads have stopped before moving on.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
  • Loading branch information
dcpleung committed Jan 10, 2025
1 parent 1f48740 commit 6f8bb1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ static void msgq_thread(struct k_msgq *pmsgq)

/**TESTPOINT: msgq purge*/
purge_msgq(pmsgq);

k_thread_join(tid, K_FOREVER);
}

static void thread_entry_overflow(void *p1, void *p2, void *p3)
Expand Down Expand Up @@ -145,6 +147,8 @@ static void msgq_thread_overflow(struct k_msgq *pmsgq)

/**TESTPOINT: msgq purge*/
k_msgq_purge(pmsgq);

k_thread_join(tid, K_FOREVER);
}

static void msgq_isr(struct k_msgq *pmsgq)
Expand Down Expand Up @@ -196,6 +200,9 @@ static void msgq_thread_data_passing(struct k_msgq *pmsgq)

/**TESTPOINT: msgq purge*/
k_msgq_purge(pmsgq);

k_thread_join(tid, K_FOREVER);
k_thread_join(tid1, K_FOREVER);
}

static void get_empty_entry(void *p1, void *p2, void *p3)
Expand Down Expand Up @@ -417,6 +424,7 @@ ZTEST(msgq_api_1cpu, test_msgq_empty)
zassert_equal(ret, 0);

k_thread_abort(tid);
k_thread_join(tid, K_FOREVER);
}

/**
Expand Down Expand Up @@ -449,6 +457,7 @@ ZTEST(msgq_api_1cpu, test_msgq_full)
/* that putting thread is being blocked now */
zassert_equal(tid->base.thread_state, _THREAD_PENDING);
k_thread_abort(tid);
k_thread_join(tid, K_FOREVER);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/kernel/msgq/msgq_api/src/test_msgq_purge.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void purge_when_put(struct k_msgq *q)
}

k_thread_abort(&tdata);
k_thread_join(&tdata, K_FOREVER);
}

/**
Expand Down

0 comments on commit 6f8bb1a

Please sign in to comment.