Fix pthread_attr_getstack__main_thread failure on glibc.

Move test of bionic specific implementation into bionic ifdef.

Bug: 19805726
Change-Id: Idf369b16e7f41f060c75b0aaf34e05cf3c161aa9
This commit is contained in:
Yabin Cui 2015-05-19 15:09:23 -07:00
parent c02bdc76a2
commit b0c6f2dba2

View File

@ -1154,6 +1154,7 @@ TEST(pthread, pthread_attr_getstack__main_thread) {
// The two methods of asking for the stack size should agree. // The two methods of asking for the stack size should agree.
EXPECT_EQ(stack_size, stack_size2); EXPECT_EQ(stack_size, stack_size2);
#if defined(__BIONIC__)
// What does /proc/self/maps' [stack] line say? // What does /proc/self/maps' [stack] line say?
void* maps_stack_hi = NULL; void* maps_stack_hi = NULL;
FILE* fp = fopen("/proc/self/maps", "r"); FILE* fp = fopen("/proc/self/maps", "r");
@ -1170,15 +1171,18 @@ TEST(pthread, pthread_attr_getstack__main_thread) {
} }
fclose(fp); fclose(fp);
// The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
// Remember that the stack grows down (and is mapped in on demand), so the low address of the
// region isn't very interesting.
EXPECT_EQ(maps_stack_hi, reinterpret_cast<uint8_t*>(stack_base) + stack_size);
// The stack size should correspond to RLIMIT_STACK. // The stack size should correspond to RLIMIT_STACK.
rlimit rl; rlimit rl;
ASSERT_EQ(0, getrlimit(RLIMIT_STACK, &rl)); ASSERT_EQ(0, getrlimit(RLIMIT_STACK, &rl));
uint64_t original_rlim_cur = rl.rlim_cur; uint64_t original_rlim_cur = rl.rlim_cur;
#if defined(__BIONIC__)
if (rl.rlim_cur == RLIM_INFINITY) { if (rl.rlim_cur == RLIM_INFINITY) {
rl.rlim_cur = 8 * 1024 * 1024; // Bionic reports unlimited stacks as 8MiB. rl.rlim_cur = 8 * 1024 * 1024; // Bionic reports unlimited stacks as 8MiB.
} }
#endif
EXPECT_EQ(rl.rlim_cur, stack_size); EXPECT_EQ(rl.rlim_cur, stack_size);
auto guard = make_scope_guard([&rl, original_rlim_cur]() { auto guard = make_scope_guard([&rl, original_rlim_cur]() {
@ -1186,11 +1190,6 @@ TEST(pthread, pthread_attr_getstack__main_thread) {
ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl)); ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
}); });
// The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
// Remember that the stack grows down (and is mapped in on demand), so the low address of the
// region isn't very interesting.
EXPECT_EQ(maps_stack_hi, reinterpret_cast<uint8_t*>(stack_base) + stack_size);
// //
// What if RLIMIT_STACK is smaller than the stack's current extent? // What if RLIMIT_STACK is smaller than the stack's current extent?
// //
@ -1218,6 +1217,7 @@ TEST(pthread, pthread_attr_getstack__main_thread) {
EXPECT_EQ(stack_size, stack_size2); EXPECT_EQ(stack_size, stack_size2);
ASSERT_EQ(6666U, stack_size); ASSERT_EQ(6666U, stack_size);
#endif
} }
static void pthread_attr_getstack_18908062_helper(void*) { static void pthread_attr_getstack_18908062_helper(void*) {