No need to intercept prof_dump_header() in tests

This commit is contained in:
Yinan Zhang 2020-06-26 15:26:51 -07:00
parent f58ebdff7a
commit c2e7a06392
3 changed files with 7 additions and 30 deletions

View File

@ -28,8 +28,6 @@ void prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx);
/* Used in unit tests. */
size_t prof_tdata_count(void);
size_t prof_bt_count(void);
typedef void (prof_dump_header_t)(void *, const prof_cnt_t *);
extern prof_dump_header_t *JET_MUTABLE prof_dump_header;
void prof_cnt_all(prof_cnt_t *cnt_all);
#endif /* JEMALLOC_INTERNAL_PROF_DATA_H */

View File

@ -792,8 +792,7 @@ prof_tdata_dump_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata,
}
static void
prof_dump_header_impl(void *opaque, const prof_cnt_t *cnt_all) {
prof_dump_iter_arg_t *arg = (prof_dump_iter_arg_t *)opaque;
prof_dump_header(prof_dump_iter_arg_t *arg, const prof_cnt_t *cnt_all) {
prof_dump_printf(arg->prof_dump_write, arg->cbopaque,
"heap_v2/%"FMTu64"\n t*: ", ((uint64_t)1U << lg_prof_sample));
prof_dump_print_cnts(arg->prof_dump_write, arg->cbopaque, cnt_all);
@ -803,7 +802,6 @@ prof_dump_header_impl(void *opaque, const prof_cnt_t *cnt_all) {
tdata_tree_iter(&tdatas, NULL, prof_tdata_dump_iter, arg);
malloc_mutex_unlock(arg->tsdn, &tdatas_mtx);
}
prof_dump_header_t *JET_MUTABLE prof_dump_header = prof_dump_header_impl;
static void
prof_dump_gctx(prof_dump_iter_arg_t *arg, prof_gctx_t *gctx,

View File

@ -84,45 +84,26 @@ TEST_BEGIN(test_prof_reset_basic) {
}
TEST_END
bool prof_dump_header_intercepted = false;
prof_cnt_t cnt_all_copy = {0, 0, 0, 0};
static void
prof_dump_header_intercept(void *opaque, const prof_cnt_t *cnt_all) {
prof_dump_header_intercepted = true;
memcpy(&cnt_all_copy, cnt_all, sizeof(prof_cnt_t));
}
TEST_BEGIN(test_prof_reset_cleanup) {
void *p;
prof_dump_header_t *prof_dump_header_orig;
test_skip_if(!config_prof);
set_prof_active(true);
expect_zu_eq(prof_bt_count(), 0, "Expected 0 backtraces");
p = mallocx(1, 0);
void *p = mallocx(1, 0);
expect_ptr_not_null(p, "Unexpected mallocx() failure");
expect_zu_eq(prof_bt_count(), 1, "Expected 1 backtrace");
prof_dump_header_orig = prof_dump_header;
prof_dump_header = prof_dump_header_intercept;
expect_false(prof_dump_header_intercepted, "Unexpected intercept");
expect_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0),
0, "Unexpected error while dumping heap profile");
expect_true(prof_dump_header_intercepted, "Expected intercept");
expect_u64_eq(cnt_all_copy.curobjs, 1, "Expected 1 allocation");
prof_cnt_t cnt_all;
prof_cnt_all(&cnt_all);
expect_u64_eq(cnt_all.curobjs, 1, "Expected 1 allocation");
expect_d_eq(mallctl("prof.reset", NULL, NULL, NULL, 0), 0,
"Unexpected error while resetting heap profile data");
expect_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0),
0, "Unexpected error while dumping heap profile");
expect_u64_eq(cnt_all_copy.curobjs, 0, "Expected 0 allocations");
prof_cnt_all(&cnt_all);
expect_u64_eq(cnt_all.curobjs, 0, "Expected 0 allocations");
expect_zu_eq(prof_bt_count(), 1, "Expected 1 backtrace");
prof_dump_header = prof_dump_header_orig;
dallocx(p, 0);
expect_zu_eq(prof_bt_count(), 0, "Expected 0 backtraces");