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:
parent
e870829e64
commit
c7a87e0e0b
@ -102,7 +102,6 @@ C_SRCS := $(srcroot)src/jemalloc.c \
|
|||||||
$(srcroot)src/extent_dss.c \
|
$(srcroot)src/extent_dss.c \
|
||||||
$(srcroot)src/extent_mmap.c \
|
$(srcroot)src/extent_mmap.c \
|
||||||
$(srcroot)src/hash.c \
|
$(srcroot)src/hash.c \
|
||||||
$(srcroot)src/hooks.c \
|
|
||||||
$(srcroot)src/large.c \
|
$(srcroot)src/large.c \
|
||||||
$(srcroot)src/log.c \
|
$(srcroot)src/log.c \
|
||||||
$(srcroot)src/malloc_io.c \
|
$(srcroot)src/malloc_io.c \
|
||||||
@ -116,6 +115,7 @@ C_SRCS := $(srcroot)src/jemalloc.c \
|
|||||||
$(srcroot)src/stats.c \
|
$(srcroot)src/stats.c \
|
||||||
$(srcroot)src/sz.c \
|
$(srcroot)src/sz.c \
|
||||||
$(srcroot)src/tcache.c \
|
$(srcroot)src/tcache.c \
|
||||||
|
$(srcroot)src/test_hooks.c \
|
||||||
$(srcroot)src/ticker.c \
|
$(srcroot)src/ticker.c \
|
||||||
$(srcroot)src/tsd.c \
|
$(srcroot)src/tsd.c \
|
||||||
$(srcroot)src/witness.c
|
$(srcroot)src/witness.c
|
||||||
@ -172,7 +172,6 @@ TESTS_UNIT := \
|
|||||||
$(srcroot)test/unit/extent_quantize.c \
|
$(srcroot)test/unit/extent_quantize.c \
|
||||||
$(srcroot)test/unit/fork.c \
|
$(srcroot)test/unit/fork.c \
|
||||||
$(srcroot)test/unit/hash.c \
|
$(srcroot)test/unit/hash.c \
|
||||||
$(srcroot)test/unit/hooks.c \
|
|
||||||
$(srcroot)test/unit/junk.c \
|
$(srcroot)test/unit/junk.c \
|
||||||
$(srcroot)test/unit/junk_alloc.c \
|
$(srcroot)test/unit/junk_alloc.c \
|
||||||
$(srcroot)test/unit/junk_free.c \
|
$(srcroot)test/unit/junk_free.c \
|
||||||
@ -205,6 +204,7 @@ TESTS_UNIT := \
|
|||||||
$(srcroot)test/unit/spin.c \
|
$(srcroot)test/unit/spin.c \
|
||||||
$(srcroot)test/unit/stats.c \
|
$(srcroot)test/unit/stats.c \
|
||||||
$(srcroot)test/unit/stats_print.c \
|
$(srcroot)test/unit/stats_print.c \
|
||||||
|
$(srcroot)test/unit/test_hooks.c \
|
||||||
$(srcroot)test/unit/ticker.c \
|
$(srcroot)test/unit/ticker.c \
|
||||||
$(srcroot)test/unit/nstime.c \
|
$(srcroot)test/unit/nstime.c \
|
||||||
$(srcroot)test/unit/tsd.c \
|
$(srcroot)test/unit/tsd.c \
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
#ifndef JEMALLOC_INTERNAL_HOOKS_H
|
|
||||||
#define JEMALLOC_INTERNAL_HOOKS_H
|
|
||||||
|
|
||||||
extern JEMALLOC_EXPORT void (*hooks_arena_new_hook)();
|
|
||||||
extern JEMALLOC_EXPORT void (*hooks_libc_hook)();
|
|
||||||
|
|
||||||
#define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn)
|
|
||||||
|
|
||||||
#define open JEMALLOC_HOOK(open, hooks_libc_hook)
|
|
||||||
#define read JEMALLOC_HOOK(read, hooks_libc_hook)
|
|
||||||
#define write JEMALLOC_HOOK(write, hooks_libc_hook)
|
|
||||||
#define readlink JEMALLOC_HOOK(readlink, hooks_libc_hook)
|
|
||||||
#define close JEMALLOC_HOOK(close, hooks_libc_hook)
|
|
||||||
#define creat JEMALLOC_HOOK(creat, hooks_libc_hook)
|
|
||||||
#define secure_getenv JEMALLOC_HOOK(secure_getenv, hooks_libc_hook)
|
|
||||||
/* Note that this is undef'd and re-define'd in src/prof.c. */
|
|
||||||
#define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, hooks_libc_hook)
|
|
||||||
|
|
||||||
#endif /* JEMALLOC_INTERNAL_HOOKS_H */
|
|
@ -45,7 +45,7 @@
|
|||||||
# include "jemalloc/internal/private_namespace_jet.h"
|
# include "jemalloc/internal/private_namespace_jet.h"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#include "jemalloc/internal/hooks.h"
|
#include "jemalloc/internal/test_hooks.h"
|
||||||
|
|
||||||
#ifdef JEMALLOC_DEFINE_MADVISE_FREE
|
#ifdef JEMALLOC_DEFINE_MADVISE_FREE
|
||||||
# define JEMALLOC_MADV_FREE 8
|
# define JEMALLOC_MADV_FREE 8
|
||||||
|
19
include/jemalloc/internal/test_hooks.h
Normal file
19
include/jemalloc/internal/test_hooks.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef JEMALLOC_INTERNAL_TEST_HOOKS_H
|
||||||
|
#define JEMALLOC_INTERNAL_TEST_HOOKS_H
|
||||||
|
|
||||||
|
extern JEMALLOC_EXPORT void (*test_hooks_arena_new_hook)();
|
||||||
|
extern JEMALLOC_EXPORT void (*test_hooks_libc_hook)();
|
||||||
|
|
||||||
|
#define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn)
|
||||||
|
|
||||||
|
#define open JEMALLOC_HOOK(open, test_hooks_libc_hook)
|
||||||
|
#define read JEMALLOC_HOOK(read, test_hooks_libc_hook)
|
||||||
|
#define write JEMALLOC_HOOK(write, test_hooks_libc_hook)
|
||||||
|
#define readlink JEMALLOC_HOOK(readlink, test_hooks_libc_hook)
|
||||||
|
#define close JEMALLOC_HOOK(close, test_hooks_libc_hook)
|
||||||
|
#define creat JEMALLOC_HOOK(creat, test_hooks_libc_hook)
|
||||||
|
#define secure_getenv JEMALLOC_HOOK(secure_getenv, test_hooks_libc_hook)
|
||||||
|
/* Note that this is undef'd and re-define'd in src/prof.c. */
|
||||||
|
#define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, test_hooks_libc_hook)
|
||||||
|
|
||||||
|
#endif /* JEMALLOC_INTERNAL_TEST_HOOKS_H */
|
@ -1900,8 +1900,8 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) {
|
|||||||
*/
|
*/
|
||||||
assert(!tsdn_null(tsdn));
|
assert(!tsdn_null(tsdn));
|
||||||
pre_reentrancy(tsdn_tsd(tsdn), arena);
|
pre_reentrancy(tsdn_tsd(tsdn), arena);
|
||||||
if (hooks_arena_new_hook) {
|
if (test_hooks_arena_new_hook) {
|
||||||
hooks_arena_new_hook();
|
test_hooks_arena_new_hook();
|
||||||
}
|
}
|
||||||
post_reentrancy(tsdn_tsd(tsdn));
|
post_reentrancy(tsdn_tsd(tsdn));
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
#undef _Unwind_Backtrace
|
#undef _Unwind_Backtrace
|
||||||
#include <unwind.h>
|
#include <unwind.h>
|
||||||
#define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, hooks_libc_hook)
|
#define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, test_hooks_libc_hook)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* from outside the generated library, so that we can use them in test code.
|
* from outside the generated library, so that we can use them in test code.
|
||||||
*/
|
*/
|
||||||
JEMALLOC_EXPORT
|
JEMALLOC_EXPORT
|
||||||
void (*hooks_arena_new_hook)() = NULL;
|
void (*test_hooks_arena_new_hook)() = NULL;
|
||||||
|
|
||||||
JEMALLOC_EXPORT
|
JEMALLOC_EXPORT
|
||||||
void (*hooks_libc_hook)() = NULL;
|
void (*test_hooks_libc_hook)() = NULL;
|
@ -69,7 +69,7 @@ static const bool config_debug =
|
|||||||
|
|
||||||
# define JEMALLOC_N(n) @private_namespace@##n
|
# define JEMALLOC_N(n) @private_namespace@##n
|
||||||
# include "jemalloc/internal/private_namespace.h"
|
# include "jemalloc/internal/private_namespace.h"
|
||||||
# include "jemalloc/internal/hooks.h"
|
# include "jemalloc/internal/test_hooks.h"
|
||||||
|
|
||||||
/* Hermetic headers. */
|
/* Hermetic headers. */
|
||||||
# include "jemalloc/internal/assert.h"
|
# include "jemalloc/internal/assert.h"
|
||||||
|
@ -48,12 +48,12 @@ do_hook(bool *hook_ran, void (**hook)()) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
libc_reentrancy_hook() {
|
libc_reentrancy_hook() {
|
||||||
do_hook(&libc_hook_ran, &hooks_libc_hook);
|
do_hook(&libc_hook_ran, &test_hooks_libc_hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
arena_new_reentrancy_hook() {
|
arena_new_reentrancy_hook() {
|
||||||
do_hook(&arena_new_hook_ran, &hooks_arena_new_hook);
|
do_hook(&arena_new_hook_ran, &test_hooks_arena_new_hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actual test infrastructure. */
|
/* Actual test infrastructure. */
|
||||||
@ -131,7 +131,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||||||
for (; t != NULL; t = va_arg(ap, test_t *)) {
|
for (; t != NULL; t = va_arg(ap, test_t *)) {
|
||||||
/* Non-reentrant run. */
|
/* Non-reentrant run. */
|
||||||
reentrancy = non_reentrant;
|
reentrancy = non_reentrant;
|
||||||
hooks_arena_new_hook = hooks_libc_hook = NULL;
|
test_hooks_arena_new_hook = test_hooks_libc_hook = NULL;
|
||||||
t();
|
t();
|
||||||
if (test_status > ret) {
|
if (test_status > ret) {
|
||||||
ret = test_status;
|
ret = test_status;
|
||||||
@ -139,16 +139,16 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||||||
/* Reentrant run. */
|
/* Reentrant run. */
|
||||||
if (do_reentrant) {
|
if (do_reentrant) {
|
||||||
reentrancy = libc_reentrant;
|
reentrancy = libc_reentrant;
|
||||||
hooks_arena_new_hook = NULL;
|
test_hooks_arena_new_hook = NULL;
|
||||||
hooks_libc_hook = &libc_reentrancy_hook;
|
test_hooks_libc_hook = &libc_reentrancy_hook;
|
||||||
t();
|
t();
|
||||||
if (test_status > ret) {
|
if (test_status > ret) {
|
||||||
ret = test_status;
|
ret = test_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
reentrancy = arena_new_reentrant;
|
reentrancy = arena_new_reentrant;
|
||||||
hooks_libc_hook = NULL;
|
test_hooks_libc_hook = NULL;
|
||||||
hooks_arena_new_hook = &arena_new_reentrancy_hook;
|
test_hooks_arena_new_hook = &arena_new_reentrancy_hook;
|
||||||
t();
|
t();
|
||||||
if (test_status > ret) {
|
if (test_status > ret) {
|
||||||
ret = test_status;
|
ret = test_status;
|
||||||
|
@ -12,10 +12,10 @@ func_to_hook(int arg1, int arg2) {
|
|||||||
return arg1 + arg2;
|
return arg1 + arg2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook)
|
#define func_to_hook JEMALLOC_HOOK(func_to_hook, test_hooks_libc_hook)
|
||||||
|
|
||||||
TEST_BEGIN(unhooked_call) {
|
TEST_BEGIN(unhooked_call) {
|
||||||
hooks_libc_hook = NULL;
|
test_hooks_libc_hook = NULL;
|
||||||
hook_called = false;
|
hook_called = false;
|
||||||
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
||||||
assert_false(hook_called, "Nulling out hook didn't take.");
|
assert_false(hook_called, "Nulling out hook didn't take.");
|
||||||
@ -23,7 +23,7 @@ TEST_BEGIN(unhooked_call) {
|
|||||||
TEST_END
|
TEST_END
|
||||||
|
|
||||||
TEST_BEGIN(hooked_call) {
|
TEST_BEGIN(hooked_call) {
|
||||||
hooks_libc_hook = &hook;
|
test_hooks_libc_hook = &hook;
|
||||||
hook_called = false;
|
hook_called = false;
|
||||||
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
|
||||||
assert_true(hook_called, "Hook should have executed.");
|
assert_true(hook_called, "Hook should have executed.");
|
Loading…
Reference in New Issue
Block a user