1 #include "test/jemalloc_test.h"
2
3 #ifdef JEMALLOC_PROF
4 const char *malloc_conf =
5 "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0,"
6 "lg_prof_interval:0";
7 #endif
8
9 static bool did_prof_dump_open;
10
11 static int
prof_dump_open_intercept(bool propagate_err,const char * filename)12 prof_dump_open_intercept(bool propagate_err, const char *filename)
13 {
14 int fd;
15
16 did_prof_dump_open = true;
17
18 fd = open("/dev/null", O_WRONLY);
19 assert_d_ne(fd, -1, "Unexpected open() failure");
20
21 return (fd);
22 }
23
TEST_BEGIN(test_idump)24 TEST_BEGIN(test_idump)
25 {
26 bool active;
27 void *p;
28
29 test_skip_if(!config_prof);
30
31 active = true;
32 assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)),
33 0, "Unexpected mallctl failure while activating profiling");
34
35 prof_dump_open = prof_dump_open_intercept;
36
37 did_prof_dump_open = false;
38 p = mallocx(1, 0);
39 assert_ptr_not_null(p, "Unexpected mallocx() failure");
40 dallocx(p, 0);
41 assert_true(did_prof_dump_open, "Expected a profile dump");
42 }
43 TEST_END
44
45 int
main(void)46 main(void)
47 {
48
49 return (test(
50 test_idump));
51 }
52