test_concurrent_stop ported to use pthread instead of fork()

This commit is contained in:
Evgeny Grin (Karlson2k)
2016-04-23 20:20:12 +00:00
parent 61ad888a7b
commit 89060147a1
3 changed files with 77 additions and 60 deletions
+4
View File
@@ -1,3 +1,7 @@
Sat Apr 23 20:12:01 CET 2016
Tests perf_get_concurrent and test_concurrent_stop ported to use
pthread instead of fork(). Added more error detections. -EG
Sat Apr 23 16:06:30 CET 2016
Improved test_quiesce test. -EG
+4 -3
View File
@@ -17,7 +17,6 @@ AM_CPPFLAGS = \
$(LIBCURL_CPPFLAGS)
if !HAVE_W32
TEST_CONCURRENT_STOP=test_concurrent_stop
if HAVE_CURL_BINARY
CURL_FORK_TEST = test_get_response_cleanup
endif
@@ -30,7 +29,6 @@ check_PROGRAMS = \
test_get_sendfile \
test_urlparse \
test_put \
$(TEST_CONCURRENT_STOP) \
test_process_headers \
test_process_arguments \
test_parse_cookies \
@@ -53,6 +51,7 @@ check_PROGRAMS = \
if HAVE_POSIX_THREADS
check_PROGRAMS += \
test_quiesce \
test_concurrent_stop \
perf_get_concurrent
endif
@@ -89,9 +88,11 @@ test_start_stop_LDADD = \
test_concurrent_stop_SOURCES = \
test_concurrent_stop.c
test_concurrent_stop_CFLAGS = \
$(PTHREAD_CFLAGS) $(AM_CFLAGS)
test_concurrent_stop_LDADD = \
$(top_builddir)/src/microhttpd/libmicrohttpd.la \
@LIBCURL@
$(PTHREAD_LIBS) @LIBCURL@
test_options_SOURCES = \
test_options.c
+69 -57
View File
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include "gauger.h"
#ifdef CPU_COUNT
@@ -100,74 +101,85 @@ ahc_echo (void *cls,
}
static pid_t
do_gets (int port)
static void *
thread_gets (void *param)
{
pid_t ret;
CURL *c;
CURLcode errornum;
unsigned int i;
char * const url = (char*) param;
for (i=0;i<ROUNDS;i++)
{
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
setting NOSIGNAL results in really weird
crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
if (CURLE_OK != (errornum = curl_easy_perform (c)))
{
curl_easy_cleanup (c);
return NULL;
}
curl_easy_cleanup (c);
}
return NULL;
}
#ifndef SIGKILL
#define SIGKILL SIGTERM
#endif /* ! SIGKILL */
static void *
do_gets (void * param)
{
unsigned int j;
pid_t par[PAR];
pthread_t par[PAR];
char url[64];
int port = (int)(intptr_t)param;
sprintf(url, "http://127.0.0.1:%d/hello_world", port);
ret = fork ();
if (ret == -1) abort ();
if (ret != 0)
return ret;
for (j=0;j<PAR;j++)
{
par[j] = fork ();
if (par[j] == 0)
{
for (i=0;i<ROUNDS;i++)
{
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
setting NOSIGNAL results in really weird
crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
if (CURLE_OK != (errornum = curl_easy_perform (c)))
{
curl_easy_cleanup (c);
_exit (1);
}
curl_easy_cleanup (c);
}
_exit (0);
}
if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url))
{
for (j--; j >= 0; j--)
pthread_join(par[j], NULL);
fprintf(stderr, "pthread_create failed.\n");
_exit(99);
}
}
sleep (1);
for (j=0;j<PAR;j++)
{
kill (par[j], SIGKILL);
waitpid (par[j], NULL, 0);
}
_exit (0);
{
pthread_kill(par[j], SIGKILL);
pthread_join(par[j], NULL);
}
return NULL;
}
static void
join_gets (pid_t pid)
pthread_t start_gets(int port)
{
int status;
status = 1;
waitpid (pid, &status, 0);
if (0 != status)
abort ();
pthread_t tid;
if (0 != pthread_create(&tid, NULL, &do_gets, (void*)(intptr_t)port))
{
fprintf(stderr, "pthread_create failed.\n");
_exit(99);
}
return tid;
}
@@ -176,7 +188,7 @@ testMultithreadedGet (int port,
int poll_flag)
{
struct MHD_Daemon *d;
pid_t p;
pthread_t p;
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag,
port,
@@ -185,10 +197,10 @@ testMultithreadedGet (int port,
MHD_OPTION_END);
if (d == NULL)
return 16;
p = do_gets (port);
p = start_gets (port);
sleep (1);
MHD_stop_daemon (d);
join_gets (p);
pthread_join (p, NULL);
return 0;
}
@@ -198,7 +210,7 @@ testMultithreadedPoolGet (int port,
int poll_flag)
{
struct MHD_Daemon *d;
pid_t p;
pthread_t p;
d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
port,
@@ -208,10 +220,10 @@ testMultithreadedPoolGet (int port,
MHD_OPTION_END);
if (d == NULL)
return 16;
p = do_gets (port);
p = start_gets (port);
sleep (1);
MHD_stop_daemon (d);
join_gets (p);
pthread_join (p, NULL);
return 0;
}