X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftools%2Ftdbtorture.c;fp=ccan%2Ftdb2%2Ftools%2Ftdbtorture.c;h=84223aa32a0ec2ac8ff2aa8ee11d47ff06f44d16;hp=0000000000000000000000000000000000000000;hb=81defbc32d0c3b0aa3f6e71405a3cf1f76afec45;hpb=43d881a232a4999e0d23db8e4335604dd5f3474a diff --git a/ccan/tdb2/tools/tdbtorture.c b/ccan/tdb2/tools/tdbtorture.c new file mode 100644 index 00000000..84223aa3 --- /dev/null +++ b/ccan/tdb2/tools/tdbtorture.c @@ -0,0 +1,496 @@ +/* this tests tdb by doing lots of ops from several simultaneous + writers - that stresses the locking code. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#define REOPEN_PROB 30 +#define DELETE_PROB 8 +#define STORE_PROB 4 +#define APPEND_PROB 6 +//#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 +#define KEYLEN 3 +#define DATALEN 100 + +static struct tdb_context *db; +static int in_transaction; +static int in_traverse; +static int error_count; +#if TRANSACTION_PROB +static int always_transaction = 0; +#endif +static int loopnum; +static int count_pipe; +static union tdb_attribute log_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, ...) +{ + va_list ap; + + 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); + } +#endif +} + +#include "../private.h" + +static void segv_handler(int signal, 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); + _exit(11); +} + +static void fatal(const char *why) +{ + perror(why); + error_count++; +} + +static char *randbuf(int len) +{ + char *buf; + int i; + buf = (char *)malloc(len+1); + + for (i=0;i