torture3: Add verification for g_lock_retry
authorVolker Lendecke <vl@samba.org>
Mon, 3 Jul 2017 06:09:18 +0000 (08:09 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 25 Jul 2017 15:43:17 +0000 (17:43 +0200)
During development I had a bug that would have been found early
by this

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/torture/test_g_lock.c

index 61ec69d71ca4e19e4117611bc9687898b609d5bb..253d20ca944e0afa44c19754dd9efb293aa10918 100644 (file)
@@ -397,6 +397,41 @@ static void lock4_waited(struct tevent_req *subreq)
        printf("child %d exited with %d\n", (int)child, status);
 }
 
+struct lock4_check_state {
+       struct server_id me;
+       bool ok;
+};
+
+static void lock4_check(const struct g_lock_rec *locks,
+                       size_t num_locks,
+                       const uint8_t *data,
+                       size_t datalen,
+                       void *private_data)
+{
+       struct lock4_check_state *state = private_data;
+
+       if (num_locks != 1) {
+               fprintf(stderr, "num_locks=%zu\n", num_locks);
+               return;
+       }
+
+       if (!serverid_equal(&state->me, &locks[0].pid)) {
+               struct server_id_buf buf1, buf2;
+               fprintf(stderr, "me=%s, locker=%s\n",
+                       server_id_str_buf(state->me, &buf1),
+                       server_id_str_buf(locks[0].pid, &buf2));
+               return;
+       }
+
+       if (locks[0].lock_type != G_LOCK_WRITE) {
+               fprintf(stderr, "wrong lock type: %d\n",
+                       (int)locks[0].lock_type);
+               return;
+       }
+
+       state->ok = true;
+}
+
 /*
  * Test a lock conflict
  */
@@ -493,6 +528,23 @@ bool run_g_lock4(int dummy)
                }
        }
 
+       {
+               struct lock4_check_state state = {
+                       .me = messaging_server_id(msg)
+               };
+
+               status = g_lock_dump(ctx, lockname, lock4_check, &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, "lock4_check failed\n");
+                       goto fail;
+               }
+       }
+
        ret = true;
 fail:
        TALLOC_FREE(ctx);