test.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 /* !checksrc! disable ASSIGNWITHINCONDITION all */
00024 
00025 /* Now include the curl_setup.h file from libcurl's private libdir (the source
00026    version, but that might include "curl_config.h" from the build dir so we
00027    need both of them in the include path), so that we get good in-depth
00028    knowledge about the system we're building this on */
00029 
00030 #define CURL_NO_OLDIES
00031 
00032 #include "curl_setup.h"
00033 
00034 #include <curl/curl.h>
00035 
00036 #ifdef HAVE_SYS_SELECT_H
00037 /* since so many tests use select(), we can just as well include it here */
00038 #include <sys/select.h>
00039 #endif
00040 
00041 #ifdef TPF
00042 #  include "select.h"
00043 #endif
00044 
00045 #include "curl_printf.h"
00046 
00047 #define test_setopt(A,B,C) \
00048   if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) goto test_cleanup
00049 
00050 #define test_multi_setopt(A,B,C) \
00051   if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK) goto test_cleanup
00052 
00053 extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
00054 extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
00055 
00056 /* argc and argv as passed in to the main() function */
00057 extern int test_argc;
00058 extern char **test_argv;
00059 
00060 extern struct timeval tv_test_start; /* for test timing */
00061 
00062 extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
00063                           struct timeval *tv);
00064 
00065 extern void wait_ms(int ms); /* wait this many milliseconds */
00066 
00067 extern int test(char *URL); /* the actual test function provided by each
00068                                individual libXXX.c file */
00069 
00070 extern char *hexdump(unsigned char *buffer, size_t len);
00071 
00072 #ifdef UNITTESTS
00073 extern int unitfail;
00074 #endif
00075 
00076 /*
00077 ** TEST_ERR_* values must be greater than CURL_LAST CURLcode in order
00078 ** to avoid confusion with any CURLcode or CURLMcode. These TEST_ERR_*
00079 ** codes are returned to signal test specific situations and should
00080 ** not get mixed with CURLcode or CURLMcode values.
00081 **
00082 ** For portability reasons TEST_ERR_* values should be less than 127.
00083 */
00084 
00085 #define TEST_ERR_MAJOR_BAD     126
00086 #define TEST_ERR_RUNS_FOREVER  125
00087 #define TEST_ERR_EASY_INIT     124
00088 #define TEST_ERR_MULTI_INIT    123
00089 #define TEST_ERR_NUM_HANDLES   122
00090 #define TEST_ERR_SELECT        121
00091 #define TEST_ERR_SUCCESS       120
00092 #define TEST_ERR_FAILURE       119
00093 #define TEST_ERR_USAGE         118
00094 #define TEST_ERR_FOPEN         117
00095 #define TEST_ERR_FSTAT         116
00096 #define TEST_ERR_BAD_TIMEOUT   115
00097 
00098 /*
00099 ** Macros for test source code readability/maintainability.
00100 **
00101 ** All of the following macros require that an int data type 'res' variable
00102 ** exists in scope where macro is used, and that it has been initialized to
00103 ** zero before the macro is used.
00104 **
00105 ** exe_* and chk_* macros are helper macros not intended to be used from
00106 ** outside of this header file. Arguments 'Y' and 'Z' of these represent
00107 ** source code file and line number, while Arguments 'A', 'B', etc, are
00108 ** the arguments used to actually call a libcurl function.
00109 **
00110 ** All easy_* and multi_* macros call a libcurl function and evaluate if
00111 ** the function has succeeded or failed. When the function succeeds 'res'
00112 ** variable is not set nor cleared and program continues normal flow. On
00113 ** the other hand if function fails 'res' variable is set and a jump to
00114 ** label 'test_cleanup' is performed.
00115 **
00116 ** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
00117 ** counterpart that operates in the same way with the exception that no
00118 ** jump takes place in case of failure. res_easy_* and res_multi_* macros
00119 ** should be immediately followed by checking if 'res' variable has been
00120 ** set.
00121 **
00122 ** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
00123 ** TEST_ERR_* values defined above. It is advisable to return this value
00124 ** as test result.
00125 */
00126 
00127 /* ---------------------------------------------------------------- */
00128 
00129 #define exe_easy_init(A,Y,Z) do {                                 \
00130   if(((A) = curl_easy_init()) == NULL) {                          \
00131     fprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
00132     res = TEST_ERR_EASY_INIT;                                     \
00133   }                                                               \
00134 } WHILE_FALSE
00135 
00136 #define res_easy_init(A) \
00137   exe_easy_init((A), (__FILE__), (__LINE__))
00138 
00139 #define chk_easy_init(A,Y,Z) do { \
00140   exe_easy_init((A), (Y), (Z));   \
00141   if(res)                         \
00142     goto test_cleanup;            \
00143 } WHILE_FALSE
00144 
00145 #define easy_init(A) \
00146   chk_easy_init((A), (__FILE__), (__LINE__))
00147 
00148 /* ---------------------------------------------------------------- */
00149 
00150 #define exe_multi_init(A,Y,Z) do {                                 \
00151   if(((A) = curl_multi_init()) == NULL) {                          \
00152     fprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
00153     res = TEST_ERR_MULTI_INIT;                                     \
00154   }                                                                \
00155 } WHILE_FALSE
00156 
00157 #define res_multi_init(A) \
00158   exe_multi_init((A), (__FILE__), (__LINE__))
00159 
00160 #define chk_multi_init(A,Y,Z) do { \
00161   exe_multi_init((A), (Y), (Z));   \
00162   if(res)                          \
00163     goto test_cleanup;             \
00164 } WHILE_FALSE
00165 
00166 #define multi_init(A) \
00167   chk_multi_init((A), (__FILE__), (__LINE__))
00168 
00169 /* ---------------------------------------------------------------- */
00170 
00171 #define exe_easy_setopt(A,B,C,Y,Z) do {                    \
00172   CURLcode ec;                                             \
00173   if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) { \
00174     fprintf(stderr, "%s:%d curl_easy_setopt() failed, "    \
00175             "with code %d (%s)\n",                         \
00176             (Y), (Z), (int)ec, curl_easy_strerror(ec));    \
00177     res = (int)ec;                                         \
00178   }                                                        \
00179 } WHILE_FALSE
00180 
00181 #define res_easy_setopt(A, B, C) \
00182   exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
00183 
00184 #define chk_easy_setopt(A, B, C, Y, Z) do { \
00185   exe_easy_setopt((A), (B), (C), (Y), (Z)); \
00186   if(res)                                   \
00187     goto test_cleanup;                      \
00188 } WHILE_FALSE
00189 
00190 #define easy_setopt(A, B, C) \
00191   chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
00192 
00193 /* ---------------------------------------------------------------- */
00194 
00195 #define exe_multi_setopt(A, B, C, Y, Z) do {                \
00196   CURLMcode ec;                                             \
00197   if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) { \
00198     fprintf(stderr, "%s:%d curl_multi_setopt() failed, "    \
00199             "with code %d (%s)\n",                          \
00200             (Y), (Z), (int)ec, curl_multi_strerror(ec));    \
00201     res = (int)ec;                                          \
00202   }                                                         \
00203 } WHILE_FALSE
00204 
00205 #define res_multi_setopt(A,B,C) \
00206   exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
00207 
00208 #define chk_multi_setopt(A,B,C,Y,Z) do {     \
00209   exe_multi_setopt((A), (B), (C), (Y), (Z)); \
00210   if(res)                                    \
00211     goto test_cleanup;                       \
00212 } WHILE_FALSE
00213 
00214 #define multi_setopt(A,B,C) \
00215   chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
00216 
00217 /* ---------------------------------------------------------------- */
00218 
00219 #define exe_multi_add_handle(A,B,Y,Z) do {                   \
00220   CURLMcode ec;                                              \
00221   if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) {   \
00222     fprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
00223             "with code %d (%s)\n",                           \
00224             (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
00225     res = (int)ec;                                           \
00226   }                                                          \
00227 } WHILE_FALSE
00228 
00229 #define res_multi_add_handle(A, B) \
00230   exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
00231 
00232 #define chk_multi_add_handle(A, B, Y, Z) do { \
00233   exe_multi_add_handle((A), (B), (Y), (Z));   \
00234   if(res)                                     \
00235     goto test_cleanup;                        \
00236 } WHILE_FALSE
00237 
00238 #define multi_add_handle(A, B) \
00239   chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
00240 
00241 /* ---------------------------------------------------------------- */
00242 
00243 #define exe_multi_remove_handle(A,B,Y,Z) do {                   \
00244   CURLMcode ec;                                                 \
00245   if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) {   \
00246     fprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
00247             "with code %d (%s)\n",                              \
00248             (Y), (Z), (int)ec, curl_multi_strerror(ec));        \
00249     res = (int)ec;                                              \
00250   }                                                             \
00251 } WHILE_FALSE
00252 
00253 #define res_multi_remove_handle(A, B) \
00254   exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
00255 
00256 #define chk_multi_remove_handle(A, B, Y, Z) do { \
00257   exe_multi_remove_handle((A), (B), (Y), (Z));   \
00258   if(res)                                        \
00259     goto test_cleanup;                           \
00260 } WHILE_FALSE
00261 
00262 
00263 #define multi_remove_handle(A, B) \
00264   chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
00265 
00266 /* ---------------------------------------------------------------- */
00267 
00268 #define exe_multi_perform(A,B,Y,Z) do {                          \
00269   CURLMcode ec;                                                  \
00270   if((ec = curl_multi_perform((A), (B))) != CURLM_OK) {          \
00271     fprintf(stderr, "%s:%d curl_multi_perform() failed, "        \
00272             "with code %d (%s)\n",                               \
00273             (Y), (Z), (int)ec, curl_multi_strerror(ec));         \
00274     res = (int)ec;                                               \
00275   }                                                              \
00276   else if(*((B)) < 0) {                                          \
00277     fprintf(stderr, "%s:%d curl_multi_perform() succeeded, "     \
00278             "but returned invalid running_handles value (%d)\n", \
00279             (Y), (Z), (int)*((B)));                              \
00280     res = TEST_ERR_NUM_HANDLES;                                  \
00281   }                                                              \
00282 } WHILE_FALSE
00283 
00284 #define res_multi_perform(A, B) \
00285   exe_multi_perform((A), (B), (__FILE__), (__LINE__))
00286 
00287 #define chk_multi_perform(A, B, Y, Z) do { \
00288   exe_multi_perform((A), (B), (Y), (Z));   \
00289   if(res)                                  \
00290     goto test_cleanup;                     \
00291 } WHILE_FALSE
00292 
00293 #define multi_perform(A,B) \
00294   chk_multi_perform((A), (B), (__FILE__), (__LINE__))
00295 
00296 /* ---------------------------------------------------------------- */
00297 
00298 #define exe_multi_fdset(A, B, C, D, E, Y, Z) do {                    \
00299   CURLMcode ec;                                                      \
00300   if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
00301     fprintf(stderr, "%s:%d curl_multi_fdset() failed, "              \
00302             "with code %d (%s)\n",                                   \
00303             (Y), (Z), (int)ec, curl_multi_strerror(ec));             \
00304     res = (int)ec;                                                   \
00305   }                                                                  \
00306   else if(*((E)) < -1) {                                             \
00307     fprintf(stderr, "%s:%d curl_multi_fdset() succeeded, "           \
00308             "but returned invalid max_fd value (%d)\n",              \
00309             (Y), (Z), (int)*((E)));                                  \
00310     res = TEST_ERR_NUM_HANDLES;                                      \
00311   }                                                                  \
00312 } WHILE_FALSE
00313 
00314 #define res_multi_fdset(A, B, C, D, E) \
00315   exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00316 
00317 #define chk_multi_fdset(A, B, C, D, E, Y, Z) do {       \
00318     exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
00319     if(res)                                             \
00320       goto test_cleanup;                                \
00321   } WHILE_FALSE
00322 
00323 #define multi_fdset(A, B, C, D, E) \
00324   chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00325 
00326 /* ---------------------------------------------------------------- */
00327 
00328 #define exe_multi_timeout(A,B,Y,Z) do {                      \
00329   CURLMcode ec;                                              \
00330   if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) {      \
00331     fprintf(stderr, "%s:%d curl_multi_timeout() failed, "    \
00332             "with code %d (%s)\n",                           \
00333             (Y), (Z), (int)ec, curl_multi_strerror(ec));     \
00334     res = (int)ec;                                           \
00335   }                                                          \
00336   else if(*((B)) < -1L) {                                    \
00337     fprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
00338             "but returned invalid timeout value (%ld)\n",    \
00339             (Y), (Z), (long)*((B)));                         \
00340     res = TEST_ERR_BAD_TIMEOUT;                              \
00341   }                                                          \
00342 } WHILE_FALSE
00343 
00344 #define res_multi_timeout(A, B) \
00345   exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
00346 
00347 #define chk_multi_timeout(A, B, Y, Z) do { \
00348     exe_multi_timeout((A), (B), (Y), (Z)); \
00349     if(res)                                \
00350       goto test_cleanup;                   \
00351   } WHILE_FALSE
00352 
00353 #define multi_timeout(A, B) \
00354   chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
00355 
00356 /* ---------------------------------------------------------------- */
00357 
00358 #define exe_select_test(A, B, C, D, E, Y, Z) do {               \
00359     int ec;                                                     \
00360     if(select_wrapper((A), (B), (C), (D), (E)) == -1) {         \
00361       ec = SOCKERRNO;                                           \
00362       fprintf(stderr, "%s:%d select() failed, with "            \
00363               "errno %d (%s)\n",                                \
00364               (Y), (Z), ec, strerror(ec));                      \
00365       res = TEST_ERR_SELECT;                                    \
00366     }                                                           \
00367   } WHILE_FALSE
00368 
00369 #define res_select_test(A, B, C, D, E) \
00370   exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00371 
00372 #define chk_select_test(A, B, C, D, E, Y, Z) do {       \
00373     exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
00374     if(res)                                             \
00375       goto test_cleanup;                                \
00376   } WHILE_FALSE
00377 
00378 #define select_test(A, B, C, D, E) \
00379   chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00380 
00381 /* ---------------------------------------------------------------- */
00382 
00383 #define start_test_timing() do { \
00384   tv_test_start = tutil_tvnow(); \
00385 } WHILE_FALSE
00386 
00387 #define exe_test_timedout(Y,Z) do {                                    \
00388   if(tutil_tvdiff(tutil_tvnow(), tv_test_start) > TEST_HANG_TIMEOUT) { \
00389     fprintf(stderr, "%s:%d ABORTING TEST, since it seems "             \
00390                     "that it would have run forever.\n", (Y), (Z));    \
00391     res = TEST_ERR_RUNS_FOREVER;                                       \
00392   }                                                                    \
00393 } WHILE_FALSE
00394 
00395 #define res_test_timedout() \
00396   exe_test_timedout((__FILE__), (__LINE__))
00397 
00398 #define chk_test_timedout(Y, Z) do { \
00399     exe_test_timedout(Y, Z);         \
00400     if(res)                          \
00401       goto test_cleanup;             \
00402   } WHILE_FALSE
00403 
00404 #define abort_on_test_timeout() \
00405   chk_test_timedout((__FILE__), (__LINE__))
00406 
00407 /* ---------------------------------------------------------------- */
00408 
00409 #define exe_global_init(A,Y,Z) do {                     \
00410   CURLcode ec;                                          \
00411   if((ec = curl_global_init((A))) != CURLE_OK) {        \
00412     fprintf(stderr, "%s:%d curl_global_init() failed, " \
00413             "with code %d (%s)\n",                      \
00414             (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
00415     res = (int)ec;                                      \
00416   }                                                     \
00417 } WHILE_FALSE
00418 
00419 #define res_global_init(A) \
00420   exe_global_init((A), (__FILE__), (__LINE__))
00421 
00422 #define chk_global_init(A, Y, Z) do { \
00423     exe_global_init((A), (Y), (Z));   \
00424     if(res)                           \
00425       return res;                     \
00426   } WHILE_FALSE
00427 
00428 /* global_init() is different than other macros. In case of
00429    failure it 'return's instead of going to 'test_cleanup'. */
00430 
00431 #define global_init(A) \
00432   chk_global_init((A), (__FILE__), (__LINE__))
00433 
00434 /* ---------------------------------------------------------------- */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06