From 04be602881b24469117facd39542b87689fc7352 Mon Sep 17 00:00:00 2001 From: Steeve Goveas Date: Fri, 28 May 2021 18:04:45 +0530 Subject: [PATCH] Enable gating tests for libtdb Resolves: rhbz#1962774 --- gating.yaml | 6 + tests/sanity/Makefile | 15 ++ tests/sanity/tdbtest.c | 297 ++++++++++++++++++++++ tests/sanity/tdbtest.sh | 4 + tests/sanity/tdbtorture.c | 501 ++++++++++++++++++++++++++++++++++++++ tests/tests.yml | 17 ++ 6 files changed, 840 insertions(+) create mode 100644 gating.yaml create mode 100644 tests/sanity/Makefile create mode 100644 tests/sanity/tdbtest.c create mode 100755 tests/sanity/tdbtest.sh create mode 100644 tests/sanity/tdbtorture.c create mode 100644 tests/tests.yml diff --git a/gating.yaml b/gating.yaml new file mode 100644 index 0000000..648918d --- /dev/null +++ b/gating.yaml @@ -0,0 +1,6 @@ +--- !Policy +product_versions: + - rhel-9 +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional} diff --git a/tests/sanity/Makefile b/tests/sanity/Makefile new file mode 100644 index 0000000..472fb49 --- /dev/null +++ b/tests/sanity/Makefile @@ -0,0 +1,15 @@ + +tdbtorture: tdbtorture.c + gcc tdbtorture.c -g -ltdb -o tdbtorture + +tdbtest: tdbtest.c + gcc tdbtest.c -ltdb -lgdbm -g -o tdbtest + +run: tdbtorture tdbtest + @echo "Running tdbtorture" + ./tdbtorture + @echo "Running tdbtest" + ./tdbtest + +clean: + rm -f tdbtorture tdbtest *.tdb *.gdbm diff --git a/tests/sanity/tdbtest.c b/tests/sanity/tdbtest.c new file mode 100644 index 0000000..92dbe6c --- /dev/null +++ b/tests/sanity/tdbtest.c @@ -0,0 +1,297 @@ +/* a test program for tdb - the trivial database */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define DELETE_PROB 7 +#define STORE_PROB 5 + +static struct tdb_context *db; +static GDBM_FILE gdbm; + +struct timeval tp1,tp2; + +static void _start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double _end_timer(void) +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + +static void fatal(const char *why) +{ + perror(why); + exit(1); +} + +#ifdef PRINTF_ATTRIBUTE +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +#endif +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); + fflush(stdout); +} + +static void compare_db(void) +{ + TDB_DATA d, key, nextkey; + datum gd, gkey, gnextkey; + + key = tdb_firstkey(db); + while (key.dptr) { + d = tdb_fetch(db, key); + gkey.dptr = key.dptr; + gkey.dsize = key.dsize; + + gd = gdbm_fetch(gdbm, gkey); + + if (!gd.dptr) fatal("key not in gdbm"); + if (gd.dsize != d.dsize) fatal("data sizes differ"); + if (memcmp(gd.dptr, d.dptr, d.dsize)) { + fatal("data differs"); + } + + nextkey = tdb_nextkey(db, key); + free(key.dptr); + free(d.dptr); + free(gd.dptr); + key = nextkey; + } + + gkey = gdbm_firstkey(gdbm); + while (gkey.dptr) { + gd = gdbm_fetch(gdbm, gkey); + key.dptr = gkey.dptr; + key.dsize = gkey.dsize; + + d = tdb_fetch(db, key); + + if (!d.dptr) fatal("key not in db"); + if (d.dsize != gd.dsize) fatal("data sizes differ"); + if (memcmp(d.dptr, gd.dptr, gd.dsize)) { + fatal("data differs"); + } + + gnextkey = gdbm_nextkey(gdbm, gkey); + free(gkey.dptr); + free(gd.dptr); + free(d.dptr); + gkey = gnextkey; + } +} + +static char *randbuf(int len) +{ + char *buf; + int i; + buf = (char *)malloc(len+1); + + for (i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#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 int 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