summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:13:26 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:13:26 +0930
commit01b2214a1893db5071addf1fdf17e9ac06ed63a0 (patch)
treee3fe69fccee166bef42e4dbad2bc2f1655824fdb /lib
parentef70f5dd35974115a85850d04b0f4b64e511659f (diff)
downloadsamba-01b2214a1893db5071addf1fdf17e9ac06ed63a0.tar.gz
samba-01b2214a1893db5071addf1fdf17e9ac06ed63a0.tar.bz2
samba-01b2214a1893db5071addf1fdf17e9ac06ed63a0.zip
tdb2: test: try (almost) all tests with TDB_VERSION1 flag.
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. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 818ed29730b030ce79855fc35c212b51adff3180)
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb2/test/external-agent.c12
-rw-r--r--lib/tdb2/test/lock-tracking.c13
-rw-r--r--lib/tdb2/test/run-01-new_database.c7
-rw-r--r--lib/tdb2/test/run-05-readonly-open.c9
-rw-r--r--lib/tdb2/test/run-10-simple-store.c7
-rw-r--r--lib/tdb2/test/run-11-simple-fetch.c7
-rw-r--r--lib/tdb2/test/run-13-delete.c7
-rw-r--r--lib/tdb2/test/run-14-exists.c7
-rw-r--r--lib/tdb2/test/run-15-append.c35
-rw-r--r--lib/tdb2/test/run-16-wipe_all.c7
-rw-r--r--lib/tdb2/test/run-21-parse_record.c7
-rw-r--r--lib/tdb2/test/run-35-convert.c5
-rw-r--r--lib/tdb2/test/run-55-transaction.c5
-rw-r--r--lib/tdb2/test/run-56-open-during-transaction.c11
-rw-r--r--lib/tdb2/test/run-57-die-during-transaction.c33
-rw-r--r--lib/tdb2/test/run-80-tdb_fd.c7
-rw-r--r--lib/tdb2/test/run-81-seqnum.c44
-rw-r--r--lib/tdb2/test/run-82-lockattr.c52
-rw-r--r--lib/tdb2/test/run-83-openhook.c10
-rw-r--r--lib/tdb2/test/run-90-get-set-attributes.c61
-rw-r--r--lib/tdb2/test/run-91-get-stats.c5
-rw-r--r--lib/tdb2/test/run-92-get-set-readonly.c20
-rw-r--r--lib/tdb2/test/run-add-remove-flags.c9
-rw-r--r--lib/tdb2/test/run-check-callback.c7
-rw-r--r--lib/tdb2/test/run-expand-in-transaction.c5
-rw-r--r--lib/tdb2/test/run-firstkey-nextkey.c11
-rw-r--r--lib/tdb2/test/run-fork-test.c32
-rw-r--r--lib/tdb2/test/run-lockall.c9
-rw-r--r--lib/tdb2/test/run-locktimeout.c5
-rw-r--r--lib/tdb2/test/run-open-multiple-times.c16
-rw-r--r--lib/tdb2/test/run-record-expand.c7
-rw-r--r--lib/tdb2/test/run-simple-delete.c7
-rw-r--r--lib/tdb2/test/run-summary.c13
33 files changed, 364 insertions, 128 deletions
diff --git a/lib/tdb2/test/external-agent.c b/lib/tdb2/test/external-agent.c
index 055b5de736..23874777da 100644
--- a/lib/tdb2/test/external-agent.c
+++ b/lib/tdb2/test/external-agent.c
@@ -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;
diff --git a/lib/tdb2/test/lock-tracking.c b/lib/tdb2/test/lock-tracking.c
index ba09399219..e253db9f71 100644
--- a/lib/tdb2/test/lock-tracking.c
+++ b/lib/tdb2/test/lock-tracking.c
@@ -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",
diff --git a/lib/tdb2/test/run-01-new_database.c b/lib/tdb2/test/run-01-new_database.c
index 0786d4a65b..27d18ccc28 100644
--- a/lib/tdb2/test/run-01-new_database.c
+++ b/lib/tdb2/test/run-01-new_database.c
@@ -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;
diff --git a/lib/tdb2/test/run-05-readonly-open.c b/lib/tdb2/test/run-05-readonly-open.c
index 1062f1c484..c4776f53b2 100644
--- a/lib/tdb2/test/run-05-readonly-open.c
+++ b/lib/tdb2/test/run-05-readonly-open.c
@@ -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);
diff --git a/lib/tdb2/test/run-10-simple-store.c b/lib/tdb2/test/run-10-simple-store.c
index a8e80589fc..bedb64baf0 100644
--- a/lib/tdb2/test/run-10-simple-store.c
+++ b/lib/tdb2/test/run-10-simple-store.c
@@ -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);
diff --git a/lib/tdb2/test/run-11-simple-fetch.c b/lib/tdb2/test/run-11-simple-fetch.c
index 700a4eb93b..bb06000ef7 100644
--- a/lib/tdb2/test/run-11-simple-fetch.c
+++ b/lib/tdb2/test/run-11-simple-fetch.c
@@ -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);
diff --git a/lib/tdb2/test/run-13-delete.c b/lib/tdb2/test/run-13-delete.c
index b5586dc215..fdbc9db70a 100644
--- a/lib/tdb2/test/run-13-delete.c
+++ b/lib/tdb2/test/run-13-delete.c
@@ -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 };
diff --git a/lib/tdb2/test/run-14-exists.c b/lib/tdb2/test/run-14-exists.c
index b27fc7060b..7ff4514262 100644
--- a/lib/tdb2/test/run-14-exists.c
+++ b/lib/tdb2/test/run-14-exists.c
@@ -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++) {
diff --git a/lib/tdb2/test/run-15-append.c b/lib/tdb2/test/run-15-append.c
index ac37960a6f..46a77ff976 100644
--- a/lib/tdb2/test/run-15-append.c
+++ b/lib/tdb2/test/run-15-append.c
@@ -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);
}
diff --git a/lib/tdb2/test/run-16-wipe_all.c b/lib/tdb2/test/run-16-wipe_all.c
index 1ca23c3363..27d6f4388c 100644
--- a/lib/tdb2/test/run-16-wipe_all.c
+++ b/lib/tdb2/test/run-16-wipe_all.c
@@ -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++) {
diff --git a/lib/tdb2/test/run-21-parse_record.c b/lib/tdb2/test/run-21-parse_record.c
index 6f95ff70ac..c7414a4dcd 100644
--- a/lib/tdb2/test/run-21-parse_record.c
+++ b/lib/tdb2/test/run-21-parse_record.c
@@ -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++) {
diff --git a/lib/tdb2/test/run-35-convert.c b/lib/tdb2/test/run-35-convert.c
index faadfb7646..b7b1e6e562 100644
--- a/lib/tdb2/test/run-35-convert.c
+++ b/lib/tdb2/test/run-35-convert.c
@@ -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;
diff --git a/lib/tdb2/test/run-55-transaction.c b/lib/tdb2/test/run-55-transaction.c
index a6607d11db..95545b7e12 100644
--- a/lib/tdb2/test/run-55-transaction.c
+++ b/lib/tdb2/test/run-55-transaction.c
@@ -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;
diff --git a/lib/tdb2/test/run-56-open-during-transaction.c b/lib/tdb2/test/run-56-open-during-transaction.c
index 1c714dc8b8..9262c0528e 100644
--- a/lib/tdb2/test/run-56-open-during-transaction.c
+++ b/lib/tdb2/test/run-56-open-during-transaction.c
@@ -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");
diff --git a/lib/tdb2/test/run-57-die-during-transaction.c b/lib/tdb2/test/run-57-die-during-transaction.c
index e622395537..6e9cb1e3e7 100644
--- a/lib/tdb2/test/run-57-die-during-transaction.c
+++ b/lib/tdb2/test/run-57-die-during-transaction.c
@@ -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);
diff --git a/lib/tdb2/test/run-80-tdb_fd.c b/lib/tdb2/test/run-80-tdb_fd.c
index 82daffea16..3b642971fd 100644
--- a/lib/tdb2/test/run-80-tdb_fd.c
+++ b/lib/tdb2/test/run-80-tdb_fd.c
@@ -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++) {
diff --git a/lib/tdb2/test/run-81-seqnum.c b/lib/tdb2/test/run-81-seqnum.c
index 6af3f91ee1..914a850ba6 100644
--- a/lib/tdb2/test/run-81-seqnum.c
+++ b/lib/tdb2/test/run-81-seqnum.c
@@ -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);
diff --git a/lib/tdb2/test/run-82-lockattr.c b/lib/tdb2/test/run-82-lockattr.c
index 20d0aaafa0..acad439941 100644
--- a/lib/tdb2/test/run-82-lockattr.c
+++ b/lib/tdb2/test/run-82-lockattr.c
@@ -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. */
diff --git a/lib/tdb2/test/run-83-openhook.c b/lib/tdb2/test/run-83-openhook.c
index 69447b54d8..d43f634a69 100644
--- a/lib/tdb2/test/run-83-openhook.c
+++ b/lib/tdb2/test/run-83-openhook.c
@@ -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;
diff --git a/lib/tdb2/test/run-90-get-set-attributes.c b/lib/tdb2/test/run-90-get-set-attributes.c
index e2cde96a96..4cbbda03c7 100644
--- a/lib/tdb2/test/run-90-get-set-attributes.c
+++ b/lib/tdb2/test/run-90-get-set-attributes.c
@@ -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);
diff --git a/lib/tdb2/test/run-91-get-stats.c b/lib/tdb2/test/run-91-get-stats.c
index 53a0ff5990..f00abb3c7d 100644
--- a/lib/tdb2/test/run-91-get-stats.c
+++ b/lib/tdb2/test/run-91-get-stats.c
@@ -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);
diff --git a/lib/tdb2/test/run-92-get-set-readonly.c b/lib/tdb2/test/run-92-get-set-readonly.c
index 31404be20d..c8bbe627d8 100644
--- a/lib/tdb2/test/run-92-get-set-readonly.c
+++ b/lib/tdb2/test/run-92-get-set-readonly.c
@@ -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);
diff --git a/lib/tdb2/test/run-add-remove-flags.c b/lib/tdb2/test/run-add-remove-flags.c
index 96c6bbe7e0..e0f018b838 100644
--- a/lib/tdb2/test/run-add-remove-flags.c
+++ b/lib/tdb2/test/run-add-remove-flags.c
@@ -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);
diff --git a/lib/tdb2/test/run-check-callback.c b/lib/tdb2/test/run-check-callback.c
index 7e15d6ff27..112e368e5b 100644
--- a/lib/tdb2/test/run-check-callback.c
+++ b/lib/tdb2/test/run-check-callback.c
@@ -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++) {
diff --git a/lib/tdb2/test/run-expand-in-transaction.c b/lib/tdb2/test/run-expand-in-transaction.c
index 26b7c45715..0fa2a57f4d 100644
--- a/lib/tdb2/test/run-expand-in-transaction.c
+++ b/lib/tdb2/test/run-expand-in-transaction.c
@@ -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);
diff --git a/lib/tdb2/test/run-firstkey-nextkey.c b/lib/tdb2/test/run-firstkey-nextkey.c
index a46151f6c3..816ff42fd1 100644
--- a/lib/tdb2/test/run-firstkey-nextkey.c
+++ b/lib/tdb2/test/run-firstkey-nextkey.c
@@ -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;
diff --git a/lib/tdb2/test/run-fork-test.c b/lib/tdb2/test/run-fork-test.c
index 2734742571..7ff71366cf 100644
--- a/lib/tdb2/test/run-fork-test.c
+++ b/lib/tdb2/test/run-fork-test.c
@@ -19,16 +19,24 @@
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)
diff --git a/lib/tdb2/test/run-lockall.c b/lib/tdb2/test/run-lockall.c
index 201757fe84..7cd9b849ef 100644
--- a/lib/tdb2/test/run-lockall.c
+++ b/lib/tdb2/test/run-lockall.c
@@ -20,10 +20,11 @@
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);
diff --git a/lib/tdb2/test/run-locktimeout.c b/lib/tdb2/test/run-locktimeout.c
index 44ae7d57e7..dd82f1482d 100644
--- a/lib/tdb2/test/run-locktimeout.c
+++ b/lib/tdb2/test/run-locktimeout.c
@@ -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);
diff --git a/lib/tdb2/test/run-open-multiple-times.c b/lib/tdb2/test/run-open-multiple-times.c
index f49e65d8b6..4d60b20279 100644
--- a/lib/tdb2/test/run-open-multiple-times.c
+++ b/lib/tdb2/test/run-open-multiple-times.c
@@ -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. */
diff --git a/lib/tdb2/test/run-record-expand.c b/lib/tdb2/test/run-record-expand.c
index 1db22c5501..620294446b 100644
--- a/lib/tdb2/test/run-record-expand.c
+++ b/lib/tdb2/test/run-record-expand.c
@@ -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;
diff --git a/lib/tdb2/test/run-simple-delete.c b/lib/tdb2/test/run-simple-delete.c
index 336e98115c..ad7e0153d0 100644
--- a/lib/tdb2/test/run-simple-delete.c
+++ b/lib/tdb2/test/run-simple-delete.c
@@ -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);
diff --git a/lib/tdb2/test/run-summary.c b/lib/tdb2/test/run-summary.c
index ef29be2440..33012bae1e 100644
--- a/lib/tdb2/test/run-summary.c
+++ b/lib/tdb2/test/run-summary.c
@@ -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);