[compiler-rt] r253658 - [tsan] Make tests that use CLOCK_MONOTONIC portable
Kuba Brecka via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 20 03:07:16 PST 2015
Author: kuba.brecka
Date: Fri Nov 20 05:07:16 2015
New Revision: 253658
URL: http://llvm.org/viewvc/llvm-project?rev=253658&view=rev
Log:
[tsan] Make tests that use CLOCK_MONOTONIC portable
Several tests rely on CLOCK_MONOTONIC, which doesn't exist on OS X. This patch fixes these tests by either disabling them (in case of cond_version.c which doesn't make sense on OS X), or by porting the test to also work on OS X.
Differential Revision: http://reviews.llvm.org/D14861
Modified:
compiler-rt/trunk/test/tsan/cond_version.c
compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc
compiler-rt/trunk/test/tsan/setuid2.c
compiler-rt/trunk/test/tsan/test.h
Modified: compiler-rt/trunk/test/tsan/cond_version.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cond_version.c?rev=253658&r1=253657&r2=253658&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/cond_version.c (original)
+++ compiler-rt/trunk/test/tsan/cond_version.c Fri Nov 20 05:07:16 2015
@@ -3,6 +3,9 @@
// previously there were issues with versioned symbols.
// CHECK: OK
+// OS X doesn't have pthread_condattr_setclock.
+// UNSUPPORTED: darwin
+
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
Modified: compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc?rev=253658&r1=253657&r2=253658&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc (original)
+++ compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc Fri Nov 20 05:07:16 2015
@@ -8,6 +8,7 @@
#include <errno.h>
#include <vector>
#include <algorithm>
+#include <sys/time.h>
const int kThreads = 4;
const int kMutexes = 16 << 10;
@@ -165,9 +166,9 @@ void *Thread(void *seed) {
}
int main() {
- timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- unsigned s = (unsigned)ts.tv_nsec;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ unsigned s = tv.tv_sec + tv.tv_usec;
fprintf(stderr, "seed %d\n", s);
srand(s);
for (int i = 0; i < kMutexes; i++)
Modified: compiler-rt/trunk/test/tsan/setuid2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/setuid2.c?rev=253658&r1=253657&r2=253658&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/setuid2.c (original)
+++ compiler-rt/trunk/test/tsan/setuid2.c Fri Nov 20 05:07:16 2015
@@ -7,11 +7,11 @@
// Test that setuid call works in presence of stoptheworld.
int main() {
- struct timespec tp0, tp1;
- clock_gettime(CLOCK_MONOTONIC, &tp0);
- clock_gettime(CLOCK_MONOTONIC, &tp1);
- while (tp1.tv_sec - tp0.tv_sec < 3) {
- clock_gettime(CLOCK_MONOTONIC, &tp1);
+ unsigned long long tp0, tp1;
+ tp0 = monotonic_clock_ns();
+ tp1 = monotonic_clock_ns();
+ while (tp1 - tp0 < 3 * 1000000000ull) {
+ tp1 = monotonic_clock_ns();
setuid(0);
}
fprintf(stderr, "DONE\n");
Modified: compiler-rt/trunk/test/tsan/test.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/test.h?rev=253658&r1=253657&r2=253658&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/test.h (original)
+++ compiler-rt/trunk/test/tsan/test.h Fri Nov 20 05:07:16 2015
@@ -6,6 +6,10 @@
#include <stddef.h>
#include <sched.h>
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
+
// TSan-invisible barrier.
// Tests use it to establish necessary execution order in a way that does not
// interfere with tsan (does not establish synchronization between threads).
@@ -60,3 +64,17 @@ void print_address(void *address) {
fprintf(stderr, format, (unsigned long) address);
#endif
}
+
+#ifdef __APPLE__
+unsigned long long monotonic_clock_ns() {
+ static mach_timebase_info_data_t timebase_info;
+ if (timebase_info.denom == 0) mach_timebase_info(&timebase_info);
+ return (mach_absolute_time() * timebase_info.numer) / timebase_info.denom;
+}
+#else
+unsigned long long monotonic_clock_ns() {
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return (unsigned long long)t.tv_sec * 1000000000ull + t.tv_nsec;
+}
+#endif
More information about the llvm-commits
mailing list