mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 01:29:52 +00:00
[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
This commit is contained in:
parent
a8dd275609
commit
8aa56d3cc8
@ -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>
|
||||
|
@ -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++)
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user