]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libtests: make test 1503,1504,1505 use the 1502 binary
authorDaniel Stenberg <daniel@haxx.se>
Wed, 11 Jun 2025 09:58:27 +0000 (11:58 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 11 Jun 2025 12:25:54 +0000 (14:25 +0200)
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

tests/data/test1503
tests/data/test1504
tests/data/test1505
tests/libtest/Makefile.inc
tests/libtest/first.c
tests/libtest/lib1502.c
tests/libtest/test.h
tests/runner.pm

index 9c746c74e809b4766bbd59eaa7db460eb39bedbe..c387b8d3c549233b952826dc3a3daed38d5df1ba 100644 (file)
@@ -32,7 +32,7 @@ Funny-head: yesyes
 http
 </server>
 <tool>
-lib%TESTNUMBER
+lib1502
 </tool>
 <name>
 HTTP multi with CURLOPT_RESOLVE, cleanup sequence PA
index 663e25e274e70a1678291acddbe85616fdcc7a1e..916a40ba8c777ebea8adf5f1fc00023a8c6ce0e1 100644 (file)
@@ -32,7 +32,7 @@ Funny-head: yesyes
 http
 </server>
 <tool>
-lib%TESTNUMBER
+lib1502
 </tool>
 <name>
 HTTP multi with CURLOPT_RESOLVE, cleanup sequence UB
index 666e4d984bb00e283aaa7e98f31434619cad6057..61e634641a094b6698353b681f74f41ea8f33f8e 100644 (file)
@@ -32,7 +32,7 @@ Funny-head: yesyes
 http
 </server>
 <tool>
-lib%TESTNUMBER
+lib1502
 </tool>
 <name>
 HTTP multi with CURLOPT_RESOLVE, cleanup sequence PB
index 293b0f097013567cc4bae003ae6e00af45320699..d8c5e14c3d5ab18079d74372e00b178887ff46a8 100644 (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)
index a10f87106d4bbb081569e29586a4440183db1683..a90c2d7f1e5e916c49c1fca9b5e55b437d2d354b 100644 (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);
index b4f56407f561b42fb4b7bc70c06e4fa4b2bc9fe0..b118fd7786d7fda38a8c6bac3cb45c2f41b76f65 100644 (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);
 
index 753d549498498f59e155927b8b6141d3d92df5b5..9d57f7a51c66dc2a2cfa00972ec5019ccbcf4671 100644 (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,
index da26efb3467ce5cdcf887f87d9bb06323a59a183..1f2ff73328bd1ea5fb112117fc31d806d7571572 100644 (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);