1 #include "test/jemalloc_test.h" 2 3 #include "jemalloc/internal/prof_sys.h" 4 5 #define TEST_PREFIX "test_prefix" 6 7 static bool did_prof_dump_open; 8 9 static int 10 prof_dump_open_file_intercept(const char *filename, int mode) { 11 int fd; 12 13 did_prof_dump_open = true; 14 15 const char filename_prefix[] = TEST_PREFIX "."; 16 expect_d_eq(strncmp(filename_prefix, filename, sizeof(filename_prefix) 17 - 1), 0, "Dump file name should start with \"" TEST_PREFIX ".\""); 18 19 fd = open("/dev/null", O_WRONLY); 20 assert_d_ne(fd, -1, "Unexpected open() failure"); 21 22 return fd; 23 } 24 25 TEST_BEGIN(test_idump) { 26 bool active; 27 void *p; 28 29 const char *test_prefix = TEST_PREFIX; 30 31 test_skip_if(!config_prof); 32 33 active = true; 34 35 expect_d_eq(mallctl("prof.prefix", NULL, NULL, (void *)&test_prefix, 36 sizeof(test_prefix)), 0, 37 "Unexpected mallctl failure while overwriting dump prefix"); 38 39 expect_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_file = prof_dump_open_file_intercept; 44 45 did_prof_dump_open = false; 46 p = mallocx(1, 0); 47 expect_ptr_not_null(p, "Unexpected mallocx() failure"); 48 dallocx(p, 0); 49 expect_true(did_prof_dump_open, "Expected a profile dump"); 50 } 51 TEST_END 52 53 int 54 main(void) { 55 return test( 56 test_idump); 57 } 58