redis_study/deps/jemalloc/test/unit/hooks.c

39 lines
752 B
C
Raw Normal View History

2020-09-12 14:49:33 +00:00
#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;
}
2020-09-12 15:01:52 +00:00
#define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook)
2020-09-12 14:49:33 +00:00
TEST_BEGIN(unhooked_call) {
2020-09-12 15:01:52 +00:00
hooks_libc_hook = NULL;
2020-09-12 14:49:33 +00:00
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) {
2020-09-12 15:01:52 +00:00
hooks_libc_hook = &hook;
2020-09-12 14:49:33 +00:00
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);
}