aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Lettner <jlettner@apple.com>2019-03-18 21:55:41 +0000
committerJulian Lettner <jlettner@apple.com>2019-03-18 21:55:41 +0000
commit181435565595a637f524a5a18fd12d9b52568f33 (patch)
tree7a76e3c0be41fe88fd5a14e8c5f531c65b7c41f8
parent61b302f94fd9983651bf210c8a1c0b116612022a (diff)
downloadllvm-181435565595a637f524a5a18fd12d9b52568f33.zip
llvm-181435565595a637f524a5a18fd12d9b52568f33.tar.gz
llvm-181435565595a637f524a5a18fd12d9b52568f33.tar.bz2
[NFC][TSan][libdispatch] Fix test for dispatch_apply[_f]
* Array index out of bounds: 100 iterations, but size of array is 2. * Unmatched barrier_init (2) with barrier_wait (200) * Number of iterations must be smaller than the available parallelism for the queue, otherwise we deadlock (since every barrier_wait call blocks the thread). Scary: All of this worked reliably in gcd-apply.mm (for Darwin) Rievewed By: kubamracek Differential Revision: https://reviews.llvm.org/D59510 llvm-svn: 356418
-rw-r--r--compiler-rt/test/tsan/libdispatch/apply.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/compiler-rt/test/tsan/libdispatch/apply.c b/compiler-rt/test/tsan/libdispatch/apply.c
index d5c991f..d361169 100644
--- a/compiler-rt/test/tsan/libdispatch/apply.c
+++ b/compiler-rt/test/tsan/libdispatch/apply.c
@@ -1,16 +1,13 @@
// RUN: %clang_tsan %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-
-// TODO(yln): Deadlocks while gcd-apply.mm does not. What's the difference
-// between C and Obj-C compiler?
-// REQUIRES: disable
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
#include <dispatch/dispatch.h>
#include "../test.h"
+const size_t size = 2;
long global;
-long array[2];
+long array[size];
void callback(void *context, size_t i) {
long n = global;
@@ -19,7 +16,6 @@ void callback(void *context, size_t i) {
}
int main(int argc, const char *argv[]) {
- barrier_init(&barrier, 2);
fprintf(stderr, "start\n");
// Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
@@ -29,24 +25,34 @@ int main(int argc, const char *argv[]) {
global = 42;
- dispatch_apply(100, q, ^(size_t i) {
+ barrier_init(&barrier, size);
+ dispatch_apply(size, q, ^(size_t i) {
long n = global;
array[i] = n + i;
barrier_wait(&barrier);
});
- for (int i = 0; i < 100; i++) {
- fprintf(stderr, "array[%d] = %ld\n", i, array[i]);
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
}
- global = 43;
+ global = 142;
+
+ barrier_init(&barrier, size);
+ dispatch_apply_f(size, q, NULL, &callback);
- dispatch_apply_f(100, q, NULL, &callback);
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
+ }
fprintf(stderr, "done\n");
return 0;
}
// CHECK: start
+// CHECK: array[0] = 42
+// CHECK: array[1] = 43
+// CHECK: array[0] = 142
+// CHECK: array[1] = 143
// CHECK: done
// CHECK-NOT: WARNING: ThreadSanitizer