prof_gdump.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "test/jemalloc_test.h"
  2. #include "jemalloc/internal/prof_sys.h"
  3. static bool did_prof_dump_open;
  4. static int
  5. prof_dump_open_file_intercept(const char *filename, int mode) {
  6. int fd;
  7. did_prof_dump_open = true;
  8. fd = open("/dev/null", O_WRONLY);
  9. assert_d_ne(fd, -1, "Unexpected open() failure");
  10. return fd;
  11. }
  12. TEST_BEGIN(test_gdump) {
  13. test_skip_if(opt_hpa);
  14. bool active, gdump, gdump_old;
  15. void *p, *q, *r, *s;
  16. size_t sz;
  17. test_skip_if(!config_prof);
  18. active = true;
  19. expect_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
  20. sizeof(active)), 0,
  21. "Unexpected mallctl failure while activating profiling");
  22. prof_dump_open_file = prof_dump_open_file_intercept;
  23. did_prof_dump_open = false;
  24. p = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
  25. expect_ptr_not_null(p, "Unexpected mallocx() failure");
  26. expect_true(did_prof_dump_open, "Expected a profile dump");
  27. did_prof_dump_open = false;
  28. q = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
  29. expect_ptr_not_null(q, "Unexpected mallocx() failure");
  30. expect_true(did_prof_dump_open, "Expected a profile dump");
  31. gdump = false;
  32. sz = sizeof(gdump_old);
  33. expect_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
  34. (void *)&gdump, sizeof(gdump)), 0,
  35. "Unexpected mallctl failure while disabling prof.gdump");
  36. assert(gdump_old);
  37. did_prof_dump_open = false;
  38. r = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
  39. expect_ptr_not_null(q, "Unexpected mallocx() failure");
  40. expect_false(did_prof_dump_open, "Unexpected profile dump");
  41. gdump = true;
  42. sz = sizeof(gdump_old);
  43. expect_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
  44. (void *)&gdump, sizeof(gdump)), 0,
  45. "Unexpected mallctl failure while enabling prof.gdump");
  46. assert(!gdump_old);
  47. did_prof_dump_open = false;
  48. s = mallocx((1U << SC_LG_LARGE_MINCLASS), 0);
  49. expect_ptr_not_null(q, "Unexpected mallocx() failure");
  50. expect_true(did_prof_dump_open, "Expected a profile dump");
  51. dallocx(p, 0);
  52. dallocx(q, 0);
  53. dallocx(r, 0);
  54. dallocx(s, 0);
  55. }
  56. TEST_END
  57. int
  58. main(void) {
  59. return test_no_reentrancy(
  60. test_gdump);
  61. }