summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2017-05-19 16:59:06 +0200
committerVolker Lendecke <vl@samba.org>2017-06-15 13:19:14 +0200
commit8f1cf7b4309cddc55feaceaff76db15305265567 (patch)
tree754473b28d129b14c52400eaa3e76299f5f6210d
parent90d7784d45d2a43f5e8a68596c793e7ba8a5b350 (diff)
downloadsamba-8f1cf7b4309cddc55feaceaff76db15305265567.tar.gz
torture3: Test g_lock_write_data
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rwxr-xr-xsource3/selftest/tests.py1
-rw-r--r--source3/torture/proto.h1
-rw-r--r--source3/torture/test_g_lock.c96
-rw-r--r--source3/torture/torture.c1
4 files changed, 99 insertions, 0 deletions
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 768aeb105bb..7ad75b717b9 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -149,6 +149,7 @@ local_tests = [
"LOCAL-DBWRAP-WATCH1",
"LOCAL-DBWRAP-WATCH2",
"LOCAL-G-LOCK1",
+ "LOCAL-G-LOCK2",
"LOCAL-hex_encode_buf",
"LOCAL-remove_duplicate_addrs2"]
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index f93100a20b3..df2a241665e 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -125,5 +125,6 @@ bool run_messaging_fdpass2b(int dummy);
bool run_oplock_cancel(int dummy);
bool run_pthreadpool_tevent(int dummy);
bool run_g_lock1(int dummy);
+bool run_g_lock2(int dummy);
#endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 222a2984590..5a1ee605ead 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -102,3 +102,99 @@ fail:
TALLOC_FREE(ev);
return ret;
}
+
+struct lock2_parser_state {
+ uint8_t *rdata;
+ bool ok;
+};
+
+static void lock2_parser(const struct g_lock_rec *locks,
+ size_t num_locks,
+ const uint8_t *data,
+ size_t datalen,
+ void *private_data)
+{
+ struct lock2_parser_state *state = private_data;
+
+ if (datalen != sizeof(uint8_t)) {
+ return;
+ }
+ *state->rdata = *data;
+ state->ok = true;
+}
+
+/*
+ * Test g_lock_write_data
+ */
+
+bool run_g_lock2(int dummy)
+{
+ struct tevent_context *ev = NULL;
+ struct messaging_context *msg = NULL;
+ struct g_lock_ctx *ctx = NULL;
+ const char *lockname = "lock2";
+ uint8_t data = 42;
+ uint8_t rdata;
+ struct lock2_parser_state state = { .rdata = &rdata };
+ NTSTATUS status;
+ bool ret = false;
+ bool ok;
+
+ ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
+ if (!ok) {
+ goto fail;
+ }
+
+ status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_LOCKED)) {
+ fprintf(stderr, "unlocked g_lock_write_data returned %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+ (struct timeval) { .tv_sec = 1 });
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_lock returned %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_write_data failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_unlock(ctx, lockname);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_unlock failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_dump(ctx, lockname, lock2_parser, &state);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_dump failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ if (!state.ok) {
+ fprintf(stderr, "Could not parse data\n");
+ goto fail;
+ }
+ if (rdata != data) {
+ fprintf(stderr, "Returned %"PRIu8", expected %"PRIu8"\n",
+ rdata, data);
+ goto fail;
+ }
+
+ ret = true;
+fail:
+ TALLOC_FREE(ctx);
+ TALLOC_FREE(msg);
+ TALLOC_FREE(ev);
+ return ret;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 5ef4d4e16c7..2bdb079f83a 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -11478,6 +11478,7 @@ static struct {
{ "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
{ "LOCAL-PTHREADPOOL-TEVENT", run_pthreadpool_tevent, 0 },
{ "LOCAL-G-LOCK1", run_g_lock1, 0 },
+ { "LOCAL-G-LOCK2", run_g_lock2, 0 },
{ "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
{ "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
{NULL, NULL, 0}};