[compiler-rt] r256207 - [asan] Add mincore test.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 14:35:04 PST 2015


Author: eugenis
Date: Mon Dec 21 16:35:03 2015
New Revision: 256207

URL: http://llvm.org/viewvc/llvm-project?rev=256207&view=rev
Log:
[asan] Add mincore test.

ASan does not really do anything interesting with mincore, but this
test verifies that the function still works correctly.

Added:
    compiler-rt/trunk/test/asan/TestCases/Linux/mincore.cc

Added: compiler-rt/trunk/test/asan/TestCases/Linux/mincore.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/mincore.cc?rev=256207&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/mincore.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/mincore.cc Mon Dec 21 16:35:03 2015
@@ -0,0 +1,34 @@
+// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+int main(void) {
+  unsigned char vec[20];
+  int res;
+  size_t PS = sysconf(_SC_PAGESIZE);
+  void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE,
+                    MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+
+  res = mincore(addr, 10 * PS, vec);
+  assert(res == 0);
+  for (int i = 0; i < 10; ++i)
+    assert((vec[i] & 1) == 0);
+
+  for (int i = 0; i < 5; ++i)
+    ((char *)addr)[i * PS] = 1;
+  res = mincore(addr, 10 * PS, vec);
+  assert(res == 0);
+  for (int i = 0; i < 10; ++i)
+    assert((vec[i] & 1) == (i < 5));
+
+  for (int i = 5; i < 10; ++i)
+    ((char *)addr)[i * PS] = 1;
+  res = mincore(addr, 10 * PS, vec);
+  assert(res == 0);
+  for (int i = 0; i < 10; ++i)
+    assert((vec[i] & 1) == 1);
+
+  return 0;
+}




More information about the llvm-commits mailing list