tdb2: test: try (almost) all tests with TDB_VERSION1 flag.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)
There are some minor changes required, in particular:

1) Make sure lockcheck understands tdb1 allrecord lock upgrades.
2) Handle tdb1 sequence number jumps: various operations increment the
   sequence number twice, especually tdb_append.
3) Don't test fail on unlock, since it gets triggered with traversal on the
   tdb1 backend (we didn't actually ever test this case for tdb2).
4) Move clear_if_first to offset 4, to match tdb1.

33 files changed:
ccan/tdb2/test/external-agent.c
ccan/tdb2/test/lock-tracking.c
ccan/tdb2/test/run-01-new_database.c
ccan/tdb2/test/run-05-readonly-open.c
ccan/tdb2/test/run-10-simple-store.c
ccan/tdb2/test/run-11-simple-fetch.c
ccan/tdb2/test/run-13-delete.c
ccan/tdb2/test/run-14-exists.c
ccan/tdb2/test/run-15-append.c
ccan/tdb2/test/run-16-wipe_all.c
ccan/tdb2/test/run-21-parse_record.c
ccan/tdb2/test/run-35-convert.c
ccan/tdb2/test/run-55-transaction.c
ccan/tdb2/test/run-56-open-during-transaction.c
ccan/tdb2/test/run-57-die-during-transaction.c
ccan/tdb2/test/run-80-tdb_fd.c
ccan/tdb2/test/run-81-seqnum.c
ccan/tdb2/test/run-82-lockattr.c
ccan/tdb2/test/run-83-openhook.c
ccan/tdb2/test/run-90-get-set-attributes.c
ccan/tdb2/test/run-91-get-stats.c
ccan/tdb2/test/run-92-get-set-readonly.c
ccan/tdb2/test/run-add-remove-flags.c
ccan/tdb2/test/run-check-callback.c
ccan/tdb2/test/run-expand-in-transaction.c
ccan/tdb2/test/run-firstkey-nextkey.c
ccan/tdb2/test/run-fork-test.c
ccan/tdb2/test/run-lockall.c
ccan/tdb2/test/run-locktimeout.c
ccan/tdb2/test/run-open-multiple-times.c
ccan/tdb2/test/run-record-expand.c
ccan/tdb2/test/run-simple-delete.c
ccan/tdb2/test/run-summary.c

index 055b5de736f6f04334fd990dc2409d1630650ff6..23874777da827e8297f4bf6c556a2ad231e4fde4 100644 (file)
@@ -10,7 +10,7 @@
 #include <limits.h>
 #include <string.h>
 #include <errno.h>
-#include <ccan/tdb2/private.h>
+#include <ccan/tdb2/tdb1_private.h>
 #include <ccan/tap/tap.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -19,12 +19,13 @@ static struct tdb_context *tdb;
 
 static enum TDB_ERROR clear_if_first(int fd, void *arg)
 {
-/* We hold a lock offset 63 always, so we can tell if anyone is holding it. */
+/* We hold a lock offset 4 always, so we can tell if anyone is holding it.
+ * (This is compatible with tdb1's TDB_CLEAR_IF_FIRST flag).  */
        struct flock fl;
 
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_SET;
-       fl.l_start = 63;
+       fl.l_start = 4;
        fl.l_len = 1;
 
        if (fcntl(fd, F_SETLK, &fl) == 0) {
@@ -115,7 +116,10 @@ static enum agent_return do_operation(enum operation op, const char *name)
                ret = tdb_transaction_commit(tdb)==0 ? SUCCESS : OTHER_FAILURE;
                break;
        case NEEDS_RECOVERY:
-               ret = tdb_needs_recovery(tdb) ? SUCCESS : FAILED;
+               if (tdb->flags & TDB_VERSION1)
+                       ret = tdb1_needs_recovery(tdb) ? SUCCESS : FAILED;
+               else
+                       ret = tdb_needs_recovery(tdb) ? SUCCESS : FAILED;
                break;
        case CHECK:
                ret = tdb_check(tdb, NULL, NULL) == 0 ? SUCCESS : OTHER_FAILURE;
index ba09399219258d1cd2c56b28ca5c3b44a3447e18..e253db9f710e6860ef2c4d7758daa5e010693a71 100644 (file)
@@ -1,5 +1,5 @@
 /* We save the locks so we can reaquire them. */
-#include <ccan/tdb2/private.h>
+#include <ccan/tdb2/tdb1_private.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdarg.h>
@@ -110,6 +110,17 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
                                        i->type = F_WRLCK;
                                goto done;
                        }
+                       /* allrecord upgrade for tdb1. */
+                       if (i->type == F_RDLCK && fl->l_type == F_WRLCK
+                           && i->off == TDB1_FREELIST_TOP
+                           && fl->l_start == TDB1_FREELIST_TOP
+                           && i->len == 0
+                           && fl->l_len == 0) {
+                               if (ret == 0)
+                                       i->type = F_WRLCK;
+                               goto done;
+                       }
+
                        if (!suppress_lockcheck) {
                                diag("%s lock %u@%u overlaps %u@%u",
                                     fl->l_type == F_WRLCK ? "write" : "read",
index 93b20401e6992d3a951a6d47f530a757b4f61639..43bd206af9a2ce815671e7398d1832c9694d4cf1 100644 (file)
@@ -11,7 +11,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        failtest_init(argc, argv);
        failtest_hook = block_repeat_failures;
index 1062f1c484707757623c3060d91a6f2f10e61944..c4776f53b23651771175f596d1930605b11f7012 100644 (file)
@@ -21,7 +21,10 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4), d;
        union tdb_attribute seed_attr;
@@ -39,7 +42,9 @@ int main(int argc, char *argv[])
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                tdb = tdb_open("run-05-readonly-open.tdb", flags[i],
-                              O_RDWR|O_CREAT|O_TRUNC, 0600, &seed_attr);
+                              O_RDWR|O_CREAT|O_TRUNC, 0600,
+                              flags[i] & TDB_VERSION1
+                              ? &tap_log_attr : &seed_attr);
                ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
                tdb_close(tdb);
 
index 71570a24efe388fbe85d7bf293ead81e54e45f03..ac08548c422dc489310b8397f9183879827ec12b 100644 (file)
@@ -22,7 +22,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
 
index ed3dcad64f28a82725912ea711523ea31cf27eb2..517d64dc8b7ba1073b6dcbc706b0bea6d852d4b0 100644 (file)
@@ -22,7 +22,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
 
index b5586dc215553d9da5657d3cdbb04d4e26b68129..fdbc9db70aefaba4f91982e192b425b065c445ff 100644 (file)
@@ -146,7 +146,12 @@ int main(int argc, char *argv[])
                              .data = &seed } };
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        /* These two values gave trouble before. */
        int vals[] = { 755, 837 };
 
