mirror of
https://github.com/curl/curl.git
synced 2026-08-24 23:43:40 +03:00
tests: merge clients into libtests, drop duplicate code
libtests and clients were built the same way after recent overhauls. libtests are used by runtests, clients by pytests. Merge clients into libtests, aligning their entry function signature, dropping common utility functions, and simplifying the build. Note: After this patch `CURLDEBUG` applies to cli tests, when enabled. Also: - lib552: drop local copy-paste debug callback in favor of testtrace. - lib552: drop local copy-paste dump function in favor of testtrace. - clients: use `long` for HTTP version, drop casts. - clients: replace local dump function in favor of testrace clone. - sync cli test entry function prototype with libtests'. - h2_serverpush: replace local trace callback with testtrace. - de-duplicate 3 websocket close, ping, ping, functions. Kept the pong iteration from `ws_pingpong`. Note: the pong clone in `lib2304` was returning an error when `curl_ws_recv()` returned non-zero and the payload matched the expected one anyway. After this patch, this case returns success, as it does in `ws_pingpong`. `lib2304` keeps passing, but I'm not sure if the previous behavior was intentional. - display full value in websocket close, ping, pong, drop casts. Closes #18079
This commit is contained in:
parent
952c929bdf
commit
00887aee8c
48 changed files with 541 additions and 1041 deletions
|
|
@ -61,6 +61,69 @@ struct curltime tv_test_start; /* for test timing */
|
|||
|
||||
int unitfail; /* for unittests */
|
||||
|
||||
int coptind;
|
||||
const char *coptarg;
|
||||
|
||||
int cgetopt(int argc, const char * const argv[], const char *optstring)
|
||||
{
|
||||
static int optpos = 1;
|
||||
int coptopt;
|
||||
const char *arg;
|
||||
|
||||
if(coptind == 0) { /* Reset? */
|
||||
coptind = !!argc;
|
||||
optpos = 1;
|
||||
}
|
||||
|
||||
arg = argv[coptind];
|
||||
if(arg && strcmp(arg, "--") == 0) {
|
||||
coptind++;
|
||||
return -1;
|
||||
}
|
||||
else if(!arg || arg[0] != '-') {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
const char *opt = strchr(optstring, arg[optpos]);
|
||||
coptopt = arg[optpos];
|
||||
if(!opt) {
|
||||
if(!arg[++optpos]) {
|
||||
coptind++;
|
||||
optpos = 1;
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
else if(opt[1] == ':') {
|
||||
if(arg[optpos + 1]) {
|
||||
coptarg = arg + optpos + 1;
|
||||
coptind++;
|
||||
optpos = 1;
|
||||
return coptopt;
|
||||
}
|
||||
else if(argv[coptind + 1]) {
|
||||
coptarg = argv[coptind + 1];
|
||||
coptind += 2;
|
||||
optpos = 1;
|
||||
return coptopt;
|
||||
}
|
||||
else {
|
||||
if(!arg[++optpos]) {
|
||||
coptind++;
|
||||
optpos = 1;
|
||||
}
|
||||
return *optstring == ':' ? ':' : '?';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!arg[++optpos]) {
|
||||
coptind++;
|
||||
optpos = 1;
|
||||
}
|
||||
return coptopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CURLDEBUG
|
||||
static void memory_tracking_init(void)
|
||||
{
|
||||
|
|
@ -97,10 +160,59 @@ char *hexdump(const unsigned char *buf, size_t len)
|
|||
return dump;
|
||||
}
|
||||
|
||||
#ifndef CURL_DISABLE_WEBSOCKETS
|
||||
CURLcode ws_send_ping(CURL *curl, const char *send_payload)
|
||||
{
|
||||
size_t sent;
|
||||
CURLcode result = curl_ws_send(curl, send_payload, strlen(send_payload),
|
||||
&sent, 0, CURLWS_PING);
|
||||
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %zu\n",
|
||||
result, sent);
|
||||
return result;
|
||||
}
|
||||
|
||||
CURLcode ws_recv_pong(CURL *curl, const char *expected_payload)
|
||||
{
|
||||
size_t rlen;
|
||||
const struct curl_ws_frame *meta;
|
||||
char buffer[256];
|
||||
CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
||||
if(result) {
|
||||
curl_mfprintf(stderr, "ws: curl_ws_recv returned %u, received %zd\n",
|
||||
result, rlen);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(!(meta->flags & CURLWS_PONG)) {
|
||||
curl_mfprintf(stderr, "recv_pong: wrong frame, got %zd bytes rflags %x\n",
|
||||
rlen, meta->flags);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
|
||||
curl_mfprintf(stderr, "ws: got PONG back\n");
|
||||
if(rlen == strlen(expected_payload) &&
|
||||
!memcmp(expected_payload, buffer, rlen)) {
|
||||
curl_mfprintf(stderr, "ws: got the same payload back\n");
|
||||
return CURLE_OK; /* lib2304 returned 'result' here. Intentional? */
|
||||
}
|
||||
curl_mfprintf(stderr, "ws: did NOT get the same payload back\n");
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
|
||||
/* just close the connection */
|
||||
void ws_close(CURL *curl)
|
||||
{
|
||||
size_t sent;
|
||||
CURLcode result = curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE);
|
||||
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %zu\n",
|
||||
result, sent);
|
||||
}
|
||||
#endif /* CURL_DISABLE_WEBSOCKETS */
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
const char *URL;
|
||||
const char *URL = "";
|
||||
CURLcode result;
|
||||
entry_func_t entry_func;
|
||||
const char *entry_name;
|
||||
|
|
@ -126,8 +238,9 @@ int main(int argc, const char **argv)
|
|||
test_argc = argc - 1;
|
||||
test_argv = argv + 1;
|
||||
|
||||
if(argc < 3) {
|
||||
curl_mfprintf(stderr, "Pass testname and URL as arguments please\n");
|
||||
if(argc < 2) {
|
||||
curl_mfprintf(stderr, "Pass testname "
|
||||
"(and URL as argument for numbered tests) please\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +258,11 @@ int main(int argc, const char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if(argc > 2) {
|
||||
URL = argv[2];
|
||||
curl_mfprintf(stderr, "URL: %s\n", URL);
|
||||
}
|
||||
|
||||
if(argc > 3)
|
||||
libtest_arg2 = argv[3];
|
||||
|
||||
|
|
@ -154,16 +272,12 @@ int main(int argc, const char **argv)
|
|||
if(argc > 5)
|
||||
libtest_arg4 = argv[5];
|
||||
|
||||
URL = argv[2]; /* 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 = entry_func(URL);
|
||||
curl_mfprintf(stderr, "Test ended with result %d\n", result);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue