[compiler-rt] 764b35d - tsan: extend mmap test

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 24 01:57:26 PST 2021


Author: Dmitry Vyukov
Date: 2021-11-24T10:57:21+01:00
New Revision: 764b35d89f57a9052d84898422a865dc2e08edca

URL: https://github.com/llvm/llvm-project/commit/764b35d89f57a9052d84898422a865dc2e08edca
DIFF: https://github.com/llvm/llvm-project/commit/764b35d89f57a9052d84898422a865dc2e08edca.diff

LOG: tsan: extend mmap test

Test size larger than clear_shadow_mmap_threshold,
which is handled differently.

Depends on D114348.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D114366

Added: 
    

Modified: 
    compiler-rt/test/tsan/ignored-interceptors-mmap.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp
index 451fd1b6c679..2b35627229df 100644
--- a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp
+++ b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp
@@ -1,6 +1,8 @@
 // RUN: %clangxx_tsan -O0 %s -o %t
-// RUN: not %run %t        2>&1 | FileCheck %s --check-prefix=CHECK-RACE
-// RUN:     %run %t ignore 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE
+// RUN: not %run %t          2>&1 | FileCheck %s --check-prefix=CHECK-RACE
+// Test size larger than clear_shadow_mmap_threshold, which is handled 
diff erently.
+// RUN: not %run %t - 262144 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
+// RUN:     %run %t ignore   2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE
 
 #include <sys/mman.h>
 #include <string.h>
@@ -14,11 +16,10 @@
 // respects ignore annotations.
 std::atomic<int*> global_p;
 
-void mmap_ignored(bool ignore) {
-  const size_t kSize = sysconf(_SC_PAGESIZE);
-
+void mmap_ignored(bool ignore, size_t size) {
   if (ignore) AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
-  void *p = mmap(0, kSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+  void *p =
+      mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
   if (ignore) AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
 
   // Use relaxed to retain the race between the mmap call and the memory write
@@ -35,11 +36,12 @@ void *WriteToMemory(void *unused) {
 // Create race between allocating (mmap) and writing memory
 int main(int argc, const char *argv[]) {
   bool ignore = (argc > 1) && (strcmp(argv[1], "ignore") == 0);
+  size_t size = argc > 2 ? atoi(argv[2]) : sysconf(_SC_PAGESIZE);
 
   barrier_init(&barrier, 2);
   pthread_t t;
   pthread_create(&t, 0, WriteToMemory, 0);
-  mmap_ignored(ignore);
+  mmap_ignored(ignore, size);
   pthread_join(t, 0);
 
   assert(global_p[0] == 7);


        


More information about the llvm-commits mailing list