prof_gdump.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_gdump) {
  12. bool active, gdump, gdump_old;
  13. void *p, *q, *r, *s;
  14. size_t sz;
  15. test_skip_if(!config_prof);
  16. active = true;
  17. assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
  18. sizeof(active)), 0,
  19. "Unexpected mallctl failure while activating profiling");
  20. prof_dump_open = prof_dump_open_intercept;
  21. did_prof_dump_open = false;
  22. p = mallocx((1U << LG_LARGE_MINCLASS), 0);
  23. assert_ptr_not_null(p, "Unexpected mallocx() failure");
  24. assert_true(did_prof_dump_open, "Expected a profile dump");
  25. did_prof_dump_open = false;
  26. q = mallocx((1U << LG_LARGE_MINCLASS), 0);
  27. assert_ptr_not_null(q, "Unexpected mallocx() failure");
  28. assert_true(did_prof_dump_open, "Expected a profile dump");
  29. gdump = false;
  30. sz = sizeof(gdump_old);
  31. assert_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
  32. (void *)&gdump, sizeof(gdump)), 0,
  33. "Unexpected mallctl failure while disabling prof.gdump");
  34. assert(gdump_old);
  35. did_prof_dump_open = false;
  36. r = mallocx((1U << LG_LARGE_MINCLASS), 0);
  37. assert_ptr_not_null(q, "Unexpected mallocx() failure");
  38. assert_false(did_prof_dump_open, "Unexpected profile dump");
  39. gdump = true;
  40. sz = sizeof(gdump_old);
  41. assert_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz,
  42. (void *)&gdump, sizeof(gdump)), 0,
  43. "Unexpected mallctl failure while enabling prof.gdump");
  44. assert(!gdump_old);
  45. did_prof_dump_open = false;
  46. s = mallocx((1U << LG_LARGE_MINCLASS), 0);
  47. assert_ptr_not_null(q, "Unexpected mallocx() failure");
  48. assert_true(did_prof_dump_open, "Expected a profile dump");
  49. dallocx(p, 0);
  50. dallocx(q, 0);
  51. dallocx(r, 0);
  52. dallocx(s, 0);
  53. }
  54. TEST_END
  55. int
  56. main(void) {
  57. return test_no_reentrancy(
  58. test_gdump);
  59. }