diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2015-12-21 22:35:03 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2015-12-21 22:35:03 +0000 |
commit | ed61ae6cde6d278ae1c2c794686fa98d9f696cd5 (patch) | |
tree | 77ef5feea27c3155e2c32adf73caf0e1013fe65a | |
parent | 14a97c26c85b09df0d059a51b2a58c8adf354abc (diff) | |
download | bcm5719-llvm-ed61ae6cde6d278ae1c2c794686fa98d9f696cd5.tar.gz bcm5719-llvm-ed61ae6cde6d278ae1c2c794686fa98d9f696cd5.zip |
[asan] Add mincore test.
ASan does not really do anything interesting with mincore, but this
test verifies that the function still works correctly.
llvm-svn: 256207
-rw-r--r-- | compiler-rt/test/asan/TestCases/Linux/mincore.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Linux/mincore.cc b/compiler-rt/test/asan/TestCases/Linux/mincore.cc new file mode 100644 index 00000000000..30f450830fc --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Linux/mincore.cc @@ -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; +} |