libtests: make test 1503,1504,1505 use the 1502 binary

Adjust the differences at runtime instead of build-time, to avoid
extra buillds.

Set the `CURL_TESTNUM` env variable to pass test numbers to tests.

Make libtest/first.c use that env variable to set the `testnum` global
variable to allow tests to differ based on which test that runs it.

Closes #17591
This commit is contained in:
Daniel Stenberg 2025-06-11 11:58:27 +02:00
parent aea336aa23
commit 02dd471bbf
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
8 changed files with 46 additions and 49 deletions

View File

@ -32,7 +32,7 @@ Funny-head: yesyes
http
</server>
<tool>
lib%TESTNUMBER
lib1502
</tool>
<name>
HTTP multi with CURLOPT_RESOLVE, cleanup sequence PA

View File

@ -32,7 +32,7 @@ Funny-head: yesyes
http
</server>
<tool>
lib%TESTNUMBER
lib1502
</tool>
<name>
HTTP multi with CURLOPT_RESOLVE, cleanup sequence UB

View File

@ -32,7 +32,7 @@ Funny-head: yesyes
http
</server>
<tool>
lib%TESTNUMBER
lib1502
</tool>
<name>
HTTP multi with CURLOPT_RESOLVE, cleanup sequence PB

View File

@ -55,7 +55,7 @@ LIBTESTPROGS = libauthretry libntlmconnect libprereq \
lib1301 \
lib1308 \
lib1485 \
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
lib1500 lib1501 lib1502 lib1506 lib1507 lib1508 \
lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \
lib1518 lib1520 lib1521 lib1522 lib1523 \
lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \
@ -376,19 +376,6 @@ lib1501_LDADD = $(TESTUTIL_LIBS)
lib1502_SOURCES = lib1502.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1502_LDADD = $(TESTUTIL_LIBS)
lib1502_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1502
lib1503_SOURCES = lib1502.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1503_LDADD = $(TESTUTIL_LIBS)
lib1503_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1503
lib1504_SOURCES = lib1502.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1504_LDADD = $(TESTUTIL_LIBS)
lib1504_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1504
lib1505_SOURCES = lib1502.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1505_LDADD = $(TESTUTIL_LIBS)
lib1505_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1505
lib1506_SOURCES = lib1506.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1506_LDADD = $(TESTUTIL_LIBS)

View File

@ -73,6 +73,7 @@ char *libtest_arg3 = NULL;
char *libtest_arg4 = NULL;
int test_argc;
char **test_argv;
int testnum;
struct timeval tv_test_start; /* for test timing */
@ -121,6 +122,7 @@ int main(int argc, char **argv)
CURLcode result;
int basearg;
test_func_t test_func;
char *env;
CURL_SET_BINMODE(stdout);
@ -191,6 +193,12 @@ int main(int argc, char **argv)
URL = argv[basearg]; /* provide this to the rest */
env = getenv("CURL_TESTNUM");
if(env)
testnum = atoi(env);
else
testnum = 0;
curl_mfprintf(stderr, "URL: %s\n", URL);
result = test_func(URL);

View File

@ -23,7 +23,7 @@
***************************************************************************/
/*
* This source code is used for lib1502, lib1503, lib1504 and lib1505 with
* only #ifdefs controlling the cleanup sequence.
* only the testnum controlling the cleanup sequence.
*
* Test case 1502 converted from bug report #3575448, identifying a memory
* leak in the CURLOPT_RESOLVE handling with the multi interface.
@ -44,7 +44,6 @@ CURLcode test(char *URL)
CURLM *multi = NULL;
int still_running;
CURLcode res = CURLE_OK;
char redirect[160];
/* DNS cache injection */
@ -121,35 +120,35 @@ CURLcode test(char *URL)
test_cleanup:
#ifdef LIB1502
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(easy);
curl_global_cleanup();
#endif
#ifdef LIB1503
/* proper cleanup sequence - type PA */
curl_multi_remove_handle(multi, easy);
curl_multi_cleanup(multi);
curl_easy_cleanup(easy);
curl_global_cleanup();
#endif
#ifdef LIB1504
/* undocumented cleanup sequence - type UB */
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
#endif
#ifdef LIB1505
/* proper cleanup sequence - type PB */
curl_multi_remove_handle(multi, easy);
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
#endif
switch(testnum) {
case 1502:
default:
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(easy);
curl_global_cleanup();
break;
case 1503:
/* proper cleanup sequence - type PA */
curl_multi_remove_handle(multi, easy);
curl_multi_cleanup(multi);
curl_easy_cleanup(easy);
curl_global_cleanup();
break;
case 1504:
/* undocumented cleanup sequence - type UB */
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
break;
case 1505:
/* proper cleanup sequence - type PB */
curl_multi_remove_handle(multi, easy);
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
break;
}
curl_slist_free_all(dns_cache_list);

View File

@ -71,7 +71,7 @@ extern char *libtest_arg4; /* set by first.c to the argv[4] or NULL */
/* argc and argv as passed in to the main() function */
extern int test_argc;
extern char **test_argv;
extern int testnum;
extern struct timeval tv_test_start; /* for test timing */
extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,

View File

@ -756,6 +756,9 @@ sub singletest_prepare {
# write the instructions to file
writearray("$LOGDIR/$SERVERCMD", \@ftpservercmd);
# provide an environment variable
$ENV{'CURL_TESTNUM'} = $testnum;
# create (possibly-empty) files before starting the test
for my $partsuffix (('', '1', '2', '3', '4')) {
my @inputfile=getpart("client", "file".$partsuffix);