]> git.saurik.com Git - apple/libpthread.git/blame_incremental - tests/main_stack.c
libpthread-454.100.8.tar.gz
[apple/libpthread.git] / tests / main_stack.c
... / ...
CommitLineData
1#include <stdlib.h>
2#include <pthread.h>
3#include "darwintest_defaults.h"
4#include <machine/vmparam.h>
5
6T_DECL(main_stack, "tests the reported values for the main thread stack",
7 T_META_CHECK_LEAKS(NO), T_META_ALL_VALID_ARCHS(YES)){
8 const uintptr_t stackaddr = (uintptr_t)pthread_get_stackaddr_np(pthread_self());
9 const size_t stacksize = pthread_get_stacksize_np(pthread_self());
10 T_LOG("stack: %zx -> %zx (+%zx)", stackaddr - stacksize, stackaddr, stacksize);
11 T_EXPECT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL);
12 T_EXPECT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL);
13
14 struct rlimit lim;
15 T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &lim), NULL);
16 T_EXPECT_EQ((size_t)lim.rlim_cur, pthread_get_stacksize_np(pthread_self()), "reported rlimit should match stacksize");
17
18 lim.rlim_cur = lim.rlim_cur / 8;
19 T_ASSERT_POSIX_SUCCESS(setrlimit(RLIMIT_STACK, &lim), NULL);
20
21 T_EXPECTFAIL;
22 T_EXPECT_EQ((size_t)lim.rlim_cur, pthread_get_stacksize_np(pthread_self()), "new rlimit should should match stacksize");
23}