Index: compiler-rt/trunk/test/tsan/cond_version.c =================================================================== --- compiler-rt/trunk/test/tsan/cond_version.c +++ compiler-rt/trunk/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 #include #include Index: compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc =================================================================== --- compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc +++ compiler-rt/trunk/test/tsan/real_deadlock_detector_stress_test.cc @@ -8,6 +8,7 @@ #include #include #include +#include const int kThreads = 4; const int kMutexes = 16 << 10; @@ -165,9 +166,9 @@ } 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++) Index: compiler-rt/trunk/test/tsan/setuid2.c =================================================================== --- compiler-rt/trunk/test/tsan/setuid2.c +++ compiler-rt/trunk/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"); Index: compiler-rt/trunk/test/tsan/test.h =================================================================== --- compiler-rt/trunk/test/tsan/test.h +++ compiler-rt/trunk/test/tsan/test.h @@ -6,6 +6,10 @@ #include #include +#ifdef __APPLE__ +#include +#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 @@ 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