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++) {
sz = allocx_sizes[i];
/* mallocx(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
p = mallocx(large0, 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 large mallocx()"); "Expected ticker to tick during mallocx() (sz=%zu)",
/* Large rallocx(). */ sz);
/* rallocx(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
p = rallocx(p, large0, MALLOCX_TCACHE_NONE); p = rallocx(p, sz, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected rallocx() failure"); assert_ptr_not_null(p, "Unexpected rallocx() 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 large rallocx()"); "Expected ticker to tick during rallocx() (sz=%zu)",
/* Large xallocx(). */ sz);
/* xallocx(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
xallocx(p, large0, 0, MALLOCX_TCACHE_NONE); xallocx(p, sz, 0, MALLOCX_TCACHE_NONE);
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 large xallocx()"); "Expected ticker to tick during xallocx() (sz=%zu)",
/* Large dallocx(). */ sz);
/* dallocx(). */
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
dallocx(p, MALLOCX_TCACHE_NONE); dallocx(p, MALLOCX_TCACHE_NONE);
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 large dallocx()"); "Expected ticker to tick during dallocx() (sz=%zu)",
/* Large sdallocx(). */ sz);
p = mallocx(large0, MALLOCX_TCACHE_NONE); /* sdallocx(). */
p = mallocx(sz, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected mallocx() failure"); assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
sdallocx(p, large0, MALLOCX_TCACHE_NONE); sdallocx(p, sz, MALLOCX_TCACHE_NONE);
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 large sdallocx()"); "Expected ticker to tick during sdallocx() "
"(sz=%zu)", sz);
}
}
/* Small mallocx(). */ /*
tick0 = ticker_read(decay_ticker); * Test tcache fill/flush interactions for large and small size classes,
p = mallocx(1, MALLOCX_TCACHE_NONE); * using an explicit tcache.
assert_ptr_not_null(p, "Unexpected mallocx() failure"); */
tick1 = ticker_read(decay_ticker); {
assert_u32_ne(tick1, tick0, unsigned tcache_ind, i;
"Expected ticker to tick during small mallocx()"); size_t tcache_sizes[2];
/* Small rallocx(). */ tcache_sizes[0] = large0;
tick0 = ticker_read(decay_ticker); tcache_sizes[1] = 1;
p = rallocx(p, 1, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected rallocx() failure"); sz = sizeof(unsigned);
tick1 = ticker_read(decay_ticker); assert_d_eq(mallctl("tcache.create", &tcache_ind, &sz, NULL, 0),
assert_u32_ne(tick1, tick0, 0, "Unexpected mallctl failure");
"Expected ticker to tick during small rallocx()");
/* Small xallocx(). */ for (i = 0; i < sizeof(tcache_sizes) / sizeof(size_t); i++) {
tick0 = ticker_read(decay_ticker); sz = tcache_sizes[i];
xallocx(p, 1, 0, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during small xallocx()");
/* Small 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 small dallocx()");
/* Small sdallocx(). */
p = mallocx(1, MALLOCX_TCACHE_NONE);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tick0 = ticker_read(decay_ticker);
sdallocx(p, 1, MALLOCX_TCACHE_NONE);
tick1 = ticker_read(decay_ticker);
assert_u32_ne(tick1, tick0,
"Expected ticker to tick during small sdallocx()");
/* tcache fill. */ /* tcache fill. */
sz = sizeof(unsigned);
assert_d_eq(mallctl("tcache.create", &tcache_ind, &sz, NULL, 0), 0,
"Unexpected mallctl failure");
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
p = mallocx(1, MALLOCX_TCACHE(tcache_ind)); p = mallocx(sz, MALLOCX_TCACHE(tcache_ind));
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 tcache fill"); "Expected ticker to tick during tcache fill "
"(sz=%zu)", sz);
/* tcache flush. */ /* tcache flush. */
dallocx(p, MALLOCX_TCACHE(tcache_ind)); dallocx(p, MALLOCX_TCACHE(tcache_ind));
tick0 = ticker_read(decay_ticker); tick0 = ticker_read(decay_ticker);
assert_d_eq(mallctl("tcache.flush", NULL, NULL, &tcache_ind, assert_d_eq(mallctl("tcache.flush", NULL, NULL,
sizeof(unsigned)), 0, "Unexpected mallctl failure"); &tcache_ind, sizeof(unsigned)), 0,
"Unexpected mallctl 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 tcache flush"); "Expected ticker to tick during tcache flush "
"(sz=%zu)", sz);
}
}
} }
TEST_END TEST_END