Skip to content

Commit

Permalink
tests: posix: add tests for pthread_setschedprio()
Browse files Browse the repository at this point in the history
Add tests for pthread_setschedprio()

Signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
  • Loading branch information
moonlight83340 committed Apr 3, 2024
1 parent 1d651d1 commit eb2bd1d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/posix/common/src/pthread.c
Expand Up @@ -539,6 +539,33 @@ ZTEST(pthread, test_pthread_testcancel)
zassert_false(testcancel_failed);
}

static void *test_pthread_setschedprio_fn(void *arg)
{
pthread_t self;
int prio = K_LOWEST_APPLICATION_THREAD_PRIO;
int policy;
struct sched_param getschedparam;

getschedparam.sched_priority = K_HIGHEST_APPLICATION_THREAD_PRIO;

self = pthread_self();

zassert_equal(pthread_setschedprio(self, PRIO_INVALID), EINVAL, "EINVAL was expected");
zassert_equal(pthread_setschedprio(PTHREAD_INVALID, prio), ESRCH, "ESRCH was expected");

zassert_ok(pthread_setschedprio(self, prio));
zassert_ok(pthread_getschedparam(self, &policy, &getschedparam));
zassert_equal(getschedparam.sched_priority, prio, "Priority unchanged");
}

ZTEST(pthread, test_pthread_setschedprio)
{
pthread_t th;

zassert_ok(pthread_create(&th, NULL, test_pthread_setschedprio_fn, NULL));
zassert_ok(pthread_join(th, NULL));
}

static void before(void *arg)
{
ARG_UNUSED(arg);
Expand Down
2 changes: 1 addition & 1 deletion tests/posix/headers/src/pthread_h.c
Expand Up @@ -151,7 +151,7 @@ ZTEST(posix_headers, test_pthread_h)
zassert_not_null(pthread_setcanceltype);
zassert_not_null(pthread_setconcurrency);
zassert_not_null(pthread_setschedparam);
/* zassert_not_null(pthread_setschedprio); */ /* not implemented */
zassert_not_null(pthread_setschedprio);
zassert_not_null(pthread_setspecific);
zassert_not_null(pthread_spin_destroy);
zassert_not_null(pthread_spin_init);
Expand Down

0 comments on commit eb2bd1d

Please sign in to comment.