• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "test/jemalloc_test.h"
2 
3 static bool hook_called = false;
4 
5 static void
hook()6 hook() {
7 	hook_called = true;
8 }
9 
10 static int
func_to_hook(int arg1,int arg2)11 func_to_hook(int arg1, int arg2) {
12 	return arg1 + arg2;
13 }
14 
15 #define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook)
16 
TEST_BEGIN(unhooked_call)17 TEST_BEGIN(unhooked_call) {
18 	hooks_libc_hook = NULL;
19 	hook_called = false;
20 	assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
21 	assert_false(hook_called, "Nulling out hook didn't take.");
22 }
23 TEST_END
24 
TEST_BEGIN(hooked_call)25 TEST_BEGIN(hooked_call) {
26 	hooks_libc_hook = &hook;
27 	hook_called = false;
28 	assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
29 	assert_true(hook_called, "Hook should have executed.");
30 }
31 TEST_END
32 
33 int
main(void)34 main(void) {
35 	return test(
36 	    unhooked_call,
37 	    hooked_call);
38 }
39