1 #include <ccan/failtest/failtest_override.h>
2 #include "tdb2-source.h"
3 #include <ccan/tap/tap.h>
4 #include <ccan/failtest/failtest.h>
6 #include "failtest_helper.h"
8 static bool failtest_suppress = false;
10 /* Don't need to test everything here, just want expand testing. */
11 static enum failtest_result
12 suppress_failure(struct failtest_call *history, unsigned num)
14 if (failtest_suppress)
15 return FAIL_DONT_FAIL;
16 return block_repeat_failures(history, num);
19 int main(int argc, char *argv[])
22 struct tdb_context *tdb;
23 int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
24 TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
25 struct tdb_data key = tdb_mkdata("key", 3);
26 struct tdb_data data = tdb_mkdata("data", 4), d;
27 union tdb_attribute seed_attr;
28 unsigned int msgs = 0;
30 failtest_init(argc, argv);
31 failtest_hook = suppress_failure;
32 failtest_exit_check = exit_check_log;
34 seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
35 seed_attr.base.next = &tap_log_attr;
36 seed_attr.seed.seed = 0;
38 failtest_suppress = true;
39 plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
40 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
41 tdb = tdb_open("run-05-readonly-open.tdb", flags[i],
42 O_RDWR|O_CREAT|O_TRUNC, 0600, &seed_attr);
43 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
46 failtest_suppress = false;
47 tdb = tdb_open("run-05-readonly-open.tdb", flags[i],
48 O_RDONLY, 0600, &tap_log_attr);
51 ok1(tap_log_messages == msgs);
52 /* Fetch should succeed, stores should fail. */
53 if (!ok1(tdb_fetch(tdb, key, &d) == 0))
55 ok1(tdb_deq(d, data));
57 if (!ok1(tdb_store(tdb, key, data, TDB_MODIFY)
60 ok1(tap_log_messages == ++msgs);
61 if (!ok1(tdb_store(tdb, key, data, TDB_INSERT)
64 ok1(tap_log_messages == ++msgs);
65 failtest_suppress = true;
66 ok1(tdb_check(tdb, NULL, NULL) == 0);
68 ok1(tap_log_messages == msgs);
69 /* SIGH: failtest bug, it doesn't save the tdb file because
70 * we have it read-only. If we go around again, it gets
71 * changed underneath us and things get screwy. */
72 if (failtest_has_failed())
75 failtest_exit(exit_status());
78 failtest_suppress = true;
80 failtest_exit(exit_status());