[compiler-rt] r358023 - [TSan][libdispatch] Replace CFRunLoop with dispatch_semaphore, pt. 1
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 10:51:55 PDT 2019
Author: yln
Date: Tue Apr 9 10:51:55 2019
New Revision: 358023
URL: http://llvm.org/viewvc/llvm-project?rev=358023&view=rev
Log:
[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
Modified:
compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm
compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm
compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm
compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm
compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm
compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm Tue Apr 9 10:51:55 2019
@@ -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;
}
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm Tue Apr 9 10:51:55 2019
@@ -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.
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm Tue Apr 9 10:51:55 2019
@@ -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.
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm Tue Apr 9 10:51:55 2019
@@ -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");
}
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm Tue Apr 9 10:51:55 2019
@@ -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");
}
Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm?rev=358023&r1=358022&r2=358023&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm Tue Apr 9 10:51:55 2019
@@ -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");
}
More information about the llvm-commits
mailing list