aboutsummaryrefslogtreecommitdiff
path: root/lib/tsan/tests/rtl/tsan_posix.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tsan/tests/rtl/tsan_posix.cc')
-rw-r--r--lib/tsan/tests/rtl/tsan_posix.cc69
1 files changed, 36 insertions, 33 deletions
diff --git a/lib/tsan/tests/rtl/tsan_posix.cc b/lib/tsan/tests/rtl/tsan_posix.cc
index e1a61b5e43f1..9c0e013e5735 100644
--- a/lib/tsan/tests/rtl/tsan_posix.cc
+++ b/lib/tsan/tests/rtl/tsan_posix.cc
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include "tsan_interface.h"
+#include "tsan_posix_util.h"
#include "tsan_test_util.h"
#include "gtest/gtest.h"
#include <pthread.h>
@@ -30,10 +31,10 @@ struct thread_key {
static void thread_secific_dtor(void *v) {
thread_key *k = (thread_key *)v;
- EXPECT_EQ(pthread_mutex_lock(k->mtx), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(k->mtx), 0);
(*k->cnt)++;
__tsan_write4(&k->cnt);
- EXPECT_EQ(pthread_mutex_unlock(k->mtx), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(k->mtx), 0);
if (k->val == 42) {
// Okay.
} else if (k->val == 43 || k->val == 44) {
@@ -55,22 +56,22 @@ TEST(Posix, ThreadSpecificDtors) {
pthread_key_t key;
EXPECT_EQ(pthread_key_create(&key, thread_secific_dtor), 0);
pthread_mutex_t mtx;
- EXPECT_EQ(pthread_mutex_init(&mtx, 0), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_init(&mtx, 0), 0);
pthread_t th[3];
thread_key k1 = thread_key(key, &mtx, 42, &cnt);
thread_key k2 = thread_key(key, &mtx, 43, &cnt);
thread_key k3 = thread_key(key, &mtx, 44, &cnt);
- EXPECT_EQ(pthread_create(&th[0], 0, dtors_thread, &k1), 0);
- EXPECT_EQ(pthread_create(&th[1], 0, dtors_thread, &k2), 0);
- EXPECT_EQ(pthread_join(th[0], 0), 0);
- EXPECT_EQ(pthread_create(&th[2], 0, dtors_thread, &k3), 0);
- EXPECT_EQ(pthread_join(th[1], 0), 0);
- EXPECT_EQ(pthread_join(th[2], 0), 0);
+ EXPECT_EQ(__interceptor_pthread_create(&th[0], 0, dtors_thread, &k1), 0);
+ EXPECT_EQ(__interceptor_pthread_create(&th[1], 0, dtors_thread, &k2), 0);
+ EXPECT_EQ(__interceptor_pthread_join(th[0], 0), 0);
+ EXPECT_EQ(__interceptor_pthread_create(&th[2], 0, dtors_thread, &k3), 0);
+ EXPECT_EQ(__interceptor_pthread_join(th[1], 0), 0);
+ EXPECT_EQ(__interceptor_pthread_join(th[2], 0), 0);
EXPECT_EQ(pthread_key_delete(key), 0);
EXPECT_EQ(6, cnt);
}
-#ifndef __aarch64__
+#if !defined(__aarch64__) && !defined(__APPLE__)
static __thread int local_var;
static void *local_thread(void *p) {
@@ -81,10 +82,10 @@ static void *local_thread(void *p) {
const int kThreads = 4;
pthread_t th[kThreads];
for (int i = 0; i < kThreads; i++)
- EXPECT_EQ(pthread_create(&th[i], 0, local_thread,
+ EXPECT_EQ(__interceptor_pthread_create(&th[i], 0, local_thread,
(void*)((long)p - 1)), 0); // NOLINT
for (int i = 0; i < kThreads; i++)
- EXPECT_EQ(pthread_join(th[i], 0), 0);
+ EXPECT_EQ(__interceptor_pthread_join(th[i], 0), 0);
return 0;
}
#endif
@@ -92,7 +93,9 @@ static void *local_thread(void *p) {
TEST(Posix, ThreadLocalAccesses) {
// The test is failing with high thread count for aarch64.
// FIXME: track down the issue and re-enable the test.
-#ifndef __aarch64__
+// On Darwin, we're running unit tests without interceptors and __thread is
+// using malloc and free, which causes false data race reports.
+#if !defined(__aarch64__) && !defined(__APPLE__)
local_thread((void*)2);
#endif
}
@@ -106,46 +109,46 @@ struct CondContext {
static void *cond_thread(void *p) {
CondContext &ctx = *static_cast<CondContext*>(p);
- EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(&ctx.m), 0);
EXPECT_EQ(ctx.data, 0);
ctx.data = 1;
- EXPECT_EQ(pthread_cond_signal(&ctx.c), 0);
- EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_signal(&ctx.c), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(&ctx.m), 0);
- EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(&ctx.m), 0);
while (ctx.data != 2)
- EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
- EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_wait(&ctx.c, &ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(&ctx.m), 0);
- EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(&ctx.m), 0);
ctx.data = 3;
EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
- EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(&ctx.m), 0);
return 0;
}
TEST(Posix, CondBasic) {
CondContext ctx;
- EXPECT_EQ(pthread_mutex_init(&ctx.m, 0), 0);
- EXPECT_EQ(pthread_cond_init(&ctx.c, 0), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_init(&ctx.m, 0), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_init(&ctx.c, 0), 0);
ctx.data = 0;
pthread_t th;
- EXPECT_EQ(pthread_create(&th, 0, cond_thread, &ctx), 0);
+ EXPECT_EQ(__interceptor_pthread_create(&th, 0, cond_thread, &ctx), 0);
- EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(&ctx.m), 0);
while (ctx.data != 1)
- EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_wait(&ctx.c, &ctx.m), 0);
ctx.data = 2;
- EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(&ctx.m), 0);
EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
- EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_lock(&ctx.m), 0);
while (ctx.data != 3)
- EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
- EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_wait(&ctx.c, &ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_unlock(&ctx.m), 0);
- EXPECT_EQ(pthread_join(th, 0), 0);
- EXPECT_EQ(pthread_cond_destroy(&ctx.c), 0);
- EXPECT_EQ(pthread_mutex_destroy(&ctx.m), 0);
+ EXPECT_EQ(__interceptor_pthread_join(th, 0), 0);
+ EXPECT_EQ(__interceptor_pthread_cond_destroy(&ctx.c), 0);
+ EXPECT_EQ(__interceptor_pthread_mutex_destroy(&ctx.m), 0);
}