mirror of
https://github.com/curl/curl.git
synced 2026-04-13 12:41:42 +08:00
Make test bundles the default. Drop non-bundle build mode.
Also do all the optimizations and tidy-ups this allows, simpler builds,
less bundle exceptions, streamlined build mechanics.
Also rework the init/deinit macro magic for unit tests. The new method
allows using unique init/deinit function names, and calling them with
arguments. This is in turn makes it possible to reduce the use of global
variables.
Note this drop existing build options `-DCURL_TEST_BUNDLES=` from cmake
and `--enable-test-bundles` / `--disable-test-bundles` from autotools.
Also:
- rename test entry functions to have unique names: `test_<testname>`
This removes the last exception that was handled in the generator.
- fix `make dist` to not miss test sources with test bundles enabled.
- sync and merge `tests/mk-bundle.pl` into `scripts/mk-unity.pl`.
- mk-unity.pl: add `--embed` option and use it when `CURL_CLANG_TIDY=ON`
to ensure that `clang-tidy` does not miss external test C sources.
(because `clang-tidy` ignores code that's #included.)
- tests/unit: drop no-op setup/stop functions.
- tests: reduce symbol scopes, global macros, other fixes and tidy-ups.
- tool1621: fix to run, also fix it to pass.
- sockfilt: fix Windows compiler warning in certain unity include order,
by explicitly including `warnless.h`.
Follow-up to 6897aeb105 #17468
Closes #17590
153 lines
4.3 KiB
C
153 lines
4.3 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* 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
|
|
*
|
|
***************************************************************************/
|
|
#include "test.h"
|
|
|
|
#include "testutil.h"
|
|
#include "timediff.h"
|
|
#include "warnless.h"
|
|
#include "memdebug.h"
|
|
|
|
/*
|
|
* This is the list of basic details you need to tweak to get things right.
|
|
*/
|
|
#define USERNAME "user@example.com"
|
|
#define PASSWORD "123qwerty"
|
|
#define RECIPIENT "<1507-recipient@example.com>"
|
|
#define MAILFROM "<1507-realuser@example.com>"
|
|
|
|
static size_t t1507_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
|
|
{
|
|
(void)ptr;
|
|
(void)size;
|
|
(void)nmemb;
|
|
(void)userp;
|
|
return CURL_READFUNC_ABORT;
|
|
}
|
|
|
|
static CURLcode test_lib1507(char *URL)
|
|
{
|
|
static const int MULTI_PERFORM_HANG_TIMEOUT = 60 * 1000;
|
|
|
|
CURLcode res = CURLE_OK;
|
|
CURL *curl = NULL;
|
|
CURLM *mcurl = NULL;
|
|
int still_running = 1;
|
|
struct timeval mp_start;
|
|
struct curl_slist *rcpt_list = NULL;
|
|
|
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
|
|
|
easy_init(curl);
|
|
|
|
multi_init(mcurl);
|
|
|
|
rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
|
|
/* more addresses can be added here
|
|
rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
|
|
*/
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, URL);
|
|
#if 0
|
|
curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
|
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
|
|
#endif
|
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
|
curl_easy_setopt(curl, CURLOPT_READFUNCTION, t1507_read_cb);
|
|
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM);
|
|
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
multi_add_handle(mcurl, curl);
|
|
|
|
mp_start = tutil_tvnow();
|
|
|
|
/* we start some action by calling perform right away */
|
|
curl_multi_perform(mcurl, &still_running);
|
|
|
|
while(still_running) {
|
|
struct timeval timeout;
|
|
int rc; /* select() return code */
|
|
|
|
fd_set fdread;
|
|
fd_set fdwrite;
|
|
fd_set fdexcep;
|
|
int maxfd = -1;
|
|
|
|
long curl_timeo = -1;
|
|
|
|
FD_ZERO(&fdread);
|
|
FD_ZERO(&fdwrite);
|
|
FD_ZERO(&fdexcep);
|
|
|
|
/* set a suitable timeout to play around with */
|
|
timeout.tv_sec = 1;
|
|
timeout.tv_usec = 0;
|
|
|
|
curl_multi_timeout(mcurl, &curl_timeo);
|
|
if(curl_timeo >= 0) {
|
|
curlx_mstotv(&timeout, curl_timeo);
|
|
if(timeout.tv_sec > 1) {
|
|
timeout.tv_sec = 1;
|
|
timeout.tv_usec = 0;
|
|
}
|
|
}
|
|
|
|
/* get file descriptors from the transfers */
|
|
curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
|
|
|
|
/* In a real-world program you OF COURSE check the return code of the
|
|
function calls. On success, the value of maxfd is guaranteed to be
|
|
greater or equal than -1. We call select(maxfd + 1, ...), specially in
|
|
case of (maxfd == -1), we call select(0, ...), which is basically equal
|
|
to sleep. */
|
|
|
|
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
|
|
|
|
if(tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
|
|
curl_mfprintf(stderr, "ABORTING TEST, since it seems "
|
|
"that it would have run forever.\n");
|
|
break;
|
|
}
|
|
|
|
switch(rc) {
|
|
case -1:
|
|
/* select error */
|
|
break;
|
|
case 0: /* timeout */
|
|
default: /* action */
|
|
curl_multi_perform(mcurl, &still_running);
|
|
break;
|
|
}
|
|
}
|
|
|
|
test_cleanup:
|
|
|
|
curl_slist_free_all(rcpt_list);
|
|
curl_multi_remove_handle(mcurl, curl);
|
|
curl_multi_cleanup(mcurl);
|
|
curl_easy_cleanup(curl);
|
|
curl_global_cleanup();
|
|
|
|
return res;
|
|
}
|