Skip to content

Commit b702c8e

Browse files
committed
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 <[email protected]>
1 parent fcd139d commit b702c8e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tests/posix/common/src/pthread.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define ONE_SECOND 1
1919

2020
/* arbitrary number that is also a legal stack size */
21-
#define OKAY_STACK_SIZE (STACKS + 42)
21+
#define OKAY_STACK_SIZE (STACKS + 1)
2222

2323
/* Macros to test invalid states */
2424
#define PTHREAD_CANCEL_INVALID -1
@@ -959,11 +959,14 @@ ZTEST(posix_apis, test_pthread_attr_setguardsize)
959959
size_t size_after;
960960
size_t size_before;
961961
pthread_attr_t attr;
962-
size_t sizes[] = {0, OKAY_STACK_SIZE, UINT16_MAX};
962+
size_t sizes[] = {0, BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS / 2),
963+
BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS)};
963964

964965
attr = (pthread_attr_t){0};
965966
zassert_equal(pthread_attr_setguardsize(&attr, 0), EINVAL);
966967
zassert_ok(pthread_attr_init(&attr));
968+
zassert_ok(pthread_attr_getguardsize(&attr, &size_before));
969+
zassert_equal(size_before, CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT);
967970
zassert_equal(pthread_attr_setguardsize(NULL, SIZE_MAX), EINVAL);
968971
zassert_equal(pthread_attr_setguardsize(NULL, 0), EINVAL);
969972
zassert_equal(pthread_attr_setguardsize(&attr, SIZE_MAX), EINVAL);
@@ -976,3 +979,16 @@ ZTEST(posix_apis, test_pthread_attr_setguardsize)
976979
}
977980
zassert_ok(pthread_attr_destroy(&attr));
978981
}
982+
983+
ZTEST(posix_apis, test_pthread_attr_large_stacksize)
984+
{
985+
size_t actual_size;
986+
const size_t expect_size = BIT(CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS);
987+
pthread_attr_t attr;
988+
989+
zassert_ok(pthread_attr_init(&attr));
990+
zassert_ok(pthread_attr_setstacksize(&attr, expect_size));
991+
zassert_ok(pthread_attr_getstacksize(&attr, &actual_size));
992+
zassert_equal(actual_size, expect_size);
993+
zassert_ok(pthread_attr_destroy(&attr));
994+
}

0 commit comments

Comments
 (0)