From: Rusty Russell Date: Thu, 4 Feb 2010 03:59:50 +0000 (+1030) Subject: Add -k option to tdbtorture, run tdb_check at end. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=5ebc1701896a415e88a81fb29bd0cc94d2e05835 Add -k option to tdbtorture, run tdb_check at end. This patch is made larger by moving the work out to a separate function: with -k, the parent can't run the ops itself but the children must do it. --- diff --git a/ccan/tdb/tools/tdbtorture.c b/ccan/tdb/tools/tdbtorture.c index e9c793ac..58bef81a 100644 --- a/ccan/tdb/tools/tdbtorture.c +++ b/ccan/tdb/tools/tdbtorture.c @@ -36,6 +36,10 @@ static int in_transaction; static int in_traverse; static int error_count; static int always_transaction = 0; +static int hash_size = 2; +static int loopnum; +static int count_pipe; +static struct tdb_logging_context log_ctx; #ifdef PRINTF_ATTRIBUTE static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); @@ -43,16 +47,18 @@ static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const c static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) { va_list ap; - - error_count++; + + if (level != TDB_DEBUG_TRACE) + error_count++; va_start(ap, format); vfprintf(stdout, format, ap); va_end(ap); 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()); system(ptr); free(ptr); @@ -232,54 +238,20 @@ static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, static void usage(void) { - printf("Usage: tdbtorture [-t] [-n NUM_PROCS] [-l NUM_LOOPS] [-s SEED] [-H HASH_SIZE]\n"); + printf("Usage: tdbtorture [-t] [-k] [-n NUM_PROCS] [-l NUM_LOOPS] [-s SEED] [-H HASH_SIZE]\n"); exit(0); } -int main(int argc, char * const *argv) +static void send_count_and_suicide(int sig) { - int i, seed = -1; - int num_procs = 3; - int num_loops = 5000; - int hash_size = 2; - int c; - extern char *optarg; - pid_t *pids; - - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_log; - - while ((c = getopt(argc, argv, "n:l:s:H:th")) != -1) { - switch (c) { - case 'n': - num_procs = strtol(optarg, NULL, 0); - break; - case 'l': - num_loops = strtol(optarg, NULL, 0); - break; - case 'H': - hash_size = strtol(optarg, NULL, 0); - break; - case 's': - seed = strtol(optarg, NULL, 0); - break; - case 't': - always_transaction = 1; - break; - default: - usage(); - } - } - - unlink("torture.tdb"); - - pids = (pid_t *)calloc(sizeof(pid_t), num_procs); - pids[0] = getpid(); - - for (i=0;i