|
rpm-build |
ca8475 |
#include "../common/tdb_private.h"
|
|
rpm-build |
ca8475 |
#include "../common/io.c"
|
|
rpm-build |
ca8475 |
#include "../common/tdb.c"
|
|
rpm-build |
ca8475 |
#include "../common/lock.c"
|
|
rpm-build |
ca8475 |
#include "../common/freelist.c"
|
|
rpm-build |
ca8475 |
#include "../common/traverse.c"
|
|
rpm-build |
ca8475 |
#include "../common/transaction.c"
|
|
rpm-build |
ca8475 |
#include "../common/error.c"
|
|
rpm-build |
ca8475 |
#include "../common/open.c"
|
|
rpm-build |
ca8475 |
#include "../common/check.c"
|
|
rpm-build |
ca8475 |
#include "../common/hash.c"
|
|
rpm-build |
ca8475 |
#include "../common/mutex.c"
|
|
rpm-build |
ca8475 |
#include "tap-interface.h"
|
|
rpm-build |
ca8475 |
#include <stdlib.h>
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static unsigned int tdb_dumb_hash(TDB_DATA *key)
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
return key->dsize;
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
unsigned int *count = tdb_get_logging_private(tdb);
|
|
rpm-build |
ca8475 |
if (strstr(fmt, "hash"))
|
|
rpm-build |
ca8475 |
(*count)++;
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static unsigned int hdr_rwlocks(const char *fname)
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
struct tdb_header hdr;
|
|
rpm-build |
ca8475 |
ssize_t nread;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
int fd = open(fname, O_RDONLY);
|
|
rpm-build |
ca8475 |
if (fd == -1)
|
|
rpm-build |
ca8475 |
return -1;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
nread = read(fd, &hdr, sizeof(hdr));
|
|
rpm-build |
ca8475 |
close(fd);
|
|
rpm-build |
ca8475 |
if (nread != sizeof(hdr)) {
|
|
rpm-build |
ca8475 |
return -1;
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
return hdr.rwlocks;
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
int main(int argc, char *argv[])
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
struct tdb_context *tdb;
|
|
rpm-build |
ca8475 |
unsigned int log_count, flags;
|
|
rpm-build |
ca8475 |
TDB_DATA d, r;
|
|
rpm-build |
ca8475 |
struct tdb_logging_context log_ctx = { log_fn, &log_count };
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
plan_tests(38 * 2);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
for (flags = 0; flags <= TDB_CONVERT; flags += TDB_CONVERT) {
|
|
rpm-build |
ca8475 |
unsigned int rwmagic = TDB_HASH_RWLOCK_MAGIC;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
if (flags & TDB_CONVERT)
|
|
rpm-build |
ca8475 |
tdb_convert(&rwmagic, sizeof(rwmagic));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Create an old-style hash. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, flags,
|
|
rpm-build |
ca8475 |
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx,
|
|
rpm-build |
ca8475 |
NULL);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
d.dptr = discard_const_p(uint8_t, "Hello");
|
|
rpm-build |
ca8475 |
d.dsize = 5;
|
|
rpm-build |
ca8475 |
ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Should not have marked rwlocks field. */
|
|
rpm-build |
ca8475 |
ok1(hdr_rwlocks("run-incompatible.tdb") == 0);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* We can still open any old-style with incompat flag. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0,
|
|
rpm-build |
ca8475 |
TDB_INCOMPATIBLE_HASH,
|
|
rpm-build |
ca8475 |
O_RDWR, 0600, &log_ctx, NULL);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
r = tdb_fetch(tdb, d);
|
|
rpm-build |
ca8475 |
ok1(r.dsize == 5);
|
|
rpm-build |
ca8475 |
free(r.dptr);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
|
|
rpm-build |
ca8475 |
0, &log_ctx, tdb_jenkins_hash);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
|
|
rpm-build |
ca8475 |
0, &log_ctx, tdb_jenkins_hash);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* OK, now create with incompatible flag, default hash. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0,
|
|
rpm-build |
ca8475 |
flags|TDB_INCOMPATIBLE_HASH,
|
|
rpm-build |
ca8475 |
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx,
|
|
rpm-build |
ca8475 |
NULL);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
d.dptr = discard_const_p(uint8_t, "Hello");
|
|
rpm-build |
ca8475 |
d.dsize = 5;
|
|
rpm-build |
ca8475 |
ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Should have marked rwlocks field. */
|
|
rpm-build |
ca8475 |
ok1(hdr_rwlocks("run-incompatible.tdb") == rwmagic);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Cannot open with old hash. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, 0,
|
|
rpm-build |
ca8475 |
O_RDWR, 0600, &log_ctx, tdb_old_hash);
|
|
rpm-build |
ca8475 |
ok1(!tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 1);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Can open with jenkins hash. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, 0,
|
|
rpm-build |
ca8475 |
O_RDWR, 0600, &log_ctx, tdb_jenkins_hash);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
r = tdb_fetch(tdb, d);
|
|
rpm-build |
ca8475 |
ok1(r.dsize == 5);
|
|
rpm-build |
ca8475 |
free(r.dptr);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Can open by letting it figure it out itself. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, 0,
|
|
rpm-build |
ca8475 |
O_RDWR, 0600, &log_ctx, NULL);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
r = tdb_fetch(tdb, d);
|
|
rpm-build |
ca8475 |
ok1(r.dsize == 5);
|
|
rpm-build |
ca8475 |
free(r.dptr);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* We can also use incompatible hash with other hashes. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0,
|
|
rpm-build |
ca8475 |
flags|TDB_INCOMPATIBLE_HASH,
|
|
rpm-build |
ca8475 |
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx,
|
|
rpm-build |
ca8475 |
tdb_dumb_hash);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
d.dptr = discard_const_p(uint8_t, "Hello");
|
|
rpm-build |
ca8475 |
d.dsize = 5;
|
|
rpm-build |
ca8475 |
ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Should have marked rwlocks field. */
|
|
rpm-build |
ca8475 |
ok1(hdr_rwlocks("run-incompatible.tdb") == rwmagic);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* It should not open if we don't specify. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, 0, O_RDWR, 0,
|
|
rpm-build |
ca8475 |
&log_ctx, NULL);
|
|
rpm-build |
ca8475 |
ok1(!tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 1);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* Should reopen with correct hash. */
|
|
rpm-build |
ca8475 |
log_count = 0;
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("run-incompatible.tdb", 0, 0, O_RDWR, 0,
|
|
rpm-build |
ca8475 |
&log_ctx, tdb_dumb_hash);
|
|
rpm-build |
ca8475 |
ok1(tdb);
|
|
rpm-build |
ca8475 |
ok1(log_count == 0);
|
|
rpm-build |
ca8475 |
r = tdb_fetch(tdb, d);
|
|
rpm-build |
ca8475 |
ok1(r.dsize == 5);
|
|
rpm-build |
ca8475 |
free(r.dptr);
|
|
rpm-build |
ca8475 |
ok1(tdb_check(tdb, NULL, NULL) == 0);
|
|
rpm-build |
ca8475 |
tdb_close(tdb);
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
return exit_status();
|
|
rpm-build |
ca8475 |
}
|