]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-10-simple-store.c
tdb2: suppress failtest more than once on mmap.
[ccan] / ccan / tdb2 / test / run-10-simple-store.c
1 #include <ccan/failtest/failtest_override.h>
2 #include "tdb2-source.h"
3 #include <ccan/tap/tap.h>
4 #include <ccan/failtest/failtest.h>
5 #include "logging.h"
6 #include "failtest_helper.h"
7
8 int main(int argc, char *argv[])
9 {
10         unsigned int i;
11         struct tdb_context *tdb;
12         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
13                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, 
14                         TDB_NOMMAP|TDB_CONVERT,
15                         TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1,
16                         TDB_NOMMAP|TDB_VERSION1,
17                         TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1,
18                         TDB_CONVERT|TDB_VERSION1,
19                         TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
20         struct tdb_data key = tdb_mkdata("key", 3);
21         struct tdb_data data = tdb_mkdata("data", 4);
22
23         failtest_init(argc, argv);
24         failtest_hook = block_repeat_failures;
25         failtest_exit_check = exit_check_log;
26
27         failtest_suppress = true;
28         plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
29         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
30                 tdb = tdb_open("run-10-simple-store.tdb", flags[i],
31                                O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
32                 if (!ok1(tdb))
33                         break;
34                 /* Modify should fail. */
35                 failtest_suppress = false;
36                 if (!ok1(tdb_store(tdb, key, data, TDB_MODIFY)
37                          == TDB_ERR_NOEXIST))
38                         goto fail;
39                 failtest_suppress = true;
40                 ok1(tdb_check(tdb, NULL, NULL) == 0);
41                 /* Insert should succeed. */
42                 failtest_suppress = false;
43                 if (!ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0))
44                         goto fail;
45                 failtest_suppress = true;
46                 ok1(tdb_check(tdb, NULL, NULL) == 0);
47                 /* Second insert should fail. */
48                 failtest_suppress = false;
49                 if (!ok1(tdb_store(tdb, key, data, TDB_INSERT)
50                          == TDB_ERR_EXISTS))
51                         goto fail;
52                 failtest_suppress = true;
53                 ok1(tdb_check(tdb, NULL, NULL) == 0);
54                 tdb_close(tdb);
55         }
56         ok1(tap_log_messages == 0);
57         failtest_exit(exit_status());
58
59 fail:
60         failtest_suppress = true;
61         tdb_close(tdb);
62         failtest_exit(exit_status());
63 }