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 2c27a67daa #17590

Closes #17702
This commit is contained in:
Viktor Szakats 2025-06-22 11:17:07 +02:00
parent 855acb3bb0
commit 855ae76513
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
2 changed files with 21 additions and 20 deletions

View file

@ -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);

View 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 chk_test_timedout(Y, Z) do { \
exe_test_timedout(Y, Z); \
if(res) \
goto test_cleanup; \
#define res_test_timedout_custom(T) \
exe_test_timedout((T), (__FILE__), (__LINE__))
#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