Incorporated the recent problems in Comon into the QA test for vsys.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 2 Jul 2008 18:19:25 +0000 (18:19 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 2 Jul 2008 18:19:25 +0000 (18:19 +0000)
qaapi/qa/tests/node/support/vsys_conctest.c

index c155f80..d4750c4 100644 (file)
@@ -4,7 +4,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 
 int main()
 {
@@ -15,89 +17,115 @@ int main()
   char buf[4096];
   int fd_in = -1, fd_out;
   int res;
-  int flag;
+  int flag,flag2;
   int count = 1;
   struct timeval tv={.tv_sec=5,.tv_usec=0};
 
-  while (count < 100) {
+  while (count < 200000) {
     fd_set readSet;
     int res;
     int nlines=0;
 
-    printf("(.)", count);
-
+    
+    printf("(%d)", count);fflush(stdout);
     if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) {
       fprintf(stderr, "error executing top\n");
       exit(-1);
     }
-    if ((fd_in = open(top_in_file, O_WRONLY)) < 0) {
-      fprintf(stderr, "error opening %s\n", top_in_file);
-      exit(-1);
+
+    
+    while ((fd_in = open(top_in_file, O_WRONLY| O_NONBLOCK)) < 0) {
+      fprintf(stderr, "Waiting for %s (%s)\n", top_in_file,strerror(errno));
+       usleep (50); 
     }
 
+    
     if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
       printf("fcntl get failed\n");
       exit(-1);
     }
+    
 
-    FD_ZERO(&readSet);
-    FD_SET(fd_out, &readSet);
-
-    res = select(fd_out + 1, &readSet, NULL, NULL, &tv);
-    if (res < 1) {
-      printf("select failed\n");
+    
+       if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) {
+      printf("fcntl get failed\n");
       exit(-1);
     }
+    
+
+
+    while (1) {
+           FD_ZERO(&readSet);
+           FD_SET(fd_out, &readSet);
+
+    
+           res = select(fd_out + 1, &readSet, NULL, NULL, NULL);
+    
+           if (res < 0) {
+                   if (errno == EINTR || errno == EAGAIN) {
+                           printf(".");
+                           continue;
+                   }
+                   fprintf(stderr,"select failed errno=%d errstr=%s\n", errno, strerror(errno));
+                   exit(-1);
+           }
+           break; /* we're done */
+    }
 
+    
     if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) {
       printf("fcntl set failed\n");
       exit(-1);
     }
+    
 
+    
     if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
       printf("fcntl get failed\n");
       exit(-1);
     }
+    
 
-    if (flag & O_NONBLOCK == 0) {
-      printf("fd_out still nonblocking\n");
+
+    
+    if (fcntl(fd_in, F_SETFL, flag2 & ~O_NONBLOCK) == -1) {
+      printf("fcntl set failed\n");
       exit(-1);
     }
 
-    if ((fp = fdopen(fd_out, "r")) == NULL) {
-      printf("fdopen failed\n");
+    
+    if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) {
+      printf("fcntl get failed\n");
       exit(-1);
     }
+    
 
-    if ((out_fp = fopen("/tmp/vsys_passwd_test", "w")) == NULL) {
-           printf("could not create tmp file for test\n");
-            exit(-1);
+    if (flag & O_NONBLOCK == 0) {
+      printf("fd_out still nonblocking\n");
+      exit(-1);
     }
 
-    while (fgets(buf, sizeof(buf), fp) != NULL) {
-       fprintf(out_fp, "%s",buf);
+    if (flag & O_NONBLOCK == 0) {
+      printf("fd_in still nonblocking\n");
+      exit(-1);
     }
-
-    fflush(out_fp);
-    fclose(out_fp);
-
-    if ((diff_fp = popen("/usr/bin/diff -u /tmp/vsys_passwd_test /etc/passwd","r")) == NULL) {
-           printf("Could not diff results\n");
-           exit(-1);
+    if ((fp = fdopen(fd_out, "r")) == NULL) {
+      printf("fdopen failed\n");
+      exit(-1);
     }
 
-    while (fgets(buf, sizeof(buf), diff_fp) != NULL) {
+    while (fgets(buf, sizeof(buf), fp) != NULL) {
            nlines++;
     }
 
-    if (nlines) {
+    if (nlines<5) {
            printf("Test returned different results - run again to verify\n");
            exit(-1);
     }
 
-    pclose (diff_fp);
     fclose(fp);
     close(fd_in);
+    close(fd_out);
     count++;
   }
   printf("test successful.\n");