Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: kernel/msgq_api: add k_thread_join after k_thread_abort #83834

Merged

Conversation

dcpleung
Copy link
Member

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.

@cfriedt
Copy link
Member

cfriedt commented Jan 17, 2025

It might be safer to call k_thtead_join() from an after() function. Just a thought.

@dcpleung
Copy link
Member Author

I don't think that's going to work. AFAIK, the "after" function is set at the test suite level and it works for all tests. Since not all tests are creating additional threads, it is possible that the thread struct has never been initialized before the function is called. The struct may even contain random data (if in noinit section) and k_thread_join() is possibly going to do something unexpected.

@cfriedt
Copy link
Member

cfriedt commented Jan 18, 2025

@dcpleung - you could use an array of k_tid_t since those would necessarily need to be initialized in the tests (and would otherwise be NULL).

I've used that approach a fair bit and it works well.

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
after each test, we need to do k_thread_join() on those threads
to make sure they are no longer active.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
@dcpleung dcpleung force-pushed the tests/msgq_api_thread_join branch from 6f8bb1a to 54d11e2 Compare January 22, 2025 17:46
@kartben kartben merged commit 32f5ef5 into zephyrproject-rtos:main Jan 22, 2025
18 checks passed
@dcpleung dcpleung deleted the tests/msgq_api_thread_join branch January 22, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants