1 #include "../common/tdb_private.h"
2 #include "lock-tracking.h"
3 #define fcntl fcntl_with_lockcheck
4 #include "../common/io.c"
5 #include "../common/tdb.c"
6 #include "../common/lock.c"
7 #include "../common/freelist.c"
8 #include "../common/traverse.c"
9 #include "../common/transaction.c"
10 #include "../common/error.c"
11 #include "../common/open.c"
12 #include "../common/check.c"
13 #include "../common/hash.c"
14 #include "tap-interface.h"
18 #include "external-agent.h"
21 static struct agent
*agent
;
23 static bool correct_key(TDB_DATA key
)
25 return key
.dsize
== strlen("hi")
26 && memcmp(key
.dptr
, "hi", key
.dsize
) == 0;
29 static bool correct_data(TDB_DATA data
)
31 return data
.dsize
== strlen("world")
32 && memcmp(data
.dptr
, "world", data
.dsize
) == 0;
35 static int traverse2(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
38 ok1(correct_key(key
));
39 ok1(correct_data(data
));
43 static int traverse1(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
46 ok1(correct_key(key
));
47 ok1(correct_data(data
));
48 ok1(external_agent_operation(agent
, TRANSACTION_START
, tdb_name(tdb
))
49 == WOULD_HAVE_BLOCKED
);
50 tdb_traverse(tdb
, traverse2
, NULL
);
52 /* That should *not* release the transaction lock! */
53 ok1(external_agent_operation(agent
, TRANSACTION_START
, tdb_name(tdb
))
54 == WOULD_HAVE_BLOCKED
);
58 int main(int argc
, char *argv
[])
60 struct tdb_context
*tdb
;
64 agent
= prepare_external_agent();
66 tdb
= tdb_open_ex("run-nested-traverse.tdb", 1024, TDB_CLEAR_IF_FIRST
,
67 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &taplogctx
, NULL
);
70 ok1(external_agent_operation(agent
, OPEN
, tdb_name(tdb
)) == SUCCESS
);
71 ok1(external_agent_operation(agent
, TRANSACTION_START
, tdb_name(tdb
))
73 ok1(external_agent_operation(agent
, TRANSACTION_COMMIT
, tdb_name(tdb
))
76 key
.dsize
= strlen("hi");
77 key
.dptr
= (void *)"hi";
78 data
.dptr
= (void *)"world";
79 data
.dsize
= strlen("world");
81 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == 0);
82 tdb_traverse(tdb
, traverse1
, NULL
);
83 tdb_traverse_read(tdb
, traverse1
, NULL
);