1 #define _XOPEN_SOURCE 500
2 #include <ccan/tdb/tdb.h>
3 #include <ccan/tdb/io.c>
4 #include <ccan/tdb/tdb.c>
5 #include <ccan/tdb/lock.c>
6 #include <ccan/tdb/freelist.c>
7 #include <ccan/tdb/traverse.c>
8 #include <ccan/tdb/transaction.c>
9 #include <ccan/tdb/error.c>
10 #include <ccan/tdb/open.c>
11 #include <ccan/tdb/check.c>
12 #include <ccan/hash/hash.h>
13 #include <ccan/tap/tap.h>
17 static unsigned int jenkins_hash(TDB_DATA *key)
19 return hash_stable(key->dptr, key->dsize, 0);
22 static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
24 unsigned int *count = tdb_get_logging_private(tdb);
25 /* Old code used to complain about spinlocks when we put something
27 if (strstr(fmt, "wrong hash") || strstr(fmt, "spinlock"))
31 int main(int argc, char *argv[])
33 struct tdb_context *tdb;
34 unsigned int log_count;
35 struct tdb_logging_context log_ctx = { log_fn, &log_count };
39 /* Create with default hash. */
41 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
42 O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
47 /* Fail to open with different hash. */
48 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
49 &log_ctx, jenkins_hash);
53 /* Create with different hash. */
55 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
56 O_CREAT|O_RDWR|O_TRUNC,
57 0600, &log_ctx, jenkins_hash);
62 /* Endian should be no problem. */
64 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
70 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
76 /* Fail to open with defailt hash. */
77 tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
83 tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
84 0, &log_ctx, jenkins_hash);
90 tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
91 0, &log_ctx, jenkins_hash);