torture3: Test dbwrap_do_locked
authorVolker Lendecke <vl@samba.org>
Tue, 27 Jun 2017 06:25:36 +0000 (08:25 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 25 Jul 2017 15:43:16 +0000 (17:43 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_dbwrap_do_locked.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 38afa081e0fa9b146aecac1ad772c47a3f6cb3af..a624f85b8f67ed61046fae74581ec0fb39927a4a 100755 (executable)
@@ -148,6 +148,7 @@ local_tests = [
     "LOCAL-CANONICALIZE-PATH",
     "LOCAL-DBWRAP-WATCH1",
     "LOCAL-DBWRAP-WATCH2",
+    "LOCAL-DBWRAP-DO-LOCKED1",
     "LOCAL-G-LOCK1",
     "LOCAL-G-LOCK2",
     "LOCAL-G-LOCK3",
index fc468984090657466a46293c178207364be4fe66..8a032da892d75552efe8b57a983e3e3496a6bbb9 100644 (file)
@@ -111,6 +111,7 @@ bool run_notify_bench2(int dummy);
 bool run_notify_bench3(int dummy);
 bool run_dbwrap_watch1(int dummy);
 bool run_dbwrap_watch2(int dummy);
+bool run_dbwrap_do_locked1(int dummy);
 bool run_idmap_tdb_common_test(int dummy);
 bool run_local_dbwrap_ctdb(int dummy);
 bool run_qpathinfo_bufsize(int dummy);
diff --git a/source3/torture/test_dbwrap_do_locked.c b/source3/torture/test_dbwrap_do_locked.c
new file mode 100644 (file)
index 0000000..92dec38
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Test dbwrap_watch API
+ * Copyright (C) Volker Lendecke 2017
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "torture/proto.h"
+#include "system/filesys.h"
+#include "lib/dbwrap/dbwrap.h"
+#include "lib/dbwrap/dbwrap_open.h"
+#include "lib/dbwrap/dbwrap_watch.h"
+#include "lib/util/util_tdb.h"
+#include "source3/include/util_tdb.h"
+
+struct do_locked1_state {
+       TDB_DATA value;
+       NTSTATUS status;
+};
+
+static void do_locked1_cb(struct db_record *rec, void *private_data)
+{
+       struct do_locked1_state *state =
+               (struct do_locked1_state *)private_data;
+
+       state->status = dbwrap_record_store(rec, state->value, 0);
+}
+
+static void do_locked1_check(TDB_DATA key, TDB_DATA value,
+                            void *private_data)
+{
+       struct do_locked1_state *state =
+               (struct do_locked1_state *)private_data;
+       int ret;
+
+       ret = tdb_data_cmp(value, state->value);
+       if (ret != 0) {
+               state->status = NT_STATUS_DATA_ERROR;
+               return;
+       }
+
+       state->status = NT_STATUS_OK;
+}
+
+static void do_locked1_del(struct db_record *rec, void *private_data)
+{
+       struct do_locked1_state *state =
+               (struct do_locked1_state *)private_data;
+
+       state->status = dbwrap_record_delete(rec);
+}
+
+bool run_dbwrap_do_locked1(int dummy)
+{
+       struct db_context *db;
+       const char *dbname = "test_do_locked.tdb";
+       const char *keystr = "key";
+       TDB_DATA key = string_term_tdb_data(keystr);
+       const char *valuestr = "value";
+       TDB_DATA value = string_term_tdb_data(valuestr);
+       struct do_locked1_state state = { .value = value };
+       int ret = false;
+       NTSTATUS status;
+
+       db = db_open(talloc_tos(), dbname, 0, TDB_CLEAR_IF_FIRST,
+                    O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1,
+                    DBWRAP_FLAG_NONE);
+       if (db == NULL) {
+               fprintf(stderr, "db_open failed: %s\n", strerror(errno));
+               return false;
+       }
+
+       status = dbwrap_do_locked(db, key, do_locked1_cb, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "dbwrap_do_locked failed: %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+       if (!NT_STATUS_IS_OK(state.status)) {
+               fprintf(stderr, "store returned %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       status = dbwrap_parse_record(db, key, do_locked1_check, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "dbwrap_parse_record failed: %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+       if (!NT_STATUS_IS_OK(state.status)) {
+               fprintf(stderr, "data compare returned %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = dbwrap_do_locked(db, key, do_locked1_del, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "dbwrap_do_locked failed: %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+       if (!NT_STATUS_IS_OK(state.status)) {
+               fprintf(stderr, "delete returned %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       status = dbwrap_parse_record(db, key, do_locked1_check, &state);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               fprintf(stderr, "parse_record returned %s, "
+                       "expected NOT_FOUND\n", nt_errstr(status));
+               goto fail;
+       }
+
+       ret = true;
+fail:
+       TALLOC_FREE(db);
+       unlink(dbname);
+       return ret;
+}
index 28d7563695ef25c6904fc80d76c4c75416960ce4..636eef0f986771a7506ffa1ca8e056507740130b 100644 (file)
@@ -11660,6 +11660,7 @@ static struct {
        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
        { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
        { "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
+       { "LOCAL-DBWRAP-DO-LOCKED1", run_dbwrap_do_locked1, 0 },
        { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
        { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
        { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },
index 1c5e4c80c0fabaa835eb9664cc155652cfd1a509..7b3d383ab5d0c0c01b56b12fbe96212065817b57 100644 (file)
@@ -1195,6 +1195,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                         torture/test_notify.c
                         lib/tevent_barrier.c
                         torture/test_dbwrap_watch.c
+                        torture/test_dbwrap_do_locked.c
                         torture/test_idmap_tdb_common.c
                         torture/test_dbwrap_ctdb.c
                         torture/test_buffersize.c