LCOV - code coverage report
Current view: top level - source3/torture - test_dbwrap_ctdb.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 0 75 0.0 %
Date: 2021-09-23 10:06:22 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Test dbwrap_ctdb API
       4             :  * Copyright (C) Volker Lendecke 2012
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "torture/proto.h"
      22             : #include "system/filesys.h"
      23             : #include "lib/dbwrap/dbwrap.h"
      24             : #include "lib/dbwrap/dbwrap_ctdb.h"
      25             : #include "messages.h"
      26             : #include "lib/messages_ctdb.h"
      27             : #include "lib/global_contexts.h"
      28             : 
      29           0 : bool run_local_dbwrap_ctdb1(int dummy)
      30             : {
      31           0 :         struct db_context *db = NULL;
      32             :         int res;
      33           0 :         bool ret = false;
      34             :         NTSTATUS status;
      35             :         uint32_t val;
      36             :         struct messaging_context *msg_ctx;
      37             : 
      38           0 :         msg_ctx = global_messaging_context();
      39             : 
      40           0 :         db = db_open_ctdb(
      41             :                 talloc_tos(),
      42             :                 msg_ctx,
      43             :                 "torture.tdb",
      44             :                 0,
      45             :                 TDB_DEFAULT,
      46             :                 O_RDWR|O_CREAT,
      47             :                 0755,
      48             :                 DBWRAP_LOCK_ORDER_1,
      49             :                 DBWRAP_FLAG_NONE);
      50           0 :         if (db == NULL) {
      51           0 :                 perror("db_open_ctdb failed");
      52           0 :                 goto fail;
      53             :         }
      54             : 
      55           0 :         res = dbwrap_transaction_start(db);
      56           0 :         if (res != 0) {
      57           0 :                 fprintf(stderr, "dbwrap_transaction_start failed");
      58           0 :                 goto fail;
      59             :         }
      60           0 :         res = dbwrap_transaction_cancel(db);
      61           0 :         if (res != 0) {
      62           0 :                 fprintf(stderr, "dbwrap_transaction_cancel failed");
      63           0 :                 goto fail;
      64             :         }
      65             : 
      66           0 :         res = dbwrap_transaction_start(db);
      67           0 :         if (res != 0) {
      68           0 :                 fprintf(stderr, "dbwrap_transaction_start failed");
      69           0 :                 goto fail;
      70             :         }
      71             : 
      72           0 :         status = dbwrap_store_uint32_bystring(db, "foo", 1);
      73           0 :         if (!NT_STATUS_IS_OK(status)) {
      74           0 :                 fprintf(stderr, "store_uint32 failed: %s\n",
      75             :                         nt_errstr(status));
      76           0 :                 goto fail;
      77             :         }
      78           0 :         status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
      79           0 :         if (!NT_STATUS_IS_OK(status)) {
      80           0 :                 fprintf(stderr, "fetch_uint32 failed: %s\n",
      81             :                         nt_errstr(status));
      82           0 :                 goto fail;
      83             :         }
      84           0 :         if (val != 1) {
      85           0 :                 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
      86             :                         (unsigned)val);
      87           0 :                 goto fail;
      88             :         }
      89             : 
      90           0 :         status = dbwrap_store_uint32_bystring(db, "bar", 5);
      91           0 :         if (!NT_STATUS_IS_OK(status)) {
      92           0 :                 fprintf(stderr, "store_uint32 failed: %s\n",
      93             :                         nt_errstr(status));
      94           0 :                 goto fail;
      95             :         }
      96           0 :         status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
      97           0 :         if (!NT_STATUS_IS_OK(status)) {
      98           0 :                 fprintf(stderr, "fetch_uint32 failed: %s\n",
      99             :                         nt_errstr(status));
     100           0 :                 goto fail;
     101             :         }
     102           0 :         if (val != 5) {
     103           0 :                 fprintf(stderr, "fetch_uint32 gave %u, expected 5",
     104             :                         (unsigned)val);
     105           0 :                 goto fail;
     106             :         }
     107             : 
     108           0 :         status = dbwrap_store_uint32_bystring(db, "foo", 2);
     109           0 :         if (!NT_STATUS_IS_OK(status)) {
     110           0 :                 fprintf(stderr, "store_uint32 failed: %s\n",
     111             :                         nt_errstr(status));
     112           0 :                 goto fail;
     113             :         }
     114           0 :         status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
     115           0 :         if (!NT_STATUS_IS_OK(status)) {
     116           0 :                 fprintf(stderr, "fetch_uint32 failed: %s\n",
     117             :                         nt_errstr(status));
     118           0 :                 goto fail;
     119             :         }
     120           0 :         if (val != 2) {
     121           0 :                 fprintf(stderr, "fetch_uint32 gave %u, expected 2",
     122             :                         (unsigned)val);
     123           0 :                 goto fail;
     124             :         }
     125             : 
     126           0 :         res = dbwrap_transaction_commit(db);
     127           0 :         if (res != 0) {
     128           0 :                 fprintf(stderr, "dbwrap_transaction_commit failed");
     129           0 :                 goto fail;
     130             :         }
     131             : 
     132             :         /*
     133             :          * check that the values have reached the disk
     134             :          */
     135           0 :         status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
     136           0 :         if (!NT_STATUS_IS_OK(status)) {
     137           0 :                 fprintf(stderr, "fetch_uint32 failed: %s\n",
     138             :                         nt_errstr(status));
     139           0 :                 goto fail;
     140             :         }
     141           0 :         if (val != 2) {
     142           0 :                 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
     143             :                         (unsigned)val);
     144           0 :                 goto fail;
     145             :         }
     146             : 
     147           0 :         status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
     148           0 :         if (!NT_STATUS_IS_OK(status)) {
     149           0 :                 fprintf(stderr, "fetch_uint32 failed: %s\n",
     150             :                         nt_errstr(status));
     151           0 :                 goto fail;
     152             :         }
     153           0 :         if (val != 5) {
     154           0 :                 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
     155             :                         (unsigned)val);
     156           0 :                 goto fail;
     157             :         }
     158             : 
     159           0 :         ret = true;
     160           0 : fail:
     161           0 :         TALLOC_FREE(db);
     162           0 :         return ret;
     163             : }

Generated by: LCOV version 1.13