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"
8 int main(int argc
, char *argv
[])
11 struct ntdb_context
*ntdb
;
12 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
,
13 NTDB_CONVERT
, NTDB_NOMMAP
|NTDB_CONVERT
};
14 NTDB_DATA key
= ntdb_mkdata("key", 3);
15 NTDB_DATA data
= ntdb_mkdata("data", 4), d
;
16 union ntdb_attribute seed_attr
;
17 unsigned int msgs
= 0;
19 failtest_init(argc
, argv
);
20 failtest_hook
= block_repeat_failures
;
21 failtest_exit_check
= exit_check_log
;
23 seed_attr
.base
.attr
= NTDB_ATTRIBUTE_SEED
;
24 seed_attr
.base
.next
= &tap_log_attr
;
25 seed_attr
.seed
.seed
= 0;
27 failtest_suppress
= true;
28 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 11);
29 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
30 ntdb
= ntdb_open("run-05-readonly-open.ntdb",
31 flags
[i
]|MAYBE_NOSYNC
,
32 O_RDWR
|O_CREAT
|O_TRUNC
, 0600,
34 ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
) == 0);
37 failtest_suppress
= false;
38 ntdb
= ntdb_open("run-05-readonly-open.ntdb",
39 flags
[i
]|MAYBE_NOSYNC
,
40 O_RDONLY
, 0600, &tap_log_attr
);
43 ok1(tap_log_messages
== msgs
);
44 /* Fetch should succeed, stores should fail. */
45 if (!ok1(ntdb_fetch(ntdb
, key
, &d
) == 0))
47 ok1(ntdb_deq(d
, data
));
49 if (!ok1(ntdb_store(ntdb
, key
, data
, NTDB_MODIFY
)
52 ok1(tap_log_messages
== ++msgs
);
53 if (!ok1(ntdb_store(ntdb
, key
, data
, NTDB_INSERT
)
56 ok1(tap_log_messages
== ++msgs
);
57 failtest_suppress
= true;
58 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
60 ok1(tap_log_messages
== msgs
);
61 /* SIGH: failtest bug, it doesn't save the ntdb file because
62 * we have it read-only. If we go around again, it gets
63 * changed underneath us and things get screwy. */
64 if (failtest_has_failed())
67 failtest_exit(exit_status());
70 failtest_suppress
= true;
72 failtest_exit(exit_status());