From 295eb1b1a0129126b8b994b039ef1334a41aade4 Mon Sep 17 00:00:00 2001 From: Mateusz Marszalek Date: Sun, 27 Aug 2023 12:41:28 +0200 Subject: [PATCH] POSIX: Add tests for pthread_condattr Add test coverage for init, destroy, setclock, getclock Signed-off-by: Mateusz Marszalek --- tests/posix/common/src/pthread.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index f02570d70ef0ef..6b7cb25616e33d 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -233,6 +233,28 @@ void *thread_top_term(void *p1) return NULL; } +ZTEST(posix_apis, test_pthread_condattr) +{ + clockid_t clock_id; + pthread_condattr_t att; + + zassert_ok(pthread_condattr_init(&att), "pthread_condattr_init failed"); + + zassert_ok(pthread_condattr_getclock(&att, &clock_id), "pthread_condattr_getclock failed"); + zassert_equal(clock_id, CLOCK_MONOTONIC, "clock attribute not set correctly"); + + zassert_ok(pthread_condattr_setclock(&att, CLOCK_REALTIME), + "pthread_condattr_setclock failed"); + + zassert_ok(pthread_condattr_getclock(&att, &clock_id), "pthread_condattr_setclock failed"); + zassert_equal(clock_id, CLOCK_REALTIME, "clock attribute not set correctly"); + + zassert_equal(pthread_condattr_setclock(&att, 42), + -EINVAL, "pthread_condattr_setclock did not return EINVAL"); + + zassert_ok(pthread_condattr_destroy(&att), "pthread_condattr_destroy failed"); +} + ZTEST(posix_apis, test_pthread_execution) { int i, ret, min_prio, max_prio;