summaryrefslogtreecommitdiff
path: root/test/unit/test_hooks.c
diff options
context:
space:
mode:
authorYoav Steinberg <yoav@monfort.co.il>2021-10-10 18:26:48 +0300
committerYoav Steinberg <yoav@monfort.co.il>2021-10-10 18:26:48 +0300
commit220a0f0880419450c9409202aac1fab4b8be0719 (patch)
treeeb52a159ee9b9cf80e87e809a80035e49d7f96e2 /test/unit/test_hooks.c
downloadredis-220a0f0880419450c9409202aac1fab4b8be0719.tar.gz
Squashed 'deps/jemalloc/' content from commit 886e40bb3
git-subtree-dir: deps/jemalloc git-subtree-split: 886e40bb339ec1358a5ff2a52fdb782ca66461cb
Diffstat (limited to 'test/unit/test_hooks.c')
-rw-r--r--test/unit/test_hooks.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/unit/test_hooks.c b/test/unit/test_hooks.c
new file mode 100644
index 000000000..ded8698bc
--- /dev/null
+++ b/test/unit/test_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, test_hooks_libc_hook)
+
+TEST_BEGIN(unhooked_call) {
+ test_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) {
+ test_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);
+}