diff options
author | Vitaly Buka <vitalybuka@google.com> | 2023-05-05 16:55:27 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2023-05-05 17:12:17 -0700 |
commit | 74937f24043960d5ad9035ef377b5b8c8e6ceca8 (patch) | |
tree | ef65ef01f1bde0e880e4698783b08c1dc0f6d676 /compiler-rt/test | |
parent | f6ac7e3c6d5bd11c69f4dd2f083f9842fe6b84ae (diff) | |
download | llvm-74937f24043960d5ad9035ef377b5b8c8e6ceca8.tar.gz |
[test][sanitizer] Add tests for join variants
Diffstat (limited to 'compiler-rt/test')
-rw-r--r-- | compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join.cpp new file mode 100644 index 000000000000..ae293225911a --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join.cpp @@ -0,0 +1,50 @@ +// RUN: %clangxx -pthread %s -o %t && %run %t + +// XFAIL: msan + +// REQUIRES: glibc + +#include <assert.h> +#include <ctime> +#include <pthread.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> + +static void *fn(void *args) { + sleep(1); + return (void *)(~(uintptr_t)args); +} + +int main(int argc, char **argv) { + pthread_t thread[4]; + assert(!pthread_create(&thread[0], 0, fn, (void *)1000)); + assert(!pthread_create(&thread[1], 0, fn, (void *)1001)); + assert(!pthread_create(&thread[2], 0, fn, (void *)1002)); + assert(!pthread_create(&thread[3], 0, fn, (void *)1003)); + + assert(!pthread_detach(thread[0])); + + { + void *res; + while (pthread_tryjoin_np(thread[1], &res)) + sleep(1); + assert(~(uintptr_t)res == 1001); + } + + { + void *res; + timespec tm = {0, 1}; + while (pthread_timedjoin_np(thread[2], &res, &tm)) + sleep(1); + assert(~(uintptr_t)res == 1002); + } + + { + void *res; + assert(!pthread_join(thread[3], &res)); + assert(~(uintptr_t)res == 1003); + } + + return 0; +} |