X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=junkcode%2Frusty%40rustcorp.com.au-ntdb%2Ftools%2Fntdbtorture.c;fp=junkcode%2Frusty%40rustcorp.com.au-ntdb%2Ftools%2Fntdbtorture.c;h=9fd25ca7c6c9bda38d6f09eafb6ade35c591ece3;hb=1aab74723e837a0fd8091e264a325bb2cdcdd0fa;hp=0000000000000000000000000000000000000000;hpb=979071e8587d4819a7f78613b68d29e222e5db63;p=ccan diff --git a/junkcode/rusty@rustcorp.com.au-ntdb/tools/ntdbtorture.c b/junkcode/rusty@rustcorp.com.au-ntdb/tools/ntdbtorture.c new file mode 100644 index 00000000..9fd25ca7 --- /dev/null +++ b/junkcode/rusty@rustcorp.com.au-ntdb/tools/ntdbtorture.c @@ -0,0 +1,535 @@ +/* this tests ntdb by doing lots of ops from several simultaneous + writers - that stresses the locking code. +*/ + +#include "config.h" +#include "ntdb.h" +#include "private.h" +#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_MOD_PROB 100 +#define TRAVERSE_ABORT_PROB 500 +#define CULL_PROB 100 +#define KEYLEN 3 +#define DATALEN 100 + +static struct ntdb_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 ntdb_attribute log_attr; +static union ntdb_attribute seed_attr; +static union ntdb_attribute hsize_attr; + +static void ntdb_log(struct ntdb_context *ntdb, + enum ntdb_log_level level, + enum NTDB_ERROR ecode, + const char *message, + void *data) +{ + printf("ntdb:%s:%s:%s\n", + ntdb_name(ntdb), ntdb_errorstr(ecode), message); + fflush(stdout); +#if 0 + { + char str[200]; + signal(SIGUSR1, SIG_IGN); + sprintf(str,"xterm -e gdb /proc/%u/exe %u", (unsigned int)getpid(), (unsigned int)getpid()); + system(str); + } +#endif +} + +#include "../private.h" + +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 %zu)\n", + (unsigned int)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); +} + +static void warn_on_err(enum NTDB_ERROR e, struct ntdb_context *ntdb, + const char *why) +{ + if (e != NTDB_SUCCESS) { + fprintf(stderr, "%u:%s:%s\n", (unsigned int)getpid(), why, + ntdb ? ntdb_errorstr(e) : "(no ntdb)"); + error_count++; + } +} + +static char *randbuf(int len) +{ + char *buf; + int i; + buf = (char *)malloc(len+1); + if (buf == NULL) { + perror("randbuf: unable to allocate memory for buffer.\n"); + exit(1); + } + + for (i=0;i