• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, (void *)&active,
33 	    sizeof(active)), 0,
34 	    "Unexpected mallctl failure while activating profiling");
35 
36 	prof_dump_open = prof_dump_open_intercept;
37 
38 	did_prof_dump_open = false;
39 	p = mallocx(1, 0);
40 	assert_ptr_not_null(p, "Unexpected mallocx() failure");
41 	dallocx(p, 0);
42 	assert_true(did_prof_dump_open, "Expected a profile dump");
43 }
44 TEST_END
45 
46 int
main(void)47 main(void)
48 {
49 
50 	return (test(
51 	    test_idump));
52 }
53