X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-03-coalesce.c;h=a382ae08ddcb9b10a053201ee08f68d119e9bcfd;hp=b8bf25cb02fce7f9fdcb28016faf2210cb10e3de;hb=04cf551d15ee93716aa0462adadc0a3891480813;hpb=d70577b6aff24ccf6815896509dabb8c9ac07904 diff --git a/ccan/tdb2/test/run-03-coalesce.c b/ccan/tdb2/test/run-03-coalesce.c index b8bf25cb..a382ae08 100644 --- a/ccan/tdb2/test/run-03-coalesce.c +++ b/ccan/tdb2/test/run-03-coalesce.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "logging.h" #include "layout.h" @@ -16,7 +17,7 @@ static tdb_len_t free_record_length(struct tdb_context *tdb, tdb_off_t off) return TDB_OFF_ERR; if (frec_magic(&f) != TDB_FREE_MAGIC) return TDB_OFF_ERR; - return f.data_len; + return frec_len(&f); } int main(int argc, char *argv[]) @@ -37,15 +38,15 @@ int main(int argc, char *argv[]) /* No coalescing can be done due to EOF */ layout = new_tdb_layout(NULL); - tdb_layout_add_freelist(layout); + tdb_layout_add_freetable(layout); len = 1024; - tdb_layout_add_free(layout, len); + tdb_layout_add_free(layout, len, 0); tdb = tdb_layout_get(layout); ok1(tdb_check(tdb, NULL, NULL) == 0); ok1(free_record_length(tdb, layout->elem[1].base.off) == len); /* Figure out which bucket free entry is. */ - b_off = bucket_off(tdb->flist_off, size_to_bucket(len)); + b_off = bucket_off(tdb->ftable_off, size_to_bucket(len)); /* Lock and fail to coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); ok1(coalesce(tdb, layout->elem[1].base.off, b_off, len) == 0); @@ -56,15 +57,15 @@ int main(int argc, char *argv[]) /* No coalescing can be done due to used record */ layout = new_tdb_layout(NULL); - tdb_layout_add_freelist(layout); - tdb_layout_add_free(layout, 1024); + tdb_layout_add_freetable(layout); + tdb_layout_add_free(layout, 1024, 0); tdb_layout_add_used(layout, key, data, 6); tdb = tdb_layout_get(layout); 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(tdb->flist_off, size_to_bucket(1024)); + b_off = bucket_off(tdb->ftable_off, size_to_bucket(1024)); /* Lock and fail to coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024) == 0); @@ -75,20 +76,20 @@ int main(int argc, char *argv[]) /* Coalescing can be done due to two free records, then EOF */ layout = new_tdb_layout(NULL); - tdb_layout_add_freelist(layout); - tdb_layout_add_free(layout, 1024); - tdb_layout_add_free(layout, 2048); + tdb_layout_add_freetable(layout); + tdb_layout_add_free(layout, 1024, 0); + tdb_layout_add_free(layout, 2048, 0); tdb = tdb_layout_get(layout); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); ok1(free_record_length(tdb, layout->elem[2].base.off) == 2048); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket (first) free entry is. */ - b_off = bucket_off(tdb->flist_off, size_to_bucket(1024)); + b_off = bucket_off(tdb->ftable_off, size_to_bucket(1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024) == 1); - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + 2048); ok1(tdb_check(tdb, NULL, NULL) == 0); @@ -96,9 +97,9 @@ int main(int argc, char *argv[]) /* Coalescing can be done due to two free records, then data */ layout = new_tdb_layout(NULL); - tdb_layout_add_freelist(layout); - tdb_layout_add_free(layout, 1024); - tdb_layout_add_free(layout, 512); + tdb_layout_add_freetable(layout); + tdb_layout_add_free(layout, 1024, 0); + tdb_layout_add_free(layout, 512, 0); tdb_layout_add_used(layout, key, data, 6); tdb = tdb_layout_get(layout); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); @@ -106,11 +107,11 @@ int main(int argc, char *argv[]) ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket free entry is. */ - b_off = bucket_off(tdb->flist_off, size_to_bucket(1024)); + b_off = bucket_off(tdb->ftable_off, size_to_bucket(1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024) == 1); - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + 512); ok1(tdb_check(tdb, NULL, NULL) == 0); @@ -118,10 +119,10 @@ int main(int argc, char *argv[]) /* Coalescing can be done due to three free records, then EOF */ layout = new_tdb_layout(NULL); - tdb_layout_add_freelist(layout); - tdb_layout_add_free(layout, 1024); - tdb_layout_add_free(layout, 512); - tdb_layout_add_free(layout, 256); + tdb_layout_add_freetable(layout); + tdb_layout_add_free(layout, 1024, 0); + tdb_layout_add_free(layout, 512, 0); + tdb_layout_add_free(layout, 256, 0); tdb = tdb_layout_get(layout); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); ok1(free_record_length(tdb, layout->elem[2].base.off) == 512); @@ -129,11 +130,11 @@ int main(int argc, char *argv[]) ok1(tdb_check(tdb, NULL, NULL) == 0); /* Figure out which bucket free entry is. */ - b_off = bucket_off(tdb->flist_off, size_to_bucket(1024)); + b_off = bucket_off(tdb->ftable_off, size_to_bucket(1024)); /* Lock and coalesce. */ ok1(tdb_lock_free_bucket(tdb, b_off, TDB_LOCK_WAIT) == 0); ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024) == 1); - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024 + sizeof(struct tdb_used_record) + 512 + sizeof(struct tdb_used_record) + 256);