/* $Id: tdbtorture.c 25261 2007-03-23 01:53:16Z jannis $ */ /*- * Copyright (c) 1999-2004 Andrew Tridgell * Copyright (c) 2005 Benedikt Meurer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * This file was originally part of the tdb library, which in turn is * part of the Samba suite, a Unix SMB/CIFS implementation. */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_MMAN_h #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_SYS_WAIT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_STDARG_H #include #endif #include #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_TIME_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #include /* this tests tdb by doing lots of ops from several simultaneous writers - that stresses the locking code. Build with TDB_DEBUG=1 for best effect */ #define REOPEN_PROB 30 #define DELETE_PROB 8 #define STORE_PROB 4 #define APPEND_PROB 6 #define LOCKSTORE_PROB 0 #define TRAVERSE_PROB 20 #define CULL_PROB 100 #define KEYLEN 3 #define DATALEN 100 #define LOCKLEN 20 static TDB_CONTEXT *db; static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) { va_list ap; va_start(ap, format); vfprintf(stdout, format, ap); va_end(ap); fflush(stdout); #if 0 { char *ptr; asprintf(&ptr,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid()); system(ptr); free(ptr); } #endif } static void fatal(char *why) { perror(why); exit(1); } static char *randbuf(int len) { char *buf; int i; buf = (char *)malloc(len+1); for (i=0;i