prof_gdump.c 1.9 KB

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