X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-15-append.c;h=fe7a24e0eb402767891a7705d58b9c0a0a2113c8;hp=3f1fb5b3e878c0dd81db11607cda28949efb7a33;hb=51a56b52627e635566253a3fae081c3f466b6bb6;hpb=6804501c350181dea8f531142b28c620b70edbd9 diff --git a/ccan/tdb2/test/run-15-append.c b/ccan/tdb2/test/run-15-append.c index 3f1fb5b3..fe7a24e0 100644 --- a/ccan/tdb2/test/run-15-append.c +++ b/ccan/tdb2/test/run-15-append.c @@ -4,17 +4,33 @@ #include #include #include +#include #include +#include #include "logging.h" #define MAX_SIZE 13100 #define SIZE_STEP 131 +static tdb_off_t tdb_offset(struct tdb_context *tdb, struct tdb_data key) +{ + tdb_off_t off; + struct tdb_used_record rec; + struct hash_info h; + + off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); + if (unlikely(off == TDB_OFF_ERR)) + return 0; + tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK); + return off; +} + int main(int argc, char *argv[]) { - unsigned int i, j; + unsigned int i, j, moves; struct tdb_context *tdb; unsigned char *buffer; + tdb_off_t oldoff = 0, newoff; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; @@ -26,7 +42,7 @@ int main(int argc, char *argv[]) buffer[i] = i; plan_tests(sizeof(flags) / sizeof(flags[0]) - * ((2 + MAX_SIZE/SIZE_STEP * 4) * 2 + 6) + * ((3 + MAX_SIZE/SIZE_STEP * 4) * 2 + 6) + 1); /* Using tdb_store. */ @@ -37,6 +53,7 @@ int main(int argc, char *argv[]) if (!tdb) continue; + moves = 0; for (j = 0; j < MAX_SIZE; j += SIZE_STEP) { data.dptr = buffer; data.dsize = j; @@ -46,8 +63,14 @@ int main(int argc, char *argv[]) ok1(data.dsize == j); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); + newoff = tdb_offset(tdb, key); + if (newoff != oldoff) + moves++; + oldoff = newoff; } - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + /* We should increase by 50% each time... */ + ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); } @@ -60,6 +83,7 @@ int main(int argc, char *argv[]) if (!tdb) continue; + moves = 0; for (j = 0; j < MAX_SIZE; j += SIZE_STEP) { data.dptr = buffer + prev_len; data.dsize = j - prev_len; @@ -70,8 +94,14 @@ int main(int argc, char *argv[]) ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); prev_len = data.dsize; + newoff = tdb_offset(tdb, key); + if (newoff != oldoff) + moves++; + oldoff = newoff; } - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + /* We should increase by 50% each time... */ + ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); } @@ -91,7 +121,7 @@ int main(int argc, char *argv[]) ok1(data.dsize == MAX_SIZE); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); - ok1(!tdb_has_locks(tdb)); + ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); tdb_close(tdb); }