LCOV - code coverage report
Current view: top level - lib/tdb/test - run-nested-transactions.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 43 43 100.0 %
Date: 2024-04-21 15:09:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "../common/tdb_private.h"
       2             : #include "../common/io.c"
       3             : #include "../common/tdb.c"
       4             : #include "../common/lock.c"
       5             : #include "../common/freelist.c"
       6             : #include "../common/traverse.c"
       7             : #include "../common/transaction.c"
       8             : #include "../common/error.c"
       9             : #include "../common/open.c"
      10             : #include "../common/check.c"
      11             : #include "../common/hash.c"
      12             : #include "../common/mutex.c"
      13             : #include "tap-interface.h"
      14             : #include <stdlib.h>
      15             : #include <stdbool.h>
      16             : #include "logging.h"
      17             : 
      18           1 : int main(int argc, char *argv[])
      19             : {
      20             :         struct tdb_context *tdb;
      21             :         TDB_DATA key, data;
      22             : 
      23             :         plan_tests(27);
      24           1 :         key.dsize = strlen("hi");
      25           1 :         key.dptr = discard_const_p(uint8_t, "hi");
      26             : 
      27           1 :         tdb = tdb_open_ex("run-nested-transactions.tdb",
      28             :                           1024, TDB_CLEAR_IF_FIRST|TDB_DISALLOW_NESTING,
      29             :                           O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
      30           1 :         ok1(tdb);
      31             : 
      32             :         /* Nesting disallowed. */
      33           1 :         ok1(tdb_transaction_start(tdb) == 0);
      34           1 :         data.dptr = discard_const_p(uint8_t, "world");
      35           1 :         data.dsize = strlen("world");
      36           1 :         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
      37           1 :         data = tdb_fetch(tdb, key);
      38           1 :         ok1(data.dsize == strlen("world"));
      39           1 :         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
      40           1 :         free(data.dptr);
      41           1 :         ok1(tdb_transaction_start(tdb) != 0);
      42           1 :         ok1(tdb_error(tdb) == TDB_ERR_NESTING);
      43             : 
      44           1 :         data = tdb_fetch(tdb, key);
      45           1 :         ok1(data.dsize == strlen("world"));
      46           1 :         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
      47           1 :         free(data.dptr);
      48           1 :         ok1(tdb_transaction_commit(tdb) == 0);
      49           1 :         data = tdb_fetch(tdb, key);
      50           1 :         ok1(data.dsize == strlen("world"));
      51           1 :         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
      52           1 :         free(data.dptr);
      53           1 :         tdb_close(tdb);
      54             : 
      55             :         /* Nesting allowed by default */
      56           1 :         tdb = tdb_open_ex("run-nested-transactions.tdb",
      57             :                           1024, TDB_DEFAULT, O_RDWR, 0, &taplogctx, NULL);
      58           1 :         ok1(tdb);
      59             : 
      60           1 :         ok1(tdb_transaction_start(tdb) == 0);
      61           1 :         ok1(tdb_transaction_start(tdb) == 0);
      62           1 :         ok1(tdb_delete(tdb, key) == 0);
      63           1 :         ok1(tdb_transaction_commit(tdb) == 0);
      64           1 :         ok1(!tdb_exists(tdb, key));
      65           1 :         ok1(tdb_transaction_cancel(tdb) == 0);
      66             :         /* Surprise! Kills inner "committed" transaction. */
      67           1 :         ok1(tdb_exists(tdb, key));
      68             : 
      69           1 :         ok1(tdb_transaction_start(tdb) == 0);
      70           1 :         ok1(tdb_transaction_start(tdb) == 0);
      71           1 :         ok1(tdb_delete(tdb, key) == 0);
      72           1 :         ok1(tdb_transaction_commit(tdb) == 0);
      73           1 :         ok1(!tdb_exists(tdb, key));
      74           1 :         ok1(tdb_transaction_commit(tdb) == 0);
      75           1 :         ok1(!tdb_exists(tdb, key));
      76           1 :         tdb_close(tdb);
      77             : 
      78           1 :         return exit_status();
      79             : }

Generated by: LCOV version 1.14