torture3: Test g_lock_write_data
authorVolker Lendecke <vl@samba.org>
Fri, 19 May 2017 14:59:06 +0000 (16:59 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 Jun 2017 11:19:14 +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
source3/torture/torture.c

index 768aeb105bb6577c19cafcf66a4a91d23bb33f41..7ad75b717b90ae9f171bf3aff474c2111f7d9365 100755 (executable)
@@ -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"]
 
index f93100a20b31c22f91c825becaef273664877147..df2a241665e05fc3ea8af9fd8077f4b9401c2acd 100644 (file)
@@ -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__ */
index 222a2984590d0ca725836a102a9f3212e95ed661..5a1ee605ead656d0739799817b63b3c4ec810706 100644 (file)
@@ -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;
+}
index 5ef4d4e16c77babf29f00572a1ac4ede4de0ecde..2bdb079f83ae907a3cd501d855736f22d8a9a90e 100644 (file)
@@ -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}};