From b702c8e8f01f09cb73ef554b129db0773f9f98a5 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Fri, 22 Dec 2023 15:03:25 -0500 Subject: [PATCH] tests: posix: pthread: test that big stacks can be allocated In some cases, users want to allocate (comparatively) massive thread stacks. Add a test to ensure we can allocate such a stack by default. Signed-off-by: Christopher Friedt --- tests/posix/common/src/pthread.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index cdaed3eba2e030..f8fe650ceebd14 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -18,7 +18,7 @@ #define ONE_SECOND 1 /* arbitrary number that is also a legal stack size */ -#define OKAY_STACK_SIZE (STACKS + 42) +#define OKAY_STACK_SIZE (STACKS + 1) /* Macros to test invalid states */ #define PTHREAD_CANCEL_INVALID -1 @@ -959,11 +959,14 @@ ZTEST(posix_apis, test_pthread_attr_setguardsize) size_t size_after; size_t size_before; pthread_attr_t attr; - size_t sizes[] = {0, OKAY_STACK_SIZE, UINT16_MAX}; + size_t sizes[] = {0, BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS / 2), + BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS)}; attr = (pthread_attr_t){0}; zassert_equal(pthread_attr_setguardsize(&attr, 0), EINVAL); zassert_ok(pthread_attr_init(&attr)); + zassert_ok(pthread_attr_getguardsize(&attr, &size_before)); + zassert_equal(size_before, CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT); zassert_equal(pthread_attr_setguardsize(NULL, SIZE_MAX), EINVAL); zassert_equal(pthread_attr_setguardsize(NULL, 0), EINVAL); zassert_equal(pthread_attr_setguardsize(&attr, SIZE_MAX), EINVAL); @@ -976,3 +979,16 @@ ZTEST(posix_apis, test_pthread_attr_setguardsize) } zassert_ok(pthread_attr_destroy(&attr)); } + +ZTEST(posix_apis, test_pthread_attr_large_stacksize) +{ + size_t actual_size; + const size_t expect_size = BIT(CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS); + pthread_attr_t attr; + + zassert_ok(pthread_attr_init(&attr)); + zassert_ok(pthread_attr_setstacksize(&attr, expect_size)); + zassert_ok(pthread_attr_getstacksize(&attr, &actual_size)); + zassert_equal(actual_size, expect_size); + zassert_ok(pthread_attr_destroy(&attr)); +}