]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libtests: more header tidy-ups
authorViktor Szakats <commit@vsz.me>
Wed, 9 Jul 2025 14:33:17 +0000 (16:33 +0200)
committerViktor Szakats <commit@vsz.me>
Wed, 9 Jul 2025 18:29:50 +0000 (20:29 +0200)
- make `test*` sources include `first.h`, like all others.
- drop redundant `curlx/*` includes after the above.
- merge `test.h` into `first.h`, now that no other file uses it.
  (and `first.h` had almost no content.)
  To simplify and sync header structure with other tests.

Closes #17875

tests/libtest/Makefile.inc
tests/libtest/first.h
tests/libtest/test.h [deleted file]
tests/libtest/testtrace.c
tests/libtest/testtrace.h
tests/libtest/testutil.h

index 8d338ecaba00afa41c71d2b3a9acb073bb4d5f99..8878ae85fa6db26cdd2dda5cf6cef76cb6a3e842 100644 (file)
@@ -31,7 +31,7 @@ FIRST_H = first.h
 
 # Common files used by test programs
 UTILS_C = memptr.c testutil.c testtrace.c
-UTILS_H = test.h testutil.h testtrace.h unitcheck.h
+UTILS_H = testutil.h testtrace.h unitcheck.h
 
 CURLX_C = \
   ../../lib/curlx/warnless.c \
index aa8ae859785a7cffddfca6932019ff8f8d2841a7..24aefed9c627799df159165958af4a40fc8752c9 100644 (file)
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "test.h"
+/* Now include the curl_setup.h file from libcurl's private libdir (the source
+   version, but that might include "curl_config.h" from the build dir so we
+   need both of them in the include path), so that we get good in-depth
+   knowledge about the system we're building this on */
+#include "curl_setup.h"
+
+#include <curl/curl.h>
 
 typedef CURLcode (*entry_func_t)(char *);
 
@@ -38,4 +44,470 @@ extern int unitfail; /* for unittests */
 
 #include <curlx/curlx.h>
 
