diff options
| author | Kuba Brecka <kuba.brecka@gmail.com> | 2015-11-20 11:07:16 +0000 |
|---|---|---|
| committer | Kuba Brecka <kuba.brecka@gmail.com> | 2015-11-20 11:07:16 +0000 |
| commit | 8aa56d3cc878bf230bb2d732d214deaaadc59af2 (patch) | |
| tree | 6e626c7d83b0cadf9a0a50ac1b224146605b899c | |
| parent | a8dd27560998b96d97991f5201bd6e03bd9d9906 (diff) | |
| download | bcm5719-llvm-8aa56d3cc878bf230bb2d732d214deaaadc59af2.tar.gz bcm5719-llvm-8aa56d3cc878bf230bb2d732d214deaaadc59af2.zip | |
[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
llvm-svn: 253658
| -rw-r--r-- | compiler-rt/test/tsan/cond_version.c | 3 | ||||
| -rw-r--r-- | compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc | 7 | ||||
| -rw-r--r-- | compiler-rt/test/tsan/setuid2.c | 10 | ||||
| -rw-r--r-- | compiler-rt/test/tsan/test.h | 18 |
4 files changed, 30 insertions, 8 deletions
diff --git a/compiler-rt/test/tsan/cond_version.c b/compiler-rt/test/tsan/cond_version.c index 2282c3ad738..6bae776e6a4 100644 --- a/compiler-rt/test/tsan/cond_version.c +++ b/compiler-rt/test/tsan/cond_version.c @@ -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> diff --git a/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc b/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc index 5576f125897..feb1117e80a 100644 --- a/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc +++ b/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc @@ -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++) diff --git a/compiler-rt/test/tsan/setuid2.c b/compiler-rt/test/tsan/setuid2.c index ad42db53f42..9dbb6577e1c 100644 --- a/compiler-rt/test/tsan/setuid2.c +++ b/compiler-rt/test/tsan/setuid2.c @@ -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"); diff --git a/compiler-rt/test/tsan/test.h b/compiler-rt/test/tsan/test.h index 27f6573d464..aae7ad7d171 100644 --- a/compiler-rt/test/tsan/test.h +++ b/compiler-rt/test/tsan/test.h @@ -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 |

