torture3: Initial test g_lock
authorVolker Lendecke <vl@samba.org>
Tue, 16 May 2017 13:05:49 +0000 (15:05 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 Jun 2017 11:19:13 +0000 (13:19 +0200)
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 [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 5f707c02a35433ee7f02c07d45f1f5b979402724..768aeb105bb6577c19cafcf66a4a91d23bb33f41 100755 (executable)
@@ -148,6 +148,7 @@ local_tests = [
     "LOCAL-CANONICALIZE-PATH",
     "LOCAL-DBWRAP-WATCH1",
     "LOCAL-DBWRAP-WATCH2",
+    "LOCAL-G-LOCK1",
     "LOCAL-hex_encode_buf",
     "LOCAL-remove_duplicate_addrs2"]
 
index 129c05d7e7ae6c8400fe40cc9c393a2d92150a85..f93100a20b31c22f91c825becaef273664877147 100644 (file)
@@ -124,5 +124,6 @@ bool run_messaging_fdpass2a(int dummy);
 bool run_messaging_fdpass2b(int dummy);
 bool run_oplock_cancel(int dummy);
 bool run_pthreadpool_tevent(int dummy);
+bool run_g_lock1(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
new file mode 100644 (file)
index 0000000..222a298
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Test g_lock 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 "g_lock.h"
+#include "messages.h"
+
+static bool get_g_lock_ctx(TALLOC_CTX *mem_ctx,
+                          struct tevent_context **ev,
+                          struct messaging_context **msg,
+                          struct g_lock_ctx **ctx)
+{
+       *ev = samba_tevent_context_init(mem_ctx);
+       if (*ev == NULL) {
+               fprintf(stderr, "tevent_context_init failed\n");
+               return false;
+       }
+       *msg = messaging_init(*ev, *ev);
+       if (*msg == NULL) {
+               fprintf(stderr, "messaging_init failed\n");
+               TALLOC_FREE(*ev);
+               return false;
+       }
+       *ctx = g_lock_ctx_init(*ev, *msg);
+       if (*ctx == NULL) {
+               fprintf(stderr, "g_lock_ctx_init failed\n");
+               TALLOC_FREE(*msg);
+               TALLOC_FREE(*ev);
+               return false;
+       }
+
+       return true;
+}
+
+bool run_g_lock1(int dummy)
+{
+       struct tevent_context *ev = NULL;
+       struct messaging_context *msg = NULL;
+       struct g_lock_ctx *ctx = NULL;
+       const char *lockname = "lock1";
+       NTSTATUS status;
+       bool ret = false;
+       bool ok;
+
+       ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
+       if (!ok) {
+               goto fail;
+       }
+
+       status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+                            (struct timeval) { .tv_sec = 1 });
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "g_lock_lock failed: %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+                            (struct timeval) { .tv_sec = 1 });
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) {
+               fprintf(stderr, "Double lock got %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_unlock(ctx, lockname);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               fprintf(stderr, "g_lock_unlock returned: %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       ret = true;
+fail:
+       TALLOC_FREE(ctx);
+       TALLOC_FREE(msg);
+       TALLOC_FREE(ev);
+       return ret;
+}
index bdcf1e13f17c879c9b663a8904c2fb88ba10be79..5ef4d4e16c77babf29f00572a1ac4ede4de0ecde 100644 (file)
@@ -11477,6 +11477,7 @@ static struct {
        { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 0 },
        { "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
        { "LOCAL-PTHREADPOOL-TEVENT", run_pthreadpool_tevent, 0 },
+       { "LOCAL-G-LOCK1", run_g_lock1, 0 },
        { "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
        {NULL, NULL, 0}};
index d5bb62a70ebf8ad1b4d84729d3c4d09c3f766450..2cc74e0f4ec3f497aaed94ae3c89cd772bd164f0 100644 (file)
@@ -1212,6 +1212,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                         torture/test_pthreadpool_tevent.c
                         torture/bench_pthreadpool.c
                         torture/wbc_async.c
+                        torture/test_g_lock.c
                         ''',
                  deps='''
                       talloc