prof_idump.c 1.3 KB

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