TSAN: add new test
authorMichael de Lang <kingoipo@gmail.com>
Fri, 14 May 2021 10:09:45 +0000 (12:09 +0200)
committerMartin Liska <mliska@suse.cz>
Fri, 14 May 2021 10:09:58 +0000 (12:09 +0200)
gcc/testsuite/ChangeLog:

* g++.dg/tsan/pthread_cond_clockwait.C: New test.

gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C
new file mode 100644 (file)
index 0000000..82d6a5c
--- /dev/null
@@ -0,0 +1,31 @@
+// Test pthread_cond_clockwait not generating false positives with tsan
+// { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && pthread } } }
+// { dg-options "-fsanitize=thread -lpthread" }
+
+#include <pthread.h>
+
+pthread_cond_t cv;
+pthread_mutex_t mtx;
+
+void *fn(void *vp) {
+    pthread_mutex_lock(&mtx);
+    pthread_cond_signal(&cv);
+    pthread_mutex_unlock(&mtx);
+    return NULL;
+}
+
+int main() {
+    pthread_mutex_lock(&mtx);
+
+    pthread_t tid;
+    pthread_create(&tid, NULL, fn, NULL);
+
+    struct timespec ts;
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+    ts.tv_sec += 10;
+    pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts);
+    pthread_mutex_unlock(&mtx);
+
+    pthread_join(tid, NULL);
+    return 0;
+}