]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
torture3: Test heuristic cleanup
authorVolker Lendecke <vl@samba.org>
Thu, 25 May 2017 08:48:15 +0000 (10:48 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 Jun 2017 11:19:15 +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 8a8a62d1fb60866bd4d990af38021282d6fc8d1d..965ad7eee3e9183838f66712a8e549bb7778dd30 100755 (executable)
@@ -152,6 +152,7 @@ local_tests = [
     "LOCAL-G-LOCK2",
     "LOCAL-G-LOCK3",
     "LOCAL-G-LOCK4",
+    "LOCAL-G-LOCK5",
     "LOCAL-hex_encode_buf",
     "LOCAL-remove_duplicate_addrs2"]
 
index c945d92038c9f0298ad71fc72cbe7ab471d92e1a..6d5ca7747e194ac51590370a193db91fa5ea19ce 100644 (file)
@@ -128,5 +128,6 @@ bool run_g_lock1(int dummy);
 bool run_g_lock2(int dummy);
 bool run_g_lock3(int dummy);
 bool run_g_lock4(int dummy);
+bool run_g_lock5(int dummy);
 
 #endif /* __TORTURE_H__ */
index 98fd01312f87f08f98aff57d0240c8035afae54e..ca373123e118518fb580919efe2b73d9d8527dfb 100644 (file)
@@ -500,3 +500,145 @@ fail:
        TALLOC_FREE(ev);
        return ret;
 }
+
+struct lock5_parser_state {
+       size_t num_locks;
+};
+
+static void lock5_parser(const struct g_lock_rec *locks,
+                        size_t num_locks,
+                        const uint8_t *data,
+                        size_t datalen,
+                        void *private_data)
+{
+       struct lock5_parser_state *state = private_data;
+       state->num_locks = num_locks;
+}
+
+/*
+ * Test heuristic cleanup
+ */
+
+bool run_g_lock5(int dummy)
+{
+       struct tevent_context *ev = NULL;
+       struct messaging_context *msg = NULL;
+       struct g_lock_ctx *ctx = NULL;
+       const char *lockname = "lock5";
+       pid_t child;
+       int exit_pipe[2], ready_pipe[2];
+       NTSTATUS status;
+       size_t i, nprocs;
+       int ret;
+       bool ok;
+       ssize_t nread;
+       char c;
+
+       nprocs = 5;
+
+       if ((pipe(exit_pipe) != 0) || (pipe(ready_pipe) != 0)) {
+               perror("pipe failed");
+               return false;
+       }
+
+       ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
+       if (!ok) {
+               fprintf(stderr, "get_g_lock_ctx failed");
+               return false;
+       }
+
+       for (i=0; i<nprocs; i++) {
+
+               child = fork();
+
+               if (child == -1) {
+                       perror("fork failed");
+                       return false;
+               }
+
+               if (child == 0) {
+                       TALLOC_FREE(ctx);
+                       TALLOC_FREE(msg);
+                       TALLOC_FREE(ev);
+
+                       close(ready_pipe[0]);
+                       close(exit_pipe[1]);
+
+                       ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
+                       if (!ok) {
+                               fprintf(stderr, "get_g_lock_ctx failed");
+                               exit(1);
+                       }
+                       status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+                                            (struct timeval) { .tv_sec = 1 });
+                       if (!NT_STATUS_IS_OK(status)) {
+                               fprintf(stderr,
+                                       "child g_lock_lock failed %s\n",
+                                       nt_errstr(status));
+                               exit(1);
+                       }
+                       close(ready_pipe[1]);
+                       nread = sys_read(exit_pipe[0], &c, sizeof(c));
+                       if (nread != 0) {
+                               fprintf(stderr, "sys_read returned %zu (%s)\n",
+                                       nread, strerror(errno));
+                               exit(1);
+                       }
+                       exit(0);
+               }
+       }
+
+       close(ready_pipe[1]);
+
+       nread = sys_read(ready_pipe[0], &c, sizeof(c));
+       if (nread != 0) {
+               fprintf(stderr, "sys_read returned %zu (%s)\n",
+                       nread, strerror(errno));
+               return false;
+       }
+
+       close(exit_pipe[1]);
+
+       for (i=0; i<nprocs; i++) {
+               int child_status;
+               ret = waitpid(-1, &child_status, 0);
+               if (ret == -1) {
+                       perror("waitpid failed");
+                       return false;
+               }
+       }
+
+       for (i=0; i<nprocs; i++) {
+               struct lock5_parser_state state;
+
+               status = g_lock_dump(ctx, lockname, lock5_parser, &state);
+               if (!NT_STATUS_IS_OK(status)) {
+                       fprintf(stderr, "g_lock_dump returned %s\n",
+                               nt_errstr(status));
+                       return false;
+               }
+
+               if (state.num_locks != (nprocs - i)) {
+                       fprintf(stderr, "nlocks=%zu, expected %zu\n",
+                               state.num_locks, (nprocs-i));
+                       return false;
+               }
+
+               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));
+                       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;
+               }
+       }
+
+
+       return true;
+}
index 81d180e5a367cc60d99bfab34e56eb585a9606fb..2d4b62de860fb609830dfa737421e84d6636b5cb 100644 (file)
@@ -11481,6 +11481,7 @@ static struct {
        { "LOCAL-G-LOCK2", run_g_lock2, 0 },
        { "LOCAL-G-LOCK3", run_g_lock3, 0 },
        { "LOCAL-G-LOCK4", run_g_lock4, 0 },
+       { "LOCAL-G-LOCK5", run_g_lock5, 0 },
        { "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
        {NULL, NULL, 0}};