/* Samba Linux/Unix CIFS implementation simple tool to test persistent databases Copyright (C) Michael Adam 2009 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "includes.h" #include "system/filesys.h" #include "lib/cmdline/cmdline.h" #include "dbwrap/dbwrap.h" #include "dbwrap/dbwrap_open.h" #include "messages.h" #include "lib/util/util_tdb.h" #include "lib/param/param.h" #if 0 #include "lib/events/events.h" #include "system/filesys.h" #include "popt.h" #include "cmdline.h" #include #include #endif #define DEFAULT_DB_NAME "transaction.tdb" static int timelimit = 10; static int torture_delay = 0; static int verbose = 0; static int no_trans = 0; static const char *db_name = DEFAULT_DB_NAME; static unsigned int pnn; static TDB_DATA old_data; static int success = true; static void print_counters(void) { int i; uint32_t *old_counters; printf("[%4u] Counters: ", (unsigned int)getpid()); old_counters = (uint32_t *)old_data.dptr; for (i=0; i < old_data.dsize/sizeof(uint32_t); i++) { printf("%6u ", old_counters[i]); } printf("\n"); } static void each_second(struct tevent_context *ev, struct tevent_timer *te, struct timeval t, void *private_data) { struct db_context *db = talloc_get_type(private_data, struct db_context); print_counters(); tevent_add_timer(ev, db, timeval_current_ofs(1, 0), each_second, db); } static bool check_counters(struct db_context *db, TDB_DATA data) { int i; uint32_t *counters, *old_counters; counters = (uint32_t *)data.dptr; old_counters = (uint32_t *)old_data.dptr; /* check that all the counters are monotonic increasing */ for (i=0; i < old_data.dsize/sizeof(uint32_t); i++) { if (counters[i] < old_counters[i]) { printf("[%4u] ERROR: counters has decreased for node %u From %u to %u\n", (unsigned int)getpid(), i, old_counters[i], counters[i]); success = false; return false; } } if (old_data.dsize != data.dsize) { old_data.dsize = data.dsize; old_data.dptr = (unsigned char*)talloc_realloc_size(db, old_data.dptr, old_data.dsize); } memcpy(old_data.dptr, data.dptr, data.dsize); if (verbose) print_counters(); return true; } static void do_sleep(unsigned int sec) { unsigned int i; if (sec == 0) { return; } for (i=0; i