]> git.ozlabs.org Git - ccan/blob - ccan/tdb/test/run-rwlock-check.c
tdb: put example hashes into header, so we notice incorrect hash_fn.
[ccan] / ccan / tdb / test / run-rwlock-check.c
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>
14 #include <stdlib.h>
15 #include <err.h>
16
17 static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
18 {
19         unsigned int *count = tdb_get_logging_private(tdb);
20         if (strstr(fmt, "spinlocks"))
21                 (*count)++;
22 }
23
24 /* The code should barf on TDBs created with rwlocks. */
25 int main(int argc, char *argv[])
26 {
27         struct tdb_context *tdb;
28         unsigned int log_count;
29         struct tdb_logging_context log_ctx = { log_fn, &log_count };
30
31         plan_tests(4);
32
33         /* We should fail to open rwlock-using tdbs of either endian. */
34         log_count = 0;
35         tdb = tdb_open_ex("test/rwlock-le.tdb", 0, 0, O_RDWR, 0,
36                           &log_ctx, NULL);
37         ok1(!tdb);
38         ok1(log_count == 1);
39
40         log_count = 0;
41         tdb = tdb_open_ex("test/rwlock-be.tdb", 0, 0, O_RDWR, 0,
42                           &log_ctx, NULL);
43         ok1(!tdb);
44         ok1(log_count == 1);
45
46         return exit_status();
47 }