[compiler-rt] 0163329 - [TSan] Make `mach_vm_allocate.c` test less flaky

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 15:20:14 PST 2019


Author: Julian Lettner
Date: 2019-11-21T15:19:31-08:00
New Revision: 0163329dbd6c687453a27f72e21512a8c151c5b3

URL: https://github.com/llvm/llvm-project/commit/0163329dbd6c687453a27f72e21512a8c151c5b3
DIFF: https://github.com/llvm/llvm-project/commit/0163329dbd6c687453a27f72e21512a8c151c5b3.diff

LOG: [TSan] Make `mach_vm_allocate.c` test less flaky

rdar://57365733

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c b/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
index 5b1235201bd9..2eab03f81a01 100644
--- a/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
+++ b/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
@@ -24,9 +24,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) {
@@ -39,8 +41,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);


        


More information about the llvm-commits mailing list