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