Skip to content

Commit

Permalink
Make mach_vm_allocate.c test less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Lettner authored and yln committed Nov 21, 2019
1 parent 23529f2 commit b192e95
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// RUN: %clang_tsan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'

// REQUIRES: rdar57365733

#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <pthread.h>
Expand All @@ -31,9 +29,11 @@ static int *alloc() {

static void alloc_fixed(int *ptr) {
mach_vm_address_t addr = (mach_vm_address_t)ptr;
kern_return_t res =
mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_FIXED);
assert(res == KERN_SUCCESS);
kern_return_t res;
// Re-allocation via VM_FLAGS_FIXED sporadically fails.
do {
res = mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_FIXED);
} while (res != KERN_SUCCESS);
}

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

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

0 comments on commit b192e95

Please sign in to comment.