2014-01-18 07:40:52 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2019-09-10 11:18:41 +08:00
|
|
|
#define TEST_PREFIX "test_prefix"
|
|
|
|
|
2014-01-18 07:40:52 +08:00
|
|
|
static bool did_prof_dump_open;
|
|
|
|
|
|
|
|
static int
|
2020-03-18 02:05:07 +08:00
|
|
|
prof_dump_open_file_intercept(const char *filename, int mode) {
|
2014-01-18 07:40:52 +08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
did_prof_dump_open = true;
|
|
|
|
|
2019-09-10 11:18:41 +08:00
|
|
|
const char filename_prefix[] = TEST_PREFIX ".";
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(strncmp(filename_prefix, filename, sizeof(filename_prefix)
|
2019-09-10 11:18:41 +08:00
|
|
|
- 1), 0, "Dump file name should start with \"" TEST_PREFIX ".\"");
|
|
|
|
|
2014-01-18 07:40:52 +08:00
|
|
|
fd = open("/dev/null", O_WRONLY);
|
2020-03-18 02:05:07 +08:00
|
|
|
assert_d_ne(fd, -1, "Unexpected open() failure");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
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;
|
|
|
|
|
2019-09-10 11:18:41 +08:00
|
|
|
const char *dump_prefix = TEST_PREFIX;
|
|
|
|
|
2014-01-18 07:40:52 +08:00
|
|
|
test_skip_if(!config_prof);
|
|
|
|
|
|
|
|
active = true;
|
2019-09-10 11:18:41 +08:00
|
|
|
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("prof.dump_prefix", NULL, NULL,
|
2019-09-10 11:18:41 +08:00
|
|
|
(void *)&dump_prefix, sizeof(dump_prefix)), 0,
|
|
|
|
"Unexpected mallctl failure while overwriting dump prefix");
|
|
|
|
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
|
2016-10-28 12:31:25 +08:00
|
|
|
sizeof(active)), 0,
|
|
|
|
"Unexpected mallctl failure while activating profiling");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
2020-03-18 02:05:07 +08:00
|
|
|
prof_dump_open_file = prof_dump_open_file_intercept;
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
did_prof_dump_open = false;
|
|
|
|
p = mallocx(1, 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(p, "Unexpected mallocx() failure");
|
2014-01-18 07:40:52 +08:00
|
|
|
dallocx(p, 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_true(did_prof_dump_open, "Expected a profile dump");
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|