Skip to content

Commit b192e95

Browse files
Julian Lettneryln
Julian Lettner
authored andcommitted
Make mach_vm_allocate.c test less flaky
1 parent 23529f2 commit b192e95

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler-rt/test/tsan/Darwin/mach_vm_allocate.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// RUN: %clang_tsan %s -o %t
44
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
55

6-
// REQUIRES: rdar57365733
7-
86
#include <mach/mach.h>
97
#include <mach/mach_vm.h>
108
#include <pthread.h>
@@ -31,9 +29,11 @@ static int *alloc() {
3129

3230
static void alloc_fixed(int *ptr) {
3331
mach_vm_address_t addr = (mach_vm_address_t)ptr;
34-
kern_return_t res =
35-
mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_FIXED);
36-
assert(res == KERN_SUCCESS);
32+
kern_return_t res;
33+
// Re-allocation via VM_FLAGS_FIXED sporadically fails.
34+
do {
35+
res = mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_FIXED);
36+
} while (res != KERN_SUCCESS);
3737
}
3838

3939
static void dealloc(int *ptr) {
@@ -46,8 +46,9 @@ static void *Thread(void *arg) {
4646
*global_ptr = 7; // Assignment 1
4747

4848
// We want to test that TSan does not report a race between the two
49-
// assignments to global_ptr when memory is re-allocated here. The calls to
50-
// the API itself are racy though, so ignore them.
49+
// assignments to *global_ptr when the underlying memory is re-allocated
50+
// between assignments. The calls to the API itself are racy though, so ignore
51+
// them.
5152
AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
5253
dealloc(global_ptr);
5354
alloc_fixed(global_ptr);

0 commit comments

Comments
 (0)