]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/libtest: drop `TEST_HANG_TIMEOUT` redefinition hack
authorViktor Szakats <commit@vsz.me>
Sun, 22 Jun 2025 09:17:07 +0000 (11:17 +0200)
committerViktor Szakats <commit@vsz.me>
Sun, 22 Jun 2025 11:15:13 +0000 (13:15 +0200)
Before this patch the code relied on re-initializing `TEST_HANG_TIMEOUT`
macro before compiling each test, to allow them each to override it to
a custom value for single tests. Thie required re-including `test.h`
into each test.

After this patch this macro becomes a global, immutable, default. Tests
which want to override it can now use alternate macros that do accept
a custom timeout. The only test currently affected is lib1501.

Follow-up to 2c27a67daa1b76859c18d63e4e1f528db05b5e13 #17590

Closes #17702

tests/libtest/lib1501.c
tests/libtest/test.h

index 89e35c51283e0c22f6cb7e961498a862b82e963f..78d4ad1c8b855b2f309f657df7efdeb5f628ffdf 100644 (file)
 #include "testutil.h"
 #include "memdebug.h"
 
-#undef TEST_HANG_TIMEOUT
-#define TEST_HANG_TIMEOUT 30 * 1000
-
 static CURLcode test_lib1501(char *URL)
 {
+  static const long HANG_TIMEOUT = 30 * 1000;
   /* 500 milliseconds allowed. An extreme number but lets be really
      conservative to allow old and slow machines to run this test too */
   static const int MAX_BLOCKED_TIME_MS = 500;
@@ -57,7 +55,7 @@ static CURLcode test_lib1501(char *URL)
 
   multi_perform(mhandle, &still_running);
 
-  abort_on_test_timeout();
+  abort_on_test_timeout_custom(HANG_TIMEOUT);
 
   while(still_running) {
     struct timeval timeout;
@@ -82,14 +80,14 @@ static CURLcode test_lib1501(char *URL)
 
     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
 
-    abort_on_test_timeout();
+    abort_on_test_timeout_custom(HANG_TIMEOUT);
 
     curl_mfprintf(stderr, "ping\n");
     before = tutil_tvnow();
 
     multi_perform(mhandle, &still_running);
 
-    abort_on_test_timeout();
+    abort_on_test_timeout_custom(HANG_TIMEOUT);
 
     after = tutil_tvnow();
     e = tutil_tvdiff(after, before);
index 92aebff82adc55aadaca9b756d2399acfb3ca127..fc536e56628d070b5da95d572e47d9a3dea24359 100644 (file)
@@ -437,9 +437,11 @@ extern int unitfail;
   tv_test_start = tutil_tvnow(); \
 } while(0)
 
-#define exe_test_timedout(Y,Z) do {                                     \
+#define TEST_HANG_TIMEOUT 60 * 1000  /* global default */
+
+#define exe_test_timedout(T,Y,Z) do {                                   \
   long timediff = tutil_tvdiff(tutil_tvnow(), tv_test_start);           \
-  if(timediff > (TEST_HANG_TIMEOUT)) {                                  \
+  if(timediff > (T)) {                                                  \
     curl_mfprintf(stderr, "%s:%d ABORTING TEST, since it seems "        \
                   "that it would have run forever (%ld ms > %ld ms)\n", \
                   (Y), (Z), timediff, (long) (TEST_HANG_TIMEOUT));      \
@@ -448,16 +450,22 @@ extern int unitfail;
 } while(0)
 
 #define res_test_timedout() \
-  exe_test_timedout((__FILE__), (__LINE__))
+  exe_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
+
+#define res_test_timedout_custom(T) \
+  exe_test_timedout((T), (__FILE__), (__LINE__))
 
-#define chk_test_timedout(Y, Z) do { \
-    exe_test_timedout(Y, Z);         \
-    if(res)                          \
-      goto test_cleanup;             \
+#define chk_test_timedout(T, Y, Z) do { \
+    exe_test_timedout(T, Y, Z);         \
+    if(res)                             \
+      goto test_cleanup;                \
   } while(0)
 
 #define abort_on_test_timeout() \
-  chk_test_timedout((__FILE__), (__LINE__))
+  chk_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
+
+#define abort_on_test_timeout_custom(T) \
+  chk_test_timedout((T), (__FILE__), (__LINE__))
 
 /* ---------------------------------------------------------------- */
 
@@ -493,13 +501,8 @@ extern int unitfail;
     return CURLE_UNSUPPORTED_PROTOCOL;          \
   }
 
-/* global default */
-#define NUM_HANDLES 4
+#define NUM_HANDLES 4  /* global default */
 
 /* ---------------------------------------------------------------- */
 
 #endif /* HEADER_CURL_TEST_H */
-
-/* Set default that each test may override */
-#undef TEST_HANG_TIMEOUT
-#define TEST_HANG_TIMEOUT 60 * 1000