1#include "test/jemalloc_test.h" 2 3static bool hook_called = false; 4 5static void 6hook() { 7 hook_called = true; 8} 9 10static int 11func_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 17TEST_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} 23TEST_END 24 25TEST_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} 31TEST_END 32 33int 34main(void) { 35 return test( 36 unhooked_call, 37 hooked_call); 38} 39