diff --git a/tests/posix/common/src/pthread_attr.c b/tests/posix/common/src/pthread_attr.c index 99568a85298ea3..d6ff3a5ee8df30 100644 --- a/tests/posix/common/src/pthread_attr.c +++ b/tests/posix/common/src/pthread_attr.c @@ -439,6 +439,48 @@ ZTEST(pthread_attr, test_pthread_attr_setstacksize) } } +ZTEST(pthread_attr, test_pthread_attr_getscope) +{ + int contentionscope = BIOS_FOOD; + + /* degenerate cases */ + { + if (false) { + /* undefined behaviour */ + zassert_equal(pthread_attr_getscope(NULL, NULL), EINVAL); + zassert_equal(pthread_attr_getscope(NULL, &contentionscope), EINVAL); + zassert_equal(pthread_attr_getscope(&uninit_attr, &contentionscope), + EINVAL); + } + zassert_equal(pthread_attr_getscope(&attr, NULL), EINVAL); + } + + zassert_ok(pthread_attr_getscope(&attr, &contentionscope)); + zassert_equal(contentionscope, PTHREAD_SCOPE_SYSTEM); +} + +ZTEST(pthread_attr, test_pthread_attr_setscope) +{ + int contentionscope = BIOS_FOOD; + + /* degenerate cases */ + { + if (false) { + /* undefined behaviour */ + zassert_equal(pthread_attr_setscope(NULL, PTHREAD_SCOPE_SYSTEM), EINVAL); + zassert_equal(pthread_attr_setscope(NULL, contentionscope), EINVAL); + zassert_equal(pthread_attr_setscope((pthread_attr_t *)&uninit_attr, + contentionscope), EINVAL); + } + zassert_equal(pthread_attr_setscope(&attr, 3), EINVAL); + } + + zassert_equal(pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS), ENOTSUP); + zassert_ok(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)); + zassert_ok(pthread_attr_getscope(&attr, &contentionscope)); + zassert_equal(contentionscope, PTHREAD_SCOPE_SYSTEM); +} + ZTEST(pthread_attr, test_pthread_attr_large_stacksize) { size_t actual_size; diff --git a/tests/posix/headers/src/pthread_h.c b/tests/posix/headers/src/pthread_h.c index 73467d14bf99d6..17b7768f879298 100644 --- a/tests/posix/headers/src/pthread_h.c +++ b/tests/posix/headers/src/pthread_h.c @@ -53,8 +53,8 @@ ZTEST(posix_headers, test_pthread_h) zassert_not_equal(-1, PTHREAD_PROCESS_SHARED); zassert_not_equal(-1, PTHREAD_PROCESS_PRIVATE); - /* zassert_not_equal(-1, PTHREAD_SCOPE_PROCESS); */ /* not implemented */ - /* zassert_not_equal(-1, PTHREAD_SCOPE_SYSTEM); */ /* not implemented */ + zassert_not_equal(-1, PTHREAD_SCOPE_PROCESS); + zassert_not_equal(-1, PTHREAD_SCOPE_SYSTEM); pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER; @@ -68,7 +68,7 @@ ZTEST(posix_headers, test_pthread_h) /* zassert_not_null(pthread_attr_getinheritsched); */ /* not implemented */ zassert_not_null(pthread_attr_getschedparam); zassert_not_null(pthread_attr_getschedpolicy); - /* zassert_not_null(pthread_attr_getscope); */ /* not implemented */ + zassert_not_null(pthread_attr_getscope); zassert_not_null(pthread_attr_getstack); zassert_not_null(pthread_attr_getstacksize); zassert_not_null(pthread_attr_init); @@ -77,7 +77,7 @@ ZTEST(posix_headers, test_pthread_h) /* zassert_not_null(pthread_attr_setinheritsched); */ /* not implemented */ zassert_not_null(pthread_attr_setschedparam); zassert_not_null(pthread_attr_setschedpolicy); - /* zassert_not_null(pthread_attr_setscope); */ /* not implemented */ + zassert_not_null(pthread_attr_setscope); zassert_not_null(pthread_attr_setstack); zassert_not_null(pthread_attr_setstacksize); zassert_not_null(pthread_barrier_destroy);