X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-02-expand.c;h=b681c05c1b6a5519e173d4d88541a3634a8593c3;hb=d1383862ad9a74e713dc915d351b74da4db35078;hp=b35176453ca29941225500664b6de57a29b68c1a;hpb=6804501c350181dea8f531142b28c620b70edbd9;p=ccan-lca-2011.git diff --git a/ccan/tdb2/test/run-02-expand.c b/ccan/tdb2/test/run-02-expand.c index b351764..b681c05 100644 --- a/ccan/tdb2/test/run-02-expand.c +++ b/ccan/tdb2/test/run-02-expand.c @@ -25,36 +25,47 @@ int main(int argc, char *argv[]) if (!tdb) continue; - /* First expand. Should add a zone, doubling file size.. */ - val = tdb->map_size - 1 - sizeof(struct tdb_header); + /* First expand. Should not fill zone. */ + val = tdb->map_size - sizeof(struct tdb_header); ok1(tdb_expand(tdb, 1) == 0); - ok1(tdb->map_size == 2 * val + 1 + sizeof(struct tdb_header)); + ok1(tdb->map_size < sizeof(struct tdb_header) + + (1 << INITIAL_ZONE_BITS)); ok1(tdb_check(tdb, NULL, NULL) == 0); - /* Second expand, add another zone of same size. */ - ok1(tdb_expand(tdb, 1) == 0); - ok1(tdb->map_size == 3 * val + 1 + sizeof(struct tdb_header)); + /* Fill zone. */ + val = (1<map_size - sizeof(struct tdb_header)); + ok1(tdb_expand(tdb, val) == 0); + ok1(tdb->map_size == sizeof(struct tdb_header) + + (1 << INITIAL_ZONE_BITS)); ok1(tdb_check(tdb, NULL, NULL) == 0); - /* Large expand, but can only add 4th zone of same size. */ - ok1(tdb_expand(tdb, 4*val) == 0); - ok1(tdb->map_size == 4 * val + 1 + sizeof(struct tdb_header)); + /* Second expand, adds another zone of same size. */ + ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0); + ok1(tdb->map_size == + (2<map_size == 8 * val + 1 + sizeof(struct tdb_header)); + ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0); + ok1(tdb->map_size == + (4<map_size == 16 * val + 1 + sizeof(struct tdb_header)); + ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0); + ok1(tdb->map_size == + (8<> TDB_COMFORT_FACTOR_BITS) + /* Below comfort level, won't fill zone. */ + ok1(tdb_expand(tdb, + ((3 << INITIAL_ZONE_BITS) + >> TDB_COMFORT_FACTOR_BITS) - sizeof(struct tdb_used_record)) == 0); - ok1(tdb->map_size == 24 * val + 1 + sizeof(struct tdb_header)); + ok1(tdb->map_size < (12<