[compiler-rt] 74937f2 - [test][sanitizer] Add tests for join variants
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri May 5 17:13:01 PDT 2023
Author: Vitaly Buka
Date: 2023-05-05T17:12:17-07:00
New Revision: 74937f24043960d5ad9035ef377b5b8c8e6ceca8
URL: https://github.com/llvm/llvm-project/commit/74937f24043960d5ad9035ef377b5b8c8e6ceca8
DIFF: https://github.com/llvm/llvm-project/commit/74937f24043960d5ad9035ef377b5b8c8e6ceca8.diff
LOG: [test][sanitizer] Add tests for join variants
Added:
compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join.cpp
Modified:
Removed:
################################################################################
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 0000000000000..ae293225911a7
--- /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;
+}
More information about the llvm-commits
mailing list