]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/test/run-corrupt.c
strsplit: remove nump argument
[ccan] / ccan / tdb / test / run-corrupt.c
index 3b3cb61747d0af7c7e79d7130ff6f2c32dfa2d21..6f753ea6d46c81c9dbd3f9e388c1f3078c98e30e 100644 (file)
@@ -1,17 +1,19 @@
 #define _XOPEN_SOURCE 500
-#include "tdb/tdb.h"
-#include "tdb/io.c"
-#include "tdb/tdb.c"
-#include "tdb/lock.c"
-#include "tdb/freelist.c"
-#include "tdb/traverse.c"
-#include "tdb/transaction.c"
-#include "tdb/error.c"
-#include "tdb/open.c"
-#include "tdb/check.c"
-#include "tap/tap.h"
+#include <ccan/tdb/tdb.h>
+#include <ccan/tdb/io.c>
+#include <ccan/tdb/tdb.c>
+#include <ccan/tdb/lock.c>
+#include <ccan/tdb/freelist.c>
+#include <ccan/tdb/traverse.c>
+#include <ccan/tdb/transaction.c>
+#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 <err.h>
+#include "logging.h"
 
 static int check(TDB_DATA key, TDB_DATA data, void *private)
 {
@@ -41,9 +43,11 @@ static void tdb_flip_bit(struct tdb_context *tdb, unsigned int bit)
                ((unsigned char *)tdb->map_ptr)[off] ^= mask;
        else {
                unsigned char c;
-               pread(tdb->fd, &c, 1, off);
+               if (pread(tdb->fd, &c, 1, off) != 1)
+                       err(1, "pread");
                c ^= mask;
-               pwrite(tdb->fd, &c, 1, off);
+               if (pwrite(tdb->fd, &c, 1, off) != 1)
+                       err(1, "pwrite");
        }
 }
 
@@ -72,13 +76,14 @@ static void check_test(struct tdb_context *tdb)
        /* This is how many bytes we expect to be verifiable. */
        /* From the file header. */
        verifiable = strlen(TDB_MAGIC_FOOD) + 1
-               + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t);
+               + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t)
+               + 2 * sizeof(uint32_t);
        /* From the free list chain and hash chains. */
        verifiable += 3 * sizeof(tdb_off_t);
        /* From the record headers & tailer */
-       verifiable += 5 * (sizeof(struct list_struct) + sizeof(uint32_t));
+       verifiable += 5 * (sizeof(struct tdb_record) + sizeof(uint32_t));
        /* The free block: we ignore datalen, keylen, full_hash. */
-       verifiable += sizeof(struct list_struct) - 3*sizeof(uint32_t) +
+       verifiable += sizeof(struct tdb_record) - 3*sizeof(uint32_t) +
                sizeof(uint32_t);
        /* Our check function verifies the key and data. */
        verifiable += ksize + dsize;
@@ -103,8 +108,8 @@ int main(int argc, char *argv[])
 
        plan_tests(4);
        /* This should use mmap. */
-       tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST,
-                      O_CREAT|O_TRUNC|O_RDWR, 0600);
+       tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST,
+                         O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
 
        if (!tdb)
                abort();
@@ -112,8 +117,8 @@ int main(int argc, char *argv[])
        tdb_close(tdb);
 
        /* This should not. */
-       tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP,
-                      O_CREAT|O_TRUNC|O_RDWR, 0600);
+       tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP,
+                         O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
 
        if (!tdb)
                abort();