index b27fc7060b8b3f9639700b6e6d7b85376a48ea6a..7ff4514262c02228fc88e23a999b9fa744d0bccd 100644 (file)
@@ -34,7 +34,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
index 9e82a9230568d4fe6a5e23d3546022df5aff38e2..39afaf7cd8ad5c864a43676ec0fc44bfbdf38eaf 100644 (file)
@@ -12,6 +12,12 @@ static tdb_off_t tdb_offset(struct tdb_context *tdb, struct tdb_data key)
        struct tdb_used_record rec;
        struct hash_info h;
 
+       if (tdb_get_flags(tdb) & TDB_VERSION1) {
+               struct tdb1_record rec;
+               return tdb1_find(tdb, key, tdb_hash(tdb, key.dptr, key.dsize),
+                                &rec);
+       }
+
        off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off))
                return 0;
@@ -27,7 +33,12 @@ int main(int argc, char *argv[])
        tdb_off_t oldoff = 0, newoff;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data;
 
@@ -64,8 +75,15 @@ int main(int argc, char *argv[])
                }
                ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0
                                   && tdb->file->num_lockrecs == 0));
-               /* We should increase by 50% each time... */
-               ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves);
+               if (flags[i] & TDB_VERSION1) {
+                       /* TDB1 simply over-size by 25%. */
+                       ok(moves <= ilog64(j / SIZE_STEP)*4,
+                          "Moved %u times", moves);
+               } else {
+                       /* We should increase by 50% each time... */
+                       ok(moves <= ilog64(j / SIZE_STEP)*2,
+                          "Moved %u times", moves);
+               }
                tdb_close(tdb);
        }
 
@@ -96,8 +114,15 @@ int main(int argc, char *argv[])
                }
                ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0
                                   && tdb->file->num_lockrecs == 0));
-               /* We should increase by 50% each time... */
-               ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves);
+               if (flags[i] & TDB_VERSION1) {
+                       /* TDB1 simply over-size by 25%. */
+                       ok(moves <= ilog64(j / SIZE_STEP)*4,
+                          "Moved %u times", moves);
+               } else {
+                       /* We should increase by 50% each time... */
+                       ok(moves <= ilog64(j / SIZE_STEP)*2,
+                          "Moved %u times", moves);
+               }
                tdb_close(tdb);
        }
 
