X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-15-append.c;h=e11289e99b8493723f0c4a641b34bd15a2fdd829;hb=74b0109ebd2a30d57d19ae9a56f16c0f3b3637eb;hp=51d4ddef2d3692934a52d25fc2def3e3fb958f40;hpb=e984ef661368582f7b6e7a8d2a2d709356ac7963;p=ccan diff --git a/ccan/tdb2/test/run-15-append.c b/ccan/tdb2/test/run-15-append.c index 51d4ddef..e11289e9 100644 --- a/ccan/tdb2/test/run-15-append.c +++ b/ccan/tdb2/test/run-15-append.c @@ -1,9 +1,11 @@ #include +#include #include #include #include #include #include +#include #include #include #include "logging.h" @@ -18,7 +20,7 @@ static tdb_off_t tdb_offset(struct tdb_context *tdb, struct tdb_data key) struct hash_info h; off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); - if (unlikely(off == TDB_OFF_ERR)) + if (TDB_OFF_IS_ERR(off)) return 0; tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK); return off; @@ -41,7 +43,7 @@ int main(int argc, char *argv[]) buffer[i] = i; plan_tests(sizeof(flags) / sizeof(flags[0]) - * ((3 + MAX_SIZE/SIZE_STEP * 4) * 2 + 6) + * ((3 + MAX_SIZE/SIZE_STEP * 5) * 2 + 7) + 1); /* Using tdb_store. */ @@ -58,7 +60,7 @@ int main(int argc, char *argv[]) data.dsize = j; ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == j); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); @@ -67,7 +69,8 @@ int main(int argc, char *argv[]) moves++; oldoff = newoff; } - ok1(!tdb_has_locks(tdb)); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); /* We should increase by 50% each time... */ ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); @@ -88,7 +91,7 @@ int main(int argc, char *argv[]) data.dsize = j - prev_len; ok1(tdb_append(tdb, key, data) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == j); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); @@ -98,7 +101,8 @@ int main(int argc, char *argv[]) moves++; oldoff = newoff; } - ok1(!tdb_has_locks(tdb)); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); /* We should increase by 50% each time... */ ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); @@ -116,14 +120,16 @@ int main(int argc, char *argv[]) data.dsize = MAX_SIZE; ok1(tdb_append(tdb, key, data) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == MAX_SIZE); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); - ok1(!tdb_has_locks(tdb)); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); tdb_close(tdb); } ok1(tap_log_messages == 0); + free(buffer); return exit_status(); }