tdb2: test: import tdb1's tests.
[ccan] / ccan / tdb2 / test / run-tdb1-rwlock-check.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5
6 static void log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
7 {
8         unsigned int *count = tdb1_get_logging_private(tdb);
9         if (strstr(fmt, "spinlocks"))
10                 (*count)++;
11 }
12
13 /* The code should barf on TDBs created with rwlocks. */
14 int main(int argc, char *argv[])
15 {
16         struct tdb1_context *tdb;
17         unsigned int log_count;
18         struct tdb1_logging_context log_ctx = { log_fn, &log_count };
19
20         plan_tests(4);
21
22         /* We should fail to open rwlock-using tdbs of either endian. */
23         log_count = 0;
24         tdb = tdb1_open_ex("test/rwlock-le.tdb1", 0, 0, O_RDWR, 0,
25                           &log_ctx, NULL);
26         ok1(!tdb);
27         ok1(log_count == 1);
28
29         log_count = 0;
30         tdb = tdb1_open_ex("test/rwlock-be.tdb1", 0, 0, O_RDWR, 0,
31                           &log_ctx, NULL);
32         ok1(!tdb);
33         ok1(log_count == 1);
34
35         return exit_status();
36 }