xref: /curl/tests/libtest/lib1510.c (revision 25cbc2f7)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
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 "warnless.h"
28 #include "memdebug.h"
29 
30 #define TEST_HANG_TIMEOUT 60 * 1000
31 
32 #define NUM_URLS 4
33 
test(char * URL)34 CURLcode test(char *URL)
35 {
36   CURLcode res = CURLE_OK;
37   CURL *curl = NULL;
38   int i;
39   char target_url[256];
40   char dnsentry[256];
41   struct curl_slist *slist = NULL, *slist2;
42   char *port = libtest_arg3;
43   char *address = libtest_arg2;
44 
45   (void)URL;
46 
47   /* Create fake DNS entries for serverX.example.com for all handles */
48   for(i = 0; i < NUM_URLS; i++) {
49     msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1,
50               port, address);
51     printf("%s\n", dnsentry);
52     slist2 = curl_slist_append(slist, dnsentry);
53     if(!slist2) {
54       fprintf(stderr, "curl_slist_append() failed\n");
55       goto test_cleanup;
56     }
57     slist = slist2;
58   }
59 
60   start_test_timing();
61 
62   global_init(CURL_GLOBAL_ALL);
63 
64   /* get an easy handle */
65   easy_init(curl);
66 
67   /* go verbose */
68   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
69   /* include headers */
70   easy_setopt(curl, CURLOPT_HEADER, 1L);
71 
72   easy_setopt(curl, CURLOPT_RESOLVE, slist);
73 
74   easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
75 
76   /* get NUM_HANDLES easy handles */
77   for(i = 0; i < NUM_URLS; i++) {
78     /* specify target */
79     msnprintf(target_url, sizeof(target_url),
80               "http://server%d.example.com:%s/path/1510%04i",
81               i + 1, port, i + 1);
82     target_url[sizeof(target_url) - 1] = '\0';
83     easy_setopt(curl, CURLOPT_URL, target_url);
84 
85     res = curl_easy_perform(curl);
86     if(res)
87       goto test_cleanup;
88 
89     abort_on_test_timeout();
90   }
91 
92 test_cleanup:
93 
94   /* proper cleanup sequence - type PB */
95 
96   curl_easy_cleanup(curl);
97 
98   curl_slist_free_all(slist);
99 
100   curl_global_cleanup();
101 
102   return res;
103 }
104