]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1-rwlock-check.c
76355e848ffe702fa47fc709148f80328a9e43aa
[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 tdb_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 tdb_context *tdb;
18         unsigned int log_count;
19         union tdb_attribute log_attr;
20
21         log_attr.base.attr = TDB_ATTRIBUTE_LOG;
22         log_attr.base.next = NULL;
23         log_attr.log.fn = log_fn;
24         log_attr.log.data = &log_count;
25
26         plan_tests(4);
27
28         /* We should fail to open rwlock-using tdbs of either endian. */
29         log_count = 0;
30         tdb = tdb1_open("test/rwlock-le.tdb1", 0, O_RDWR, 0,
31                         &log_attr);
32         ok1(!tdb);
33         ok1(log_count == 1);
34
35         log_count = 0;
36         tdb = tdb1_open("test/rwlock-be.tdb1", 0, O_RDWR, 0,
37                         &log_attr);
38         ok1(!tdb);
39         ok1(log_count == 1);
40
41         return exit_status();
42 }