diff --git a/tests/posix/common/src/main.c b/tests/posix/common/src/main.c index 1d9056bc680..91aaf92cf59 100644 --- a/tests/posix/common/src/main.c +++ b/tests/posix/common/src/main.c @@ -21,6 +21,7 @@ extern void test_posix_pthread_create_negative(void); extern void test_posix_pthread_termination(void); extern void test_posix_multiple_threads_single_key(void); extern void test_posix_single_thread_multiple_keys(void); +extern void test_posix_thread_attr_stacksize(void); extern void test_nanosleep_NULL_NULL(void); extern void test_nanosleep_NULL_notNULL(void); extern void test_nanosleep_notNULL_NULL(void); @@ -45,6 +46,7 @@ void test_main(void) ztest_unit_test(test_posix_pthread_termination), ztest_unit_test(test_posix_multiple_threads_single_key), ztest_unit_test(test_posix_single_thread_multiple_keys), + ztest_unit_test(test_posix_thread_attr_stacksize), ztest_unit_test(test_posix_clock), ztest_unit_test(test_posix_semaphore), ztest_unit_test(test_posix_normal_mutex), diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 4cda28fe34b..aaa6364b8ce 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -531,6 +531,28 @@ void test_posix_pthread_termination(void) zassert_equal(ret, ESRCH, "got attr from terminated thread!"); } +void test_posix_thread_attr_stacksize(void) +{ + size_t act_size; + pthread_attr_t attr; + const size_t exp_size = 0xB105F00D; + + /* TESTPOINT: specify a custom stack size via pthread_attr_t */ + zassert_equal(0, pthread_attr_init(&attr), "pthread_attr_init() failed"); + + if (PTHREAD_STACK_MIN > 0) { + zassert_equal(EINVAL, pthread_attr_setstacksize(&attr, 0), + "pthread_attr_setstacksize() did not fail"); + } + + zassert_equal(0, pthread_attr_setstacksize(&attr, exp_size), + "pthread_attr_setstacksize() failed"); + zassert_equal(0, pthread_attr_getstacksize(&attr, &act_size), + "pthread_attr_getstacksize() failed"); + zassert_equal(exp_size, act_size, "wrong size: act: %zu exp: %zu", + exp_size, act_size); +} + static void *create_thread1(void *p1) { /* do nothing */