Decay: Add a (mostly stub) test case.

This commit is contained in:
David Goldblatt 2020-03-10 10:19:38 -07:00 committed by David Goldblatt
parent f77cec311e
commit 48a2cd6d79
2 changed files with 46 additions and 0 deletions

View File

@ -197,6 +197,7 @@ TESTS_UNIT := \
$(srcroot)test/unit/cache_bin.c \ $(srcroot)test/unit/cache_bin.c \
$(srcroot)test/unit/ckh.c \ $(srcroot)test/unit/ckh.c \
$(srcroot)test/unit/counter.c \ $(srcroot)test/unit/counter.c \
$(srcroot)test/unit/decay.c \
$(srcroot)test/unit/div.c \ $(srcroot)test/unit/div.c \
$(srcroot)test/unit/edata_cache.c \ $(srcroot)test/unit/edata_cache.c \
$(srcroot)test/unit/emitter.c \ $(srcroot)test/unit/emitter.c \

45
test/unit/decay.c Normal file
View File

@ -0,0 +1,45 @@
#include "test/jemalloc_test.h"
#include "jemalloc/internal/decay.h"
/*
* Honestly, this is mostly a stub for now. Eventually, we should beef up
* testing here.
*/
TEST_BEGIN(test_decay_empty) {
/* If we never have any decaying pages, npages_limit should be 0. */
decay_t decay;
memset(&decay, 0, sizeof(decay));
nstime_t curtime;
nstime_init(&curtime, 0);
uint64_t decay_ms = 1000;
uint64_t decay_ns = decay_ms * 1000 * 1000;
bool err = decay_init(&decay, &curtime, (ssize_t)decay_ms);
assert_false(err, "");
uint64_t time_between_calls = decay_epoch_duration_ns(&decay) / 5;
int nepochs = 0;
for (uint64_t i = 0; i < decay_ns / time_between_calls * 10; i++) {
size_t dirty_pages = 0;
nstime_init(&curtime, i * time_between_calls);
bool epoch_advanced = decay_maybe_advance_epoch(&decay,
&curtime, dirty_pages);
if (epoch_advanced) {
nepochs++;
assert_zu_eq(decay_npages_limit_get(&decay), 0,
"Should not increase the limit arbitrarily");
}
}
assert_d_gt(nepochs, 0, "Should have advanced epochs");
}
TEST_END
int
main(void) {
return test(
test_decay_empty);
}