mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Rename hooks module to test_hooks.
"Hooks" is really the best name for the module that will contain the publicly exposed hooks. So lets rename the current "hooks" module (that hook external dependencies, for reentrancy testing) to "test_hooks".
This commit is contained in:
committed by
David Goldblatt
parent
e870829e64
commit
c7a87e0e0b
38
test/unit/test_hooks.c
Normal file
38
test/unit/test_hooks.c
Normal file
@@ -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_HOOK(func_to_hook, test_hooks_libc_hook)
|
||||
|
||||
TEST_BEGIN(unhooked_call) {
|
||||
test_hooks_libc_hook = NULL;
|
||||
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) {
|
||||
test_hooks_libc_hook = &hook;
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user