diff options
author | David Goldblatt <davidgoldblatt@fb.com> | 2018-04-26 15:46:08 -0700 |
---|---|---|
committer | David Goldblatt <davidtgoldblatt@gmail.com> | 2018-05-18 11:43:03 -0700 |
commit | 126e9a84a5a793fb0d53ca4656a91889b3ae40e8 (patch) | |
tree | ef1e8c2f6b85a923f6f5736757b028c74b774459 /test | |
parent | cb0707c0fc948875876b93514938646455650e2b (diff) |
Hooks: move the "extra" pointer into the hook_t itself.
This simplifies the mallctl call to install a hook, which should only take a
single argument.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/hook.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/test/unit/hook.c b/test/unit/hook.c index 693cb238..3f85ff10 100644 --- a/test/unit/hook.c +++ b/test/unit/hook.c @@ -81,8 +81,9 @@ test_expand_hook(void *extra, hook_expand_t type, void *address, TEST_BEGIN(test_hooks_basic) { /* Just verify that the record their arguments correctly. */ hooks_t hooks = { - &test_alloc_hook, &test_dalloc_hook, &test_expand_hook}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)111); + &test_alloc_hook, &test_dalloc_hook, &test_expand_hook, + (void *)111}; + void *handle = hook_install(TSDN_NULL, &hooks); uintptr_t args_raw[4] = {10, 20, 30, 40}; /* Alloc */ @@ -124,15 +125,15 @@ TEST_END TEST_BEGIN(test_hooks_null) { /* Null hooks should be ignored, not crash. */ - hooks_t hooks1 = {NULL, NULL, NULL}; - hooks_t hooks2 = {&test_alloc_hook, NULL, NULL}; - hooks_t hooks3 = {NULL, &test_dalloc_hook, NULL}; - hooks_t hooks4 = {NULL, NULL, &test_expand_hook}; + hooks_t hooks1 = {NULL, NULL, NULL, NULL}; + hooks_t hooks2 = {&test_alloc_hook, NULL, NULL, NULL}; + hooks_t hooks3 = {NULL, &test_dalloc_hook, NULL, NULL}; + hooks_t hooks4 = {NULL, NULL, &test_expand_hook, NULL}; - void *handle1 = hook_install(TSDN_NULL, &hooks1, NULL); - void *handle2 = hook_install(TSDN_NULL, &hooks2, NULL); - void *handle3 = hook_install(TSDN_NULL, &hooks3, NULL); - void *handle4 = hook_install(TSDN_NULL, &hooks4, NULL); + void *handle1 = hook_install(TSDN_NULL, &hooks1); + void *handle2 = hook_install(TSDN_NULL, &hooks2); + void *handle3 = hook_install(TSDN_NULL, &hooks3); + void *handle4 = hook_install(TSDN_NULL, &hooks4); assert_ptr_ne(handle1, NULL, "Hook installation failed"); assert_ptr_ne(handle2, NULL, "Hook installation failed"); @@ -161,8 +162,8 @@ TEST_BEGIN(test_hooks_null) { TEST_END TEST_BEGIN(test_hooks_remove) { - hooks_t hooks = {&test_alloc_hook, NULL, NULL}; - void *handle = hook_install(TSDN_NULL, &hooks, NULL); + hooks_t hooks = {&test_alloc_hook, NULL, NULL, NULL}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); call_count = 0; uintptr_t args_raw[4] = {10, 20, 30, 40}; @@ -179,8 +180,8 @@ TEST_END TEST_BEGIN(test_hooks_alloc_simple) { /* "Simple" in the sense that we're not in a realloc variant. */ - hooks_t hooks = {&test_alloc_hook, NULL, NULL}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)123); + hooks_t hooks = {&test_alloc_hook, NULL, NULL, (void *)123}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); /* Stop malloc from being optimized away. */ @@ -290,8 +291,8 @@ TEST_END TEST_BEGIN(test_hooks_dalloc_simple) { /* "Simple" in the sense that we're not in a realloc variant. */ - hooks_t hooks = {NULL, &test_dalloc_hook, NULL}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)123); + hooks_t hooks = {NULL, &test_dalloc_hook, NULL, (void *)123}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); void *volatile ptr; @@ -337,8 +338,8 @@ TEST_END TEST_BEGIN(test_hooks_expand_simple) { /* "Simple" in the sense that we're not in a realloc variant. */ - hooks_t hooks = {NULL, NULL, &test_expand_hook}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)123); + hooks_t hooks = {NULL, NULL, &test_expand_hook, (void *)123}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); void *volatile ptr; @@ -365,8 +366,8 @@ TEST_END TEST_BEGIN(test_hooks_realloc_as_malloc_or_free) { hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook, - &test_expand_hook}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)123); + &test_expand_hook, (void *)123}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); void *volatile ptr; @@ -416,8 +417,8 @@ static void do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags, int expand_type, int dalloc_type) { hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook, - &test_expand_hook}; - void *handle = hook_install(TSDN_NULL, &hooks, (void *)123); + &test_expand_hook, (void *)123}; + void *handle = hook_install(TSDN_NULL, &hooks); assert_ptr_ne(handle, NULL, "Hook installation failed"); void *volatile ptr; |