X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-03-coalesce.c;h=e60e341eca46d9fe359a98602f144184f41271bc;hb=5c4a21ab03a428373e7659b9606facf85dcbe17b;hp=d40096515a1ba5c245c2af1f452fb926b89cb471;hpb=efdf0f2d8f34b4c01c82c558b350ec36c7329b1e;p=ccan diff --git a/ccan/tdb2/test/run-03-coalesce.c b/ccan/tdb2/test/run-03-coalesce.c index d4009651..e60e341e 100644 --- a/ccan/tdb2/test/run-03-coalesce.c +++ b/ccan/tdb2/test/run-03-coalesce.c @@ -25,19 +25,18 @@ static tdb_len_t free_record_length(struct tdb_context *tdb, tdb_off_t off) int main(int argc, char *argv[]) { - tdb_off_t b_off; + tdb_off_t b_off, test; struct tdb_context *tdb; struct tdb_layout *layout; struct tdb_data data, key; tdb_len_t len; /* FIXME: Test TDB_CONVERT */ + /* FIXME: Test lock order fail. */ - plan_tests(38); - data.dptr = (void *)"world"; - data.dsize = 5; - key.dptr = (void *)"hello"; - key.dsize = 5; + plan_tests(42); + data = tdb_mkdata("world", 5); + key = tdb_mkdata("hello", 5); /* No coalescing can be done due to EOF */ layout = new_tdb_layout("run-03-coalesce.tdb"); @@ -52,9 +51,12 @@ int main(int argc, char *argv[]) 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); + test = layout->elem[1].base.off; + ok1(coalesce(tdb, layout->elem[1].base.off, b_off, len, &test, &test) + == 0); tdb_unlock_free_bucket(tdb, b_off); ok1(free_record_length(tdb, layout->elem[1].base.off) == len); + ok1(test == layout->elem[1].base.off); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); tdb_layout_free(layout); @@ -72,9 +74,12 @@ int main(int argc, char *argv[]) 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); + test = layout->elem[1].base.off; + ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024, &test, &test) + == 0); tdb_unlock_free_bucket(tdb, b_off); ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024); + ok1(test == layout->elem[1].base.off); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); tdb_layout_free(layout); @@ -93,8 +98,12 @@ int main(int argc, char *argv[]) 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + test = layout->elem[2].base.off; + ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024, &test, &test) + == 1024 + sizeof(struct tdb_used_record) + 2048); + /* Should tell us it's erased this one... */ + ok1(test == TDB_ERR_NOEXIST); + 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); @@ -116,10 +125,13 @@ int main(int argc, char *argv[]) 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + test = layout->elem[2].base.off; + ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024, &test, &test) + == 1024 + sizeof(struct tdb_used_record) + 512); + 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(test == TDB_ERR_NOEXIST); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); tdb_layout_free(layout); @@ -140,8 +152,12 @@ int main(int argc, char *argv[]) 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->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + test = layout->elem[2].base.off; + ok1(coalesce(tdb, layout->elem[1].base.off, b_off, 1024, &test, &test) + == 1024 + sizeof(struct tdb_used_record) + 512 + + sizeof(struct tdb_used_record) + 256); + 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);