]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Abort test if it seems that it would have run forever. This is just to prevent
authorYang Tse <yangsita@gmail.com>
Thu, 19 Oct 2006 17:29:25 +0000 (17:29 +0000)
committerYang Tse <yangsita@gmail.com>
Thu, 19 Oct 2006 17:29:25 +0000 (17:29 +0000)
test hanging and actually is an indication that there's a condition that is
not being properly handled at some point in the library.

Loop counter limits might need to be further increased on false positives.

tests/libtest/lib504.c
tests/libtest/lib507.c
tests/libtest/lib509.c
tests/libtest/lib525.c
tests/libtest/lib526.c
tests/libtest/lib530.c
tests/libtest/lib533.c
tests/libtest/lib536.c

index 843e9ebd0b667ce0d361b8b679f0e7106410f7f4..fed91232ce09786514690b1f46c4dadc416be3ca 100644 (file)
@@ -20,7 +20,8 @@ int test(char *URL)
   int running;
   int max_fd;
   int rc;
-  int loop=10;
+  int loop1 = 10;
+  int loop2 = 20;
 
   curl_global_init(CURL_GLOBAL_ALL);
   c = curl_easy_init();
@@ -42,12 +43,15 @@ int test(char *URL)
 
       interval.tv_sec = 1;
       interval.tv_usec = 0;
+      int loop2 = 20;
 
       fprintf(stderr, "curl_multi_perform()\n");
 
       do {
         res = curl_multi_perform(m, &running);
-      } while (res == CURLM_CALL_MULTI_PERFORM);
+      } while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM));
+      if (loop2 <= 0)
+        break;
       if(!running) {
         /* This is where this code is expected to reach */
         int numleft;
@@ -82,7 +86,12 @@ int test(char *URL)
 
       /* we only allow a certain number of loops to avoid hanging here
          forever */
-    } while(--loop>0);
+    } while(--loop1>0);
+    if ((loop1 <= 0) || (loop2 <= 0)) {
+      fprintf(stderr, "ABORTING TEST, since it seems "
+              "that it would have run forever.\n");
+      ret = 77;
+    }
   }
 
   curl_multi_remove_handle(m, c);
index 8fc4ca3ce260ce344a194437d7cc1ac15b0a4072..e4b1e35a84003947c50877bf96b68b22be4e0b91 100644 (file)
@@ -7,6 +7,8 @@ int test(char *URL)
   int still_running;
   int i = -1;
   CURLMsg *msg;
+  int loop1 = 20;
+  int loop2 = 40;
 
   multi = curl_multi_init();
 
@@ -14,8 +16,10 @@ int test(char *URL)
   curl_easy_setopt(curls, CURLOPT_URL, URL);
   curl_multi_add_handle(multi, curls);
 
-  while ( CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running) );
-  while(still_running) {
+  while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM == 
+         curl_multi_perform(multi, &still_running)));
+
+  while ((loop1>0) && (--loop2>0) && (still_running)) {
     struct timeval timeout;
     int rc;
     fd_set fdread;
@@ -34,15 +38,24 @@ int test(char *URL)
         break;
       case 0:
       default:
-        while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running));
+        loop1 = 20;
+        while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM == 
+               curl_multi_perform(multi, &still_running)));
         break;
     }
   }
-  msg = curl_multi_info_read(multi, &still_running);
-  if(msg)
-    /* this should now contain a result code from the easy handle,
-       get it */
-    i = msg->data.result;
+  if ((loop1 <= 0) || (loop2 <= 0)) {
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    i = 77;
+  }
+  else {
+    msg = curl_multi_info_read(multi, &still_running);
+    if(msg)
+      /* this should now contain a result code from the easy handle,
+         get it */
+      i = msg->data.result;
+  }
 
   curl_multi_cleanup(multi);
   curl_easy_cleanup(curls);
index 415208ac7d1fdc08e9070600f51358a04d88da4f..9327d728f333476799bf04e659866f53cd835fc2 100644 (file)
@@ -175,6 +175,9 @@ int test(char *URL)
   int i = 0;
   CURLMsg *msg;
 
+  int loop1 = 40;
+  int loop2 = 20;
+
   if(arg2) {
     portnum = atoi(arg2);
   }
@@ -205,15 +208,16 @@ int test(char *URL)
 
     res = curl_multi_add_handle(multi, p.curl);
 
