torture: Test g_lock_watch_data_send()/recv()
authorVolker Lendecke <vl@samba.org>
Thu, 31 Oct 2019 10:45:36 +0000 (11:45 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 15 May 2020 00:48:32 +0000 (00:48 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_g_lock.c
source3/torture/torture.c

index 38ed8c771c257eb3d1b68f3d4d842b569b769540..0526035c2f21c9d079ae070ef34f9994215019ef 100755 (executable)
@@ -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",
index 21966356ff902e9a2dd6f8ee46b500d737e0baa2..f9c79fd790685b7ef31b833df74f5d2387c6b4ab 100644 (file)
@@ -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);
index 05b6cecfc41e5f466a4e749a4ea375f0a852dc4c..2f98a1a227521f4729e9d2f8093db4e0b4ad5ce3 100644 (file)
@@ -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;
 
index c3d8fb4e30ca09b9b043d86eb02c2d725aec42bb..ab8e1937b0315edb8f661bd7021c434a501daf63 100644 (file)
@@ -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,