index 1ca23c33635602d73c6f6f27cf0e83d8d499d0e8..27d6f4388c37ffcda1490adb1903fe84532b7fb6 100644 (file)
@@ -22,7 +22,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
index 6f95ff70ac2118be5497b425743b0571c120b161..c7414a4dcd5594cd1c4a0eb480b6b59fa0b51e65 100644 (file)
@@ -47,7 +47,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
index faadfb76464d460eb8f031a3371b43ba42ea1cca..b7b1e6e562501dc42f1f0c33b20a7576bea939d3 100644 (file)
@@ -11,7 +11,10 @@ int main(int argc, char *argv[])
        unsigned int i, messages = 0;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        failtest_init(argc, argv);
        failtest_hook = block_repeat_failures;
index a6607d11dbd3b97575f5f3788b01c87b83706702..95545b7e1246e8f7a53d3d9d2e687da5fd479b93 100644 (file)
@@ -8,7 +8,10 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        unsigned char *buffer;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data;
 
index 1c714dc8b8fae15c0cf7cd79a0f71046ae5afa2b..9262c0528eb8a2f4bcf3b6691b30854751d7e4b0 100644 (file)
@@ -128,15 +128,16 @@ static int ftruncate_check(int fd, off_t length)
 
 int main(int argc, char *argv[])
 {
-       const int flags[] = { TDB_DEFAULT,
-                             TDB_NOMMAP,
-                             TDB_CONVERT,
-                             TDB_CONVERT | TDB_NOMMAP };
+       const int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        int i;
        struct tdb_context *tdb;
        TDB_DATA key, data;
 
-       plan_tests(20);
+       plan_tests(sizeof(flags)/sizeof(flags[0]) * 5);
        agent = prepare_external_agent();
        if (!agent)
                err(1, "preparing agent");
index e622395537afb8b85429fd7894ea5bb5021389d3..6e9cb1e3e72598a0302696ae3eee7a8d079b8378 100644 (file)
@@ -31,11 +31,24 @@ static void *malloc_noleak(size_t len)
        abort();
 }
 
