summaryrefslogtreecommitdiff
path: root/test/scudo/interface.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
commitab0bf875a5f328a6710f4e48258979ae1bc8da1c (patch)
tree66903cf9f73151825893dcc216b04c0930317a10 /test/scudo/interface.cpp
parentabacad30a54c59ad437ccf54ec5236a8dd7f3ba9 (diff)
Notes
Diffstat (limited to 'test/scudo/interface.cpp')
-rw-r--r--test/scudo/interface.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/test/scudo/interface.cpp b/test/scudo/interface.cpp
index f9353066efa37..e9575adf31008 100644
--- a/test/scudo/interface.cpp
+++ b/test/scudo/interface.cpp
@@ -1,9 +1,13 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
+// 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
// Tests that the sanitizer interface functions behave appropriately.
#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
#include <vector>
@@ -11,18 +15,33 @@
int main(int argc, char **argv)
{
- void *p;
- std::vector<ssize_t> sizes{1, 8, 16, 32, 1024, 32768,
- 1 << 16, 1 << 17, 1 << 20, 1 << 24};
- for (size_t size : sizes) {
- p = malloc(size);
- if (!p)
- return 1;
- if (!__sanitizer_get_ownership(p))
- return 1;
- if (__sanitizer_get_allocated_size(p) < size)
- return 1;
- free(p);
+ assert(argc == 2);
+
+ if (!strcmp(argv[1], "ownership")) {
+ // Ensures that __sanitizer_get_ownership can be called before any other
+ // allocator function, and that it behaves properly on a pointer not owned
+ // by us.
+ assert(!__sanitizer_get_ownership(argv));
+ }
+ if (!strcmp(argv[1], "ownership-and-size")) {
+ // Tests that __sanitizer_get_ownership and __sanitizer_get_allocated_size
+ // behave properly on chunks allocated by the Primary and Secondary.
+ void *p;
+ std::vector<ssize_t> sizes{1, 8, 16, 32, 1024, 32768,
+ 1 << 16, 1 << 17, 1 << 20, 1 << 24};
+ for (size_t size : sizes) {
+ p = malloc(size);
+ assert(p);
+ assert(__sanitizer_get_ownership(p));
+ assert(__sanitizer_get_allocated_size(p) >= size);
+ free(p);
+ }
}
+ if (!strcmp(argv[1], "heap-size")) {
+ // Ensures that __sanitizer_get_heap_size can be called before any other
+ // allocator function.
+ assert(__sanitizer_get_heap_size() >= 0);
+ }
+
return 0;
}