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