diff options
author | Vlad Tsyrklevich <vlad@tsyrklevich.net> | 2018-09-21 19:02:32 +0000 |
---|---|---|
committer | Vlad Tsyrklevich <vlad@tsyrklevich.net> | 2018-09-21 19:02:32 +0000 |
commit | 278a3aad4c33c0a69acbec3b952c58dae7ba4d5d (patch) | |
tree | bc156951b9e7e8855c91fe40550f1975ef90f665 | |
parent | c199a590f1589f552ee3a045f6db7e5e87ba6b8e (diff) |
SafeStack: Fix flaky test (PR39001)
Summary:
pthread_join() can return before a thread finishes exit()ing in the
kernel and a subsequent tgkill() can report the thread still alive.
Update the pthread-cleanup.c test to sleep and retry if it hits this
possible flake.
Thanks to Jeremy Morse for reporting.
Reviewers: jmorse, eugenis, vitalybuka
Reviewed By: jmorse, vitalybuka
Subscribers: delcypher, jfb, llvm-commits, #sanitizers, kcc
Differential Revision: https://reviews.llvm.org/D52330
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@342763 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/safestack/pthread-cleanup.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/test/safestack/pthread-cleanup.c b/test/safestack/pthread-cleanup.c index efa42bff6..55c5b42dc 100644 --- a/test/safestack/pthread-cleanup.c +++ b/test/safestack/pthread-cleanup.c @@ -29,18 +29,26 @@ int main(int argc, char **argv) if (pthread_join(t1, &t1_buffer)) abort(); + // Stack has not yet been deallocated memset(t1_buffer, 0, kBufferSize); if (arg == 0) return 0; - if (pthread_create(&t2, NULL, start, NULL)) - abort(); - // Second thread destructor cleans up the first thread's stack. - if (pthread_join(t2, NULL)) - abort(); - - // should segfault here - memset(t1_buffer, 0, kBufferSize); + for (int i = 0; i < 3; i++) { + if (pthread_create(&t2, NULL, start, NULL)) + abort(); + // Second thread destructor cleans up the first thread's stack. + if (pthread_join(t2, NULL)) + abort(); + + // Should segfault here + memset(t1_buffer, 0, kBufferSize); + + // PR39001: Re-try in the rare case that pthread_join() returns before the + // thread finishes exiting in the kernel--hence the tgkill() check for t1 + // returns that it's alive despite pthread_join() returning. + sleep(1); + } return 0; } |