summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2017-03-29 00:30:54 (GMT)
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-04-07 21:10:27 (GMT)
commit0a0fcd3e6a0816f0a56fa852416d0ece861c0abb (patch)
tree49b3c934dd8308e7c3bf31692184ef72bb1e8a0d /test/unit
parent36bd90b96212772f1adbd421a6b091b542278995 (diff)
downloadjemalloc-0a0fcd3e6a0816f0a56fa852416d0ece861c0abb.zip
jemalloc-0a0fcd3e6a0816f0a56fa852416d0ece861c0abb.tar.gz
jemalloc-0a0fcd3e6a0816f0a56fa852416d0ece861c0abb.tar.bz2
Add hooking functionality
This allows us to hook chosen functions and do interesting things there (in particular: reentrancy checking).
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/hooks.c38
-rw-r--r--test/unit/prof_accum.c2
-rw-r--r--test/unit/prof_active.c2
-rw-r--r--test/unit/prof_gdump.c2
-rw-r--r--test/unit/prof_reset.c2
-rw-r--r--test/unit/prof_tctx.c2
-rw-r--r--test/unit/tsd.c1
7 files changed, 44 insertions, 5 deletions
diff --git a/test/unit/hooks.c b/test/unit/hooks.c
new file mode 100644
index 0000000..b70172e
--- /dev/null
+++ b/test/unit/hooks.c
@@ -0,0 +1,38 @@
+#include "test/jemalloc_test.h"
+
+static bool hook_called = false;
+
+static void
+hook() {
+ hook_called = true;
+}
+
+static int
+func_to_hook(int arg1, int arg2) {
+ return arg1 + arg2;
+}
+
+#define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook)
+
+TEST_BEGIN(unhooked_call) {
+ hooks_libc_hook = NULL;
+ hook_called = false;
+ assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
+ assert_false(hook_called, "Nulling out hook didn't take.");
+}
+TEST_END
+
+TEST_BEGIN(hooked_call) {
+ hooks_libc_hook = &hook;
+ hook_called = false;
+ assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
+ assert_true(hook_called, "Hook should have executed.");
+}
+TEST_END
+
+int
+main(void) {
+ return test(
+ unhooked_call,
+ hooked_call);
+}
diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c
index 6ccab82..2522006 100644
--- a/test/unit/prof_accum.c
+++ b/test/unit/prof_accum.c
@@ -76,6 +76,6 @@ TEST_END
int
main(void) {
- return test(
+ return test_no_reentrancy(
test_idump);
}
diff --git a/test/unit/prof_active.c b/test/unit/prof_active.c
index 275aac8..850a24a 100644
--- a/test/unit/prof_active.c
+++ b/test/unit/prof_active.c
@@ -112,6 +112,6 @@ TEST_END
int
main(void) {
- return test(
+ return test_no_reentrancy(
test_prof_active);
}
diff --git a/test/unit/prof_gdump.c b/test/unit/prof_gdump.c
index 97ade68..fcb434c 100644
--- a/test/unit/prof_gdump.c
+++ b/test/unit/prof_gdump.c
@@ -69,6 +69,6 @@ TEST_END
int
main(void) {
- return test(
+ return test_no_reentrancy(
test_gdump);
}
diff --git a/test/unit/prof_reset.c b/test/unit/prof_reset.c
index 6120714..7cce42d 100644
--- a/test/unit/prof_reset.c
+++ b/test/unit/prof_reset.c
@@ -278,7 +278,7 @@ main(void) {
/* Intercept dumping prior to running any tests. */
prof_dump_open = prof_dump_open_intercept;
- return test(
+ return test_no_reentrancy(
test_prof_reset_basic,
test_prof_reset_cleanup,
test_prof_reset,
diff --git a/test/unit/prof_tctx.c b/test/unit/prof_tctx.c
index 183f7ce..30c6b17 100644
--- a/test/unit/prof_tctx.c
+++ b/test/unit/prof_tctx.c
@@ -41,6 +41,6 @@ TEST_END
int
main(void) {
- return test(
+ return test_no_reentrancy(
test_prof_realloc);
}
diff --git a/test/unit/tsd.c b/test/unit/tsd.c
index 5bfcdf4..4a0f318 100644
--- a/test/unit/tsd.c
+++ b/test/unit/tsd.c
@@ -79,6 +79,7 @@ thd_start(void *arg) {
}
TEST_BEGIN(test_tsd_main_thread) {
+ test_skip_if(test_is_reentrant());
thd_start((void *)(uintptr_t)0xa5f3e329);
}
TEST_END