From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- source3/utils/dbwrap_torture.c | 366 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100644 source3/utils/dbwrap_torture.c (limited to 'source3/utils/dbwrap_torture.c') diff --git a/source3/utils/dbwrap_torture.c b/source3/utils/dbwrap_torture.c new file mode 100644 index 0000000..ec33853 --- /dev/null +++ b/source3/utils/dbwrap_torture.c @@ -0,0 +1,366 @@ +/* + 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