2014-01-18 07:40:52 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
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);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_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_gdump) {
|
2015-01-26 13:16:57 +08:00
|
|
|
bool active, gdump, gdump_old;
|
|
|
|
void *p, *q, *r, *s;
|
|
|
|
size_t sz;
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
test_skip_if(!config_prof);
|
|
|
|
|
|
|
|
active = true;
|
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
|
|
|
|
|
|
|
prof_dump_open = prof_dump_open_intercept;
|
|
|
|
|
|
|
|
did_prof_dump_open = false;
|
2018-07-20 08:08:10 +08:00
|
|
|
p = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(p, "Unexpected mallocx() failure");
|
|
|
|
expect_true(did_prof_dump_open, "Expected a profile dump");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
did_prof_dump_open = false;
|
2018-07-20 08:08:10 +08:00
|
|
|
q = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(q, "Unexpected mallocx() failure");
|
|
|
|
expect_true(did_prof_dump_open, "Expected a profile dump");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
2015-01-26 13:16:57 +08:00
|
|
|
gdump = false;
|
|
|
|
sz = sizeof(gdump_old);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
|
2016-10-28 12:31:25 +08:00
|
|
|
(void *)&gdump, sizeof(gdump)), 0,
|
2015-01-26 13:16:57 +08:00
|
|
|
"Unexpected mallctl failure while disabling prof.gdump");
|
|
|
|
assert(gdump_old);
|
|
|
|
did_prof_dump_open = false;
|
2018-07-20 08:08:10 +08:00
|
|
|
r = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(q, "Unexpected mallocx() failure");
|
|
|
|
expect_false(did_prof_dump_open, "Unexpected profile dump");
|
2015-01-26 13:16:57 +08:00
|
|
|
|
|
|
|
gdump = true;
|
|
|
|
sz = sizeof(gdump_old);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
|
2016-10-28 12:31:25 +08:00
|
|
|
(void *)&gdump, sizeof(gdump)), 0,
|
2015-01-26 13:16:57 +08:00
|
|
|
"Unexpected mallctl failure while enabling prof.gdump");
|
|
|
|
assert(!gdump_old);
|
|
|
|
did_prof_dump_open = false;
|
2018-07-20 08:08:10 +08:00
|
|
|
s = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(q, "Unexpected mallocx() failure");
|
|
|
|
expect_true(did_prof_dump_open, "Expected a profile dump");
|
2015-01-26 13:16:57 +08:00
|
|
|
|
2014-01-18 07:40:52 +08:00
|
|
|
dallocx(p, 0);
|
|
|
|
dallocx(q, 0);
|
2015-01-26 13:16:57 +08:00
|
|
|
dallocx(r, 0);
|
|
|
|
dallocx(s, 0);
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-03-29 08:30:54 +08:00
|
|
|
return test_no_reentrancy(
|
2017-01-20 10:15:45 +08:00
|
|
|
test_gdump);
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|