Over the last few weeks, I've been hammering my poor head against an
obscure bug in "ipcsocket.c".  (Details of that to follow next week.)
As part of this I found myself tinkering with its tester program,
"ipctest".

I propose the attached patch, which simply assists in such debugging,
which I propose applying early next week, if there are no objections.
It adds two flags:
 1. "-v" (verbose): print some diagnostic information (and which has the
    future potential to increment to increasing values);
 2. "-i <n>": adjust the number of "iterations" from the default 10,000
    (in my debugging "3" was very useful, and the remaining 9,997
    were massively clogging up the output!).

Any objections?

-- 

:  David Lee                                I.T. Service          :
:  Senior Systems Programmer                Computer Centre       :
:                                           Durham University     :
:  http://www.dur.ac.uk/t.d.lee/            South Road            :
:                                           Durham DH1 3LE        :
:  Phone: +44 191 334 2752                  U.K.                  :
--- lib/clplumbing/ipctest.c.orig       Mon Dec 19 19:05:33 2005
+++ lib/clplumbing/ipctest.c    Fri Jan  6 17:49:15 2006
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <libgen.h>
 #include <glib.h>
 #include <clplumbing/cl_log.h>
 #include <clplumbing/cl_poll.h>
@@ -55,6 +56,11 @@
 static int (*PollFunc)(struct pollfd * fds, unsigned int, int)
 =      (int (*)(struct pollfd * fds, unsigned int, int))  poll;
 static gboolean checkmsg(IPC_Message* rmsg, const char * who, int rcount);
+
+int iter_def = 10000;  /* number of iterations */
+int verbosity = 0;     /* verbosity level */
+const char *procname;
+
 static int
 channelpair(TestFunc_t clientfunc, TestFunc_t serverfunc, int count)
 {
@@ -62,12 +68,20 @@
        int             rc  = 0;
        int             waitstat = 0;
 
+       if (verbosity >= 1) {
+               cl_log(LOG_DEBUG, "%s[%d]%d: main process",
+                 procname, (int)getpid(), __LINE__);
+       }
        switch (fork()) {
                case -1:
                        cl_perror("can't fork");
                        exit(1);
                        break;
                default: /* Parent */
+                       if (verbosity >= 1) {
+                               cl_log(LOG_DEBUG, "%s[%d]%d: main waiting...",
+                                 procname, (int)getpid(), __LINE__);
+                       }
                        while (wait(&waitstat) > 0) {
                                if (WIFEXITED(waitstat)) {
                                        rc += WEXITSTATUS(waitstat);
@@ -75,6 +89,10 @@
                                        rc += 1;
                                }
                        }
+                       if (verbosity >= 1) {
+                               cl_log(LOG_DEBUG, "%s[%d]%d: main ended rc: %d",
+                                 procname, (int)getpid(), __LINE__, rc);
+                       }
                        if (rc > 127) {
                                rc = 127;
                        }
@@ -99,7 +117,15 @@
                case 0:         /* echo "client" Child */
                        channels[1]->ops->destroy(channels[1]);
                        channels[1] = NULL;
+                       if (verbosity >= 1) {
+                               cl_log(LOG_DEBUG, "%s[%d]%d: client 
starting...",
+                                 procname, (int)getpid(), __LINE__);
+                       }
                        rc = clientfunc(channels[0], count);
+                       if (verbosity >= 1) {
+                               cl_log(LOG_DEBUG, "%s[%d]%d: client ended 
rc:%d",
+                                 procname, (int)getpid(), __LINE__, rc);
+                       }
                        exit (rc > 127 ? 127 : rc);
                        break;
 
@@ -108,6 +134,10 @@
        }
        channels[0]->ops->destroy(channels[0]);
        channels[0] = NULL;
+       if (verbosity >= 1) {
+               cl_log(LOG_DEBUG, "%s[%d]%d: server starting...",
+                 procname, (int)getpid(), __LINE__);
+       }
        rc = serverfunc(channels[1], count);
        wait(&waitstat);
        if (WIFEXITED(waitstat)) {
@@ -115,6 +145,10 @@
        }else{
                rc += 1;
        }
+       if (verbosity >= 1) {
+               cl_log(LOG_DEBUG, "%s[%d]%d: server ended rc:%d",
+                 procname, (int)getpid(), __LINE__, rc);
+       }
        return(rc);
 }
 
@@ -183,16 +217,48 @@
 int
 main(int argc, char ** argv)
 {
+       int argflag, argerrs;
+       int iterations;
        int     rc = 0;
 
+       /*
+        * Check and process arguments.
+        *      -v: verbose
+        *      -i: number of iterations
+        */
+       procname = basename(argv[0]);
+
+       argerrs = 0;
+       iterations = iter_def;
+       while ((argflag = getopt(argc, argv, "i:v")) != EOF) {
+               switch (argflag) {
+               case 'i':       /* iterations */
+                       iterations = atoi(optarg);
+                       break;
+               case 'v':       /* verbosity */
+                       verbosity++;
+                       break;
+               default:
+                       argerrs++;
+                       break;
+               }
+       }
+       if (argerrs) {
+               fprintf(stderr, "Usage: %s [-v] [-i iterations]\n"
+                       "\t-v : verbose\n"
+                       "\t-i : iterations (default %d)\n",
+                 procname, iter_def);
+               exit(1);
+       }
+
        cl_malloc_forced_for_glib();
 
-       cl_log_set_entity("ipctest");
+       cl_log_set_entity(procname);
        cl_log_enable_stderr(TRUE);
 
 
 
-       rc += transport_tests(10000);
+       rc += transport_tests(iterations);
 
 #if 0
        /* Broken for the moment - need to fix it long term */
@@ -201,7 +267,7 @@
        g_main_set_poll_func(cl_glibpoll);
        ipc_set_pollfunc(cl_poll);
 
-       rc += transport_tests(50000);
+       rc += transport_tests(5 * iterations);
 #endif
        
        cl_log(LOG_INFO, "TOTAL errors: %d", rc);
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to