From bd8128271ad96c97ddaf5c86915a981ddbff86c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 18:49:38 +0200 Subject: Adding upstream version 1.4.10. Signed-off-by: Daniel Baumann --- tools/tdbtorture.c | 500 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 500 insertions(+) create mode 100644 tools/tdbtorture.c (limited to 'tools/tdbtorture.c') diff --git a/tools/tdbtorture.c b/tools/tdbtorture.c new file mode 100644 index 0000000..1063f14 --- /dev/null +++ b/tools/tdbtorture.c @@ -0,0 +1,500 @@ +/* this tests tdb by doing lots of ops from several simultaneous + writers - that stresses the locking code. +*/ + +#include "replace.h" +#include "system/time.h" +#include "system/wait.h" +#include "system/filesys.h" +#include "tdb.h" + +#ifdef HAVE_GETOPT_H +#include +#endif + + +#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 CULL_PROB 100 +#define KEYLEN 3 +#define DATALEN 100 + +static struct tdb_context *db; +static int in_transaction; +static int error_count; +static int always_transaction = 0; +static int hash_size = 2; +static unsigned loopnum; +static int count_pipe; +static bool mutex = false; +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); +#endif +static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) +{ + va_list ap; + + /* trace level messages do not indicate an error */ + 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 +} + +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