X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftools%2Ftdbtorture.c;h=c6b71de51c407d6aaa8aa90da4a8bad60769479f;hp=46dc1c72ab70a98a2d3f9095d827bc513190f1f3;hb=94c8763345a51fe59e97daf4e29051f56331c63c;hpb=e2cb71e5d46801a94a3f0f546b8dcc2b7a79b66c diff --git a/ccan/tdb2/tools/tdbtorture.c b/ccan/tdb2/tools/tdbtorture.c index 46dc1c72..c6b71de5 100644 --- a/ccan/tdb2/tools/tdbtorture.c +++ b/ccan/tdb2/tools/tdbtorture.c @@ -20,11 +20,10 @@ #define DELETE_PROB 8 #define STORE_PROB 4 #define APPEND_PROB 6 -//#define TRANSACTION_PROB 10 -//#define TRANSACTION_PREPARE_PROB 2 +#define TRANSACTION_PROB 10 +#define TRANSACTION_PREPARE_PROB 2 #define LOCKSTORE_PROB 5 #define TRAVERSE_PROB 20 -#define TRAVERSE_READ_PROB 20 #define TRAVERSE_MOD_PROB 100 #define TRAVERSE_ABORT_PROB 500 #define CULL_PROB 100 @@ -43,22 +42,13 @@ static int count_pipe; static union tdb_attribute log_attr; static union tdb_attribute seed_attr; -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...) PRINTF_ATTRIBUTE(4,5); -#endif -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...) +static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level, + void *private, const char *message) { - va_list ap; - - if (level != TDB_DEBUG_TRACE) - error_count++; - - va_start(ap, format); - vfprintf(stdout, format, ap); - va_end(ap); + fputs(message, stdout); fflush(stdout); #if 0 - if (level != TDB_DEBUG_TRACE) { + { char *ptr; signal(SIGUSR1, SIG_IGN); asprintf(&ptr,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid()); @@ -70,14 +60,15 @@ static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *p #include "../private.h" -static void segv_handler(int signal, siginfo_t *info, void *p) +static void segv_handler(int sig, siginfo_t *info, void *p) { char string[100]; - sprintf(string, "%u: death at %p (map_ptr %p, map_size %llu)\n", - getpid(), info->si_addr, db->map_ptr, db->map_size); - write(2, string, strlen(string)); - sleep(60); + sprintf(string, "%u: death at %p (map_ptr %p, map_size %zu)\n", + getpid(), info->si_addr, db->file->map_ptr, + (size_t)db->file->map_size); + if (write(2, string, strlen(string)) > 0) + sleep(60); _exit(11); } @@ -171,9 +162,7 @@ static void addrec_db(void) } if (in_traverse == 0 && in_transaction && random() % TRANSACTION_PROB == 0) { - if (tdb_transaction_cancel(db) != 0) { - fatal("tdb_transaction_cancel failed"); - } + tdb_transaction_cancel(db); in_transaction--; goto next; } @@ -207,7 +196,7 @@ static void addrec_db(void) #if LOCKSTORE_PROB if (random() % LOCKSTORE_PROB == 0) { tdb_chainlock(db, key); - data = tdb_fetch(db, key); + tdb_fetch(db, key, &data); if (tdb_store(db, key, data, TDB_REPLACE) != 0) { fatal("tdb_store failed"); } @@ -227,17 +216,8 @@ static void addrec_db(void) } #endif -#if TRAVERSE_READ_PROB - if (in_traverse == 0 && random() % TRAVERSE_READ_PROB == 0) { - in_traverse++; - tdb_traverse_read(db, NULL, NULL); - in_traverse--; - goto next; - } -#endif - - data = tdb_fetch(db, key); - if (data.dptr) free(data.dptr); + if (tdb_fetch(db, key, &data) == TDB_SUCCESS) + free(data.dptr); next: free(k); @@ -264,7 +244,8 @@ static void usage(void) static void send_count_and_suicide(int sig) { /* This ensures our successor can continue where we left off. */ - write(count_pipe, &loopnum, sizeof(loopnum)); + if (write(count_pipe, &loopnum, sizeof(loopnum)) != sizeof(loopnum)) + exit(2); /* This gives a unique signature. */ kill(getpid(), SIGUSR2); } @@ -301,7 +282,7 @@ static int run_child(int i, int seed, unsigned num_loops, unsigned start) } if (error_count == 0) { - tdb_traverse_read(db, NULL, NULL); + tdb_traverse(db, NULL, NULL); #if TRANSACTION_PROB if (always_transaction) { while (in_transaction) { @@ -454,8 +435,11 @@ int main(int argc, char * const *argv) || WTERMSIG(status) == SIGUSR1) { /* SIGUSR2 means they wrote to pipe. */ if (WTERMSIG(status) == SIGUSR2) { - read(pfds[0], &done[j], - sizeof(done[j])); + if (read(pfds[0], &done[j], + sizeof(done[j])) + != sizeof(done[j])) + err(1, + "Short read from child?"); } pids[j] = fork(); if (pids[j] == 0)