From 90dcfa4e59276467b89d07c1fc6fc14ed4c225ff Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 31 Oct 2019 11:45:36 +0100 Subject: [PATCH] torture: Test g_lock_watch_data_send()/recv() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/selftest/tests.py | 1 + source3/torture/proto.h | 1 + source3/torture/test_g_lock.c | 76 +++++++++++++++++++++++++++++++++++ source3/torture/torture.c | 4 ++ 4 files changed, 82 insertions(+) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 38ed8c771c2..0526035c2f2 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -233,6 +233,7 @@ local_tests = [ "LOCAL-G-LOCK5", "LOCAL-G-LOCK6", "LOCAL-G-LOCK7", + "LOCAL-G-LOCK8", "LOCAL-NAMEMAP-CACHE1", "LOCAL-IDMAP-CACHE1", "LOCAL-hex_encode_buf", diff --git a/source3/torture/proto.h b/source3/torture/proto.h index 21966356ff9..f9c79fd7906 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -140,6 +140,7 @@ bool run_g_lock4a(int dummy); bool run_g_lock5(int dummy); bool run_g_lock6(int dummy); bool run_g_lock7(int dummy); +bool run_g_lock8(int dummy); bool run_g_lock_ping_pong(int dummy); bool run_local_namemap_cache1(int dummy); bool run_local_idmap_cache1(int dummy); diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c index 05b6cecfc41..2f98a1a2275 100644 --- a/source3/torture/test_g_lock.c +++ b/source3/torture/test_g_lock.c @@ -25,6 +25,7 @@ #include "lib/util/server_id.h" #include "lib/util/sys_rw.h" #include "lib/util/util_tdb.h" +#include "lib/util/tevent_ntstatus.h" static bool get_g_lock_ctx(TALLOC_CTX *mem_ctx, struct tevent_context **ev, @@ -1207,6 +1208,81 @@ fail: return ret; } +bool run_g_lock8(int dummy) +{ + struct tevent_context *ev = NULL; + struct messaging_context *msg = NULL; + struct g_lock_ctx *ctx = NULL; + struct tevent_req *req = NULL; + TDB_DATA lockname = string_term_tdb_data("lock8"); + NTSTATUS status; + bool ok; + + ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx); + if (!ok) { + fprintf(stderr, "get_g_lock_ctx failed"); + return false; + } + + req = g_lock_watch_data_send( + ev, ev, ctx, lockname, (struct server_id) { .pid = 0 }); + if (req == NULL) { + fprintf(stderr, "get_g_lock_ctx failed"); + return false; + } + + status = g_lock_lock( + ctx, + lockname, + G_LOCK_WRITE, + (struct timeval) { .tv_sec = 999 }); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, + "g_lock_lock failed: %s\n", + nt_errstr(status)); + return false; + } + + status = g_lock_write_data( + ctx, lockname, lockname.dptr, lockname.dsize); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, + "g_lock_write_data failed: %s\n", + nt_errstr(status)); + return false; + } + + status = g_lock_write_data(ctx, lockname, NULL, 0); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, + "g_lock_write_data failed: %s\n", + nt_errstr(status)); + return false; + } + + status = g_lock_unlock(ctx, lockname); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, + "g_lock_unlock failed: %s\n", + nt_errstr(status)); + return false; + } + + ok = tevent_req_poll_ntstatus(req, ev, &status); + if (!ok) { + fprintf(stderr, "tevent_req_poll_ntstatus failed\n"); + return false; + } + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, + "tevent_req_poll_ntstatus failed: %s\n", + nt_errstr(status)); + return false; + } + + return true; +} + extern int torture_numops; extern int torture_nprocs; diff --git a/source3/torture/torture.c b/source3/torture/torture.c index c3d8fb4e30c..ab8e1937b03 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -14971,6 +14971,10 @@ static struct { .name = "LOCAL-G-LOCK7", .fn = run_g_lock7, }, + { + .name = "LOCAL-G-LOCK8", + .fn = run_g_lock8, + }, { .name = "LOCAL-G-LOCK-PING-PONG", .fn = run_g_lock_ping_pong,