1 #include "../private.h"
3 #include "lock-tracking.h"
5 #define fcntl fcntl_with_lockcheck
6 #include "ntdb-source.h"
8 #include "tap-interface.h"
12 #include "external-agent.h"
14 #include "helprun-external-agent.h"
16 #define TEST_DBNAME "run-lockall.ntdb"
21 int main(int argc, char *argv[])
24 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
25 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
28 plan_tests(13 * sizeof(flags)/sizeof(flags[0]) + 1);
29 agent = prepare_external_agent();
31 err(1, "preparing agent");
33 for (i = 0; i < sizeof(flags)/sizeof(flags[0]); i++) {
34 enum agent_return ret;
35 struct ntdb_context *ntdb;
37 ntdb = ntdb_open(TEST_DBNAME, flags[i]|MAYBE_NOSYNC,
38 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
41 ret = external_agent_operation(agent, OPEN, TEST_DBNAME);
44 ok1(ntdb_lockall(ntdb) == NTDB_SUCCESS);
45 ok1(external_agent_operation(agent, STORE, KEY_STR "=" KEY_STR)
46 == WOULD_HAVE_BLOCKED);
47 ok1(external_agent_operation(agent, FETCH, KEY_STR "=" KEY_STR)
48 == WOULD_HAVE_BLOCKED);
50 ok1(ntdb_lockall(ntdb) == NTDB_SUCCESS);
54 ok1(external_agent_operation(agent, STORE, KEY_STR "=" KEY_STR)
57 ok1(ntdb_lockall_read(ntdb) == NTDB_SUCCESS);
58 ok1(external_agent_operation(agent, STORE, KEY_STR "=" KEY_STR)
59 == WOULD_HAVE_BLOCKED);
60 ok1(external_agent_operation(agent, FETCH, KEY_STR "=" KEY_STR)
62 ok1(ntdb_lockall_read(ntdb) == NTDB_SUCCESS);
63 ntdb_unlockall_read(ntdb);
64 ntdb_unlockall_read(ntdb);
66 ok1(external_agent_operation(agent, STORE, KEY_STR "=" KEY_STR)
68 ok1(external_agent_operation(agent, CLOSE, NULL) == SUCCESS);
72 free_external_agent(agent);
73 ok1(tap_log_messages == 0);