X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-03-coalesce.c;h=c3583d850c369b74af84817d84f623729a851386;hb=1ad66fedf81fdaf0f07a2b00d6787614c58a23ef;hp=a382ae08ddcb9b10a053201ee08f68d119e9bcfd;hpb=2491b65a6d10cd6ca1a3e05bf535eb0180047922;p=ccan diff --git a/ccan/tdb2/test/run-03-coalesce.c b/ccan/tdb2/test/run-03-coalesce.c index a382ae08..c3583d85 100644 --- a/ccan/tdb2/test/run-03-coalesce.c +++ b/ccan/tdb2/test/run-03-coalesce.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -12,11 +13,13 @@ static tdb_len_t free_record_length(struct tdb_context *tdb, tdb_off_t off) { struct tdb_free_record f; + enum TDB_ERROR ecode; - if (tdb_read_convert(tdb, off, &f, sizeof(f)) != 0) - return TDB_OFF_ERR; + ecode = tdb_read_convert(tdb, off, &f, sizeof(f)); + if (ecode != TDB_SUCCESS) + return ecode; if (frec_magic(&f) != TDB_FREE_MAGIC) - return TDB_OFF_ERR; + return TDB_ERR_CORRUPT; return frec_len(&f); } @@ -37,7 +40,7 @@ int main(int argc, char *argv[]) key.dsize = 5; /* No coalescing can be done due to EOF */ - layout = new_tdb_layout(NULL); + layout = new_tdb_layout("run-03-coalesce.tdb"); tdb_layout_add_freetable(layout); len = 1024; tdb_layout_add_free(layout, len, 0); @@ -54,9 +57,10 @@ int main(int argc, char *argv[]) ok1(free_record_length(tdb, layout->elem[1].base.off) == len); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); + tdb_layout_free(layout); /* No coalescing can be done due to used record */ - layout = new_tdb_layout(NULL); + layout = new_tdb_layout("run-03-coalesce.tdb"); tdb_layout_add_freetable(layout); tdb_layout_add_free(layout, 1024, 0); tdb_layout_add_used(layout, key, data, 6); @@ -73,9 +77,10 @@ int main(int argc, char *argv[]) ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); + tdb_layout_free(layout); /* Coalescing can be done due to two free records, then EOF */ - layout = new_tdb_layout(NULL); + layout = new_tdb_layout("run-03-coalesce.tdb"); tdb_layout_add_freetable(layout); tdb_layout_add_free(layout, 1024, 0); tdb_layout_add_free(layout, 2048, 0); @@ -89,14 +94,15 @@ int main(int argc, char *argv[]) /* 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(tdb->file->allrecord_lock.count == 0 && tdb->file->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); tdb_close(tdb); + tdb_layout_free(layout); /* Coalescing can be done due to two free records, then data */ - layout = new_tdb_layout(NULL); + layout = new_tdb_layout("run-03-coalesce.tdb"); tdb_layout_add_freetable(layout); tdb_layout_add_free(layout, 1024, 0); tdb_layout_add_free(layout, 512, 0); @@ -111,14 +117,15 @@ int main(int argc, char *argv[]) /* 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(tdb->file->allrecord_lock.count == 0 && tdb->file->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); tdb_close(tdb); + tdb_layout_free(layout); /* Coalescing can be done due to three free records, then EOF */ - layout = new_tdb_layout(NULL); + layout = new_tdb_layout("run-03-coalesce.tdb"); tdb_layout_add_freetable(layout); tdb_layout_add_free(layout, 1024, 0); tdb_layout_add_free(layout, 512, 0); @@ -134,12 +141,14 @@ int main(int argc, char *argv[]) /* 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(tdb->file->allrecord_lock.count == 0 + && tdb->file->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); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); + tdb_layout_free(layout); ok1(tap_log_messages == 0); return exit_status();