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