prof_gdump.c 1.1 KB

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