+#ifdef HAVE_SYS_SELECT_H
+/* since so many tests use select(), we can just as well include it here */
+#include <sys/select.h>
+#endif
+
+#include "curl_printf.h"
+
+/* GCC <4.6 does not support '#pragma GCC diagnostic push' and
+   does not support 'pragma GCC diagnostic' inside functions. */
+#if (defined(__GNUC__) && \
+  ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
+#define CURL_GNUC_DIAG
+#endif
+
+#define test_setopt(A,B,C)                                      \
+  if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK)       \
+    goto test_cleanup
+
+#define test_multi_setopt(A,B,C)                                \
+  if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK)      \
+    goto test_cleanup
+
+extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
+extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
+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 curltime tv_test_start; /* for test timing */
+
+extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
+                          struct timeval *tv);
+
+extern char *hexdump(const unsigned char *buffer, size_t len);
+
+/*
+** TEST_ERR_* values must within the CURLcode range to not cause compiler
+** errors.
+
+** For portability reasons TEST_ERR_* values should be less than 127.
+*/
+
+#define TEST_ERR_MAJOR_BAD     CURLE_OBSOLETE20
+#define TEST_ERR_RUNS_FOREVER  CURLE_OBSOLETE24
+#define TEST_ERR_EASY_INIT     CURLE_OBSOLETE29
+#define TEST_ERR_MULTI         CURLE_OBSOLETE32
+#define TEST_ERR_NUM_HANDLES   CURLE_OBSOLETE34
+#define TEST_ERR_SELECT        CURLE_OBSOLETE40
+#define TEST_ERR_SUCCESS       CURLE_OBSOLETE41
+#define TEST_ERR_FAILURE       CURLE_OBSOLETE44
+#define TEST_ERR_USAGE         CURLE_OBSOLETE46
+#define TEST_ERR_FOPEN         CURLE_OBSOLETE50
+#define TEST_ERR_FSTAT         CURLE_OBSOLETE51
+#define TEST_ERR_BAD_TIMEOUT   CURLE_OBSOLETE57
+
+/*
+** Macros for test source code readability/maintainability.
+**
+** All of the following macros require that an int data type 'res' variable
+** exists in scope where macro is used, and that it has been initialized to
+** zero before the macro is used.
+**
+** exe_* and chk_* macros are helper macros not intended to be used from
+** outside of this header file. Arguments 'Y' and 'Z' of these represent
+** source code file and line number, while Arguments 'A', 'B', etc, are
+** the arguments used to actually call a libcurl function.
+**
+** All easy_* and multi_* macros call a libcurl function and evaluate if
+** the function has succeeded or failed. When the function succeeds 'res'
+** variable is not set nor cleared and program continues normal flow. On
+** the other hand if function fails 'res' variable is set and a jump to
+** label 'test_cleanup' is performed.
+**
+** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
+** counterpart that operates in the same way with the exception that no
+** jump takes place in case of failure. res_easy_* and res_multi_* macros
+** should be immediately followed by checking if 'res' variable has been
+** set.
+**
+** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
+** TEST_ERR_* values defined above. It is advisable to return this value
+** as test result.
+*/
+
+/* ---------------------------------------------------------------- */
+
+#define exe_easy_init(A,Y,Z) do {                                       \
+  if(((A) = curl_easy_init()) == NULL) {                                \
+    curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
+    res = TEST_ERR_EASY_INIT;                                           \
+  }                                                                     \
+} while(0)
+
+#define res_easy_init(A) \
+  exe_easy_init((A), (__FILE__), (__LINE__))
+
+#define chk_easy_init(A,Y,Z) do { \
+  exe_easy_init((A), (Y), (Z));   \
+  if(res)                         \
+    goto test_cleanup;            \
+} while(0)
+
+#define easy_init(A) \
+  chk_easy_init((A), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_init(A,Y,Z) do {                                       \
+  if(((A) = curl_multi_init()) == NULL) {                                \
+    curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
+    res = TEST_ERR_MULTI;                                                \
+  }                                                                      \
+} while(0)
+
+#define res_multi_init(A) \
+  exe_multi_init((A), (__FILE__), (__LINE__))
+
+#define chk_multi_init(A,Y,Z) do { \
+  exe_multi_init((A), (Y), (Z));   \
+  if(res)                          \
+    goto test_cleanup;             \
+} while(0)
+
+#define multi_init(A) \
+  chk_multi_init((A), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_easy_setopt(A,B,C,Y,Z) do {                       \
+  CURLcode ec;                                                \
+  if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) {    \
+    curl_mfprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
+                  "with code %d (%s)\n",                      \
+                  (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
+    res = ec;                                                 \
+  }                                                           \
+} while(0)
+
+#define res_easy_setopt(A, B, C) \
+  exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
+
+#define chk_easy_setopt(A, B, C, Y, Z) do { \
+  exe_easy_setopt((A), (B), (C), (Y), (Z)); \
+  if(res)                                   \
+    goto test_cleanup;                      \
+} while(0)
+
+#define easy_setopt(A, B, C) \
+  chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_setopt(A, B, C, Y, Z) do {                   \
+  CURLMcode ec;                                                \
+  if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) {    \
+    curl_mfprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
+                  "with code %d (%s)\n",                       \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+    res = TEST_ERR_MULTI;                                      \
+  }                                                            \
+} while(0)
+
+#define res_multi_setopt(A,B,C) \
+  exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
+
+#define chk_multi_setopt(A,B,C,Y,Z) do {     \
+  exe_multi_setopt((A), (B), (C), (Y), (Z)); \
+  if(res)                                    \
+    goto test_cleanup;                       \
+} while(0)
+
+#define multi_setopt(A,B,C) \
+  chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_add_handle(A,B,Y,Z) do {                         \
+  CURLMcode ec;                                                    \
+  if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) {         \
+    curl_mfprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
+                  "with code %d (%s)\n",                           \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
+    res = TEST_ERR_MULTI;                                          \
+  }                                                                \
+} while(0)
+
+#define res_multi_add_handle(A, B) \
+  exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
+
+#define chk_multi_add_handle(A, B, Y, Z) do { \
+  exe_multi_add_handle((A), (B), (Y), (Z));   \
+  if(res)                                     \
+    goto test_cleanup;                        \
+} while(0)
+
+#define multi_add_handle(A, B) \
+  chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_remove_handle(A,B,Y,Z) do {                         \
+  CURLMcode ec;                                                       \
+  if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) {         \
+    curl_mfprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
+                  "with code %d (%s)\n",                              \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));        \
+    res = TEST_ERR_MULTI;                                             \
+  }                                                                   \
+} while(0)
+
+#define res_multi_remove_handle(A, B) \
+  exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
+
+#define chk_multi_remove_handle(A, B, Y, Z) do { \
+  exe_multi_remove_handle((A), (B), (Y), (Z));   \
+  if(res)                                        \
+    goto test_cleanup;                           \
+} while(0)
+
+
+#define multi_remove_handle(A, B) \
+  chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_perform(A,B,Y,Z) do {                                \
+  CURLMcode ec;                                                        \
+  if((ec = curl_multi_perform((A), (B))) != CURLM_OK) {                \
+    curl_mfprintf(stderr, "%s:%d curl_multi_perform() failed, "        \
+                  "with code %d (%s)\n",                               \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));         \
+    res = TEST_ERR_MULTI;                                              \
+  }                                                                    \
+  else if(*((B)) < 0) {                                                \
+    curl_mfprintf(stderr, "%s:%d curl_multi_perform() succeeded, "     \
+                  "but returned invalid running_handles value (%d)\n", \
+                  (Y), (Z), (int)*((B)));                              \
+    res = TEST_ERR_NUM_HANDLES;                                        \
+  }                                                                    \
+} while(0)
+
+#define res_multi_perform(A, B) \
+  exe_multi_perform((A), (B), (__FILE__), (__LINE__))
+
+#define chk_multi_perform(A, B, Y, Z) do { \
+  exe_multi_perform((A), (B), (Y), (Z));   \
+  if(res)                                  \
+    goto test_cleanup;                     \
+} while(0)
+
+#define multi_perform(A,B) \
+  chk_multi_perform((A), (B), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_fdset(A, B, C, D, E, Y, Z) do {                    \
+  CURLMcode ec;                                                      \
+  if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
+    curl_mfprintf(stderr, "%s:%d curl_multi_fdset() failed, "        \
+                  "with code %d (%s)\n",                             \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));       \
+    res = TEST_ERR_MULTI;                                            \
+  }                                                                  \
+  else if(*((E)) < -1) {                                             \
+    curl_mfprintf(stderr, "%s:%d curl_multi_fdset() succeeded, "     \
+                  "but returned invalid max_fd value (%d)\n",        \
+                  (Y), (Z), (int)*((E)));                            \
+    res = TEST_ERR_NUM_HANDLES;                                      \
+  }                                                                  \
+} while(0)
+
+#define res_multi_fdset(A, B, C, D, E) \
+  exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+#define chk_multi_fdset(A, B, C, D, E, Y, Z) do {       \
+    exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
+    if(res)                                             \
+      goto test_cleanup;                                \
+  } while(0)
+
+#define multi_fdset(A, B, C, D, E) \
+  chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_timeout(A,B,Y,Z) do {                            \
+  CURLMcode ec;                                                    \
+  if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) {            \
+    curl_mfprintf(stderr, "%s:%d curl_multi_timeout() failed, "    \
+                  "with code %d (%s)\n",                           \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
+    res = TEST_ERR_BAD_TIMEOUT;                                    \
+  }                                                                \
+  else if(*((B)) < -1L) {                                          \
+    curl_mfprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
+                  "but returned invalid timeout value (%ld)\n",    \
+                  (Y), (Z), (long)*((B)));                         \
+    res = TEST_ERR_BAD_TIMEOUT;                                    \
+  }                                                                \
+} while(0)
+
+#define res_multi_timeout(A, B) \
+  exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
+
+#define chk_multi_timeout(A, B, Y, Z) do { \
+    exe_multi_timeout((A), (B), (Y), (Z)); \
+    if(res)                                \
+      goto test_cleanup;                   \
+  } while(0)
+
+#define multi_timeout(A, B) \
+  chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_poll(A,B,C,D,E,Y,Z) do {                          \
+  CURLMcode ec;                                                     \
+  if((ec = curl_multi_poll((A), (B), (C), (D), (E))) != CURLM_OK) { \
+    curl_mfprintf(stderr, "%s:%d curl_multi_poll() failed, "        \
+                  "with code %d (%s)\n",                            \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec));      \
+    res = TEST_ERR_MULTI;                                           \
+  }                                                                 \
+  else if(*((E)) < 0) {                                             \
+    curl_mfprintf(stderr, "%s:%d curl_multi_poll() succeeded, "     \
+                  "but returned invalid numfds value (%d)\n",       \
+                  (Y), (Z), (int)*((E)));                           \
+    res = TEST_ERR_NUM_HANDLES;                                     \
+  }                                                                 \
+} while(0)
+
+#define res_multi_poll(A, B, C, D, E) \
+  exe_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+#define chk_multi_poll(A, B, C, D, E, Y, Z) do {     \
+  exe_multi_poll((A), (B), (C), (D), (E), (Y), (Z)); \
+  if(res)                                            \
+    goto test_cleanup;                               \
+} while(0)
+
+#define multi_poll(A, B, C, D, E) \
+  chk_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_wakeup(A,Y,Z) do {                           \
+  CURLMcode ec;                                                \
+  if((ec = curl_multi_wakeup((A))) != CURLM_OK) {              \
+    curl_mfprintf(stderr, "%s:%d curl_multi_wakeup() failed, " \
+                  "with code %d (%s)\n",                       \
+                  (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+    res = TEST_ERR_MULTI;                                      \
+  }                                                            \
+} while(0)
+
+#define res_multi_wakeup(A) \
+  exe_multi_wakeup((A), (__FILE__), (__LINE__))
+
+#define chk_multi_wakeup(A, Y, Z) do { \
+  exe_multi_wakeup((A), (Y), (Z));     \
+  if(res)                              \
+    goto test_cleanup;                 \
+} while(0)
+
+#define multi_wakeup(A) \
+  chk_multi_wakeup((A), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_select_test(A, B, C, D, E, Y, Z) do {          \
+    int ec;                                                \
+    if(select_wrapper((A), (B), (C), (D), (E)) == -1) {    \
+      ec = SOCKERRNO;                                      \
+      curl_mfprintf(stderr, "%s:%d select() failed, with " \
+                    "errno %d (%s)\n",                     \
+                    (Y), (Z), ec, strerror(ec));           \
+      res = TEST_ERR_SELECT;                               \
+    }                                                      \
+  } while(0)
+
+#define res_select_test(A, B, C, D, E) \
+  exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+#define chk_select_test(A, B, C, D, E, Y, Z) do {       \
+    exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
+    if(res)                                             \
+      goto test_cleanup;                                \
+  } while(0)
+
+#define select_test(A, B, C, D, E) \
+  chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define start_test_timing() do { \
+  tv_test_start = curlx_now(); \
+} while(0)
+
+#define TEST_HANG_TIMEOUT 60 * 1000  /* global default */
+
+#define exe_test_timedout(T,Y,Z) do {                                   \
+  timediff_t timediff = curlx_timediff(curlx_now(), tv_test_start);     \
+  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), (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
+    res = TEST_ERR_RUNS_FOREVER;                                        \
+  }                                                                     \
+} while(0)
+
+#define res_test_timedout() \
+  exe_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
+
+#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(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
+
+#define abort_on_test_timeout_custom(T) \
+  chk_test_timedout((T), (__FILE__), (__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_global_init(A,Y,Z) do {                           \
+  CURLcode ec;                                                \
+  if((ec = curl_global_init((A))) != CURLE_OK) {              \
+    curl_mfprintf(stderr, "%s:%d curl_global_init() failed, " \
+                  "with code %d (%s)\n",                      \
+                  (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
+    res = ec;                                                 \
+  }                                                           \
+} while(0)
+
+#define res_global_init(A) \
+  exe_global_init((A), (__FILE__), (__LINE__))
+
+#define chk_global_init(A, Y, Z) do { \
+    exe_global_init((A), (Y), (Z));   \
+    if(res)                           \
+      return res;                     \
+  } while(0)
+
+/* global_init() is different than other macros. In case of
+   failure it 'return's instead of going to 'test_cleanup'. */
+
+#define global_init(A) \
+  chk_global_init((A), (__FILE__), (__LINE__))
+
+#define NO_SUPPORT_BUILT_IN                     \
+  {                                             \
+    (void)URL;                                  \
+    curl_mfprintf(stderr, "Missing support\n"); \
+    return CURLE_UNSUPPORTED_PROTOCOL;          \
+  }
+
+#define NUM_HANDLES 4  /* global default */
+
 #endif /* HEADER_LIBTEST_FIRST_H */
diff --git a/tests/libtest/test.h b/tests/libtest/test.h
deleted file mode 100644 (file)
index 53c9091..0000000
+++ /dev/null
@@ -1,505 +0,0 @@
-#ifndef HEADER_CURL_TEST_H
-#define HEADER_CURL_TEST_H
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-
-/* Now include the curl_setup.h file from libcurl's private libdir (the source
-   version, but that might include "curl_config.h" from the build dir so we
-   need both of them in the include path), so that we get good in-depth
-   knowledge about the system we're building this on */
-
-#include "curl_setup.h"
-
-#include <curl/curl.h>
-#include <curlx/timeval.h>
-
-#ifdef HAVE_SYS_SELECT_H
-/* since so many tests use select(), we can just as well include it here */
-#include <sys/select.h>
-#endif
-
-#include "curl_printf.h"
-
-/* GCC <4.6 does not support '#pragma GCC diagnostic push' and
-   does not support 'pragma GCC diagnostic' inside functions. */
-#if (defined(__GNUC__) && \
-  ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
-#define CURL_GNUC_DIAG
-#endif
-
-#define test_setopt(A,B,C)                                      \
-  if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK)       \
-    goto test_cleanup
-
-#define test_multi_setopt(A,B,C)                                \
-  if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK)      \
-    goto test_cleanup
-
-extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
-extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
-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 curltime tv_test_start; /* for test timing */
-
-extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
-                          struct timeval *tv);
-
-extern char *hexdump(const unsigned char *buffer, size_t len);
-
-/*
-** TEST_ERR_* values must within the CURLcode range to not cause compiler
-** errors.
-
-** For portability reasons TEST_ERR_* values should be less than 127.
-*/
-
-#define TEST_ERR_MAJOR_BAD     CURLE_OBSOLETE20
-#define TEST_ERR_RUNS_FOREVER  CURLE_OBSOLETE24
-#define TEST_ERR_EASY_INIT     CURLE_OBSOLETE29
-#define TEST_ERR_MULTI         CURLE_OBSOLETE32
-#define TEST_ERR_NUM_HANDLES   CURLE_OBSOLETE34
-#define TEST_ERR_SELECT        CURLE_OBSOLETE40
-#define TEST_ERR_SUCCESS       CURLE_OBSOLETE41
-#define TEST_ERR_FAILURE       CURLE_OBSOLETE44
-#define TEST_ERR_USAGE         CURLE_OBSOLETE46
-#define TEST_ERR_FOPEN         CURLE_OBSOLETE50
-#define TEST_ERR_FSTAT         CURLE_OBSOLETE51
-#define TEST_ERR_BAD_TIMEOUT   CURLE_OBSOLETE57
-
-/*
-** Macros for test source code readability/maintainability.
-**
-** All of the following macros require that an int data type 'res' variable
-** exists in scope where macro is used, and that it has been initialized to
-** zero before the macro is used.
-**
-** exe_* and chk_* macros are helper macros not intended to be used from
-** outside of this header file. Arguments 'Y' and 'Z' of these represent
-** source code file and line number, while Arguments 'A', 'B', etc, are
-** the arguments used to actually call a libcurl function.
-**
-** All easy_* and multi_* macros call a libcurl function and evaluate if
-** the function has succeeded or failed. When the function succeeds 'res'
-** variable is not set nor cleared and program continues normal flow. On
-** the other hand if function fails 'res' variable is set and a jump to
-** label 'test_cleanup' is performed.
-**
-** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
-** counterpart that operates in the same way with the exception that no
-** jump takes place in case of failure. res_easy_* and res_multi_* macros
-** should be immediately followed by checking if 'res' variable has been
-** set.
-**
-** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
-** TEST_ERR_* values defined above. It is advisable to return this value
-** as test result.
-*/
-
-/* ---------------------------------------------------------------- */
-
-#define exe_easy_init(A,Y,Z) do {                                       \
-  if(((A) = curl_easy_init()) == NULL) {                                \
-    curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
-    res = TEST_ERR_EASY_INIT;                                           \
-  }                                                                     \
-} while(0)
-
-#define res_easy_init(A) \
-  exe_easy_init((A), (__FILE__), (__LINE__))
-
-#define chk_easy_init(A,Y,Z) do { \
-  exe_easy_init((A), (Y), (Z));   \
-  if(res)                         \
-    goto test_cleanup;            \
-} while(0)
-
-#define easy_init(A) \
-  chk_easy_init((A), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_init(A,Y,Z) do {                                       \
-  if(((A) = curl_multi_init()) == NULL) {                                \
-    curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
-    res = TEST_ERR_MULTI;                                                \
-  }                                                                      \
-} while(0)
-
-#define res_multi_init(A) \
-  exe_multi_init((A), (__FILE__), (__LINE__))
-
-#define chk_multi_init(A,Y,Z) do { \
-  exe_multi_init((A), (Y), (Z));   \
-  if(res)                          \
-    goto test_cleanup;             \
-} while(0)
-
-#define multi_init(A) \
-  chk_multi_init((A), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_easy_setopt(A,B,C,Y,Z) do {                       \
-  CURLcode ec;                                                \
-  if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) {    \
-    curl_mfprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
-                  "with code %d (%s)\n",                      \
-                  (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
-    res = ec;                                                 \
-  }                                                           \
-} while(0)
-
-#define res_easy_setopt(A, B, C) \
-  exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
-
-#define chk_easy_setopt(A, B, C, Y, Z) do { \
-  exe_easy_setopt((A), (B), (C), (Y), (Z)); \
-  if(res)                                   \
-    goto test_cleanup;                      \
-} while(0)
-
-#define easy_setopt(A, B, C) \
-  chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_setopt(A, B, C, Y, Z) do {                   \
-  CURLMcode ec;                                                \
-  if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) {    \
-    curl_mfprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
-                  "with code %d (%s)\n",                       \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
-    res = TEST_ERR_MULTI;                                      \
-  }                                                            \
-} while(0)
-
-#define res_multi_setopt(A,B,C) \
-  exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
-
-#define chk_multi_setopt(A,B,C,Y,Z) do {     \
-  exe_multi_setopt((A), (B), (C), (Y), (Z)); \
-  if(res)                                    \
-    goto test_cleanup;                       \
-} while(0)
-
-#define multi_setopt(A,B,C) \
-  chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_add_handle(A,B,Y,Z) do {                         \
-  CURLMcode ec;                                                    \
-  if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) {         \
-    curl_mfprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
-                  "with code %d (%s)\n",                           \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
-    res = TEST_ERR_MULTI;                                          \
-  }                                                                \
-} while(0)
-
-#define res_multi_add_handle(A, B) \
-  exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
-
-#define chk_multi_add_handle(A, B, Y, Z) do { \
-  exe_multi_add_handle((A), (B), (Y), (Z));   \
-  if(res)                                     \
-    goto test_cleanup;                        \
-} while(0)
-
-#define multi_add_handle(A, B) \
-  chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_remove_handle(A,B,Y,Z) do {                         \
-  CURLMcode ec;                                                       \
-  if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) {         \
-    curl_mfprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
-                  "with code %d (%s)\n",                              \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));        \
-    res = TEST_ERR_MULTI;                                             \
-  }                                                                   \
-} while(0)
-
-#define res_multi_remove_handle(A, B) \
-  exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
-
-#define chk_multi_remove_handle(A, B, Y, Z) do { \
-  exe_multi_remove_handle((A), (B), (Y), (Z));   \
-  if(res)                                        \
-    goto test_cleanup;                           \
-} while(0)
-
-
-#define multi_remove_handle(A, B) \
-  chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_perform(A,B,Y,Z) do {                                \
-  CURLMcode ec;                                                        \
-  if((ec = curl_multi_perform((A), (B))) != CURLM_OK) {                \
-    curl_mfprintf(stderr, "%s:%d curl_multi_perform() failed, "        \
-                  "with code %d (%s)\n",                               \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));         \
-    res = TEST_ERR_MULTI;                                              \
-  }                                                                    \
-  else if(*((B)) < 0) {                                                \
-    curl_mfprintf(stderr, "%s:%d curl_multi_perform() succeeded, "     \
-                  "but returned invalid running_handles value (%d)\n", \
-                  (Y), (Z), (int)*((B)));                              \
-    res = TEST_ERR_NUM_HANDLES;                                        \
-  }                                                                    \
-} while(0)
-
-#define res_multi_perform(A, B) \
-  exe_multi_perform((A), (B), (__FILE__), (__LINE__))
-
-#define chk_multi_perform(A, B, Y, Z) do { \
-  exe_multi_perform((A), (B), (Y), (Z));   \
-  if(res)                                  \
-    goto test_cleanup;                     \
-} while(0)
-
-#define multi_perform(A,B) \
-  chk_multi_perform((A), (B), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_fdset(A, B, C, D, E, Y, Z) do {                    \
-  CURLMcode ec;                                                      \
-  if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
-    curl_mfprintf(stderr, "%s:%d curl_multi_fdset() failed, "        \
-                  "with code %d (%s)\n",                             \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));       \
-    res = TEST_ERR_MULTI;                                            \
-  }                                                                  \
-  else if(*((E)) < -1) {                                             \
-    curl_mfprintf(stderr, "%s:%d curl_multi_fdset() succeeded, "     \
-                  "but returned invalid max_fd value (%d)\n",        \
-                  (Y), (Z), (int)*((E)));                            \
-    res = TEST_ERR_NUM_HANDLES;                                      \
-  }                                                                  \
-} while(0)
-
-#define res_multi_fdset(A, B, C, D, E) \
-  exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-#define chk_multi_fdset(A, B, C, D, E, Y, Z) do {       \
-    exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
-    if(res)                                             \
-      goto test_cleanup;                                \
-  } while(0)
-
-#define multi_fdset(A, B, C, D, E) \
-  chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_timeout(A,B,Y,Z) do {                            \
-  CURLMcode ec;                                                    \
-  if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) {            \
-    curl_mfprintf(stderr, "%s:%d curl_multi_timeout() failed, "    \
-                  "with code %d (%s)\n",                           \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
-    res = TEST_ERR_BAD_TIMEOUT;                                    \
-  }                                                                \
-  else if(*((B)) < -1L) {                                          \
-    curl_mfprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
-                  "but returned invalid timeout value (%ld)\n",    \
-                  (Y), (Z), (long)*((B)));                         \
-    res = TEST_ERR_BAD_TIMEOUT;                                    \
-  }                                                                \
-} while(0)
-
-#define res_multi_timeout(A, B) \
-  exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
-
-#define chk_multi_timeout(A, B, Y, Z) do { \
-    exe_multi_timeout((A), (B), (Y), (Z)); \
-    if(res)                                \
-      goto test_cleanup;                   \
-  } while(0)
-
-#define multi_timeout(A, B) \
-  chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_poll(A,B,C,D,E,Y,Z) do {                          \
-  CURLMcode ec;                                                     \
-  if((ec = curl_multi_poll((A), (B), (C), (D), (E))) != CURLM_OK) { \
-    curl_mfprintf(stderr, "%s:%d curl_multi_poll() failed, "        \
-                  "with code %d (%s)\n",                            \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec));      \
-    res = TEST_ERR_MULTI;                                           \
-  }                                                                 \
-  else if(*((E)) < 0) {                                             \
-    curl_mfprintf(stderr, "%s:%d curl_multi_poll() succeeded, "     \
-                  "but returned invalid numfds value (%d)\n",       \
-                  (Y), (Z), (int)*((E)));                           \
-    res = TEST_ERR_NUM_HANDLES;                                     \
-  }                                                                 \
-} while(0)
-
-#define res_multi_poll(A, B, C, D, E) \
-  exe_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-#define chk_multi_poll(A, B, C, D, E, Y, Z) do {     \
-  exe_multi_poll((A), (B), (C), (D), (E), (Y), (Z)); \
-  if(res)                                            \
-    goto test_cleanup;                               \
-} while(0)
-
-#define multi_poll(A, B, C, D, E) \
-  chk_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_multi_wakeup(A,Y,Z) do {                           \
-  CURLMcode ec;                                                \
-  if((ec = curl_multi_wakeup((A))) != CURLM_OK) {              \
-    curl_mfprintf(stderr, "%s:%d curl_multi_wakeup() failed, " \
-                  "with code %d (%s)\n",                       \
-                  (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
-    res = TEST_ERR_MULTI;                                      \
-  }                                                            \
-} while(0)
-
-#define res_multi_wakeup(A) \
-  exe_multi_wakeup((A), (__FILE__), (__LINE__))
-
-#define chk_multi_wakeup(A, Y, Z) do { \
-  exe_multi_wakeup((A), (Y), (Z));     \
-  if(res)                              \
-    goto test_cleanup;                 \
-} while(0)
-
-#define multi_wakeup(A) \
-  chk_multi_wakeup((A), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_select_test(A, B, C, D, E, Y, Z) do {          \
-    int ec;                                                \
-    if(select_wrapper((A), (B), (C), (D), (E)) == -1) {    \
-      ec = SOCKERRNO;                                      \
-      curl_mfprintf(stderr, "%s:%d select() failed, with " \
-                    "errno %d (%s)\n",                     \
-                    (Y), (Z), ec, strerror(ec));           \
-      res = TEST_ERR_SELECT;                               \
-    }                                                      \
-  } while(0)
-
-#define res_select_test(A, B, C, D, E) \
-  exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-#define chk_select_test(A, B, C, D, E, Y, Z) do {       \
-    exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
-    if(res)                                             \
-      goto test_cleanup;                                \
-  } while(0)
-
-#define select_test(A, B, C, D, E) \
-  chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define start_test_timing() do { \
-  tv_test_start = curlx_now(); \
-} while(0)
-
-#define TEST_HANG_TIMEOUT 60 * 1000  /* global default */
-
-#define exe_test_timedout(T,Y,Z) do {                                   \
-  timediff_t timediff = curlx_timediff(curlx_now(), tv_test_start);     \
-  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), (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
-    res = TEST_ERR_RUNS_FOREVER;                                        \
-  }                                                                     \
-} while(0)
-
-#define res_test_timedout() \
-  exe_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
-
-#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(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
-
-#define abort_on_test_timeout_custom(T) \
-  chk_test_timedout((T), (__FILE__), (__LINE__))
-
-/* ---------------------------------------------------------------- */
-
-#define exe_global_init(A,Y,Z) do {                           \
-  CURLcode ec;                                                \
-  if((ec = curl_global_init((A))) != CURLE_OK) {              \
-    curl_mfprintf(stderr, "%s:%d curl_global_init() failed, " \
-                  "with code %d (%s)\n",                      \
-                  (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
-    res = ec;                                                 \
-  }                                                           \
-} while(0)
-
-#define res_global_init(A) \
-  exe_global_init((A), (__FILE__), (__LINE__))
-
-#define chk_global_init(A, Y, Z) do { \
-    exe_global_init((A), (Y), (Z));   \
-    if(res)                           \
-      return res;                     \
-  } while(0)
-
-/* global_init() is different than other macros. In case of
-   failure it 'return's instead of going to 'test_cleanup'. */
-
-#define global_init(A) \
-  chk_global_init((A), (__FILE__), (__LINE__))
-
-#define NO_SUPPORT_BUILT_IN                     \
-  {                                             \
-    (void)URL;                                  \
-    curl_mfprintf(stderr, "Missing support\n"); \
-    return CURLE_UNSUPPORTED_PROTOCOL;          \
-  }
-
-#define NUM_HANDLES 4  /* global default */
-
-/* ---------------------------------------------------------------- */
-
-#endif /* HEADER_CURL_TEST_H */
index e6ea57587cda49a30f32e3a60153d30d54746afc..7e287cd885e6e7ecf7e11ce063558c9f73af289b 100644 (file)
@@ -23,8 +23,6 @@
  ***************************************************************************/
 #include "testtrace.h"
 
-#include <curlx/timeval.h>
-
 #include "memdebug.h"
 
 struct libtest_trace_cfg libtest_debug_config;
index dc064f4161d0912cfc935e14538add36aa5ad8bd..82d75988d384838b0e3043435df24f295d411541 100644 (file)
@@ -23,7 +23,7 @@
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "test.h"
+#include "first.h"
 
 struct libtest_trace_cfg {
   int tracetime;  /* 0 represents FALSE, anything else TRUE */
index f7bedff4070664f14a536821dc69d18eab384f7f..7c98e0aadee2b806481f51468b4211cf0739c647 100644 (file)
@@ -23,7 +23,7 @@
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "test.h"
+#include "first.h"
 
 /* build request url */
 char *tutil_suburl(const char *base, int i);