2014-01-18 07:40:52 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2016-05-28 15:17:28 +08:00
|
|
|
const char *malloc_conf = ""
|
2014-01-18 07:40:52 +08:00
|
|
|
#ifdef JEMALLOC_PROF
|
2016-05-28 15:17:28 +08:00
|
|
|
"prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0"
|
|
|
|
",lg_prof_interval:0"
|
|
|
|
# ifdef JEMALLOC_TCACHE
|
|
|
|
","
|
|
|
|
# endif
|
2014-01-18 07:40:52 +08:00
|
|
|
#endif
|
2016-05-28 15:17:28 +08:00
|
|
|
#ifdef JEMALLOC_TCACHE
|
|
|
|
"tcache:false"
|
|
|
|
#endif
|
|
|
|
;
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
static bool did_prof_dump_open;
|
|
|
|
|
|
|
|
static int
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_dump_open_intercept(bool propagate_err, const char *filename) {
|
2014-01-18 07:40:52 +08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
did_prof_dump_open = true;
|
|
|
|
|
|
|
|
fd = open("/dev/null", O_WRONLY);
|
|
|
|
assert_d_ne(fd, -1, "Unexpected open() failure");
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return fd;
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_idump) {
|
2014-01-18 07:40:52 +08:00
|
|
|
bool active;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
test_skip_if(!config_prof);
|
|
|
|
|
|
|
|
active = true;
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
|
|
|
|
sizeof(active)), 0,
|
|
|
|
"Unexpected mallctl failure while activating profiling");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
prof_dump_open = prof_dump_open_intercept;
|
|
|
|
|
|
|
|
did_prof_dump_open = false;
|
|
|
|
p = mallocx(1, 0);
|
|
|
|
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
|
|
|
dallocx(p, 0);
|
|
|
|
assert_true(did_prof_dump_open, "Expected a profile dump");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
|
|
|
test_idump);
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|