]>
git.saurik.com Git - apple/libpthread.git/blob - tests/stack_size.c
4 #include "darwintest_defaults.h"
7 #define PTHREAD_T_OFFSET (12*1024)
9 #define PTHREAD_T_OFFSET (0)
15 size_t expected_size
= (size_t)(uintptr_t)arg
;
16 T_ASSERT_EQ(pthread_get_stacksize_np(pthread_self()), expected_size
,
17 "saw expected pthread_get_stacksize_np");
21 T_DECL(stack_size_default
, "stack size of default pthread",
22 T_META_ALL_VALID_ARCHS(YES
))
24 static const size_t dflsize
= 512 * 1024;
28 T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr
), NULL
);
29 T_ASSERT_POSIX_ZERO(pthread_create(&thread
, &attr
, function
,
30 (void *)(dflsize
+ PTHREAD_T_OFFSET
)), NULL
);
31 T_ASSERT_POSIX_ZERO(pthread_join(thread
, NULL
), NULL
);
34 T_DECL(stack_size_customsize
, "stack size of thread with custom stack size",
35 T_META_ALL_VALID_ARCHS(YES
))
37 static const size_t stksize
= 768 * 1024;
41 T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr
), NULL
);
42 T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr
, stksize
), NULL
);
43 T_ASSERT_POSIX_ZERO(pthread_create(&thread
, &attr
, function
,
44 (void *)(stksize
+ PTHREAD_T_OFFSET
)), NULL
);
45 T_ASSERT_POSIX_ZERO(pthread_join(thread
, NULL
), NULL
);
48 T_DECL(stack_size_customaddr
, "stack size of thread with custom stack addr",
49 T_META_ALL_VALID_ARCHS(YES
))
51 static const size_t stksize
= 512 * 1024;
55 uintptr_t stackaddr
= (uintptr_t)valloc(stksize
);
56 stackaddr
+= stksize
; // address is top of stack
58 T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr
), NULL
);
59 T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr
, (void *)stackaddr
),
61 T_ASSERT_POSIX_ZERO(pthread_create(&thread
, &attr
, function
,
62 (void *)stksize
), NULL
);
63 T_ASSERT_POSIX_ZERO(pthread_join(thread
, NULL
), NULL
);
64 free((void *)(stackaddr
- stksize
));
67 T_DECL(stack_size_custom
, "stack size of thread with custom stack addr+size",
68 T_META_ALL_VALID_ARCHS(YES
))
70 static const size_t stksize
= 768 * 1024;
74 uintptr_t stackaddr
= (uintptr_t)valloc(stksize
);
75 stackaddr
+= stksize
; // address is top of stack
77 T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr
), NULL
);
78 T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr
, (void *)stackaddr
),
80 T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr
, stksize
), NULL
);
81 T_ASSERT_POSIX_ZERO(pthread_create(&thread
, &attr
, function
,
82 (void *)stksize
), NULL
);
83 T_ASSERT_POSIX_ZERO(pthread_join(thread
, NULL
), NULL
);
84 free((void *)(stackaddr
- stksize
));