From 83aafaf1aee47eb5c44bf7b8e1ab62eb96dbea76 Mon Sep 17 00:00:00 2001 From: Marvin Ouma Date: Thu, 20 Mar 2025 15:59:45 +0300 Subject: [PATCH] tests: posix: xsi_realtime: move more tests into xsi_realtime move tests with _POSIX_PRIORITY_SCHEDULING Option to xsi_realtime testsuite Signed-off-by: Marvin Ouma --- tests/posix/common/src/pthread.c | 78 +++++------------------------ tests/posix/xsi_realtime/src/main.c | 53 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 66 deletions(-) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index b86c1b4f395..3801d3b4186 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -12,16 +12,16 @@ #define DETACH_THR_ID 2 -#define N_THR_E 3 -#define N_THR_T 4 -#define BOUNCES 64 +#define N_THR_E 3 +#define N_THR_T 4 +#define BOUNCES 64 #define ONE_SECOND 1 /* Macros to test invalid states */ #define PTHREAD_CANCEL_INVALID -1 -#define SCHED_INVALID -1 -#define PRIO_INVALID -1 -#define PTHREAD_INVALID -1 +#define SCHED_INVALID -1 +#define PRIO_INVALID -1 +#define PTHREAD_INVALID -1 static void *thread_top_exec(void *p1); static void *thread_top_term(void *p1); @@ -57,13 +57,13 @@ static int barrier_return[N_THR_E]; static void *thread_top_exec(void *p1) { - int i, j, id = (int) POINTER_TO_INT(p1); + int i, j, id = (int)POINTER_TO_INT(p1); int policy; struct sched_param schedparam; pthread_getschedparam(pthread_self(), &policy, &schedparam); - printk("Thread %d starting with scheduling policy %d & priority %d\n", - id, policy, schedparam.sched_priority); + printk("Thread %d starting with scheduling policy %d & priority %d\n", id, policy, + schedparam.sched_priority); /* Try a double-lock here to exercise the failing case of * trylock. We don't support RECURSIVE locks, so this is * guaranteed to fail. @@ -201,11 +201,9 @@ static void *thread_top_term(void *p1) "Unable to set thread priority!"); zassert_false(pthread_getschedparam(self, &policy, &getschedparam), - "Unable to get thread priority!"); + "Unable to get thread priority!"); - printk("Thread %d starting with a priority of %d\n", - id, - getschedparam.sched_priority); + printk("Thread %d starting with a priority of %d\n", id, getschedparam.sched_priority); if (id % 2) { ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); @@ -304,8 +302,7 @@ ZTEST(pthread, test_pthread_execution) zassert_false(ret, "Set thread name failed!"); /* TESTPOINT: Try getting thread name */ - ret = pthread_getname_np(newthread[0], thr_name_buf, - sizeof(thr_name_buf)); + ret = pthread_getname_np(newthread[0], thr_name_buf, sizeof(thr_name_buf)); zassert_false(ret, "Get thread name failed!"); /* TESTPOINT: Thread names match */ @@ -460,57 +457,6 @@ ZTEST(pthread, test_pthread_descriptor_leak) } } -ZTEST(pthread, test_sched_getparam) -{ - struct sched_param param; - int rc = sched_getparam(0, ¶m); - int err = errno; - - zassert_true((rc == -1 && err == ENOSYS)); -} - -ZTEST(pthread, test_sched_getscheduler) -{ - int rc = sched_getscheduler(0); - int err = errno; - - zassert_true((rc == -1 && err == ENOSYS)); -} -ZTEST(pthread, test_sched_setparam) -{ - struct sched_param param = { - .sched_priority = 2, - }; - int rc = sched_setparam(0, ¶m); - int err = errno; - - zassert_true((rc == -1 && err == ENOSYS)); -} - -ZTEST(pthread, test_sched_setscheduler) -{ - struct sched_param param = { - .sched_priority = 2, - }; - int policy = 0; - int rc = sched_setscheduler(0, policy, ¶m); - int err = errno; - - zassert_true((rc == -1 && err == ENOSYS)); -} - -ZTEST(pthread, test_sched_rr_get_interval) -{ - struct timespec interval = { - .tv_sec = 0, - .tv_nsec = 0, - }; - int rc = sched_rr_get_interval(0, &interval); - int err = errno; - - zassert_true((rc == -1 && err == ENOSYS)); -} - ZTEST(pthread, test_pthread_equal) { zassert_true(pthread_equal(pthread_self(), pthread_self())); diff --git a/tests/posix/xsi_realtime/src/main.c b/tests/posix/xsi_realtime/src/main.c index 3021c9b3706..034517eb783 100644 --- a/tests/posix/xsi_realtime/src/main.c +++ b/tests/posix/xsi_realtime/src/main.c @@ -4,6 +4,59 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + #include +ZTEST(xsi_realtime, test_sched_getparam) +{ + struct sched_param param; + int rc = sched_getparam(0, ¶m); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + +ZTEST(xsi_realtime, test_sched_getscheduler) +{ + int rc = sched_getscheduler(0); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} +ZTEST(xsi_realtime, test_sched_setparam) +{ + struct sched_param param = { + .sched_priority = 2, + }; + int rc = sched_setparam(0, ¶m); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + +ZTEST(xsi_realtime, test_sched_setscheduler) +{ + struct sched_param param = { + .sched_priority = 2, + }; + int policy = 0; + int rc = sched_setscheduler(0, policy, ¶m); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + +ZTEST(xsi_realtime, test_sched_rr_get_interval) +{ + struct timespec interval = { + .tv_sec = 0, + .tv_nsec = 0, + }; + int rc = sched_rr_get_interval(0, &interval); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + ZTEST_SUITE(xsi_realtime, NULL, NULL, NULL, NULL, NULL);