From: Viktor Szakats Date: Sun, 22 Jun 2025 09:17:07 +0000 (+0200) Subject: tests/libtest: drop `TEST_HANG_TIMEOUT` redefinition hack X-Git-Tag: curl-8_15_0~190 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=855ae7651360d5fbe490634edb86da9f05d1d559;p=thirdparty%2Fcurl.git tests/libtest: drop `TEST_HANG_TIMEOUT` redefinition hack 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 --- diff --git a/tests/libtest/lib1501.c b/tests/libtest/lib1501.c index 89e35c5128..78d4ad1c8b 100644 --- a/tests/libtest/lib1501.c +++ b/tests/libtest/lib1501.c @@ -28,11 +28,9 @@ #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); diff --git a/tests/libtest/test.h b/tests/libtest/test.h index 92aebff82a..fc536e5662 100644 --- a/tests/libtest/test.h +++ b/tests/libtest/test.h @@ -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