2017-03-29 08:30:54 +08: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;
|
|
|
|
}
|
|
|
|
|
2021-09-23 05:59:53 +08:00
|
|
|
#define func_to_hook JEMALLOC_TEST_HOOK(func_to_hook, test_hooks_libc_hook)
|
2017-03-29 08:30:54 +08:00
|
|
|
|
|
|
|
TEST_BEGIN(unhooked_call) {
|
2018-04-10 09:09:34 +08:00
|
|
|
test_hooks_libc_hook = NULL;
|
2017-03-29 08:30:54 +08:00
|
|
|
hook_called = false;
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
|
|
|
expect_false(hook_called, "Nulling out hook didn't take.");
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
TEST_BEGIN(hooked_call) {
|
2018-04-10 09:09:34 +08:00
|
|
|
test_hooks_libc_hook = &hook;
|
2017-03-29 08:30:54 +08:00
|
|
|
hook_called = false;
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
|
|
|
expect_true(hook_called, "Hook should have executed.");
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
return test(
|
|
|
|
unhooked_call,
|
|
|
|
hooked_call);
|
|
|
|
}
|