mallctl.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "test/jemalloc_test.h"
  2. #include "test/bench.h"
  3. static void
  4. mallctl_short(void) {
  5. const char *version;
  6. size_t sz = sizeof(version);
  7. int err = mallctl("version", &version, &sz, NULL, 0);
  8. assert_d_eq(err, 0, "mallctl failure");
  9. }
  10. size_t mib_short[1];
  11. static void
  12. mallctlbymib_short(void) {
  13. size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
  14. const char *version;
  15. size_t sz = sizeof(version);
  16. int err = mallctlbymib(mib_short, miblen, &version, &sz, NULL, 0);
  17. assert_d_eq(err, 0, "mallctlbymib failure");
  18. }
  19. TEST_BEGIN(test_mallctl_vs_mallctlbymib_short) {
  20. size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
  21. int err = mallctlnametomib("version", mib_short, &miblen);
  22. assert_d_eq(err, 0, "mallctlnametomib failure");
  23. compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_short",
  24. mallctl_short, "mallctlbymib_short", mallctlbymib_short);
  25. }
  26. TEST_END
  27. static void
  28. mallctl_long(void) {
  29. uint64_t nmalloc;
  30. size_t sz = sizeof(nmalloc);
  31. int err = mallctl("stats.arenas.0.bins.0.nmalloc", &nmalloc, &sz, NULL,
  32. 0);
  33. assert_d_eq(err, 0, "mallctl failure");
  34. }
  35. size_t mib_long[6];
  36. static void
  37. mallctlbymib_long(void) {
  38. size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
  39. uint64_t nmalloc;
  40. size_t sz = sizeof(nmalloc);
  41. int err = mallctlbymib(mib_long, miblen, &nmalloc, &sz, NULL, 0);
  42. assert_d_eq(err, 0, "mallctlbymib failure");
  43. }
  44. TEST_BEGIN(test_mallctl_vs_mallctlbymib_long) {
  45. /*
  46. * We want to use the longest mallctl we have; that needs stats support
  47. * to be allowed.
  48. */
  49. test_skip_if(!config_stats);
  50. size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
  51. int err = mallctlnametomib("stats.arenas.0.bins.0.nmalloc", mib_long,
  52. &miblen);
  53. assert_d_eq(err, 0, "mallctlnametomib failure");
  54. compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_long",
  55. mallctl_long, "mallctlbymib_long", mallctlbymib_long);
  56. }
  57. TEST_END
  58. int
  59. main(void) {
  60. return test_no_reentrancy(
  61. test_mallctl_vs_mallctlbymib_short,
  62. test_mallctl_vs_mallctlbymib_long);
  63. }