diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-23 20:20:12 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-23 20:20:12 +0000 |
commit | 89060147a1caa97df25dd063a3772d51e4f33162 (patch) | |
tree | f2b07f859fc1a42d41e37488f77328807767b9a0 | |
parent | 61ad888a7be9be0b14e2f3f648ba9b6e6d2808d6 (diff) | |
download | libmicrohttpd-89060147a1caa97df25dd063a3772d51e4f33162.tar.gz libmicrohttpd-89060147a1caa97df25dd063a3772d51e4f33162.zip |
test_concurrent_stop ported to use pthread instead of fork()
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/testcurl/Makefile.am | 7 | ||||
-rw-r--r-- | src/testcurl/test_concurrent_stop.c | 126 |
3 files changed, 77 insertions, 60 deletions
@@ -1,3 +1,7 @@ | |||
1 | Sat Apr 23 20:12:01 CET 2016 | ||
2 | Tests perf_get_concurrent and test_concurrent_stop ported to use | ||
3 | pthread instead of fork(). Added more error detections. -EG | ||
4 | |||
1 | Sat Apr 23 16:06:30 CET 2016 | 5 | Sat Apr 23 16:06:30 CET 2016 |
2 | Improved test_quiesce test. -EG | 6 | Improved test_quiesce test. -EG |
3 | 7 | ||
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am index 510516c3..47ebda5a 100644 --- a/src/testcurl/Makefile.am +++ b/src/testcurl/Makefile.am | |||
@@ -17,7 +17,6 @@ AM_CPPFLAGS = \ | |||
17 | $(LIBCURL_CPPFLAGS) | 17 | $(LIBCURL_CPPFLAGS) |
18 | 18 | ||
19 | if !HAVE_W32 | 19 | if !HAVE_W32 |
20 | TEST_CONCURRENT_STOP=test_concurrent_stop | ||
21 | if HAVE_CURL_BINARY | 20 | if HAVE_CURL_BINARY |
22 | CURL_FORK_TEST = test_get_response_cleanup | 21 | CURL_FORK_TEST = test_get_response_cleanup |
23 | endif | 22 | endif |
@@ -30,7 +29,6 @@ check_PROGRAMS = \ | |||
30 | test_get_sendfile \ | 29 | test_get_sendfile \ |
31 | test_urlparse \ | 30 | test_urlparse \ |
32 | test_put \ | 31 | test_put \ |
33 | $(TEST_CONCURRENT_STOP) \ | ||
34 | test_process_headers \ | 32 | test_process_headers \ |
35 | test_process_arguments \ | 33 | test_process_arguments \ |
36 | test_parse_cookies \ | 34 | test_parse_cookies \ |
@@ -53,6 +51,7 @@ check_PROGRAMS = \ | |||
53 | if HAVE_POSIX_THREADS | 51 | if HAVE_POSIX_THREADS |
54 | check_PROGRAMS += \ | 52 | check_PROGRAMS += \ |
55 | test_quiesce \ | 53 | test_quiesce \ |
54 | test_concurrent_stop \ | ||
56 | perf_get_concurrent | 55 | perf_get_concurrent |
57 | endif | 56 | endif |
58 | 57 | ||
@@ -89,9 +88,11 @@ test_start_stop_LDADD = \ | |||
89 | 88 | ||
90 | test_concurrent_stop_SOURCES = \ | 89 | test_concurrent_stop_SOURCES = \ |
91 | test_concurrent_stop.c | 90 | test_concurrent_stop.c |
91 | test_concurrent_stop_CFLAGS = \ | ||
92 | $(PTHREAD_CFLAGS) $(AM_CFLAGS) | ||
92 | test_concurrent_stop_LDADD = \ | 93 | test_concurrent_stop_LDADD = \ |
93 | $(top_builddir)/src/microhttpd/libmicrohttpd.la \ | 94 | $(top_builddir)/src/microhttpd/libmicrohttpd.la \ |
94 | @LIBCURL@ | 95 | $(PTHREAD_LIBS) @LIBCURL@ |
95 | 96 | ||
96 | test_options_SOURCES = \ | 97 | test_options_SOURCES = \ |
97 | test_options.c | 98 | test_options.c |
diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c index 88839ffd..1420b7c8 100644 --- a/src/testcurl/test_concurrent_stop.c +++ b/src/testcurl/test_concurrent_stop.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <time.h> | 32 | #include <time.h> |
33 | #include <pthread.h> | ||
33 | #include "gauger.h" | 34 | #include "gauger.h" |
34 | 35 | ||
35 | #ifdef CPU_COUNT | 36 | #ifdef CPU_COUNT |
@@ -100,74 +101,85 @@ ahc_echo (void *cls, | |||
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | static pid_t | 104 | static void * |
104 | do_gets (int port) | 105 | thread_gets (void *param) |
105 | { | 106 | { |
106 | pid_t ret; | ||
107 | CURL *c; | 107 | CURL *c; |
108 | CURLcode errornum; | 108 | CURLcode errornum; |
109 | unsigned int i; | 109 | unsigned int i; |
110 | char * const url = (char*) param; | ||
111 | |||
112 | for (i=0;i<ROUNDS;i++) | ||
113 | { | ||
114 | c = curl_easy_init (); | ||
115 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
116 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
117 | curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); | ||
118 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
119 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
120 | if (oneone) | ||
121 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
122 | else | ||
123 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
124 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
125 | /* NOTE: use of CONNECTTIMEOUT without also | ||
126 | setting NOSIGNAL results in really weird | ||
127 | crashes on my system! */ | ||
128 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
129 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
130 | { | ||
131 | curl_easy_cleanup (c); | ||
132 | return NULL; | ||
133 | } | ||
134 | curl_easy_cleanup (c); | ||
135 | } | ||
136 | |||
137 | return NULL; | ||
138 | } | ||
139 | |||
140 | #ifndef SIGKILL | ||
141 | #define SIGKILL SIGTERM | ||
142 | #endif /* ! SIGKILL */ | ||
143 | |||
144 | static void * | ||
145 | do_gets (void * param) | ||
146 | { | ||
110 | unsigned int j; | 147 | unsigned int j; |
111 | pid_t par[PAR]; | 148 | pthread_t par[PAR]; |
112 | char url[64]; | 149 | char url[64]; |
150 | int port = (int)(intptr_t)param; | ||
113 | 151 | ||
114 | sprintf(url, "http://127.0.0.1:%d/hello_world", port); | 152 | sprintf(url, "http://127.0.0.1:%d/hello_world", port); |
115 | 153 | ||
116 | ret = fork (); | ||
117 | if (ret == -1) abort (); | ||
118 | if (ret != 0) | ||
119 | return ret; | ||
120 | for (j=0;j<PAR;j++) | 154 | for (j=0;j<PAR;j++) |
121 | { | 155 | { |
122 | par[j] = fork (); | 156 | if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) |
123 | if (par[j] == 0) | 157 | { |
124 | { | 158 | for (j--; j >= 0; j--) |
125 | for (i=0;i<ROUNDS;i++) | 159 | pthread_join(par[j], NULL); |
126 | { | 160 | |
127 | c = curl_easy_init (); | 161 | fprintf(stderr, "pthread_create failed.\n"); |
128 | curl_easy_setopt (c, CURLOPT_URL, url); | 162 | _exit(99); |
129 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 163 | } |
130 | curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); | ||
131 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
132 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
133 | if (oneone) | ||
134 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
135 | else | ||
136 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
137 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
138 | /* NOTE: use of CONNECTTIMEOUT without also | ||
139 | setting NOSIGNAL results in really weird | ||
140 | crashes on my system! */ | ||
141 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
142 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
143 | { | ||
144 | curl_easy_cleanup (c); | ||
145 | _exit (1); | ||
146 | } | ||
147 | curl_easy_cleanup (c); | ||
148 | } | ||
149 | _exit (0); | ||
150 | } | ||
151 | } | 164 | } |
152 | sleep (1); | ||
153 | for (j=0;j<PAR;j++) | 165 | for (j=0;j<PAR;j++) |
154 | { | 166 | { |
155 | kill (par[j], SIGKILL); | 167 | pthread_kill(par[j], SIGKILL); |
156 | waitpid (par[j], NULL, 0); | 168 | pthread_join(par[j], NULL); |
157 | } | 169 | } |
158 | _exit (0); | 170 | return NULL; |
159 | } | 171 | } |
160 | 172 | ||
161 | 173 | ||
162 | static void | 174 | pthread_t start_gets(int port) |
163 | join_gets (pid_t pid) | ||
164 | { | 175 | { |
165 | int status; | 176 | pthread_t tid; |
166 | 177 | if (0 != pthread_create(&tid, NULL, &do_gets, (void*)(intptr_t)port)) | |
167 | status = 1; | 178 | { |
168 | waitpid (pid, &status, 0); | 179 | fprintf(stderr, "pthread_create failed.\n"); |
169 | if (0 != status) | 180 | _exit(99); |
170 | abort (); | 181 | } |
182 | return tid; | ||
171 | } | 183 | } |
172 | 184 | ||
173 | 185 | ||
@@ -176,7 +188,7 @@ testMultithreadedGet (int port, | |||
176 | int poll_flag) | 188 | int poll_flag) |
177 | { | 189 | { |
178 | struct MHD_Daemon *d; | 190 | struct MHD_Daemon *d; |
179 | pid_t p; | 191 | pthread_t p; |
180 | 192 | ||
181 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, | 193 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, |
182 | port, | 194 | port, |
@@ -185,10 +197,10 @@ testMultithreadedGet (int port, | |||
185 | MHD_OPTION_END); | 197 | MHD_OPTION_END); |
186 | if (d == NULL) | 198 | if (d == NULL) |
187 | return 16; | 199 | return 16; |
188 | p = do_gets (port); | 200 | p = start_gets (port); |
189 | sleep (1); | 201 | sleep (1); |
190 | MHD_stop_daemon (d); | 202 | MHD_stop_daemon (d); |
191 | join_gets (p); | 203 | pthread_join (p, NULL); |
192 | return 0; | 204 | return 0; |
193 | } | 205 | } |
194 | 206 | ||
@@ -198,7 +210,7 @@ testMultithreadedPoolGet (int port, | |||
198 | int poll_flag) | 210 | int poll_flag) |
199 | { | 211 | { |
200 | struct MHD_Daemon *d; | 212 | struct MHD_Daemon *d; |
201 | pid_t p; | 213 | pthread_t p; |
202 | 214 | ||
203 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, | 215 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, |
204 | port, | 216 | port, |
@@ -208,10 +220,10 @@ testMultithreadedPoolGet (int port, | |||
208 | MHD_OPTION_END); | 220 | MHD_OPTION_END); |
209 | if (d == NULL) | 221 | if (d == NULL) |
210 | return 16; | 222 | return 16; |
211 | p = do_gets (port); | 223 | p = start_gets (port); |
212 | sleep (1); | 224 | sleep (1); |
213 | MHD_stop_daemon (d); | 225 | MHD_stop_daemon (d); |
214 | join_gets (p); | 226 | pthread_join (p, NULL); |
215 | return 0; | 227 | return 0; |
216 | } | 228 | } |
217 | 229 | ||