+static void *realloc_noleak(void *p, size_t size)
+{
+       unsigned int i;
+
+       for (i = 0; i < MAX_ALLOCATIONS; i++) {
+               if (allocated[i] == p) {
+                       return allocated[i] = realloc(p, size);
+               }
+       }
+       diag("Untracked realloc!");
+       abort();
+}
+
 static void free_noleak(void *p)
 {
        unsigned int i;
 
-       /* We don't catch realloc, so don't care if we miss one. */
+       /* We don't catch asprintf, so don't complain if we miss one. */
        for (i = 0; i < MAX_ALLOCATIONS; i++) {
                if (allocated[i] == p) {
                        allocated[i] = NULL;
@@ -57,11 +70,13 @@ static void free_all(void)
 
 #define malloc malloc_noleak
 #define free free_noleak
+#define realloc realloc_noleak
 
 #include "tdb2-source.h"
 
 #undef malloc
 #undef free
+#undef realloc
 #undef write
 #undef pwrite
 #undef fcntl
@@ -128,7 +143,7 @@ static int ftruncate_check(int fd, off_t length)
        return ret;
 }
 
-static bool test_death(enum operation op, struct agent *agent)
+static bool test_death(enum operation op, struct agent *agent, int flags)
 {
        struct tdb_context *tdb = NULL;
        TDB_DATA key;
@@ -138,7 +153,7 @@ static bool test_death(enum operation op, struct agent *agent)
        current = target = 0;
 reset:
        unlink(TEST_DBNAME);
-       tdb = tdb_open(TEST_DBNAME, TDB_NOMMAP,
+       tdb = tdb_open(TEST_DBNAME, flags|TDB_NOMMAP,
                       O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
        if (!tdb) {
                diag("Failed opening TDB: %s", strerror(errno));
@@ -250,18 +265,20 @@ int main(int argc, char *argv[])
 {
        enum operation ops[] = { FETCH, STORE, TRANSACTION_START };
        struct agent *agent;
-       int i;
+       int i, flags;
 
-       plan_tests(12);
+       plan_tests(24);
        unlock_callback = maybe_die;
 
        agent = prepare_external_agent();
        if (!agent)
                err(1, "preparing agent");
 
-       for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
-               diag("Testing %s after death", operation_name(ops[i]));
-               ok1(test_death(ops[i], agent));
+       for (flags = TDB_DEFAULT; flags <= TDB_VERSION1; flags += TDB_VERSION1) {
+               for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
+                       diag("Testing %s after death", operation_name(ops[i]));
+                       ok1(test_death(ops[i], agent, flags));
+               }
        }
 
        free_external_agent(agent);
index fe7a9ef9f67e674a0915641addf1c5f70c5262a5..7faed41c295c31a92ba105233859506a465931e9 100644 (file)
@@ -8,7 +8,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 3);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
index 6b95f19c084edbe17f71b2c95f43c904101d805b..b33d0a218b49198c20fe26ceaf3aa4265f6bb831 100644 (file)
@@ -4,57 +4,69 @@
 
 int main(int argc, char *argv[])
 {
-       unsigned int i;
+       unsigned int i, seq;
        struct tdb_context *tdb;
        struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
-       plan_tests(sizeof(flags) / sizeof(flags[0]) * 15 + 4 * 13);
+       plan_tests(sizeof(flags) / sizeof(flags[0]) * 15 + 8 * 13);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                tdb = tdb_open("run-new_database.tdb", flags[i]|TDB_SEQNUM,
                               O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
                if (!ok1(tdb))
                        continue;
                
-               ok1(tdb_get_seqnum(tdb) == 0);
+               seq = 0;
+               ok1(tdb_get_seqnum(tdb) == seq);
                ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
-               ok1(tdb_get_seqnum(tdb) == 1);
+               ok1(tdb_get_seqnum(tdb) == ++seq);
                /* Fetch doesn't change seqnum */
                if (ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS))
                        free(d.dptr);
-               ok1(tdb_get_seqnum(tdb) == 1);
+               ok1(tdb_get_seqnum(tdb) == seq);
                ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
-               ok1(tdb_get_seqnum(tdb) == 2);
+               /* Append in tdb1 (or store over value) bumps twice! */
+               if (flags[i] & TDB_VERSION1)
+                       seq++;
+               ok1(tdb_get_seqnum(tdb) == ++seq);
 
                ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
-               ok1(tdb_get_seqnum(tdb) == 3);
+               ok1(tdb_get_seqnum(tdb) == ++seq);
                /* Empty append works */
                ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
-               ok1(tdb_get_seqnum(tdb) == 4);
+               ok1(tdb_get_seqnum(tdb) == ++seq);
 
                ok1(tdb_wipe_all(tdb) == TDB_SUCCESS);
-               ok1(tdb_get_seqnum(tdb) == 5);
+               ok1(tdb_get_seqnum(tdb) == ++seq);
 
                if (!(flags[i] & TDB_INTERNAL)) {
                        ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
                        ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
-                       ok1(tdb_get_seqnum(tdb) == 6);
+                       ok1(tdb_get_seqnum(tdb) == ++seq);
+                       /* Append in tdb1 (or store over value) bumps twice! */
+                       if (flags[i] & TDB_VERSION1)
+                               seq++;
                        ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
-                       ok1(tdb_get_seqnum(tdb) == 7);
+                       ok1(tdb_get_seqnum(tdb) == ++seq);
                        ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
-                       ok1(tdb_get_seqnum(tdb) == 8);
+                       ok1(tdb_get_seqnum(tdb) == ++seq);
                        ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
-                       ok1(tdb_get_seqnum(tdb) == 8);
+                       ok1(tdb_get_seqnum(tdb) == seq);
 
                        ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
                        ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
-                       ok1(tdb_get_seqnum(tdb) == 9);
+                       ok1(tdb_get_seqnum(tdb) == seq + 1);
                        tdb_transaction_cancel(tdb);
-                       ok1(tdb_get_seqnum(tdb) == 8);
+                       ok1(tdb_get_seqnum(tdb) == seq);
                }
                tdb_close(tdb);
                ok1(tap_log_messages == 0);
index 20d0aaafa05e1b282595093ee2c21674e5f348aa..acad4399414d14b7859dd7b26a7ebdf1b3f518d3 100644 (file)
@@ -29,29 +29,6 @@ static int mylock(int fd, int rw, off_t off, off_t len, bool waitflag,
        return ret;
 }
 
-static int myunlock(int fd, int rw, off_t off, off_t len, void *_err)
-{
-       int *lock_err = _err;
-       struct flock fl;
-       int ret;
-
-       if (*lock_err) {
-               errno = *lock_err;
-               return -1;
-       }
-
-       do {
-               fl.l_type = F_UNLCK;
-               fl.l_whence = SEEK_SET;
-               fl.l_start = off;
-               fl.l_len = len;
-
-               ret = fcntl(fd, F_SETLKW, &fl);
-       } while (ret != 0 && errno == EINTR);
-
-       return ret;
-}
-
 static int trav_err;
 static int trav(struct tdb_context *tdb, TDB_DATA k, TDB_DATA d, int *err)
 {
@@ -64,7 +41,10 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        union tdb_attribute lock_attr;
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
@@ -73,13 +53,21 @@ int main(int argc, char *argv[])
        lock_attr.base.attr = TDB_ATTRIBUTE_FLOCK;
        lock_attr.base.next = &tap_log_attr;
        lock_attr.flock.lock = mylock;
-       lock_attr.flock.unlock = myunlock;
+       lock_attr.flock.unlock = tdb_fcntl_unlock;
        lock_attr.flock.data = &lock_err;
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 80);
 
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                struct tdb_data d;
+               unsigned int num_oom_messages;
+
+               /* TDB1 double logs here. */
+               if (flags[i] & TDB_VERSION1) {
+                       num_oom_messages = 2;
+               } else {
+                       num_oom_messages = 1;
+               }
 
                /* Nonblocking open; expect no error message. */
                lock_err = EAGAIN;
@@ -121,7 +109,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(tdb_store(tdb, key, data, TDB_REPLACE) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                /* Nonblocking fetch. */
@@ -133,7 +121,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(!tdb_exists(tdb, key));
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                lock_err = EAGAIN;
@@ -144,7 +132,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(tdb_fetch(tdb, key, &d) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                /* Nonblocking delete. */
@@ -156,7 +144,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(tdb_delete(tdb, key) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                /* Nonblocking locks. */
@@ -168,7 +156,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(tdb_chainlock(tdb, key) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                lock_err = EAGAIN;
@@ -179,7 +167,7 @@ int main(int argc, char *argv[])
                ok1(tap_log_messages == 0);
                lock_err = ENOMEM;
                ok1(tdb_chainlock_read(tdb, key) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                lock_err = EAGAIN;
@@ -218,7 +206,7 @@ int main(int argc, char *argv[])
                trav_err = ENOMEM;
                lock_err = 0;
                ok1(tdb_traverse(tdb, trav, &lock_err) == TDB_ERR_LOCK);
-               ok1(tap_log_messages == 1);
+               ok1(tap_log_messages == num_oom_messages);
                tap_log_messages = 0;
 
                /* Nonblocking transactions. */
index 0bf8194e69fc63ffc2cf193c02389c47aeb8cf37..59b1e6526e51b96fb755c9383bf56cd4b069d54b 100644 (file)
@@ -9,7 +9,8 @@
 
 static enum TDB_ERROR clear_if_first(int fd, void *arg)
 {
-/* We hold a lock offset 63 always, so we can tell if anyone is holding it. */
+/* We hold a lock offset 4 always, so we can tell if anyone is holding it.
+ * (This is compatible with tdb1's TDB_CLEAR_IF_FIRST flag).  */
        struct flock fl;
 
        if (arg != clear_if_first)
@@ -17,7 +18,7 @@ static enum TDB_ERROR clear_if_first(int fd, void *arg)
 
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_SET;
-       fl.l_start = 63;
+       fl.l_start = 4;
        fl.l_len = 1;
 
        if (fcntl(fd, F_SETLK, &fl) == 0) {
@@ -42,7 +43,10 @@ int main(int argc, char *argv[])
        union tdb_attribute cif;
        struct tdb_data key = tdb_mkdata("key", 3);
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        cif.openhook.base.attr = TDB_ATTRIBUTE_OPENHOOK;
        cif.openhook.base.next = &tap_log_attr;
index e2cde96a96a7570b94b4c35f8c10bb6c97a3e5c4..4cbbda03c7ef230f23f2ed411e22684041bf52f7 100644 (file)
@@ -24,27 +24,31 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        union tdb_attribute seed_attr;
        union tdb_attribute hash_attr;
        union tdb_attribute lock_attr;
 
+       seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
+       seed_attr.base.next = &hash_attr;
+       seed_attr.seed.seed = 100;
+
        hash_attr.base.attr = TDB_ATTRIBUTE_HASH;
-       hash_attr.base.next = &seed_attr;
+       hash_attr.base.next = &lock_attr;
        hash_attr.hash.fn = hash_fn;
        hash_attr.hash.data = &hash_attr;
 
-       seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
-       seed_attr.base.next = &lock_attr;
-       seed_attr.seed.seed = 100;
-
        lock_attr.base.attr = TDB_ATTRIBUTE_FLOCK;
        lock_attr.base.next = &tap_log_attr;
        lock_attr.flock.lock = mylock;
        lock_attr.flock.unlock = myunlock;
        lock_attr.flock.data = &lock_attr;
 
-       plan_tests(sizeof(flags) / sizeof(flags[0]) * 50);
+       plan_tests(sizeof(flags) / sizeof(flags[0]) * 49
+                  + sizeof(flags) / sizeof(flags[0]) / 2);
 
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                union tdb_attribute attr;
@@ -61,17 +65,26 @@ int main(int argc, char *argv[])
                attr.base.attr = TDB_ATTRIBUTE_HASH;
                ok1(tdb_get_attribute(tdb, &attr) == 0);
                ok1(attr.base.attr == TDB_ATTRIBUTE_HASH);
-               ok1(attr.hash.fn == tdb_jenkins_hash);
+               if (flags[i] & TDB_VERSION1) {
+                       ok1(attr.hash.fn == tdb1_old_hash);
+               } else {
+                       ok1(attr.hash.fn == tdb_jenkins_hash);
+               }
                attr.base.attr = TDB_ATTRIBUTE_FLOCK;
                ok1(tdb_get_attribute(tdb, &attr) == 0);
                ok1(attr.base.attr == TDB_ATTRIBUTE_FLOCK);
                ok1(attr.flock.lock == tdb_fcntl_lock);
                ok1(attr.flock.unlock == tdb_fcntl_unlock);
                attr.base.attr = TDB_ATTRIBUTE_SEED;
-               ok1(tdb_get_attribute(tdb, &attr) == 0);
-               ok1(attr.base.attr == TDB_ATTRIBUTE_SEED);
-               /* This is possible, just astronomically unlikely. */
-               ok1(attr.seed.seed != 0);
+               if (flags[i] & TDB_VERSION1) {
+                       ok1(tdb_get_attribute(tdb, &attr) == TDB_ERR_EINVAL);
+                       tap_log_messages = 0;
+               } else {
+                       ok1(tdb_get_attribute(tdb, &attr) == 0);
+                       ok1(attr.base.attr == TDB_ATTRIBUTE_SEED);
+                       /* This is possible, just astronomically unlikely. */
+                       ok1(attr.seed.seed != 0);
+               }
 
                /* Unset attributes. */
                tdb_unset_attribute(tdb, TDB_ATTRIBUTE_LOG);
@@ -112,7 +125,17 @@ int main(int argc, char *argv[])
 
                /* Now open with all attributes. */
                tdb = tdb_open("run-90-get-set-attributes.tdb", flags[i],
-                              O_RDWR|O_CREAT|O_TRUNC, 0600, &hash_attr);
+                              O_RDWR|O_CREAT|O_TRUNC, 0600,
+                              &seed_attr);
+
+               if (flags[i] & TDB_VERSION1) {
+                       ok1(!tdb);
+                       ok1(tap_log_messages == 1);
+                       tap_log_messages = 0;
+                       tdb = tdb_open("run-90-get-set-attributes.tdb", flags[i],
+                                      O_RDWR|O_CREAT|O_TRUNC, 0600,
+                                      &hash_attr);
+               }
                ok1(tdb);
 
                /* Get will succeed */
@@ -136,9 +159,15 @@ int main(int argc, char *argv[])
                ok1(attr.flock.data == &lock_attr);
 
                attr.base.attr = TDB_ATTRIBUTE_SEED;
-               ok1(tdb_get_attribute(tdb, &attr) == 0);
-               ok1(attr.base.attr == TDB_ATTRIBUTE_SEED);
-               ok1(attr.seed.seed == seed_attr.seed.seed);
+               if (flags[i] & TDB_VERSION1) {
+                       ok1(tdb_get_attribute(tdb, &attr) == TDB_ERR_EINVAL);
+                       ok1(tap_log_messages == 1);
+                       tap_log_messages = 0;
+               } else {
+                       ok1(tdb_get_attribute(tdb, &attr) == 0);
+                       ok1(attr.base.attr == TDB_ATTRIBUTE_SEED);
+                       ok1(attr.seed.seed == seed_attr.seed.seed);
+               }
 
                /* Unset attributes. */
                tdb_unset_attribute(tdb, TDB_ATTRIBUTE_HASH);
index 53a0ff599005af67d8c964e0db63a023e544729e..f00abb3c7db03f0f5749927af917613da98c1376 100644 (file)
@@ -7,7 +7,10 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
 
index 31404be20d184d44ff01d3ac8e4d55297cdf2b56..c8bbe627d8ff4a971a24c60f897d51203b7c3fc7 100644 (file)
@@ -4,12 +4,15 @@
 
 int main(int argc, char *argv[])
 {
-       unsigned int i;
+       unsigned int i, extra_msgs;
        struct tdb_context *tdb;
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 48);
 
@@ -20,6 +23,13 @@ int main(int argc, char *argv[])
                ok1(tdb);
                ok1(!(tdb_get_flags(tdb) & TDB_RDONLY));
 
+               /* TDB1 complains multiple times. */
+               if (flags[i] & TDB_VERSION1) {
+                       extra_msgs = 1;
+               } else {
+                       extra_msgs = 0;
+               }
+
                ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
 
                tdb_add_flag(tdb, TDB_RDONLY);
@@ -29,14 +39,17 @@ int main(int argc, char *argv[])
                ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 1);
                ok1(tdb_append(tdb, key, data) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 2);
                ok1(tdb_delete(tdb, key) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 3);
 
                /* Can't start a transaction, or any write lock. */
                ok1(tdb_transaction_start(tdb) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 4);
                ok1(tdb_chainlock(tdb, key) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 5);
                ok1(tdb_lockall(tdb) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 6);
@@ -74,14 +87,17 @@ int main(int argc, char *argv[])
                ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 8);
                ok1(tdb_append(tdb, key, data) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 9);
                ok1(tdb_delete(tdb, key) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 10);
 
                /* Can't start a transaction, or any write lock. */
                ok1(tdb_transaction_start(tdb) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 11);
                ok1(tdb_chainlock(tdb, key) == TDB_ERR_RDONLY);
+               tap_log_messages -= extra_msgs;
                ok1(tap_log_messages == 12);
                ok1(tdb_lockall(tdb) == TDB_ERR_RDONLY);
                ok1(tap_log_messages == 13);
index bc778499b6d399e7d92998a0946f3b847025c224..54c48817e83dc7807a2343f2a0b89d9c0956ded1 100644 (file)
@@ -8,9 +8,14 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
-       plan_tests(87);
+       plan_tests(173);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                tdb = tdb_open("run-add-remove-flags.tdb", flags[i],
                               O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
index 290f3260c7c3ab335b65cba9419dcaa85b560dee..91a4d28747ca5a651f14b426263f9600a1e4330a 100644 (file)
@@ -54,7 +54,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
index 26b7c457158cfcaafe44148f0410cb2b66746cb6..0fa2a57f4dfacdafa07068be0f17182fe8628e12 100644 (file)
@@ -8,8 +8,9 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
                        TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
-                       TDB_CONVERT|TDB_NOSYNC,
-                       TDB_NOMMAP|TDB_CONVERT|TDB_NOSYNC };
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
 
index 3e8f4d55aaa7a8486d0f12cf1465df7b21a8f3f6..1eb265ef926b4e87834c733c9bff8ddde77fd1ac 100644 (file)
@@ -49,10 +49,14 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        union tdb_attribute seed_attr;
        enum TDB_ERROR ecode;
-
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
        seed_attr.base.next = &tap_log_attr;
@@ -62,7 +66,8 @@ int main(int argc, char *argv[])
                   * (NUM_RECORDS*6 + (NUM_RECORDS-1)*3 + 22) + 1);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
                tdb = tdb_open("run-traverse.tdb", flags[i],
-                              O_RDWR|O_CREAT|O_TRUNC, 0600, &seed_attr);
+                              O_RDWR|O_CREAT|O_TRUNC, 0600,
+                              flags[i] & TDB_VERSION1 ? NULL : &seed_attr);
                ok1(tdb);
                if (!tdb)
                        continue;
index 2734742571255f300a8f83be33f0953677631ba9..7ff71366cf6a39d1d34da26cbcacf3bf53c0c902 100644 (file)
 static enum TDB_ERROR fork_in_parse(TDB_DATA key, TDB_DATA data,
                                    struct tdb_context *tdb)
 {
-       int status;
+       int status, extra_messages;
+
+       if (tdb_get_flags(tdb) & TDB_VERSION1) {
+               extra_messages = 1;
+       } else {
+               extra_messages = 0;
+       }
 
        if (fork() == 0) {
                /* We expect this to fail. */
                if (tdb_store(tdb, key, data, TDB_REPLACE) != TDB_ERR_LOCK)
                        exit(1);
+               tap_log_messages -= extra_messages;
 
                if (tdb_fetch(tdb, key, &data) != TDB_ERR_LOCK)
                        exit(1);
 
+               tap_log_messages -= extra_messages;
                if (tap_log_messages != 2)
                        exit(2);
 
@@ -47,13 +55,22 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct tdb_context *tdb;
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
-               int status;
+               int status, extra_messages;
+
+               if (flags[i] & TDB_VERSION1) {
+                       extra_messages = 1;
+               } else {
+                       extra_messages = 0;
+               }
 
                tap_log_messages = 0;
 
@@ -70,9 +87,11 @@ int main(int argc, char *argv[])
                        /* We expect this to fail. */
                        if (tdb_store(tdb, key, data, TDB_REPLACE) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tdb_fetch(tdb, key, &data) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tap_log_messages != 2)
                                return 2;
@@ -94,9 +113,11 @@ int main(int argc, char *argv[])
                        /* We expect this to fail. */
                        if (tdb_store(tdb, key, data, TDB_REPLACE) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tdb_fetch(tdb, key, &data) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tap_log_messages != 2)
                                return 2;
@@ -119,9 +140,11 @@ int main(int argc, char *argv[])
                        /* This would always fail anyway... */
                        if (tdb_store(tdb, key, data, TDB_REPLACE) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tdb_fetch(tdb, key, &data) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tap_log_messages != 2)
                                return 2;
@@ -145,15 +168,18 @@ int main(int argc, char *argv[])
                        /* We expect this to fail. */
                        if (tdb_store(tdb, key, data, TDB_REPLACE) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tdb_fetch(tdb, key, &data) != TDB_ERR_LOCK)
                                return 1;
+                       tap_log_messages -= extra_messages;
 
                        if (tap_log_messages != 2)
                                return 2;
 
                        if (tdb_transaction_commit(tdb) != TDB_ERR_LOCK)
                                return 3;
+                       tap_log_messages -= extra_messages;
 
                        tdb_close(tdb);
                        if (tap_log_messages < 3)
index 201757fe84432002aec6aed54538d3c8c6474c60..7cd9b849ef681d049db63d8e2121207d38f831dd 100644 (file)
 int main(int argc, char *argv[])
 {
        struct agent *agent;
-       const int flags[] = { TDB_DEFAULT,
-                             TDB_NOMMAP,
-                             TDB_CONVERT,
-                             TDB_CONVERT | TDB_NOMMAP };
+       int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        int i;
 
        plan_tests(13 * sizeof(flags)/sizeof(flags[0]) + 1);
index 33b99652bf14804f6439278a1005fe2b5057a93e..18b6e1a94881ed6d0f10fe126c0dedf433ea5dff 100644 (file)
@@ -125,7 +125,10 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        TDB_DATA key = tdb_mkdata("hello", 5);
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct agent *agent;
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 15);
index f49e65d8b62231b1867c1fc21b36cbfba5e05030..4d60b2027993883dddbfa92aba8c2287196d8962 100644 (file)
@@ -4,13 +4,16 @@
 
 int main(int argc, char *argv[])
 {
-       unsigned int i;
+       unsigned int i, extra_messages;
        struct tdb_context *tdb, *tdb2;
        struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
        struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
        struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */
        int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
-                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
+                       TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
+                       TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
 
        plan_tests(sizeof(flags) / sizeof(flags[0]) * 28);
        for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
@@ -19,6 +22,12 @@ int main(int argc, char *argv[])
                ok1(tdb);
                if (!tdb)
                        continue;
+
+               if (flags[i] & TDB_VERSION1) {
+                       extra_messages = 1;
+               } else {
+                       extra_messages = 0;
+               }
                tdb2 = tdb_open("run-open-multiple-times.tdb", flags[i],
                                O_RDWR|O_CREAT, 0600, &tap_log_attr);
                ok1(tdb_check(tdb, NULL, NULL) == 0);
@@ -51,12 +60,15 @@ int main(int argc, char *argv[])
 
                /* Anything in the other one should fail. */
                ok1(tdb_fetch(tdb, key, &d) == TDB_ERR_LOCK);
+               tap_log_messages -= extra_messages;
                ok1(tap_log_messages == 1);
                ok1(tdb_store(tdb, key, data, TDB_REPLACE) == TDB_ERR_LOCK);
+               tap_log_messages -= extra_messages;
                ok1(tap_log_messages == 2);
                ok1(tdb_transaction_start(tdb) == TDB_ERR_LOCK);
                ok1(tap_log_messages == 3);
                ok1(tdb_chainlock(tdb, key) == TDB_ERR_LOCK);
+               tap_log_messages -= extra_messages;
                ok1(tap_log_messages == 4);
 
                /* Transaciton should work as normal. */
index 25c1af3d4082eb8462551ab7cc652588ec8f071d..2cde873956398f80b23069bf27334ce086b06d8e 100644 (file)
@@ -11,7 +11,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data;
 
index a3c22576f388b32b2e1c76b39117b42b48487b27..84acd194d8b00b1ac04e6a745bc1c009e9d1c809 100644 (file)
@@ -8,7 +8,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = tdb_mkdata("key", 3);
        struct tdb_data data = tdb_mkdata("data", 4);
 
index 54fbfad4e0be678f1651f2c81ead3085cfa0baad..73e180df5117b470e84047ba859cede095fce8f9 100644 (file)
@@ -8,7 +8,12 @@ int main(int argc, char *argv[])
        struct tdb_context *tdb;
        int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
                        TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
-                       TDB_NOMMAP|TDB_CONVERT };
+                       TDB_NOMMAP|TDB_CONVERT,
+                       TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
+                       TDB_NOMMAP|TDB_VERSION1,
+                       TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
+                       TDB_CONVERT|TDB_VERSION1,
+                       TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
        struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
        struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
        char *summary;
@@ -36,12 +41,14 @@ int main(int argc, char *argv[])
                        ok1(strstr(summary, "Number of records: 500\n"));
                        ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
                        ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
-                       if (j == TDB_SUMMARY_HISTOGRAMS)
+                       if (!(flags[i] & TDB_VERSION1)
+                           && j == TDB_SUMMARY_HISTOGRAMS) {
                                ok1(strstr(summary, "|")
                                    && strstr(summary, "*"));
-                       else
+                       } else {
                                ok1(!strstr(summary, "|")
                                    && !strstr(summary, "*"));
+                       }
                        free(summary);
                }
                tdb_close(tdb);