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