sc.c 930 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "test/jemalloc_test.h"
  2. TEST_BEGIN(test_update_slab_size) {
  3. sc_data_t data;
  4. memset(&data, 0, sizeof(data));
  5. sc_data_init(&data);
  6. sc_t *tiny = &data.sc[0];
  7. size_t tiny_size = (ZU(1) << tiny->lg_base)
  8. + (ZU(tiny->ndelta) << tiny->lg_delta);
  9. size_t pgs_too_big = (tiny_size * BITMAP_MAXBITS + PAGE - 1) / PAGE + 1;
  10. sc_data_update_slab_size(&data, tiny_size, tiny_size, (int)pgs_too_big);
  11. expect_zu_lt((size_t)tiny->pgs, pgs_too_big, "Allowed excessive pages");
  12. sc_data_update_slab_size(&data, 1, 10 * PAGE, 1);
  13. for (int i = 0; i < data.nbins; i++) {
  14. sc_t *sc = &data.sc[i];
  15. size_t reg_size = (ZU(1) << sc->lg_base)
  16. + (ZU(sc->ndelta) << sc->lg_delta);
  17. if (reg_size <= PAGE) {
  18. expect_d_eq(sc->pgs, 1, "Ignored valid page size hint");
  19. } else {
  20. expect_d_gt(sc->pgs, 1,
  21. "Allowed invalid page size hint");
  22. }
  23. }
  24. }
  25. TEST_END
  26. int
  27. main(void) {
  28. return test(
  29. test_update_slab_size);
  30. }