X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftools%2Ftdbtorture.c;h=efba1d65d13687edc18ae25ca68d7cb812a93cd4;hp=9bc799530851a239538d8ca5aeeb7725550ec184;hb=d9961fc330a057b0f5359b3d97a5317aee2d6efa;hpb=6d35d746f123291ba93a592997dcd5b6fe7828cf diff --git a/ccan/tdb/tools/tdbtorture.c b/ccan/tdb/tools/tdbtorture.c index 9bc79953..efba1d65 100644 --- a/ccan/tdb/tools/tdbtorture.c +++ b/ccan/tdb/tools/tdbtorture.c @@ -20,17 +20,22 @@ #define DELETE_PROB 8 #define STORE_PROB 4 #define APPEND_PROB 6 +#if 0 #define TRANSACTION_PROB 10 #define TRANSACTION_PREPARE_PROB 2 #define LOCKSTORE_PROB 5 +#endif #define TRAVERSE_PROB 20 #define TRAVERSE_READ_PROB 20 +#define TRAVERSE_MOD_PROB 100 +#define TRAVERSE_ABORT_PROB 500 #define CULL_PROB 100 #define KEYLEN 3 #define DATALEN 100 static struct tdb_context *db; static int in_transaction; +static int in_traverse; static int error_count; #ifdef PRINTF_ATTRIBUTE @@ -75,14 +80,27 @@ static char *randbuf(int len) return buf; } -static int cull_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, - void *state) +static void addrec_db(void); +static int modify_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, + void *state) { #if CULL_PROB if (random() % CULL_PROB == 0) { tdb_delete(tdb, key); } #endif + +#if TRAVERSE_MOD_PROB + if (random() % TRAVERSE_MOD_PROB == 0) { + addrec_db(); + } +#endif + +#if TRAVERSE_ABORT_PROB + if (random() % TRAVERSE_ABORT_PROB == 0) + return 1; +#endif + return 0; } @@ -105,14 +123,14 @@ static void addrec_db(void) data.dsize = dlen+1; #if TRANSACTION_PROB - if (in_transaction == 0 && random() % TRANSACTION_PROB == 0) { + if (in_traverse == 0 && in_transaction == 0 && random() % TRANSACTION_PROB == 0) { if (tdb_transaction_start(db) != 0) { fatal("tdb_transaction_start failed"); } in_transaction++; goto next; } - if (in_transaction && random() % TRANSACTION_PROB == 0) { + if (in_traverse == 0 && in_transaction && random() % TRANSACTION_PROB == 0) { #if 0 if (random() % TRANSACTION_PREPARE_PROB == 0) { if (tdb_transaction_prepare_commit(db) != 0) { @@ -126,7 +144,7 @@ static void addrec_db(void) in_transaction--; goto next; } - if (in_transaction && random() % TRANSACTION_PROB == 0) { + if (in_traverse == 0 && in_transaction && random() % TRANSACTION_PROB == 0) { if (tdb_transaction_cancel(db) != 0) { fatal("tdb_transaction_cancel failed"); } @@ -136,7 +154,7 @@ static void addrec_db(void) #endif #if REOPEN_PROB - if (in_transaction == 0 && random() % REOPEN_PROB == 0) { + if (in_traverse == 0 && in_transaction == 0 && random() % REOPEN_PROB == 0) { tdb_reopen_all(0); goto next; } @@ -181,15 +199,20 @@ static void addrec_db(void) #endif #if TRAVERSE_PROB - if (random() % TRAVERSE_PROB == 0) { - tdb_traverse(db, cull_traverse, NULL); + /* FIXME: recursive traverses break transactions? */ + if (in_traverse == 0 && random() % TRAVERSE_PROB == 0) { + in_traverse++; + tdb_traverse(db, modify_traverse, NULL); + in_traverse--; goto next; } #endif #if TRAVERSE_READ_PROB - if (random() % TRAVERSE_READ_PROB == 0) { + if (in_traverse == 0 && random() % TRAVERSE_READ_PROB == 0) { + in_traverse++; tdb_traverse_read(db, NULL, NULL); + in_traverse--; goto next; } #endif