lib1564.c (3607B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 #define WAKEUP_NUM 10 29 30 static CURLcode test_lib1564(char *URL) 31 { 32 CURLM *multi = NULL; 33 int numfds; 34 int i; 35 CURLcode res = CURLE_OK; 36 struct curltime time_before_wait, time_after_wait; 37 38 (void)URL; 39 40 start_test_timing(); 41 42 global_init(CURL_GLOBAL_ALL); 43 44 multi_init(multi); 45 46 /* no wakeup */ 47 48 time_before_wait = curlx_now(); 49 multi_poll(multi, NULL, 0, 1000, &numfds); 50 time_after_wait = curlx_now(); 51 52 if(curlx_timediff(time_after_wait, time_before_wait) < 500) { 53 curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n", 54 __FILE__, __LINE__); 55 res = TEST_ERR_MAJOR_BAD; 56 goto test_cleanup; 57 } 58 59 abort_on_test_timeout(); 60 61 /* try a single wakeup */ 62 63 res_multi_wakeup(multi); 64 65 time_before_wait = curlx_now(); 66 multi_poll(multi, NULL, 0, 1000, &numfds); 67 time_after_wait = curlx_now(); 68 69 if(curlx_timediff(time_after_wait, time_before_wait) > 500) { 70 curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n", 71 __FILE__, __LINE__); 72 res = TEST_ERR_MAJOR_BAD; 73 goto test_cleanup; 74 } 75 76 abort_on_test_timeout(); 77 78 /* previous wakeup should not wake up this */ 79 80 time_before_wait = curlx_now(); 81 multi_poll(multi, NULL, 0, 1000, &numfds); 82 time_after_wait = curlx_now(); 83 84 if(curlx_timediff(time_after_wait, time_before_wait) < 500) { 85 curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n", 86 __FILE__, __LINE__); 87 res = TEST_ERR_MAJOR_BAD; 88 goto test_cleanup; 89 } 90 91 abort_on_test_timeout(); 92 93 /* try lots of wakeup */ 94 95 for(i = 0; i < WAKEUP_NUM; ++i) 96 res_multi_wakeup(multi); 97 98 time_before_wait = curlx_now(); 99 multi_poll(multi, NULL, 0, 1000, &numfds); 100 time_after_wait = curlx_now(); 101 102 if(curlx_timediff(time_after_wait, time_before_wait) > 500) { 103 curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n", 104 __FILE__, __LINE__); 105 res = TEST_ERR_MAJOR_BAD; 106 goto test_cleanup; 107 } 108 109 abort_on_test_timeout(); 110 111 /* Even lots of previous wakeups should not wake up this. */ 112 113 time_before_wait = curlx_now(); 114 multi_poll(multi, NULL, 0, 1000, &numfds); 115 time_after_wait = curlx_now(); 116 117 if(curlx_timediff(time_after_wait, time_before_wait) < 500) { 118 curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n", 119 __FILE__, __LINE__); 120 res = TEST_ERR_MAJOR_BAD; 121 goto test_cleanup; 122 } 123 124 abort_on_test_timeout(); 125 126 test_cleanup: 127 128 curl_multi_cleanup(multi); 129 curl_global_cleanup(); 130 131 return res; 132 }