From f307b25804064eb26077f98b1481e6eb42f1dbad Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Tue, 17 Mar 2020 11:05:07 -0700 Subject: [PATCH] Only replace the dump file opening function in test --- include/jemalloc/internal/prof_externs.h | 4 ++-- src/prof_data.c | 15 ++++++++++----- test/unit/prof_accum.c | 6 +++--- test/unit/prof_gdump.c | 6 +++--- test/unit/prof_idump.c | 6 +++--- test/unit/prof_reset.c | 6 +++--- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/jemalloc/internal/prof_externs.h b/include/jemalloc/internal/prof_externs.h index 6021cf45..2f9f2c95 100644 --- a/include/jemalloc/internal/prof_externs.h +++ b/include/jemalloc/internal/prof_externs.h @@ -94,8 +94,8 @@ typedef int (prof_sys_thread_name_read_t)(char *buf, size_t limit); extern prof_sys_thread_name_read_t *JET_MUTABLE prof_sys_thread_name_read; size_t prof_tdata_count(void); size_t prof_bt_count(void); -typedef int (prof_dump_open_t)(bool, const char *); -extern prof_dump_open_t *JET_MUTABLE prof_dump_open; +typedef int (prof_dump_open_file_t)(const char *, int); +extern prof_dump_open_file_t *JET_MUTABLE prof_dump_open_file; typedef bool (prof_dump_header_t)(tsdn_t *, bool, const prof_cnt_t *); extern prof_dump_header_t *JET_MUTABLE prof_dump_header; void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs, diff --git a/src/prof_data.c b/src/prof_data.c index 49cc6ee3..396cea0d 100644 --- a/src/prof_data.c +++ b/src/prof_data.c @@ -467,13 +467,19 @@ prof_bt_count(void) { } static int -prof_dump_open_impl(bool propagate_err, const char *filename) { +prof_dump_open_file_impl(const char *filename, int mode) { + return creat(filename, mode); +} +prof_dump_open_file_t *JET_MUTABLE prof_dump_open_file = + prof_dump_open_file_impl; + +static int +prof_dump_open(bool propagate_err, const char *filename) { int fd; - fd = creat(filename, 0644); + fd = prof_dump_open_file(filename, 0644); if (fd == -1 && !propagate_err) { - malloc_printf(": creat(\"%s\"), 0644) failed\n", - filename); + malloc_printf(": failed to open \"%s\"\n", filename); if (opt_abort) { abort(); } @@ -481,7 +487,6 @@ prof_dump_open_impl(bool propagate_err, const char *filename) { return fd; } -prof_dump_open_t *JET_MUTABLE prof_dump_open = prof_dump_open_impl; static bool prof_dump_flush(bool propagate_err) { diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c index 8dfa6780..8fc58813 100644 --- a/test/unit/prof_accum.c +++ b/test/unit/prof_accum.c @@ -6,11 +6,11 @@ #define BT_COUNT_CHECK_INTERVAL 5 static int -prof_dump_open_intercept(bool propagate_err, const char *filename) { +prof_dump_open_file_intercept(const char *filename, int mode) { int fd; fd = open("/dev/null", O_WRONLY); - expect_d_ne(fd, -1, "Unexpected open() failure"); + assert_d_ne(fd, -1, "Unexpected open() failure"); return fd; } @@ -62,7 +62,7 @@ TEST_BEGIN(test_idump) { sizeof(active)), 0, "Unexpected mallctl failure while activating profiling"); - prof_dump_open = prof_dump_open_intercept; + prof_dump_open_file = prof_dump_open_file_intercept; for (i = 0; i < NTHREADS; i++) { thd_args[i] = i; diff --git a/test/unit/prof_gdump.c b/test/unit/prof_gdump.c index 4c6afbde..6209255e 100644 --- a/test/unit/prof_gdump.c +++ b/test/unit/prof_gdump.c @@ -3,13 +3,13 @@ static bool did_prof_dump_open; static int -prof_dump_open_intercept(bool propagate_err, const char *filename) { +prof_dump_open_file_intercept(const char *filename, int mode) { int fd; did_prof_dump_open = true; fd = open("/dev/null", O_WRONLY); - expect_d_ne(fd, -1, "Unexpected open() failure"); + assert_d_ne(fd, -1, "Unexpected open() failure"); return fd; } @@ -26,7 +26,7 @@ TEST_BEGIN(test_gdump) { sizeof(active)), 0, "Unexpected mallctl failure while activating profiling"); - prof_dump_open = prof_dump_open_intercept; + prof_dump_open_file = prof_dump_open_file_intercept; did_prof_dump_open = false; p = mallocx((1U << SC_LG_LARGE_MINCLASS), 0); diff --git a/test/unit/prof_idump.c b/test/unit/prof_idump.c index dfcc0ff6..b0c1bc28 100644 --- a/test/unit/prof_idump.c +++ b/test/unit/prof_idump.c @@ -5,7 +5,7 @@ static bool did_prof_dump_open; static int -prof_dump_open_intercept(bool propagate_err, const char *filename) { +prof_dump_open_file_intercept(const char *filename, int mode) { int fd; did_prof_dump_open = true; @@ -15,7 +15,7 @@ prof_dump_open_intercept(bool propagate_err, const char *filename) { - 1), 0, "Dump file name should start with \"" TEST_PREFIX ".\""); fd = open("/dev/null", O_WRONLY); - expect_d_ne(fd, -1, "Unexpected open() failure"); + assert_d_ne(fd, -1, "Unexpected open() failure"); return fd; } @@ -38,7 +38,7 @@ TEST_BEGIN(test_idump) { sizeof(active)), 0, "Unexpected mallctl failure while activating profiling"); - prof_dump_open = prof_dump_open_intercept; + prof_dump_open_file = prof_dump_open_file_intercept; did_prof_dump_open = false; p = mallocx(1, 0); diff --git a/test/unit/prof_reset.c b/test/unit/prof_reset.c index e643e546..29fa02bb 100644 --- a/test/unit/prof_reset.c +++ b/test/unit/prof_reset.c @@ -1,11 +1,11 @@ #include "test/jemalloc_test.h" static int -prof_dump_open_intercept(bool propagate_err, const char *filename) { +prof_dump_open_file_intercept(const char *filename, int mode) { int fd; fd = open("/dev/null", O_WRONLY); - expect_d_ne(fd, -1, "Unexpected open() failure"); + assert_d_ne(fd, -1, "Unexpected open() failure"); return fd; } @@ -276,7 +276,7 @@ TEST_END int main(void) { /* Intercept dumping prior to running any tests. */ - prof_dump_open = prof_dump_open_intercept; + prof_dump_open_file = prof_dump_open_file_intercept; return test_no_reentrancy( test_prof_reset_basic,