Only replace the dump file opening function in test

This commit is contained in:
Yinan Zhang 2020-03-17 11:05:07 -07:00
parent d8cea87562
commit f307b25804
6 changed files with 24 additions and 19 deletions

View File

@ -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; extern prof_sys_thread_name_read_t *JET_MUTABLE prof_sys_thread_name_read;
size_t prof_tdata_count(void); size_t prof_tdata_count(void);
size_t prof_bt_count(void); size_t prof_bt_count(void);
typedef int (prof_dump_open_t)(bool, const char *); typedef int (prof_dump_open_file_t)(const char *, int);
extern prof_dump_open_t *JET_MUTABLE prof_dump_open; 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 *); typedef bool (prof_dump_header_t)(tsdn_t *, bool, const prof_cnt_t *);
extern prof_dump_header_t *JET_MUTABLE prof_dump_header; extern prof_dump_header_t *JET_MUTABLE prof_dump_header;
void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs, void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,

View File

@ -467,13 +467,19 @@ prof_bt_count(void) {
} }
static int 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; int fd;
fd = creat(filename, 0644); fd = prof_dump_open_file(filename, 0644);
if (fd == -1 && !propagate_err) { if (fd == -1 && !propagate_err) {
malloc_printf("<jemalloc>: creat(\"%s\"), 0644) failed\n", malloc_printf("<jemalloc>: failed to open \"%s\"\n", filename);
filename);
if (opt_abort) { if (opt_abort) {
abort(); abort();
} }
@ -481,7 +487,6 @@ prof_dump_open_impl(bool propagate_err, const char *filename) {
return fd; return fd;
} }
prof_dump_open_t *JET_MUTABLE prof_dump_open = prof_dump_open_impl;
static bool static bool
prof_dump_flush(bool propagate_err) { prof_dump_flush(bool propagate_err) {

View File

@ -6,11 +6,11 @@
#define BT_COUNT_CHECK_INTERVAL 5 #define BT_COUNT_CHECK_INTERVAL 5
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_file_intercept(const char *filename, int mode) {
int fd; int fd;
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
expect_d_ne(fd, -1, "Unexpected open() failure"); assert_d_ne(fd, -1, "Unexpected open() failure");
return fd; return fd;
} }
@ -62,7 +62,7 @@ TEST_BEGIN(test_idump) {
sizeof(active)), 0, sizeof(active)), 0,
"Unexpected mallctl failure while activating profiling"); "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++) { for (i = 0; i < NTHREADS; i++) {
thd_args[i] = i; thd_args[i] = i;

View File

@ -3,13 +3,13 @@
static bool did_prof_dump_open; static bool did_prof_dump_open;
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_file_intercept(const char *filename, int mode) {
int fd; int fd;
did_prof_dump_open = true; did_prof_dump_open = true;
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
expect_d_ne(fd, -1, "Unexpected open() failure"); assert_d_ne(fd, -1, "Unexpected open() failure");
return fd; return fd;
} }
@ -26,7 +26,7 @@ TEST_BEGIN(test_gdump) {
sizeof(active)), 0, sizeof(active)), 0,
"Unexpected mallctl failure while activating profiling"); "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; did_prof_dump_open = false;
p = mallocx((1U << SC_LG_LARGE_MINCLASS), 0); p = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);

View File

@ -5,7 +5,7 @@
static bool did_prof_dump_open; static bool did_prof_dump_open;
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_file_intercept(const char *filename, int mode) {
int fd; int fd;
did_prof_dump_open = true; 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 ".\""); - 1), 0, "Dump file name should start with \"" TEST_PREFIX ".\"");
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
expect_d_ne(fd, -1, "Unexpected open() failure"); assert_d_ne(fd, -1, "Unexpected open() failure");
return fd; return fd;
} }
@ -38,7 +38,7 @@ TEST_BEGIN(test_idump) {
sizeof(active)), 0, sizeof(active)), 0,
"Unexpected mallctl failure while activating profiling"); "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; did_prof_dump_open = false;
p = mallocx(1, 0); p = mallocx(1, 0);

View File

@ -1,11 +1,11 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_file_intercept(const char *filename, int mode) {
int fd; int fd;
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
expect_d_ne(fd, -1, "Unexpected open() failure"); assert_d_ne(fd, -1, "Unexpected open() failure");
return fd; return fd;
} }
@ -276,7 +276,7 @@ TEST_END
int int
main(void) { main(void) {
/* Intercept dumping prior to running any tests. */ /* 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( return test_no_reentrancy(
test_prof_reset_basic, test_prof_reset_basic,