LCOV - code coverage report
Current view: top level - source3/torture - test_dbwrap_do_locked.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 0 70 0.0 %
Date: 2024-06-13 04:01:37 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Test dbwrap_watch API
       4             :  * Copyright (C) Volker Lendecke 2017
       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_open.h"
      25             : #include "lib/dbwrap/dbwrap_watch.h"
      26             : #include "lib/util/util_tdb.h"
      27             : #include "source3/include/util_tdb.h"
      28             : #include "lib/global_contexts.h"
      29             : 
      30             : struct do_locked1_state {
      31             :         TDB_DATA value;
      32             :         NTSTATUS status;
      33             : };
      34             : 
      35           0 : static void do_locked1_cb(
      36             :         struct db_record *rec,
      37             :         TDB_DATA value,
      38             :         void *private_data)
      39             : {
      40           0 :         struct do_locked1_state *state =
      41             :                 (struct do_locked1_state *)private_data;
      42             : 
      43           0 :         state->status = dbwrap_record_store(rec, state->value, 0);
      44           0 : }
      45             : 
      46           0 : static void do_locked1_check(TDB_DATA key, TDB_DATA value,
      47             :                              void *private_data)
      48             : {
      49           0 :         struct do_locked1_state *state =
      50             :                 (struct do_locked1_state *)private_data;
      51             :         int ret;
      52             : 
      53           0 :         ret = tdb_data_cmp(value, state->value);
      54           0 :         if (ret != 0) {
      55           0 :                 state->status = NT_STATUS_DATA_ERROR;
      56           0 :                 return;
      57             :         }
      58             : 
      59           0 :         state->status = NT_STATUS_OK;
      60             : }
      61             : 
      62           0 : static void do_locked1_del(
      63             :         struct db_record *rec,
      64             :         TDB_DATA value,
      65             :         void *private_data)
      66             : {
      67           0 :         struct do_locked1_state *state =
      68             :                 (struct do_locked1_state *)private_data;
      69             : 
      70           0 :         state->status = dbwrap_record_delete(rec);
      71           0 : }
      72             : 
      73           0 : bool run_dbwrap_do_locked1(int dummy)
      74             : {
      75             :         struct tevent_context *ev;
      76             :         struct messaging_context *msg;
      77             :         struct db_context *backend;
      78             :         struct db_context *db;
      79           0 :         const char *dbname = "test_do_locked.tdb";
      80           0 :         const char *keystr = "key";
      81           0 :         TDB_DATA key = string_term_tdb_data(keystr);
      82           0 :         const char *valuestr = "value";
      83           0 :         TDB_DATA value = string_term_tdb_data(valuestr);
      84           0 :         struct do_locked1_state state = { .value = value };
      85           0 :         int ret = false;
      86             :         NTSTATUS status;
      87             : 
      88           0 :         ev = global_event_context();
      89           0 :         if (ev == NULL) {
      90           0 :                 fprintf(stderr, "global_event_context() failed\n");
      91           0 :                 return false;
      92             :         }
      93           0 :         msg = global_messaging_context();
      94           0 :         if (msg == NULL) {
      95           0 :                 fprintf(stderr, "global_messaging_context() failed\n");
      96           0 :                 return false;
      97             :         }
      98             : 
      99           0 :         backend = db_open(talloc_tos(), dbname, 0,
     100             :                           TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0644,
     101             :                           DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
     102           0 :         if (backend == NULL) {
     103           0 :                 fprintf(stderr, "db_open failed: %s\n", strerror(errno));
     104           0 :                 return false;
     105             :         }
     106             : 
     107           0 :         db = db_open_watched(talloc_tos(), &backend, msg);
     108           0 :         if (db == NULL) {
     109           0 :                 fprintf(stderr, "db_open_watched failed: %s\n",
     110           0 :                         strerror(errno));
     111           0 :                 return false;
     112             :         }
     113             : 
     114           0 :         status = dbwrap_do_locked(db, key, do_locked1_cb, &state);
     115           0 :         if (!NT_STATUS_IS_OK(status)) {
     116           0 :                 fprintf(stderr, "dbwrap_do_locked failed: %s\n",
     117             :                         nt_errstr(status));
     118           0 :                 goto fail;
     119             :         }
     120           0 :         if (!NT_STATUS_IS_OK(state.status)) {
     121           0 :                 fprintf(stderr, "store returned %s\n",
     122             :                         nt_errstr(state.status));
     123           0 :                 goto fail;
     124             :         }
     125             : 
     126           0 :         status = dbwrap_parse_record(db, key, do_locked1_check, &state);
     127           0 :         if (!NT_STATUS_IS_OK(status)) {
     128           0 :                 fprintf(stderr, "dbwrap_parse_record failed: %s\n",
     129             :                         nt_errstr(status));
     130           0 :                 goto fail;
     131             :         }
     132           0 :         if (!NT_STATUS_IS_OK(state.status)) {
     133           0 :                 fprintf(stderr, "data compare returned %s\n",
     134             :                         nt_errstr(status));
     135           0 :                 goto fail;
     136             :         }
     137             : 
     138           0 :         status = dbwrap_do_locked(db, key, do_locked1_del, &state);
     139           0 :         if (!NT_STATUS_IS_OK(status)) {
     140           0 :                 fprintf(stderr, "dbwrap_do_locked failed: %s\n",
     141             :                         nt_errstr(status));
     142           0 :                 goto fail;
     143             :         }
     144           0 :         if (!NT_STATUS_IS_OK(state.status)) {
     145           0 :                 fprintf(stderr, "delete returned %s\n", nt_errstr(status));
     146           0 :                 goto fail;
     147             :         }
     148             : 
     149           0 :         status = dbwrap_parse_record(db, key, do_locked1_check, &state);
     150           0 :         if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
     151           0 :                 fprintf(stderr, "parse_record returned %s, "
     152             :                         "expected NOT_FOUND\n", nt_errstr(status));
     153           0 :                 goto fail;
     154             :         }
     155             : 
     156           0 :         ret = true;
     157           0 : fail:
     158           0 :         TALLOC_FREE(db);
     159           0 :         unlink(dbname);
     160           0 :         return ret;
     161             : }

Generated by: LCOV version 1.13