From 38293afb569065e0d4907cabf860477de7dac807 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 5 Apr 2025 09:18:25 -0400 Subject: [PATCH 1/3] posix: timers: correct pointer passed to k_mem_slab_free() If it is not possible to create a timer in timer_create(), then the timer_obj associated with the timer must be freed. However, the address of the pointer was mistakenly being passed to k_mem_slab_free() rather than simply the the pointer. This caused a crash in tests which can easily be avoided by passing the pointer rather than the address of the pointer. Signed-off-by: Chris Friedt --- lib/posix/options/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/posix/options/timer.c b/lib/posix/options/timer.c index 3c14a01a3add3..e810b4576f7c9 100644 --- a/lib/posix/options/timer.c +++ b/lib/posix/options/timer.c @@ -190,7 +190,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) goto out; free_timer: - k_mem_slab_free(&posix_timer_slab, (void *)&timer); + k_mem_slab_free(&posix_timer_slab, (void *)timer); out: return ret; From f4c79485a9f220f819f53738b7885fcdf85fcf20 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 5 Apr 2025 09:27:44 -0400 Subject: [PATCH 2/3] tests: posix: timers: provide at least 1 dynamic thread timer_create() will error if there are no dynamic threads to run the SIGEV_THREAD handler, causing the test to fail (where it was previously expected to pass). Ensure that there is at least 1 dynamic thread available to the POSIX API. Signed-off-by: Chris Friedt --- tests/posix/timers/prj.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/posix/timers/prj.conf b/tests/posix/timers/prj.conf index e6119b6df54f9..8567a0bbf46a1 100644 --- a/tests/posix/timers/prj.conf +++ b/tests/posix/timers/prj.conf @@ -3,3 +3,8 @@ CONFIG_ZTEST=y CONFIG_POSIX_AEP_CHOICE_BASE=y CONFIG_POSIX_TIMERS=y + +# Needed for timer_create() when using SIGEV_THREAD +CONFIG_DYNAMIC_THREAD=y +CONFIG_DYNAMIC_THREAD_POOL_SIZE=1 +CONFIG_THREAD_STACK_INFO=y From 059087c76f6a3cbcdb008584dc713605268acaa6 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 5 Apr 2025 08:22:40 -0400 Subject: [PATCH 3/3] tests: posix: timer: do not skip tests I just happened to try to run this testsuite manually today and noticed that it was being skipped due to a copy-paste error. This test was migrated from tests/posix/common, where tests were skipped for non-dynamic threads, since it would mostly duplicate tests that had already been run. However, while migrating, the condition to skip tests was mistakenly left in when it should not have been. Signed-off-by: Chris Friedt --- tests/posix/timers/src/timer.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/posix/timers/src/timer.c b/tests/posix/timers/src/timer.c index faad7f659fcb2..1d4936d6a4be6 100644 --- a/tests/posix/timers/src/timer.c +++ b/tests/posix/timers/src/timer.c @@ -154,14 +154,4 @@ static void after(void *arg) } } -static void before(void *arg) -{ - ARG_UNUSED(arg); - - if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) { - /* skip redundant testing if there is no thread pool / heap allocation */ - ztest_test_skip(); - } -} - -ZTEST_SUITE(posix_timers, NULL, NULL, before, after, NULL); +ZTEST_SUITE(posix_timers, NULL, NULL, NULL, after, NULL);