1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24 #include "test.h"
25
26 #include "testutil.h"
27 #include "testtrace.h"
28 #include "warnless.h"
29 #include "memdebug.h"
30
31 #define TEST_HANG_TIMEOUT 60 * 1000
32
xferinfo(void * p,curl_off_t dltotal,curl_off_t dlnow,curl_off_t ultotal,curl_off_t ulnow)33 static int xferinfo(void *p,
34 curl_off_t dltotal, curl_off_t dlnow,
35 curl_off_t ultotal, curl_off_t ulnow)
36 {
37 (void)p;
38 (void)dlnow;
39 (void)dltotal;
40 (void)ulnow;
41 (void)ultotal;
42 fprintf(stderr, "xferinfo fail!\n");
43 return 1; /* fail as fast as we can */
44 }
45
test(char * URL)46 CURLcode test(char *URL)
47 {
48 CURL *curls = NULL;
49 CURLM *multi = NULL;
50 int still_running;
51 CURLcode i = CURLE_OK;
52 CURLcode res = CURLE_OK;
53 curl_mimepart *field = NULL;
54 curl_mime *mime = NULL;
55 int counter = 1;
56
57 start_test_timing();
58
59 global_init(CURL_GLOBAL_ALL);
60
61 multi_init(multi);
62
63 easy_init(curls);
64
65 mime = curl_mime_init(curls);
66 field = curl_mime_addpart(mime);
67 curl_mime_name(field, "name");
68 curl_mime_data(field, "value", CURL_ZERO_TERMINATED);
69
70 easy_setopt(curls, CURLOPT_URL, URL);
71 easy_setopt(curls, CURLOPT_HEADER, 1L);
72 easy_setopt(curls, CURLOPT_VERBOSE, 1L);
73 easy_setopt(curls, CURLOPT_MIMEPOST, mime);
74 easy_setopt(curls, CURLOPT_USERPWD, "u:s");
75 easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo);
76 easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);
77
78 libtest_debug_config.nohex = 1;
79 libtest_debug_config.tracetime = 1;
80 test_setopt(curls, CURLOPT_DEBUGDATA, &libtest_debug_config);
81 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
82 easy_setopt(curls, CURLOPT_VERBOSE, 1L);
83
84 multi_add_handle(multi, curls);
85
86 multi_perform(multi, &still_running);
87
88 abort_on_test_timeout();
89
90 while(still_running && counter--) {
91 CURLMcode mres;
92 int num;
93 mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
94 if(mres != CURLM_OK) {
95 printf("curl_multi_wait() returned %d\n", mres);
96 res = TEST_ERR_MAJOR_BAD;
97 goto test_cleanup;
98 }
99
100 abort_on_test_timeout();
101
102 multi_perform(multi, &still_running);
103
104 abort_on_test_timeout();
105 }
106
107 test_cleanup:
108
109 curl_mime_free(mime);
110 curl_multi_remove_handle(multi, curls);
111 curl_multi_cleanup(multi);
112 curl_easy_cleanup(curls);
113 curl_global_cleanup();
114
115 if(res)
116 i = res;
117
118 return i; /* return the final return code */
119 }
120