Index: compiler-rt/trunk/test/tsan/Darwin/gcd-groups-norace.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-groups-norace.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-groups-norace.mm @@ -1,15 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" -#import "../test.h" +#include long global; int main() { - NSLog(@"Hello world."); - NSLog(@"addr=%p\n", &global); + fprintf(stderr, "Hello world.\n"); + dispatch_semaphore_t done = dispatch_semaphore_create(0); dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); global = 42; @@ -39,13 +39,11 @@ dispatch_group_notify(g, q, ^{ global = 48; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-serial-queue-norace.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-serial-queue-norace.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-serial-queue-norace.mm @@ -1,15 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" -#import "../test.h" +#include long global; int main() { - NSLog(@"Hello world."); - NSLog(@"addr=%p\n", &global); + fprintf(stderr, "Hello world.\n"); + dispatch_semaphore_t done = dispatch_semaphore_create(0); dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT); dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL); @@ -26,13 +26,11 @@ } dispatch_barrier_async(q1, ^{ - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel.mm @@ -1,11 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; int main(int argc, const char *argv[]) { + dispatch_semaphore_t done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -19,15 +23,13 @@ dispatch_source_set_cancel_handler(source, ^{ fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); dispatch_resume(source); dispatch_cancel(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel2.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel2.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-cancel2.mm @@ -1,19 +1,22 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; +dispatch_semaphore_t done; void handler(void *arg) { fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); } int main(int argc, const char *argv[]) { + done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -29,7 +32,7 @@ dispatch_resume(source); dispatch_cancel(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-event.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-event.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-event.mm @@ -1,11 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; int main(int argc, const char *argv[]) { + dispatch_semaphore_t done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -19,14 +23,12 @@ dispatch_source_set_event_handler(source, ^{ fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); dispatch_resume(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-event2.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-event2.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-event2.mm @@ -1,19 +1,22 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; +dispatch_semaphore_t done; void handler(void *arg) { fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); } int main(int argc, const char *argv[]) { + done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -28,7 +31,7 @@ dispatch_resume(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration.mm @@ -1,11 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; int main(int argc, const char *argv[]) { + dispatch_semaphore_t done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -17,14 +21,12 @@ dispatch_source_set_registration_handler(source, ^{ fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); dispatch_resume(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration2.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration2.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-source-registration2.mm @@ -1,19 +1,22 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; +dispatch_semaphore_t done; void handler(void *arg) { fprintf(stderr, "global = %ld\n", global); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); } int main(int argc, const char *argv[]) { + done = dispatch_semaphore_create(0); + dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -26,7 +29,7 @@ dispatch_resume(source); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-sync-norace.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-sync-norace.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-sync-norace.mm @@ -1,30 +1,35 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; static const long nIter = 1000; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); + dispatch_semaphore_t done = dispatch_semaphore_create(0); + + dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL); global = 42; for (int i = 0; i < nIter; i++) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - dispatch_sync(dispatch_get_main_queue(), ^{ + dispatch_sync(serial_q, ^{ global = i; if (i == nIter - 1) { - CFRunLoopStop(CFRunLoopGetCurrent()); + dispatch_semaphore_signal(done); } }); }); } - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-sync-race.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-sync-race.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-sync-race.mm @@ -1,15 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %deflake %run %t 2>&1 | FileCheck %s -#import - -#import "../test.h" +#include "dispatch/dispatch.h" +#include "../test.h" long global; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); print_address("addr=", 1, &global); + dispatch_semaphore_t done = dispatch_semaphore_create(0); barrier_init(&barrier, 2); dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT); @@ -27,14 +27,12 @@ barrier_wait(&barrier); global = 44; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); }); - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-target-queue-norace.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-target-queue-norace.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-target-queue-norace.mm @@ -1,11 +1,14 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; int main(int argc, const char *argv[]) { + dispatch_semaphore_t done = dispatch_semaphore_create(0); dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT); dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT); @@ -17,25 +20,22 @@ global++; if (global == 200000) { - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); } }); dispatch_async(q2, ^{ global++; if (global == 200000) { - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); } }); } - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); return 0; } // CHECK-NOT: WARNING: ThreadSanitizer +// CHECK: Done.