diff options
Diffstat (limited to 'deps/uv/test/test-thread.c')
-rw-r--r-- | deps/uv/test/test-thread.c | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/deps/uv/test/test-thread.c b/deps/uv/test/test-thread.c index 955c9f2f1b..be72d5e8b3 100644 --- a/deps/uv/test/test-thread.c +++ b/deps/uv/test/test-thread.c @@ -26,6 +26,10 @@ #include <stdlib.h> #include <string.h> /* memset */ +#ifdef __POSIX__ +#include <pthread.h> +#endif + struct getaddrinfo_req { uv_thread_t thread_id; unsigned int counter; @@ -207,10 +211,15 @@ TEST_IMPL(thread_local_storage) { static void thread_check_stack(void* arg) { #if defined(__APPLE__) + size_t expected; + expected = arg == NULL ? 0 : ((uv_thread_options_t*)arg)->stack_size; /* 512 kB is the default stack size of threads other than the main thread * on MacOS. */ - ASSERT(pthread_get_stacksize_np(pthread_self()) > 512*1024); + if (expected == 0) + expected = 512 * 1024; + ASSERT(pthread_get_stacksize_np(pthread_self()) >= expected); #elif defined(__linux__) && defined(__GLIBC__) + size_t expected; struct rlimit lim; size_t stack_size; pthread_attr_t attr; @@ -219,7 +228,10 @@ static void thread_check_stack(void* arg) { lim.rlim_cur = 2 << 20; /* glibc default. */ ASSERT(0 == pthread_getattr_np(pthread_self(), &attr)); ASSERT(0 == pthread_attr_getstacksize(&attr, &stack_size)); - ASSERT(stack_size >= lim.rlim_cur); + expected = arg == NULL ? 0 : ((uv_thread_options_t*)arg)->stack_size; + if (expected == 0) + expected = (size_t)lim.rlim_cur; + ASSERT(stack_size >= expected); #endif } @@ -230,3 +242,44 @@ TEST_IMPL(thread_stack_size) { ASSERT(0 == uv_thread_join(&thread)); return 0; } + +TEST_IMPL(thread_stack_size_explicit) { + uv_thread_t thread; + uv_thread_options_t options; + + options.flags = UV_THREAD_HAS_STACK_SIZE; + options.stack_size = 1024 * 1024; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = 8 * 1024 * 1024; /* larger than most default os sizes */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = 0; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + +#ifdef PTHREAD_STACK_MIN + options.stack_size = PTHREAD_STACK_MIN - 42; /* unaligned size */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = PTHREAD_STACK_MIN / 2 - 42; /* unaligned size */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); +#endif + + /* unaligned size, should be larger than PTHREAD_STACK_MIN */ + options.stack_size = 1234567; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + return 0; +} |