thread_tcache_enabled.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "test/jemalloc_test.h"
  2. void *
  3. thd_start(void *arg) {
  4. bool e0, e1;
  5. size_t sz = sizeof(bool);
  6. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL,
  7. 0), 0, "Unexpected mallctl failure");
  8. if (e0) {
  9. e1 = false;
  10. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  11. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  12. expect_true(e0, "tcache should be enabled");
  13. }
  14. e1 = true;
  15. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  16. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  17. expect_false(e0, "tcache should be disabled");
  18. e1 = true;
  19. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  20. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  21. expect_true(e0, "tcache should be enabled");
  22. e1 = false;
  23. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  24. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  25. expect_true(e0, "tcache should be enabled");
  26. e1 = false;
  27. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  28. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  29. expect_false(e0, "tcache should be disabled");
  30. free(malloc(1));
  31. e1 = true;
  32. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  33. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  34. expect_false(e0, "tcache should be disabled");
  35. free(malloc(1));
  36. e1 = true;
  37. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  38. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  39. expect_true(e0, "tcache should be enabled");
  40. free(malloc(1));
  41. e1 = false;
  42. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  43. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  44. expect_true(e0, "tcache should be enabled");
  45. free(malloc(1));
  46. e1 = false;
  47. expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
  48. (void *)&e1, sz), 0, "Unexpected mallctl() error");
  49. expect_false(e0, "tcache should be disabled");
  50. free(malloc(1));
  51. return NULL;
  52. }
  53. TEST_BEGIN(test_main_thread) {
  54. thd_start(NULL);
  55. }
  56. TEST_END
  57. TEST_BEGIN(test_subthread) {
  58. thd_t thd;
  59. thd_create(&thd, thd_start, NULL);
  60. thd_join(thd, NULL);
  61. }
  62. TEST_END
  63. int
  64. main(void) {
  65. /* Run tests multiple times to check for bad interactions. */
  66. return test(
  67. test_main_thread,
  68. test_subthread,
  69. test_main_thread,
  70. test_subthread,
  71. test_main_thread);
  72. }