X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-03-coalesce.c;h=529b6c7bf9625dfe980ef95a790d6fb686b16d6c;hb=a0ac303da08672d4cfe5629b794b2651e1e98399;hp=d3e624cf5bf66bdeda53e2b10487e543cfe1364c;hpb=1a24a8708494668c07e5c02284bfc2ef3b09603b;p=ccan diff --git a/ccan/tdb2/test/run-03-coalesce.c b/ccan/tdb2/test/run-03-coalesce.c index d3e624cf..529b6c7b 100644 --- a/ccan/tdb2/test/run-03-coalesce.c +++ b/ccan/tdb2/test/run-03-coalesce.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "logging.h" @@ -38,67 +39,63 @@ int main(int argc, char *argv[]) /* No coalescing can be done due to EOF */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb = tdb_layout_get(layout); - len = layout->elem[2].free.len; + len = layout->elem[1].free.len; zone_off = layout->elem[0].base.off; ok1(tdb_check(tdb, NULL, NULL) == 0); - ok1(free_record_length(tdb, layout->elem[2].base.off) == len); + ok1(free_record_length(tdb, layout->elem[1].base.off) == len); /* Figure out which bucket free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, len)); /* Lock and fail to coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, len) == 0); tdb_unlock_free_bucket(tdb, b_off); - tdb_unlock_list(tdb, 0, F_WRLCK); - ok1(free_record_length(tdb, layout->elem[2].base.off) == len); + ok1(free_record_length(tdb, layout->elem[1].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); /* No coalescing can be done due to used record */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb_layout_add_free(layout, 1024); tdb_layout_add_used(layout, key, data, 6); tdb = tdb_layout_get(layout); zone_off = layout->elem[0].base.off; - ok1(free_record_length(tdb, layout->elem[2].base.off) == 1024); + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, 1024)); /* Lock and fail to coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, 1024) == 0); tdb_unlock_free_bucket(tdb, b_off); - ok1(free_record_length(tdb, layout->elem[2].base.off) == 1024); + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); /* Coalescing can be done due to two free records, then EOF */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb_layout_add_free(layout, 1024); tdb = tdb_layout_get(layout); zone_off = layout->elem[0].base.off; - len = layout->elem[3].free.len; - ok1(free_record_length(tdb, layout->elem[2].base.off) == 1024); - ok1(free_record_length(tdb, layout->elem[3].base.off) == len); + len = layout->elem[2].free.len; + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); + ok1(free_record_length(tdb, layout->elem[2].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket (first) free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, 1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, 1024) == 1); ok1(!tdb_has_locks(tdb)); - ok1(free_record_length(tdb, layout->elem[2].base.off) + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + len); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); @@ -106,24 +103,23 @@ int main(int argc, char *argv[]) /* Coalescing can be done due to two free records, then data */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb_layout_add_free(layout, 1024); tdb_layout_add_free(layout, 512); tdb_layout_add_used(layout, key, data, 6); tdb = tdb_layout_get(layout); zone_off = layout->elem[0].base.off; - ok1(free_record_length(tdb, layout->elem[2].base.off) == 1024); - ok1(free_record_length(tdb, layout->elem[3].base.off) == 512); + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); + ok1(free_record_length(tdb, layout->elem[2].base.off) == 512); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, 1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, 1024) == 1); ok1(!tdb_has_locks(tdb)); - ok1(free_record_length(tdb, layout->elem[2].base.off) + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + 512); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); @@ -131,25 +127,24 @@ int main(int argc, char *argv[]) /* Coalescing can be done due to three free records, then EOF */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb_layout_add_free(layout, 1024); tdb_layout_add_free(layout, 512); tdb = tdb_layout_get(layout); zone_off = layout->elem[0].base.off; - len = layout->elem[4].free.len; - ok1(free_record_length(tdb, layout->elem[2].base.off) == 1024); - ok1(free_record_length(tdb, layout->elem[3].base.off) == 512); - ok1(free_record_length(tdb, layout->elem[4].base.off) == len); + len = layout->elem[3].free.len; + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); + ok1(free_record_length(tdb, layout->elem[2].base.off) == 512); + ok1(free_record_length(tdb, layout->elem[3].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, 1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, 1024) == 1); ok1(!tdb_has_locks(tdb)); - ok1(free_record_length(tdb, layout->elem[2].base.off) + ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + 512 + sizeof(struct tdb_used_record) + len); ok1(tdb_check(tdb, NULL, NULL) == 0); @@ -158,23 +153,22 @@ int main(int argc, char *argv[]) /* Coalescing across two zones isn't possible. */ layout = new_tdb_layout(); tdb_layout_add_zone(layout, zone_bits, false); - tdb_layout_add_hashtable(layout, 12, 0); tdb_layout_add_zone(layout, zone_bits, true); tdb = tdb_layout_get(layout); zone_off = layout->elem[0].base.off; - len = layout->elem[2].free.len; - ok1(free_record_length(tdb, layout->elem[2].base.off) == len); + len = layout->elem[1].free.len; + ok1(free_record_length(tdb, layout->elem[1].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which list free entry is. */ b_off = bucket_off(zone_off, size_to_bucket(zone_bits, len)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); - ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[2].base.off, + ok1(coalesce(tdb, zone_off, zone_bits, layout->elem[1].base.off, b_off, len) == 0); tdb_unlock_free_bucket(tdb, b_off); ok1(!tdb_has_locks(tdb)); - ok1(free_record_length(tdb, layout->elem[2].base.off) == len); + ok1(free_record_length(tdb, layout->elem[1].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb);