aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/https/test_https_get_parallel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/https/test_https_get_parallel.c')
-rw-r--r--src/testcurl/https/test_https_get_parallel.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c
new file mode 100644
index 00000000..4a9dd9dc
--- /dev/null
+++ b/src/testcurl/https/test_https_get_parallel.c
@@ -0,0 +1,162 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff
4
5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file tls_thread_mode_test.c
23 * @brief Testcase for libmicrohttpd HTTPS GET operations
24 * @author Sagie Amir
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "microhttpd.h"
30#include <sys/stat.h>
31#include <limits.h>
32#include <curl/curl.h>
33#include <gcrypt.h>
34#include "tls_test_common.h"
35
36extern const char srv_key_pem[];
37extern const char srv_self_signed_cert_pem[];
38
39int curl_check_version (const char *req_version, ...);
40
41/**
42 * used when spawning multiple threads executing curl server requests
43 *
44 */
45static void *
46https_transfer_thread_adapter (void *args)
47{
48 static int nonnull;
49 struct https_test_data *cargs = args;
50 int ret;
51
52 /* time spread incomming requests */
53 usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
54 ret = test_https_transfer (NULL,
55 cargs->cipher_suite, cargs->proto_version);
56 if (ret == 0)
57 return NULL;
58 return &nonnull;
59}
60
61/**
62 * Test non-parallel requests.
63 *
64 * @return: 0 upon all client requests returning '0', -1 otherwise.
65 *
66 * TODO : make client_count a parameter - number of curl client threads to spawn
67 */
68static int
69test_single_client (void *cls, const char *cipher_suite,
70 int curl_proto_version)
71{
72 void *client_thread_ret;
73 struct https_test_data client_args =
74 { NULL, cipher_suite, curl_proto_version };
75
76 client_thread_ret = https_transfer_thread_adapter (&client_args);
77 if (client_thread_ret != NULL)
78 return -1;
79 return 0;
80}
81
82/**
83 * Test parallel request handling.
84 *
85 * @return: 0 upon all client requests returning '0', -1 otherwise.
86 *
87 * TODO : make client_count a parameter - numver of curl client threads to spawn
88 */
89static int
90test_parallel_clients (void * cls, const char *cipher_suite,
91 int curl_proto_version)
92{
93 int i;
94 int client_count = 3;
95 void *client_thread_ret;
96 pthread_t client_arr[client_count];
97 struct https_test_data client_args =
98 { NULL, cipher_suite, curl_proto_version };
99
100 for (i = 0; i < client_count; ++i)
101 {
102 if (pthread_create (&client_arr[i], NULL,
103 &https_transfer_thread_adapter, &client_args) != 0)
104 {
105 fprintf (stderr, "Error: failed to spawn test client threads.\n");
106 return -1;
107 }
108 }
109
110 /* check all client requests fulfilled correctly */
111 for (i = 0; i < client_count; ++i)
112 {
113 if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
114 (client_thread_ret != NULL))
115 return -1;
116 }
117
118 return 0;
119}
120
121GCRY_THREAD_OPTION_PTHREAD_IMPL;
122
123int
124main (int argc, char *const *argv)
125{
126 unsigned int errorCount = 0;
127
128 /* initialize random seed used by curl clients */
129 unsigned int iseed = (unsigned int) time (NULL);
130 srand (iseed);
131 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
132 if (0 != curl_global_init (CURL_GLOBAL_ALL))
133 {
134 fprintf (stderr, "Error: %s\n", strerror (errno));
135 return -1;
136 }
137
138 char *aes256_sha = "AES256-SHA";
139 if (curl_uses_nss_ssl() == 0)
140 {
141 aes256_sha = "rsa_aes_256_sha";
142 }
143
144 errorCount +=
145 test_wrap ("single threaded daemon, single client", &test_single_client,
146 NULL,
147 MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
148 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
149 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
150 srv_self_signed_cert_pem, MHD_OPTION_END);
151
152 errorCount +=
153 test_wrap ("single threaded daemon, parallel clients",
154 &test_parallel_clients, NULL,
155 MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
156 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
157 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
158 srv_self_signed_cert_pem, MHD_OPTION_END);
159
160 curl_global_cleanup ();
161 return errorCount != 0;
162}