]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/test/run-die-during-transaction.c
tdb: add test for tdb_summary
[ccan] / ccan / tdb / test / run-die-during-transaction.c
index c5f802c22e9edcad94a11c3f4892ce7a758e880a..aa6b40f6bbad9eb5246d03334ff9b6c0a738cf9f 100644 (file)
@@ -20,6 +20,7 @@ static int ftruncate_check(int fd, off_t length);
 #include <ccan/tdb/error.c>
 #include <ccan/tdb/open.c>
 #include <ccan/tdb/check.c>
+#include <ccan/tdb/hash.c>
 #include <ccan/tap/tap.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -27,6 +28,7 @@ static int ftruncate_check(int fd, off_t length);
 #include <err.h>
 #include <setjmp.h>
 #include "external-agent.h"
+#include "logging.h"
 
 #undef write
 #undef pwrite
@@ -34,29 +36,11 @@ static int ftruncate_check(int fd, off_t length);
 #undef ftruncate
 
 static bool in_transaction;
-static bool suppress_logging;
 static int target, current;
 static jmp_buf jmpbuf;
 #define TEST_DBNAME "run-die-during-transaction.tdb"
 #define KEY_STRING "helloworld"
 
-static void taplog(struct tdb_context *tdb,
-                  enum tdb_debug_level level,
-                  const char *fmt, ...)
-{
-       va_list ap;
-       char line[200];
-
-       if (suppress_logging)
-               return;
-
-       va_start(ap, fmt);
-       vsprintf(line, fmt, ap);
-       va_end(ap);
-
-       diag("%s", line);
-}
-
 static void maybe_die(int fd)
 {
        if (in_transaction && current++ == target) {
@@ -109,12 +93,15 @@ static bool test_death(enum operation op, struct agent *agent)
 {
        struct tdb_context *tdb = NULL;
        TDB_DATA key;
-       struct tdb_logging_context logctx = { taplog, NULL };
        enum agent_return ret;
        int needed_recovery = 0;
 
        current = target = 0;
 reset:
+       unlink(TEST_DBNAME);
+       tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP,
+                         O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+
        if (setjmp(jmpbuf) != 0) {
                /* We're partway through.  Simulate our death. */
                close(tdb->fd);
@@ -170,10 +157,6 @@ reset:
                goto reset;
        }
 
-       unlink(TEST_DBNAME);
-       tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP,
-                         O_CREAT|O_TRUNC|O_RDWR, 0600, &logctx, NULL);
-
        /* Put key for agent to fetch. */
        key.dsize = strlen(KEY_STRING);
        key.dptr = (void *)KEY_STRING;