Commit 818ed297 authored by Rusty Russell's avatar Rusty Russell

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. 
parent 670ba98f
......@@ -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,6 +116,9 @@ 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:
if (tdb->flags & TDB_VERSION1)
ret = tdb1_needs_recovery(tdb) ? SUCCESS : FAILED;
else
ret = tdb_needs_recovery(tdb) ? SUCCESS : FAILED;
break;
case CHECK:
......
/* 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",
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 };
......
......@@ -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++) {
......
......@@ -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));
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);
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));
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);
ok(moves <= ilog64(j / SIZE_STEP)*2,
"Moved %u times", moves);
}
tdb_close(tdb);
}
......
......@@ -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++) {
......
......@@ -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++) {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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");
......
......@@ -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 (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));
ok1(test_death(ops[i], agent, flags));
}
}
free_external_agent(agent);
......
......@@ -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++) {
......
......@@ -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);
......
......@@ -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. */
......
......@@ -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;
......
......@@ -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);
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;
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;
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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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++) {
......
......@@ -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);
......
......@@ -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;
......
......@@ -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)
......
......@@ -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);
......
......@@ -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);
......
......@@ -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. */
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment