diff --git a/compiler-rt/test/tsan/Darwin/gcd-after.mm b/compiler-rt/test/tsan/Darwin/gcd-after.mm --- a/compiler-rt/test/tsan/Darwin/gcd-after.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-after.mm @@ -1,7 +1,9 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %clang_tsan %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' -#import +#include + +#include "../test.h" long my_global; long my_global2; @@ -9,33 +11,29 @@ void callback(void *context) { my_global2 = 42; - dispatch_async(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetMain()); - }); + barrier_wait(&barrier); } int main(int argc, const char *argv[]) { fprintf(stderr, "start\n"); + barrier_init(&barrier, 3); - my_global = 10; dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + + my_global = 10; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{ my_global = 42; - dispatch_async(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetMain()); - }); + barrier_wait(&barrier); }); - CFRunLoopRun(); my_global2 = 10; dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback); - CFRunLoopRun(); + barrier_wait(&barrier); fprintf(stderr, "done\n"); return 0; } // CHECK: start // CHECK: done -// CHECK-NOT: WARNING: ThreadSanitizer diff --git a/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm b/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm --- a/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm @@ -1,26 +1,26 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %clang_tsan %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' -#import +#include + +#include "../test.h" long global; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); + barrier_init(&barrier, 2); global = 42; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ global = 43; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + barrier_wait(&barrier); }); - CFRunLoopRun(); - NSLog(@"Done."); + barrier_wait(&barrier); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. // CHECK: Done. -// CHECK-NOT: WARNING: ThreadSanitizer diff --git a/compiler-rt/test/tsan/Darwin/gcd-async-race.mm b/compiler-rt/test/tsan/Darwin/gcd-async-race.mm --- a/compiler-rt/test/tsan/Darwin/gcd-async-race.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-async-race.mm @@ -1,14 +1,14 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %deflake %run %t 2>&1 | FileCheck %s -#import +#include -#import "../test.h" +#include "../test.h" long global; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); print_address("addr=", 1, &global); barrier_init(&barrier, 2); @@ -22,13 +22,11 @@ barrier_wait(&barrier); global = 44; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + barrier_wait(&barrier); }); - CFRunLoopRun(); - NSLog(@"Done."); + barrier_wait(&barrier); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. diff --git a/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm b/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm --- a/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm @@ -1,9 +1,9 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %deflake %run %t 2>&1 | FileCheck %s -#import +#include -#import "../test.h" +#include "../test.h" long global; @@ -31,13 +31,12 @@ barrier_wait(&barrier); global = 44; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + + barrier_wait(&barrier); }); }); - CFRunLoopRun(); + barrier_wait(&barrier); fprintf(stderr, "Done.\n"); } diff --git a/compiler-rt/test/tsan/Darwin/gcd-barrier.mm b/compiler-rt/test/tsan/Darwin/gcd-barrier.mm --- a/compiler-rt/test/tsan/Darwin/gcd-barrier.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-barrier.mm @@ -1,15 +1,14 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %clang_tsan %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' -#import +#include -#import "../test.h" +#include "../test.h" long global; int main() { fprintf(stderr, "Hello world.\n"); - print_address("addr=", 1, &global); barrier_init(&barrier, 2); dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -19,31 +18,28 @@ dispatch_sync(q, ^{ global = 42; }); - barrier_wait(&barrier); + barrier_wait(&barrier); // A }); dispatch_async(bgq, ^{ - barrier_wait(&barrier); + barrier_wait(&barrier); // A dispatch_barrier_sync(q, ^{ global = 43; }); dispatch_async(bgq, ^{ - barrier_wait(&barrier); + barrier_wait(&barrier); // B global = 44; }); - barrier_wait(&barrier); - - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + barrier_wait(&barrier); // B + + barrier_wait(&barrier); // C }); - CFRunLoopRun(); + barrier_wait(&barrier); // C fprintf(stderr, "Done.\n"); } // CHECK: Hello world. // CHECK: Done. -// CHECK-NOT: WARNING: ThreadSanitizer diff --git a/compiler-rt/test/tsan/Darwin/gcd-blocks.mm b/compiler-rt/test/tsan/Darwin/gcd-blocks.mm --- a/compiler-rt/test/tsan/Darwin/gcd-blocks.mm +++ b/compiler-rt/test/tsan/Darwin/gcd-blocks.mm @@ -1,34 +1,35 @@ -// RUN: %clangxx_tsan %s -o %t -framework Foundation -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %clang_tsan %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' -#import +#include + +#include "../test.h" +#include int main() { fprintf(stderr, "start\n"); + barrier_init(&barrier, 2); dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); - dispatch_queue_t main_q = dispatch_get_main_queue(); + dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL); + assert(background_q != serial_q); dispatch_async(background_q, ^{ __block long block_var = 0; - dispatch_sync(main_q, ^{ + dispatch_sync(serial_q, ^{ block_var = 42; }); fprintf(stderr, "block_var = %ld\n", block_var); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + barrier_wait(&barrier); }); - - CFRunLoopRun(); + + barrier_wait(&barrier); fprintf(stderr, "done\n"); } // CHECK: start // CHECK: block_var = 42 // CHECK: done -// CHECK-NOT: WARNING: ThreadSanitizer -// CHECK-NOT: CHECK failed