2
0

thread_tcache_enabled.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "test/jemalloc_test.h"
  2. static const bool config_tcache =
  3. #ifdef JEMALLOC_TCACHE
  4. true
  5. #else
  6. false
  7. #endif
  8. ;
  9. void *
  10. thd_start(void *arg)
  11. {
  12. int err;
  13. size_t sz;
  14. bool e0, e1;
  15. sz = sizeof(bool);
  16. if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
  17. if (err == ENOENT) {
  18. assert_false(config_tcache,
  19. "ENOENT should only be returned if tcache is "
  20. "disabled");
  21. }
  22. goto label_ENOENT;
  23. }
  24. if (e0) {
  25. e1 = false;
  26. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz),
  27. 0, "Unexpected mallctl() error");
  28. assert_true(e0, "tcache should be enabled");
  29. }
  30. e1 = true;
  31. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  32. "Unexpected mallctl() error");
  33. assert_false(e0, "tcache should be disabled");
  34. e1 = true;
  35. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  36. "Unexpected mallctl() error");
  37. assert_true(e0, "tcache should be enabled");
  38. e1 = false;
  39. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  40. "Unexpected mallctl() error");
  41. assert_true(e0, "tcache should be enabled");
  42. e1 = false;
  43. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  44. "Unexpected mallctl() error");
  45. assert_false(e0, "tcache should be disabled");
  46. free(malloc(1));
  47. e1 = true;
  48. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  49. "Unexpected mallctl() error");
  50. assert_false(e0, "tcache should be disabled");
  51. free(malloc(1));
  52. e1 = true;
  53. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  54. "Unexpected mallctl() error");
  55. assert_true(e0, "tcache should be enabled");
  56. free(malloc(1));
  57. e1 = false;
  58. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  59. "Unexpected mallctl() error");
  60. assert_true(e0, "tcache should be enabled");
  61. free(malloc(1));
  62. e1 = false;
  63. assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
  64. "Unexpected mallctl() error");
  65. assert_false(e0, "tcache should be disabled");
  66. free(malloc(1));
  67. return (NULL);
  68. label_ENOENT:
  69. test_skip("\"thread.tcache.enabled\" mallctl not available");
  70. return (NULL);
  71. }
  72. TEST_BEGIN(test_main_thread)
  73. {
  74. thd_start(NULL);
  75. }
  76. TEST_END
  77. TEST_BEGIN(test_subthread)
  78. {
  79. thd_t thd;
  80. thd_create(&thd, thd_start, NULL);
  81. thd_join(thd, NULL);
  82. }
  83. TEST_END
  84. int
  85. main(void)
  86. {
  87. /* Run tests multiple times to check for bad interactions. */
  88. return (test(
  89. test_main_thread,
  90. test_subthread,
  91. test_main_thread,
  92. test_subthread,
  93. test_main_thread));
  94. }