-    while(!done) {
+    while ((--loop1>0) && (loop2>0) && (!done)) {
       fd_set rd, wr, exc;
       int max_fd;
       struct timeval interval;
 
       interval.tv_sec = 1;
       interval.tv_usec = 0;
+      loop2 = 20;
 
-      while (res == CURLM_CALL_MULTI_PERFORM) {
+      while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
         res = curl_multi_perform(multi, &running);
         fprintf(stderr, "running=%d res=%d\n",running,res);
         if (running <= 0) {
@@ -221,7 +225,7 @@ int test(char *URL)
           break;
         }
       }
-      if(done)
+      if ((loop2 <= 0) || (done))
         break;
 
       if (res != CURLM_OK) {
@@ -249,13 +253,23 @@ int test(char *URL)
 
       res = CURLM_CALL_MULTI_PERFORM;
     }
-    msg = curl_multi_info_read(multi, &running);
-    /* this should now contain a result code from the easy handle, get it */
-    if(msg)
-      i = msg->data.result;
+
+    if ((loop1 <= 0) || (loop2 <= 0)) {
+      fprintf(stderr, "ABORTING TEST, since it seems "
+              "that it would have run forever.\n");
+      i = 77;
+    }
+    else {
+      msg = curl_multi_info_read(multi, &running);
+      /* this should now contain a result code from the easy handle, get it */
+      if(msg)
+        i = msg->data.result;
+    }
   }
 
-  fprintf(stderr, "all done\n");
+  if ((loop1>0) && (loop2>0)) {
+    fprintf(stderr, "all done\n");
+  }
 
   curl_multi_remove_handle(multi, p.curl);
   curl_easy_cleanup(p.curl);
index 9dcddaecfafbd202f12ae1038f22d5a0c0f9a63d..b5b522de1b12180bd2317ee1d6e9a839d9a23a2c 100644 (file)
@@ -24,6 +24,8 @@ int test(char *URL)
   int running;
   char done=FALSE;
   CURLM *m;
+  int loop1 = 40;
+  int loop2 = 20;
 
   if (!arg2) {
     fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
@@ -82,22 +84,23 @@ int test(char *URL)
 
   res = (int)curl_multi_add_handle(m, curl);
 
-  while(!done) {
+  while ((--loop1>0) && (loop2>0) && (!done)) {
     fd_set rd, wr, exc;
     int max_fd;
     struct timeval interval;
 
     interval.tv_sec = 1;
     interval.tv_usec = 0;
+    loop2 = 20;
 
-    while (res == CURLM_CALL_MULTI_PERFORM) {
+    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
       res = (int)curl_multi_perform(m, &running);
       if (running <= 0) {
         done = TRUE;
         break;
       }
     }
-    if(done)
+    if ((loop2 <= 0) || (done))
       break;
 
     if (res != CURLM_OK) {
@@ -125,6 +128,12 @@ int test(char *URL)
     res = CURLM_CALL_MULTI_PERFORM;
   }
 
+  if ((loop1 <= 0) || (loop2 <= 0)) {
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    res = 77;
+  }
+
 #ifdef LIB529
   /* test 529 */
   curl_multi_remove_handle(m, curl);
index dce6a9f1beec57f136670d09ee8e2938807cd322..e521b60213ed8ad7a3668e6d7b62cad21a27dad0 100644 (file)
@@ -44,6 +44,8 @@ int test(char *URL)
   CURLM *m;
   int current=0;
   int i;
+  int loop1 = 40;
+  int loop2 = 20;
 
   /* In windows, this will init the winsock stuff */
   curl_global_init(CURL_GLOBAL_ALL);
@@ -67,15 +69,16 @@ int test(char *URL)
 
   fprintf(stderr, "Start at URL 0\n");
 
-  while(!done) {
+  while ((--loop1>0) && (loop2>0) && (!done)) {
     fd_set rd, wr, exc;
     int max_fd;
     struct timeval interval;
 
     interval.tv_sec = 1;
     interval.tv_usec = 0;
+    loop2 = 20;
 
-    while (res == CURLM_CALL_MULTI_PERFORM) {
+    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
       res = (int)curl_multi_perform(m, &running);
       if (running <= 0) {
 #ifdef LIB527
@@ -112,7 +115,7 @@ int test(char *URL)
         break;
       }
     }
-    if(done)
+    if ((loop2 <= 0) || (done))
       break;
 
     if (res != CURLM_OK) {
@@ -140,6 +143,12 @@ int test(char *URL)
     res = CURLM_CALL_MULTI_PERFORM;
   }
 
+  if ((loop1 <= 0) || (loop2 <= 0)) {
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    res = 77;
+  }
+
 #ifndef LIB527
   /* get NUM_HANDLES easy handles */
   for(i=0; i < NUM_HANDLES; i++) {
index d062886f462849f752ba8fbe10dc9e14569956bc..6ee346d940c3cf589c241157e034d456c356318d 100644 (file)
@@ -23,6 +23,8 @@ int test(char *URL)
   char done=FALSE;
   CURLM *m;
   int i;
+  int loop1 = 40;
+  int loop2 = 20;
 
   /* In windows, this will init the winsock stuff */
   curl_global_init(CURL_GLOBAL_ALL);
@@ -51,22 +53,23 @@ int test(char *URL)
 
   fprintf(stderr, "Start at URL 0\n");
 
-  while(!done) {
+  while ((--loop1>0) && (loop2>0) && (!done)) {
     fd_set rd, wr, exc;
     int max_fd;
     struct timeval interval;
 
     interval.tv_sec = 1;
     interval.tv_usec = 0;
+    loop2 = 20;
 
-    while (res == CURLM_CALL_MULTI_PERFORM) {
+    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
       res = (int)curl_multi_perform(m, &running);
       if (running <= 0) {
         done = TRUE; /* bail out */
         break;
       }
     }
-    if(done)
+    if ((loop2 <= 0) || (done))
       break;
 
     if (res != CURLM_OK) {
@@ -94,6 +97,12 @@ int test(char *URL)
     res = CURLM_CALL_MULTI_PERFORM;
   }
 
+  if ((loop1 <= 0) || (loop2 <= 0)) {
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    res = 77;
+  }
+
   /* get NUM_HANDLES easy handles */
   for(i=0; i < NUM_HANDLES; i++) {
     curl_multi_remove_handle(m, curl[i]);
index 74499c2325a212ca4fb05d434b5557a034f9d2a5..4403f75ff8c7198f227f57e37791d496d376467b 100644 (file)
@@ -24,6 +24,8 @@ int test(char *URL)
   char done=FALSE;
   CURLM *m;
   int current=0;
+  int loop1 = 40;
+  int loop2 = 20;
 
   /* In windows, this will init the winsock stuff */
   curl_global_init(CURL_GLOBAL_ALL);
@@ -44,15 +46,16 @@ int test(char *URL)
 
   fprintf(stderr, "Start at URL 0\n");
 
-  while(!done) {
+  while ((--loop1>0) && (loop2>0) && (!done)) {
     fd_set rd, wr, exc;
     int max_fd;
     struct timeval interval;
 
     interval.tv_sec = 1;
     interval.tv_usec = 0;
+    loop2 = 20;
 
-    while (res == CURLM_CALL_MULTI_PERFORM) {
+    while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
       res = (int)curl_multi_perform(m, &running);
       if (running <= 0) {
         if(!current++) {
@@ -80,7 +83,7 @@ int test(char *URL)
         break;
       }
     }
-    if(done)
+    if ((loop2 <= 0) || (done))
       break;
 
     if (res != CURLM_OK) {
@@ -108,6 +111,12 @@ int test(char *URL)
     res = CURLM_CALL_MULTI_PERFORM;
   }
 
+  if ((loop1 <= 0) || (loop2 <= 0)) {
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    res = 77;
+  }
+
   curl_easy_cleanup(curl);
   curl_multi_cleanup(m);
 
index 40b45e47d2b21031dc0f35fe4a3e7d5f829f353c..53439c797433b7c85e854c010e473c8964d76b09 100644 (file)
@@ -21,8 +21,9 @@ static CURLMcode perform(CURLM * multi)
        int handles, maxfd;
        CURLMcode code;
        fd_set fdread, fdwrite, fdexcep;
+       int loop;
 
-       for (;;) {
+       for (loop=40;loop>0;loop--) {
                code = curl_multi_perform(multi, &handles);
                if (handles <= 0)
                        return CURLM_OK;
@@ -45,6 +46,11 @@ static CURLMcode perform(CURLM * multi)
                if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, 0) == -1)
                        return (CURLMcode) ~CURLM_OK;
        }
+       if (loop <= 0) {
+               fprintf(stderr, "ABORTING TEST, since it seems "
+                       "that it would have run forever.\n");
+               return (CURLMcode) ~CURLM_OK;
+       }
 }
 
 int test(char *URL)