diff options
author | Volker Lendecke <vl@samba.org> | 2017-06-27 08:25:36 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2017-07-25 17:43:16 +0200 |
commit | 86dbad3d68c74c0b84644b100252c6c4fb1c8c83 (patch) | |
tree | 308dd8857a9a8e819e2f59a2800f97ee2159d963 /source3/torture | |
parent | cb2a28eb9a16a3bfe8d0373692acc4199f04baee (diff) | |
download | samba-86dbad3d68c74c0b84644b100252c6c4fb1c8c83.tar.gz |
torture3: Test dbwrap_do_locked
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'source3/torture')
-rw-r--r-- | source3/torture/proto.h | 1 | ||||
-rw-r--r-- | source3/torture/test_dbwrap_do_locked.c | 132 | ||||
-rw-r--r-- | source3/torture/torture.c | 1 |
3 files changed, 134 insertions, 0 deletions
diff --git a/source3/torture/proto.h b/source3/torture/proto.h index fc468984090..8a032da892d 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -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 index 00000000000..92dec38ef64 --- /dev/null +++ b/source3/torture/test_dbwrap_do_locked.c @@ -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; +} diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 28d7563695e..636eef0f986 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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 }, |