Skip to content

Commit 385aa01

Browse files
[Asan] Ensure minimum stack size 128KB in ThreadedStressStackReuseTest (#165198)
Asan test `ThreadedStressStackReuseTest ` fails on AIX due to smaller default thread stack size. Set thread stack size to a minimum of 128KB to ensure reliable test behavior across platforms (platforms with smaller default thread stack size). --------- Co-authored-by: Riyaz Ahmad <[email protected]>
1 parent 5eb8d29 commit 385aa01

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

compiler-rt/lib/asan/tests/asan_test.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,15 +1115,28 @@ TEST(AddressSanitizer, StressStackReuseTest) {
11151115
LotsOfStackReuse();
11161116
}
11171117

1118+
// On some platform (ex: AIX), the default thread stack size (~96 KB) is
1119+
// insufficient for this test and can lead to stack overflows.
1120+
#define MIN_STACK_SIZE (128 * 1024) // 128 KB
11181121
TEST(AddressSanitizer, ThreadedStressStackReuseTest) {
11191122
const int kNumThreads = 20;
11201123
pthread_t t[kNumThreads];
1124+
size_t curStackSize = 0;
1125+
pthread_attr_t attr;
1126+
pthread_attr_init(&attr);
1127+
// Get the current (default) thread stack size
1128+
pthread_attr_getstacksize(&attr, &curStackSize);
1129+
if (curStackSize < MIN_STACK_SIZE) {
1130+
int rc = pthread_attr_setstacksize(&attr, MIN_STACK_SIZE);
1131+
ASSERT_EQ(0, rc);
1132+
}
11211133
for (int i = 0; i < kNumThreads; i++) {
1122-
PTHREAD_CREATE(&t[i], 0, (void* (*)(void *x))LotsOfStackReuse, 0);
1134+
PTHREAD_CREATE(&t[i], &attr, (void* (*)(void* x))LotsOfStackReuse, 0);
11231135
}
11241136
for (int i = 0; i < kNumThreads; i++) {
11251137
PTHREAD_JOIN(t[i], 0);
11261138
}
1139+
pthread_attr_destroy(&attr);
11271140
}
11281141

11291142
// pthread_exit tries to perform unwinding stuff that leads to dlopen'ing

0 commit comments

Comments
 (0)