summaryrefslogtreecommitdiffstats
path: root/deps/jemalloc/test/unit/test_hooks.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:40:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:40:54 +0000
commit317c0644ccf108aa23ef3fd8358bd66c2840bfc0 (patch)
treec417b3d25c86b775989cb5ac042f37611b626c8a /deps/jemalloc/test/unit/test_hooks.c
parentInitial commit. (diff)
downloadredis-upstream/5%7.2.4.tar.xz
redis-upstream/5%7.2.4.zip
Adding upstream version 5:7.2.4.upstream/5%7.2.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--deps/jemalloc/test/unit/test_hooks.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/deps/jemalloc/test/unit/test_hooks.c b/deps/jemalloc/test/unit/test_hooks.c
new file mode 100644
index 0000000..8cd2b3b
--- /dev/null
+++ b/deps/jemalloc/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_TEST_HOOK(func_to_hook, test_hooks_libc_hook)
+
+TEST_BEGIN(unhooked_call) {
+ test_hooks_libc_hook = NULL;
+ hook_called = false;
+ expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
+ expect_false(hook_called, "Nulling out hook didn't take.");
+}
+TEST_END
+
+TEST_BEGIN(hooked_call) {
+ test_hooks_libc_hook = &hook;
+ hook_called = false;
+ expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
+ expect_true(hook_called, "Hook should have executed.");
+}
+TEST_END
+
+int
+main(void) {
+ return test(
+ unhooked_call,
+ hooked_call);
+}