Increase test coverage in test_decay_ticks.

This commit is contained in:
Jason Evans 2016-02-20 09:02:49 -08:00
parent 243f7a0508
commit 9f24c94474

View File

@ -24,7 +24,6 @@ TEST_BEGIN(test_decay_ticks)
unsigned tick0, tick1; unsigned tick0, tick1;
size_t sz, huge0, large0; size_t sz, huge0, large0;
void *p; void *p;
unsigned tcache_ind;
test_skip_if(opt_purge != purge_mode_decay); test_skip_if(opt_purge != purge_mode_decay);
@ -38,6 +37,12 @@ TEST_BEGIN(test_decay_ticks)
assert_d_eq(mallctl("arenas.lrun.0.size", &large0, &sz, NULL, 0), 0, assert_d_eq(mallctl("arenas.lrun.0.size", &large0, &sz, NULL, 0), 0,
"Unexpected mallctl failure"); "Unexpected mallctl failure");
/*
* Test the standard APIs using a huge size class, since we can't
* control tcache interactions (except by completely disabling tcache
* for the entire test program).
*/
/* malloc(). */ /* malloc(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
p = malloc(huge0); p = malloc(huge0);
@ -95,129 +100,99 @@ TEST_BEGIN(test_decay_ticks)
tick1 = ticker_read(decay_ticker); tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0, "Expected ticker to tick during realloc()"); assert_u32_ne(tick1, tick0, "Expected ticker to tick during realloc()");
/* Huge mallocx(). */ /*
tick0 = ticker_read(decay_ticker); * Test the *allocx() APIs using huge, large, and small size classes,
p = mallocx(huge0, 0); * with tcache explicitly disabled.
assert_ptr_not_null(p, "Unexpected mallocx() failure"); */
tick1 = ticker_read(decay_ticker); {
assert_u32_ne(tick1, tick0, unsigned i;
"Expected ticker to tick during huge mallocx()"); size_t allocx_sizes[3];
/* Huge rallocx(). */ allocx_sizes[0] = huge0;
tick0 = ticker_read(decay_ticker); allocx_sizes[1] = large0;
p = rallocx(p, huge0, 0); allocx_sizes[2] = 1;
assert_ptr_not_null(p, "Unexpected rallocx() failure");
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during huge rallocx()");
/* Huge xallocx(). */
tick0 = ticker_read(decay_ticker);
xallocx(p, huge0, 0, 0);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during huge xallocx()");
/* Huge dallocx(). */
tick0 = ticker_read(decay_ticker);
dallocx(p, 0);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during huge dallocx()");
/* Huge sdallocx(). */
p = mallocx(huge0, 0);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick0 = ticker_read(decay_ticker);
sdallocx(p, huge0, 0);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during huge sdallocx()");
/* Large mallocx(). */ for (i = 0; i < sizeof(allocx_sizes) / sizeof(size_t); i++) {
tick0 = ticker_read(decay_ticker); sz = allocx_sizes[i];
p = mallocx(large0, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during large mallocx()");
/* Large rallocx(). */
tick0 = ticker_read(decay_ticker);
p = rallocx(p, large0, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected rallocx() failure");
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during large rallocx()");
/* Large xallocx(). */
tick0 = ticker_read(decay_ticker);
xallocx(p, large0, 0, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during large xallocx()");
/* Large dallocx(). */
tick0 = ticker_read(decay_ticker);
dallocx(p, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during large dallocx()");
/* Large sdallocx(). */
p = mallocx(large0, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick0 = ticker_read(decay_ticker);
sdallocx(p, large0, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during large sdallocx()");
/* Small mallocx(). */ /* mallocx(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
p = mallocx(1, MALLOCX_TCACHE_NONE); p = mallocx(sz, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected mallocx() failure"); assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick1 = ticker_read(decay_ticker); tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0, assert_u32_ne(tick1, tick0,
"Expected ticker to tick during small mallocx()"); "Expected ticker to tick during mallocx() (sz=%zu)",
/* Small rallocx(). */ sz);
tick0 = ticker_read(decay_ticker); /* rallocx(). */
p = rallocx(p, 1, MALLOCX_TCACHE_NONE); tick0 = ticker_read(decay_ticker);
assert_ptr_not_null(p, "Unexpected rallocx() failure"); p = rallocx(p, sz, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker); assert_ptr_not_null(p, "Unexpected rallocx() failure");
assert_u32_ne(tick1, tick0, tick1 = ticker_read(decay_ticker);
"Expected ticker to tick during small rallocx()"); assert_u32_ne(tick1, tick0,
/* Small xallocx(). */ "Expected ticker to tick during rallocx() (sz=%zu)",
tick0 = ticker_read(decay_ticker); sz);
xallocx(p, 1, 0, MALLOCX_TCACHE_NONE); /* xallocx(). */
tick1 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0, xallocx(p, sz, 0, MALLOCX_TCACHE_NONE);
"Expected ticker to tick during small xallocx()"); tick1 = ticker_read(decay_ticker);
/* Small dallocx(). */ assert_u32_ne(tick1, tick0,
tick0 = ticker_read(decay_ticker); "Expected ticker to tick during xallocx() (sz=%zu)",
dallocx(p, MALLOCX_TCACHE_NONE); sz);
tick1 = ticker_read(decay_ticker); /* dallocx(). */
assert_u32_ne(tick1, tick0, tick0 = ticker_read(decay_ticker);
"Expected ticker to tick during small dallocx()"); dallocx(p, MALLOCX_TCACHE_NONE);
/* Small sdallocx(). */ tick1 = ticker_read(decay_ticker);
p = mallocx(1, MALLOCX_TCACHE_NONE); assert_u32_ne(tick1, tick0,
assert_ptr_not_null(p, "Unexpected mallocx() failure"); "Expected ticker to tick during dallocx() (sz=%zu)",
tick0 = ticker_read(decay_ticker); sz);
sdallocx(p, 1, MALLOCX_TCACHE_NONE); /* sdallocx(). */
tick1 = ticker_read(decay_ticker); p = mallocx(sz, MALLOCX_TCACHE_NONE);
assert_u32_ne(tick1, tick0, assert_ptr_not_null(p, "Unexpected mallocx() failure");
"Expected ticker to tick during small sdallocx()"); tick0 = ticker_read(decay_ticker);
sdallocx(p, sz, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during sdallocx() "
"(sz=%zu)", sz);
}
}
/* tcache fill. */ /*
sz = sizeof(unsigned); * Test tcache fill/flush interactions for large and small size classes,
assert_d_eq(mallctl("tcache.create", &tcache_ind, &sz, NULL, 0), 0, * using an explicit tcache.
"Unexpected mallctl failure"); */
tick0 = ticker_read(decay_ticker); {
p = mallocx(1, MALLOCX_TCACHE(tcache_ind)); unsigned tcache_ind, i;
assert_ptr_not_null(p, "Unexpected mallocx() failure"); size_t tcache_sizes[2];
tick1 = ticker_read(decay_ticker); tcache_sizes[0] = large0;
assert_u32_ne(tick1, tick0, tcache_sizes[1] = 1;
"Expected ticker to tick during tcache fill");
/* tcache flush. */ sz = sizeof(unsigned);
dallocx(p, MALLOCX_TCACHE(tcache_ind)); assert_d_eq(mallctl("tcache.create", &tcache_ind, &sz, NULL, 0),
tick0 = ticker_read(decay_ticker); 0, "Unexpected mallctl failure");
assert_d_eq(mallctl("tcache.flush", NULL, NULL, &tcache_ind,
sizeof(unsigned)), 0, "Unexpected mallctl failure"); for (i = 0; i < sizeof(tcache_sizes) / sizeof(size_t); i++) {
tick1 = ticker_read(decay_ticker); sz = tcache_sizes[i];
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during tcache flush"); /* tcache fill. */
tick0 = ticker_read(decay_ticker);
p = mallocx(sz, MALLOCX_TCACHE(tcache_ind));
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during tcache fill "
"(sz=%zu)", sz);
/* tcache flush. */
dallocx(p, MALLOCX_TCACHE(tcache_ind));
tick0 = ticker_read(decay_ticker);
assert_d_eq(mallctl("tcache.flush", NULL, NULL,
&tcache_ind, sizeof(unsigned)), 0,
"Unexpected mallctl failure");
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during tcache flush "
"(sz=%zu)", sz);
}
}
} }
TEST_END TEST_END