diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:54 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:54 +0000 |
commit | cdf4f3055e964bb585f294cf77cb549ead82783f (patch) | |
tree | 7bceeca766b3fbe491245bc926a083f78c35d1de /test/scudo/interface.cpp | |
parent | 625108084a3ec7c19c7745004c5af0ed7aa417a9 (diff) |
Notes
Diffstat (limited to 'test/scudo/interface.cpp')
-rw-r--r-- | test/scudo/interface.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/test/scudo/interface.cpp b/test/scudo/interface.cpp index e9575adf31008..73ea0a738e43f 100644 --- a/test/scudo/interface.cpp +++ b/test/scudo/interface.cpp @@ -1,17 +1,22 @@ -// RUN: %clang_scudo %s -lstdc++ -o %t -// RUN: %run %t ownership 2>&1 -// RUN: %run %t ownership-and-size 2>&1 -// RUN: %run %t heap-size 2>&1 +// RUN: %clangxx_scudo %s -lstdc++ -o %t +// RUN: %run %t ownership 2>&1 +// RUN: %run %t ownership-and-size 2>&1 +// RUN: %run %t heap-size 2>&1 +// RUN: %env_scudo_opts="allocator_may_return_null=1" %run %t soft-limit 2>&1 +// RUN: %env_scudo_opts="allocator_may_return_null=1" not %run %t hard-limit 2>&1 +// UNSUPPORTED: armhf-linux // Tests that the sanitizer interface functions behave appropriately. #include <stdlib.h> #include <assert.h> #include <string.h> +#include <unistd.h> #include <vector> #include <sanitizer/allocator_interface.h> +#include <sanitizer/scudo_interface.h> int main(int argc, char **argv) { @@ -42,6 +47,41 @@ int main(int argc, char **argv) // allocator function. assert(__sanitizer_get_heap_size() >= 0); } + if (!strcmp(argv[1], "soft-limit")) { + // Verifies that setting the soft RSS limit at runtime works as expected. + std::vector<void *> pointers; + size_t size = 1 << 19; // 512Kb + for (int i = 0; i < 5; i++) + pointers.push_back(malloc(size)); + // Set the soft RSS limit to 1Mb. + __scudo_set_rss_limit(1, 0); + usleep(20000); + // The following allocation should return NULL. + void *p = malloc(size); + assert(!p); + // Remove the soft RSS limit. + __scudo_set_rss_limit(0, 0); + // The following allocation should succeed. + p = malloc(size); + assert(p); + free(p); + while (!pointers.empty()) { + free(pointers.back()); + pointers.pop_back(); + } + } + if (!strcmp(argv[1], "hard-limit")) { + // Verifies that setting the hard RSS limit at runtime works as expected. + std::vector<void *> pointers; + size_t size = 1 << 19; // 512Kb + for (int i = 0; i < 5; i++) + pointers.push_back(malloc(size)); + // Set the hard RSS limit to 1Mb + __scudo_set_rss_limit(1, 1); + usleep(20000); + // The following should trigger our death. + void *p = malloc(size); + } return 0; } |