X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftools%2Ftdbtorture.c;h=3547d8038b7893749f83185c3c639058edea161a;hp=9bc799530851a239538d8ca5aeeb7725550ec184;hb=68e848993dca98439f73dfaf6641f3f85ef89597;hpb=6d35d746f123291ba93a592997dcd5b6fe7828cf diff --git a/ccan/tdb/tools/tdbtorture.c b/ccan/tdb/tools/tdbtorture.c index 9bc79953..3547d803 100644 --- a/ccan/tdb/tools/tdbtorture.c +++ b/ccan/tdb/tools/tdbtorture.c @@ -22,15 +22,20 @@ #define APPEND_PROB 6 #define TRANSACTION_PROB 10 #define TRANSACTION_PREPARE_PROB 2 +#if 0 #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,9 @@ static void addrec_db(void) in_transaction--; goto next; } - if (in_transaction && random() % TRANSACTION_PROB == 0) { + +#if 0 + if (in_traverse == 0 && in_transaction && random() % TRANSACTION_PROB == 0) { if (tdb_transaction_cancel(db) != 0) { fatal("tdb_transaction_cancel failed"); } @@ -134,9 +154,10 @@ static void addrec_db(void) goto next; } #endif +#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 +202,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