summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2017-05-16 15:05:49 +0200
committerVolker Lendecke <vl@samba.org>2017-06-15 13:19:13 +0200
commitc2cdf579fc0ee98c3414d1a5920b7c72017f6deb (patch)
tree37146a6937eb815cbbbad4ee04c1822c6141810a /source3
parent90e2bf50c7eea7f6df52646f613197d397c9bc01 (diff)
downloadsamba-c2cdf579fc0ee98c3414d1a5920b7c72017f6deb.tar.gz
torture3: Initial test g_lock
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rwxr-xr-xsource3/selftest/tests.py1
-rw-r--r--source3/torture/proto.h1
-rw-r--r--source3/torture/test_g_lock.c104
-rw-r--r--source3/torture/torture.c1
-rw-r--r--source3/wscript_build1
5 files changed, 108 insertions, 0 deletions
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 5f707c02a35..768aeb105bb 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -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"]
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index 129c05d7e7a..f93100a20b3 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -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
index 00000000000..222a2984590
--- /dev/null
+++ b/source3/torture/test_g_lock.c
@@ -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;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index bdcf1e13f17..5ef4d4e16c7 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -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}};
diff --git a/source3/wscript_build b/source3/wscript_build
index d5bb62a70eb..2cc74e0f4ec 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -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