1 #include <ccan/failtest/failtest_override.h>
2 #include "ntdb-source.h"
3 #include "tap-interface.h"
4 #include <ccan/failtest/failtest.h>
6 #include "failtest_helper.h"
7 #include "helprun-external-agent.h"
9 int main(int argc, char *argv[])
12 struct ntdb_context *ntdb;
13 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
14 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
15 NTDB_DATA key = ntdb_mkdata("key", 3);
16 NTDB_DATA data = ntdb_mkdata("data", 4), d;
17 union ntdb_attribute seed_attr;
18 unsigned int msgs = 0;
20 failtest_init(argc, argv);
21 failtest_hook = block_repeat_failures;
22 failtest_exit_check = exit_check_log;
24 seed_attr.base.attr = NTDB_ATTRIBUTE_SEED;
25 seed_attr.base.next = &tap_log_attr;
26 seed_attr.seed.seed = 0;
28 failtest_suppress = true;
29 plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
30 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
31 ntdb = ntdb_open("run-05-readonly-open.ntdb",
32 flags[i]|MAYBE_NOSYNC,
33 O_RDWR|O_CREAT|O_TRUNC, 0600,
35 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
38 failtest_suppress = false;
39 ntdb = ntdb_open("run-05-readonly-open.ntdb",
40 flags[i]|MAYBE_NOSYNC,
41 O_RDONLY, 0600, &tap_log_attr);
44 ok1(tap_log_messages == msgs);
45 /* Fetch should succeed, stores should fail. */
46 if (!ok1(ntdb_fetch(ntdb, key, &d) == 0))
48 ok1(ntdb_deq(d, data));
50 if (!ok1(ntdb_store(ntdb, key, data, NTDB_MODIFY)
53 ok1(tap_log_messages == ++msgs);
54 if (!ok1(ntdb_store(ntdb, key, data, NTDB_INSERT)
57 ok1(tap_log_messages == ++msgs);
58 failtest_suppress = true;
59 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
61 ok1(tap_log_messages == msgs);
62 /* SIGH: failtest bug, it doesn't save the ntdb file because
63 * we have it read-only. If we go around again, it gets
64 * changed underneath us and things get screwy. */
65 if (failtest_has_failed())
68 failtest_exit(exit_status());
71 failtest_suppress = true;
73 failtest_exit(exit_status());
76 * We will never reach this but the compiler complains if we do not
77 * return in this function.