aboutsummaryrefslogtreecommitdiff
path: root/test/tsan
diff options
context:
space:
mode:
Diffstat (limited to 'test/tsan')
-rw-r--r--test/tsan/global_race.cc6
-rw-r--r--test/tsan/global_race2.cc6
-rw-r--r--test/tsan/global_race3.cc6
-rw-r--r--test/tsan/map32bit.cc3
-rw-r--r--test/tsan/mmap_large.cc4
-rw-r--r--test/tsan/signal_segv_handler.cc39
-rw-r--r--test/tsan/test.h9
7 files changed, 64 insertions, 9 deletions
diff --git a/test/tsan/global_race.cc b/test/tsan/global_race.cc
index d70bee4a556b..3128ec411749 100644
--- a/test/tsan/global_race.cc
+++ b/test/tsan/global_race.cc
@@ -11,9 +11,9 @@ void *Thread(void *a) {
int main() {
barrier_init(&barrier, 2);
- // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
- // match to the format used in the diagnotic message.
- fprintf(stderr, "addr=0x%012lx\n", (unsigned long) GlobalData);
+ fprintf(stderr, "addr=");
+ print_address(GlobalData);
+ fprintf(stderr, "\n");
pthread_t t;
pthread_create(&t, 0, Thread, 0);
GlobalData[2] = 43;
diff --git a/test/tsan/global_race2.cc b/test/tsan/global_race2.cc
index 6631008d85a5..4ab2842e7eef 100644
--- a/test/tsan/global_race2.cc
+++ b/test/tsan/global_race2.cc
@@ -11,9 +11,9 @@ void *Thread(void *a) {
int main() {
barrier_init(&barrier, 2);
- // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
- // match to the format used in the diagnotic message.
- fprintf(stderr, "addr2=0x%012lx\n", (unsigned long) &x);
+ fprintf(stderr, "addr2=");
+ print_address(&x);
+ fprintf(stderr, "\n");
pthread_t t;
pthread_create(&t, 0, Thread, 0);
x = 0;
diff --git a/test/tsan/global_race3.cc b/test/tsan/global_race3.cc
index e7e9a7fef028..1531d7830f78 100644
--- a/test/tsan/global_race3.cc
+++ b/test/tsan/global_race3.cc
@@ -16,9 +16,9 @@ void *Thread(void *a) {
int main() {
barrier_init(&barrier, 2);
- // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
- // match to the format used in the diagnotic message.
- fprintf(stderr, "addr3=0x%012lx\n", (unsigned long) XXX::YYY::ZZZ);
+ fprintf(stderr, "addr3=");
+ print_address(XXX::YYY::ZZZ);
+ fprintf(stderr, "\n");
pthread_t t;
pthread_create(&t, 0, Thread, 0);
XXX::YYY::ZZZ[0] = 0;
diff --git a/test/tsan/map32bit.cc b/test/tsan/map32bit.cc
index 9dae6880e7fe..d9a04655ddca 100644
--- a/test/tsan/map32bit.cc
+++ b/test/tsan/map32bit.cc
@@ -7,6 +7,9 @@
// Test for issue:
// https://code.google.com/p/thread-sanitizer/issues/detail?id=5
+// MAP_32BIT flag for mmap is supported only for x86_64.
+// XFAIL: mips64
+
void *Thread(void *ptr) {
*(int*)ptr = 42;
barrier_wait(&barrier);
diff --git a/test/tsan/mmap_large.cc b/test/tsan/mmap_large.cc
index e715ea666231..4ae4c0863501 100644
--- a/test/tsan/mmap_large.cc
+++ b/test/tsan/mmap_large.cc
@@ -5,7 +5,11 @@
#include <sys/mman.h>
int main() {
+#ifdef __x86_64__
const size_t kLog2Size = 39;
+#elif defined(__mips64)
+ const size_t kLog2Size = 32;
+#endif
const uintptr_t kLocation = 0x40ULL << kLog2Size;
void *p = mmap(
reinterpret_cast<void*>(kLocation),
diff --git a/test/tsan/signal_segv_handler.cc b/test/tsan/signal_segv_handler.cc
new file mode 100644
index 000000000000..2d806eef6764
--- /dev/null
+++ b/test/tsan/signal_segv_handler.cc
@@ -0,0 +1,39 @@
+// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="flush_memory_ms=1 memory_limit_mb=1" %run %t 2>&1 | FileCheck %s
+
+// JVM uses SEGV to preempt threads. All threads do a load from a known address
+// periodically. When runtime needs to preempt threads, it unmaps the page.
+// Threads start triggering SEGV one by one. The signal handler blocks
+// threads while runtime does its thing. Then runtime maps the page again
+// and resumes the threads.
+// Previously this pattern conflicted with stop-the-world machinery,
+// because it briefly reset SEGV handler to SIG_DFL.
+// As the consequence JVM just silently died.
+
+// This test sets memory flushing rate to maximum, then does series of
+// "benign" SEGVs that are handled by signal handler, and ensures that
+// the process survive.
+
+#include "test.h"
+#include <signal.h>
+#include <sys/mman.h>
+
+void *guard;
+
+void handler(int signo, siginfo_t *info, void *uctx) {
+ mprotect(guard, 4096, PROT_READ | PROT_WRITE);
+}
+
+int main() {
+ struct sigaction a;
+ a.sa_sigaction = handler;
+ a.sa_flags = SA_SIGINFO;
+ sigaction(SIGSEGV, &a, 0);
+ guard = mmap(0, 4096, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ for (int i = 0; i < 1000000; i++) {
+ mprotect(guard, 4096, PROT_NONE);
+ *(int*)guard = 1;
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/test/tsan/test.h b/test/tsan/test.h
index 4496e56cda87..bb861b07745e 100644
--- a/test/tsan/test.h
+++ b/test/tsan/test.h
@@ -29,3 +29,12 @@ void barrier_init(pthread_barrier_t *barrier, unsigned count) {
// Default instance of the barrier, but a test can declare more manually.
pthread_barrier_t barrier;
+void print_address(void *address) {
+// On FreeBSD, the %p conversion specifier works as 0x%x and thus does not match
+// to the format used in the diagnotic message.
+#ifdef __x86_64__
+ fprintf(stderr, "0x%012lx", (unsigned long) address);
+#elif defined(__mips64)
+ fprintf(stderr, "0x%010lx", (unsigned long) address);
+#endif
+}