LCOV - code coverage report
Current view: top level - lib/tdb/test - run-traverse-in-transaction.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 33 33 100.0 %
Date: 2024-06-13 04:01:37 Functions: 4 4 100.0 %

          Line data    Source code
       1             : #include "lock-tracking.h"
       2             : #include "../common/tdb_private.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 "../common/mutex.c"
      15             : #include "tap-interface.h"
      16             : #undef fcntl_with_lockcheck
      17             : #include <stdlib.h>
      18             : #include <stdbool.h>
      19             : #include "external-agent.h"
      20             : #include "logging.h"
      21             : 
      22             : static struct agent *agent;
      23             : 
      24           2 : static bool correct_key(TDB_DATA key)
      25             : {
      26           2 :         return key.dsize == strlen("hi")
      27           2 :                 && memcmp(key.dptr, "hi", key.dsize) == 0;
      28             : }
      29             : 
      30           2 : static bool correct_data(TDB_DATA data)
      31             : {
      32           2 :         return data.dsize == strlen("world")
      33           2 :                 && memcmp(data.dptr, "world", data.dsize) == 0;
      34             : }
      35             : 
      36           2 : static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
      37             :                      void *p)
      38             : {
      39           2 :         ok1(correct_key(key));
      40           2 :         ok1(correct_data(data));
      41           2 :         return 0;
      42             : }
      43             : 
      44           1 : int main(int argc, char *argv[])
      45             : {
      46             :         struct tdb_context *tdb;
      47             :         TDB_DATA key, data;
      48             : 
      49             :         plan_tests(13);
      50           1 :         agent = prepare_external_agent();
      51             : 
      52           1 :         tdb = tdb_open_ex("run-traverse-in-transaction.tdb",
      53             :                           1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
      54             :                           0600, &taplogctx, NULL);
      55           1 :         ok1(tdb);
      56             : 
      57           1 :         key.dsize = strlen("hi");
      58           1 :         key.dptr = discard_const_p(uint8_t, "hi");
      59           1 :         data.dptr = discard_const_p(uint8_t, "world");
      60           1 :         data.dsize = strlen("world");
      61             : 
      62           1 :         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
      63             : 
      64           1 :         ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
      65             : 
      66           1 :         ok1(tdb_transaction_active(tdb) == 0);
      67           1 :         ok1(tdb_transaction_start(tdb) == 0);
      68           1 :         ok1(tdb_transaction_active(tdb) == 1);
      69           1 :         ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
      70             :             == WOULD_HAVE_BLOCKED);
      71           1 :         tdb_traverse(tdb, traverse, NULL);
      72             : 
      73             :         /* That should *not* release the transaction lock! */
      74           1 :         ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
      75             :             == WOULD_HAVE_BLOCKED);
      76           1 :         tdb_traverse_read(tdb, traverse, NULL);
      77             : 
      78             :         /* That should *not* release the transaction lock! */
      79           1 :         ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
      80             :             == WOULD_HAVE_BLOCKED);
      81           1 :         ok1(tdb_transaction_commit(tdb) == 0);
      82           1 :         ok1(tdb_transaction_active(tdb) == 0);
      83             :         /* Now we should be fine. */
      84           1 :         ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
      85             :             == SUCCESS);
      86             : 
      87           1 :         tdb_close(tdb);
      88             : 
      89           1 :         return exit_status();
      90             : }

Generated by: LCOV version 1.13