From ff0c6b9c803891254106793e02d398aef116ef15 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Sat, 29 Apr 2023 07:50:28 -0400 Subject: [PATCH 1/2] tests: posix: pthread: init pthread_attr_t on each iteration The `test_pthread_descriptor_leak` test was causing a kernel panic on some platforms. Initially, it was not clear why. The usual cases were examined - race conditions, stack sizes, etc. Still no luck. As it turns out, recycling a thread stack (or at least the `pthread_attr_t`) in-place does not work on some platforms, and we need to reinitialize the `pthread_attr_t` and set set the stack property again prior to calling `pthread_create()`. Signed-off-by: Christopher Friedt --- tests/posix/common/src/pthread.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 92e80c2b0556a..82bb8c5de779f 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -588,11 +588,10 @@ ZTEST(posix_apis, test_pthread_descriptor_leak) pthread_t pthread1; pthread_attr_t attr; - zassert_ok(pthread_attr_init(&attr)); - zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS)); - /* If we are leaking descriptors, then this loop will never complete */ for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) { + zassert_ok(pthread_attr_init(&attr)); + zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS)); zassert_ok(pthread_create(&pthread1, &attr, create_thread1, NULL), "unable to create thread %zu", i); zassert_ok(pthread_join(pthread1, &unused), "unable to join thread %zu", i); From d1087d1d21cecc2601e7d264bd93afcfa1dc6329 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Sat, 29 Apr 2023 15:48:36 -0400 Subject: [PATCH 2/2] tests: posix: pthread: remove unused pthread return value Rather than pass an variable address to a `void *` in `pthread_join()` and do nothing with it, just pass `NULL`. Signed-off-by: Christopher Friedt --- tests/posix/common/src/pthread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 82bb8c5de779f..95fad3443e765 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -584,7 +584,6 @@ ZTEST(posix_apis, test_posix_pthread_create_negative) ZTEST(posix_apis, test_pthread_descriptor_leak) { - void *unused; pthread_t pthread1; pthread_attr_t attr; @@ -594,6 +593,6 @@ ZTEST(posix_apis, test_pthread_descriptor_leak) zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS)); zassert_ok(pthread_create(&pthread1, &attr, create_thread1, NULL), "unable to create thread %zu", i); - zassert_ok(pthread_join(pthread1, &unused), "unable to join thread %zu", i); + zassert_ok(pthread_join(pthread1, NULL), "unable to join thread %zu", i); } }