xref: /curl/tests/libtest/lib573.c (revision 25cbc2f7)
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 "testtrace.h"
27 #include "testutil.h"
28 #include "warnless.h"
29 #include "memdebug.h"
30 
31 #define TEST_HANG_TIMEOUT 60 * 1000
32 
33 /*
34  * Get a single URL without select().
35  */
36 
test(char * URL)37 CURLcode test(char *URL)
38 {
39   CURL *c = NULL;
40   CURLM *m = NULL;
41   CURLcode res = CURLE_OK;
42   int running = 1;
43   double connect_time = 0.0;
44   double dbl_epsilon;
45 
46   dbl_epsilon = 1.0;
47   do {
48     dbl_epsilon /= 2.0;
49   } while((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0);
50 
51   start_test_timing();
52 
53   global_init(CURL_GLOBAL_ALL);
54 
55   easy_init(c);
56 
57   easy_setopt(c, CURLOPT_HEADER, 1L);
58   easy_setopt(c, CURLOPT_URL, URL);
59 
60   libtest_debug_config.nohex = 1;
61   libtest_debug_config.tracetime = 1;
62   easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config);
63   easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
64   easy_setopt(c, CURLOPT_VERBOSE, 1L);
65 
66   multi_init(m);
67 
68   multi_add_handle(m, c);
69 
70   while(running) {
71     struct timeval timeout;
72     fd_set fdread, fdwrite, fdexcep;
73     int maxfd = -99;
74 
75     timeout.tv_sec = 0;
76     timeout.tv_usec = 100000L; /* 100 ms */
77 
78     multi_perform(m, &running);
79 
80     abort_on_test_timeout();
81 
82     if(!running)
83       break; /* done */
84 
85     FD_ZERO(&fdread);
86     FD_ZERO(&fdwrite);
87     FD_ZERO(&fdexcep);
88 
89     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
90 
91     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
92 
93     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
94 
95     abort_on_test_timeout();
96   }
97 
98   curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
99   if(connect_time < dbl_epsilon) {
100     fprintf(stderr, "connect time %e is < epsilon %e\n",
101             connect_time, dbl_epsilon);
102     res = TEST_ERR_MAJOR_BAD;
103   }
104 
105 test_cleanup:
106 
107   /* proper cleanup sequence - type PA */
108 
109   curl_multi_remove_handle(m, c);
110   curl_multi_cleanup(m);
111   curl_easy_cleanup(c);
112   curl_global_cleanup();
113 
114   return res;
115 }
116