prof_idump.c 828 B

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