]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1-rwlock-check.c
ec2a66a5bfd21afd3ddc4425bd66aec25e8f5a07
[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 tdb_log_level level,
7                    enum TDB_ERROR ecode, const char *message, void *priv)
8 {
9         unsigned int *count = priv;
10         if (strstr(message, "spinlocks"))
11                 (*count)++;
12 }
13
14 /* The code should barf on TDBs created with rwlocks. */
15 int main(int argc, char *argv[])
16 {
17         struct tdb1_context *tdb;
18         unsigned int log_count;
19         struct tdb1_logging_context log_ctx = { log_fn, &log_count };
20
21         plan_tests(4);
22
23         /* We should fail to open rwlock-using tdbs of either endian. */
24         log_count = 0;
25         tdb = tdb1_open_ex("test/rwlock-le.tdb1", 0, 0, O_RDWR, 0,
26                           &log_ctx, NULL);
27         ok1(!tdb);
28         ok1(log_count == 1);
29
30         log_count = 0;
31         tdb = tdb1_open_ex("test/rwlock-be.tdb1", 0, 0, O_RDWR, 0,
32                           &log_ctx, NULL);
33         ok1(!tdb);
34         ok1(log_count == 1);
35
36         return exit_status();
37 }