summaryrefslogtreecommitdiff
path: root/test/tsan/Darwin
diff options
context:
space:
mode:
authorJulian Lettner <jlettner@apple.com>2019-04-09 17:51:55 +0000
committerJulian Lettner <jlettner@apple.com>2019-04-09 17:51:55 +0000
commit62944fa59dcc3c1041ef577a3a4c3a3f9dc145c5 (patch)
tree70c175e1b4486dc02b81f6d12527812e569cb2de /test/tsan/Darwin
parentc9d0c6ed09a739b61ab6af2dc18534eaf37441d7 (diff)
downloadcompiler-rt-62944fa59dcc3c1041ef577a3a4c3a3f9dc145c5.tar.gz
[TSan][libdispatch] Replace CFRunLoop with dispatch_semaphore, pt. 1
Remove the dependency on Foundation so we can start running those tests on other platforms. Rename/move of tests will be done in a separate commit. Reviewed By: kubamracek, dvyukov Differential Revision: https://reviews.llvm.org/D60347 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@358023 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/Darwin')
-rw-r--r--test/tsan/Darwin/gcd-after.mm23
-rw-r--r--test/tsan/Darwin/gcd-async-norace.mm17
-rw-r--r--test/tsan/Darwin/gcd-async-race.mm17
-rw-r--r--test/tsan/Darwin/gcd-barrier-race.mm13
-rw-r--r--test/tsan/Darwin/gcd-barrier.mm16
-rw-r--r--test/tsan/Darwin/gcd-blocks.mm21
6 files changed, 54 insertions, 53 deletions
diff --git a/test/tsan/Darwin/gcd-after.mm b/test/tsan/Darwin/gcd-after.mm
index 4d66c5085..38c2effca 100644
--- a/test/tsan/Darwin/gcd-after.mm
+++ b/test/tsan/Darwin/gcd-after.mm
@@ -1,37 +1,38 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long my_global;
long my_global2;
+dispatch_semaphore_t done;
void callback(void *context) {
my_global2 = 42;
- dispatch_async(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetMain());
- });
+ dispatch_semaphore_signal(done);
}
int main(int argc, const char *argv[]) {
fprintf(stderr, "start\n");
+ done = dispatch_semaphore_create(0);
- 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());
- });
+ dispatch_semaphore_signal(done);
});
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
my_global2 = 10;
dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "done\n");
return 0;
}
diff --git a/test/tsan/Darwin/gcd-async-norace.mm b/test/tsan/Darwin/gcd-async-norace.mm
index 83f8c0d6f..c3b603579 100644
--- a/test/tsan/Darwin/gcd-async-norace.mm
+++ b/test/tsan/Darwin/gcd-async-norace.mm
@@ -1,24 +1,25 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
int main() {
- NSLog(@"Hello world.");
+ fprintf(stderr, "Hello world.\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
global = 42;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
global = 43;
- 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.
diff --git a/test/tsan/Darwin/gcd-async-race.mm b/test/tsan/Darwin/gcd-async-race.mm
index cb8fb4bf5..ecb2a8007 100644
--- a/test/tsan/Darwin/gcd-async-race.mm
+++ b/test/tsan/Darwin/gcd-async-race.mm
@@ -1,15 +1,16 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.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);
global = 42;
@@ -22,13 +23,11 @@ int main() {
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.
diff --git a/test/tsan/Darwin/gcd-barrier-race.mm b/test/tsan/Darwin/gcd-barrier-race.mm
index c11e147ff..417898a77 100644
--- a/test/tsan/Darwin/gcd-barrier-race.mm
+++ b/test/tsan/Darwin/gcd-barrier-race.mm
@@ -1,15 +1,16 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include "../test.h"
long global;
int main() {
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 q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -31,13 +32,11 @@ int main() {
barrier_wait(&barrier);
global = 44;
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
});
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "Done.\n");
}
diff --git a/test/tsan/Darwin/gcd-barrier.mm b/test/tsan/Darwin/gcd-barrier.mm
index 9d4dcb215..52b115ed3 100644
--- a/test/tsan/Darwin/gcd-barrier.mm
+++ b/test/tsan/Darwin/gcd-barrier.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 <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include "../test.h"
long global;
int main() {
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 q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -34,13 +34,11 @@ int main() {
});
barrier_wait(&barrier);
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+
+ dispatch_semaphore_signal(done);
});
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "Done.\n");
}
diff --git a/test/tsan/Darwin/gcd-blocks.mm b/test/tsan/Darwin/gcd-blocks.mm
index 1aac7e1f2..413b22085 100644
--- a/test/tsan/Darwin/gcd-blocks.mm
+++ b/test/tsan/Darwin/gcd-blocks.mm
@@ -1,29 +1,32 @@
-// RUN: %clangxx_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+#include <assert.h>
int main() {
fprintf(stderr, "start\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
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());
- });
+ dispatch_semaphore_signal(done);
});
-
- CFRunLoopRun();
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "done\n");
}