gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] branch master updated: Make testsuite paral


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated: Make testsuite parallel build compatible (part 2)
Date: Sun, 25 Jun 2017 19:33:40 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new 9d1596d3 Make testsuite parallel build compatible (part 2)
9d1596d3 is described below

commit 9d1596d3108ff237dbe368942296a0f6fbba47f8
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Jun 25 20:33:19 2017 +0300

    Make testsuite parallel build compatible (part 2)
---
 src/testcurl/https/test_empty_response.c           | 19 ++++++++--
 src/testcurl/https/test_https_get.c                | 36 ++++++++++++++++---
 src/testcurl/https/test_https_get_parallel.c       | 24 ++++++++-----
 .../https/test_https_get_parallel_threads.c        | 20 +++++++----
 src/testcurl/https/test_https_get_select.c         | 19 ++++++++--
 src/testcurl/https/test_https_multi_daemon.c       | 40 ++++++++++++++++++----
 src/testcurl/https/test_https_session_info.c       | 25 +++++++++++---
 src/testcurl/https/test_https_sni.c                | 30 ++++++++++++----
 src/testcurl/https/test_https_time_out.c           | 21 +++++++++---
 src/testcurl/https/test_tls_authentication.c       | 18 ++++++++--
 src/testcurl/https/test_tls_extensions.c           | 32 ++++++++++++-----
 src/testcurl/https/test_tls_options.c              | 14 +++++---
 src/testcurl/https/tls_test_common.c               | 34 ++++++++++++------
 src/testcurl/https/tls_test_common.h               | 12 +++----
 src/testcurl/test_options.c                        |  6 ++--
 15 files changed, 271 insertions(+), 79 deletions(-)

diff --git a/src/testcurl/https/test_empty_response.c 
b/src/testcurl/https/test_empty_response.c
index 44ca08a4..70baf832 100644
--- a/src/testcurl/https/test_empty_response.c
+++ b/src/testcurl/https/test_empty_response.c
@@ -77,19 +77,33 @@ testInternalSelectGet ()
   struct CURLMsg *msg;
   time_t start;
   struct timeval tv;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3000;
 
   multi = NULL;
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS | 
MHD_USE_INTERNAL_POLLING_THREAD,
-                        1082, NULL, NULL, &ahc_echo, "GET",
+                        port, NULL, NULL, &ahc_echo, "GET",
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);
   if (d == NULL)
     return 256;
 
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return 32; }
+      port = (int)dinfo->port;
+    }
   char *aes256_sha = "AES256-SHA";
   if (curl_uses_nss_ssl() == 0)
     {
@@ -97,7 +111,8 @@ testInternalSelectGet ()
     }
 
   c = curl_easy_init ();
-  curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1:1082/hello_world";);
+  curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world";);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   /* TLS options */
diff --git a/src/testcurl/https/test_https_get.c 
b/src/testcurl/https/test_https_get.c
index b8cfacbe..dfbf5dbc 100644
--- a/src/testcurl/https/test_https_get.c
+++ b/src/testcurl/https/test_https_get.c
@@ -47,9 +47,15 @@ test_cipher_option (FILE * test_fd,
 {
   int ret;
   struct MHD_Daemon *d;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3040;
 
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, 4233,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &http_ahc, NULL,
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
@@ -60,8 +66,16 @@ test_cipher_option (FILE * test_fd,
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
 
-  ret = test_https_transfer (test_fd, cipher_suite, proto_version);
+  ret = test_https_transfer (test_fd, port, cipher_suite, proto_version);
 
   MHD_stop_daemon (d);
   return ret;
@@ -76,9 +90,15 @@ test_secure_get (FILE * test_fd,
 {
   int ret;
   struct MHD_Daemon *d;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3041;
 
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, 4233,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &http_ahc, NULL,
                         MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
@@ -89,8 +109,16 @@ test_secure_get (FILE * test_fd,
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
 
-  ret = test_https_transfer (test_fd, cipher_suite, proto_version);
+  ret = test_https_transfer (test_fd, port, cipher_suite, proto_version);
 
   MHD_stop_daemon (d);
   return ret;
diff --git a/src/testcurl/https/test_https_get_parallel.c 
b/src/testcurl/https/test_https_get_parallel.c
index 96529c43..89fd6a05 100644
--- a/src/testcurl/https/test_https_get_parallel.c
+++ b/src/testcurl/https/test_https_get_parallel.c
@@ -62,7 +62,7 @@ https_transfer_thread_adapter (void *args)
 
   /* time spread incomming requests */
   usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
-  ret = test_https_transfer (NULL,
+  ret = test_https_transfer (NULL, cargs->port,
                              cargs->cipher_suite, cargs->proto_version);
   if (ret == 0)
     return NULL;
@@ -78,12 +78,12 @@ https_transfer_thread_adapter (void *args)
  * TODO : make client_count a parameter - number of curl client threads to 
spawn
  */
 static int
-test_single_client (void *cls, const char *cipher_suite,
+test_single_client (void *cls, int port, const char *cipher_suite,
                     int curl_proto_version)
 {
   void *client_thread_ret;
   struct https_test_data client_args =
-    { NULL, cipher_suite, curl_proto_version };
+    { NULL, port, cipher_suite, curl_proto_version };
 
   client_thread_ret = https_transfer_thread_adapter (&client_args);
   if (client_thread_ret != NULL)
@@ -100,7 +100,7 @@ test_single_client (void *cls, const char *cipher_suite,
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_parallel_clients (void * cls, const char *cipher_suite,
+test_parallel_clients (void * cls, int port, const char *cipher_suite,
                        int curl_proto_version)
 {
   int i;
@@ -108,7 +108,7 @@ test_parallel_clients (void * cls, const char *cipher_suite,
   void *client_thread_ret;
   pthread_t client_arr[client_count];
   struct https_test_data client_args =
-    { NULL, cipher_suite, curl_proto_version };
+    { NULL, port, cipher_suite, curl_proto_version };
 
   for (i = 0; i < client_count; ++i)
     {
@@ -137,6 +137,12 @@ main (int argc, char *const *argv)
 {  
   unsigned int errorCount = 0;
   const char *aes256_sha = "AES256-SHA";
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3020;
 
   /* initialize random seed used by curl clients */
   unsigned int iseed = (unsigned int) time (NULL);
@@ -157,7 +163,7 @@ main (int argc, char *const *argv)
 #ifdef EPOLL_SUPPORT
   errorCount +=
     test_wrap ("single threaded daemon, single client, epoll", 
&test_single_client,
-               NULL,
+               NULL, port,
                MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 
MHD_USE_ERROR_LOG | MHD_USE_EPOLL,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -165,7 +171,7 @@ main (int argc, char *const *argv)
 #endif
   errorCount +=
     test_wrap ("single threaded daemon, single client", &test_single_client,
-               NULL,
+               NULL, port,
                MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 
MHD_USE_ERROR_LOG,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -173,7 +179,7 @@ main (int argc, char *const *argv)
 #ifdef EPOLL_SUPPORT
   errorCount +=
     test_wrap ("single threaded daemon, parallel clients, epoll",
-               &test_parallel_clients, NULL,
+               &test_parallel_clients, NULL, port,
                MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 
MHD_USE_ERROR_LOG | MHD_USE_EPOLL,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -181,7 +187,7 @@ main (int argc, char *const *argv)
 #endif
   errorCount +=
     test_wrap ("single threaded daemon, parallel clients",
-               &test_parallel_clients, NULL,
+               &test_parallel_clients, NULL, port,
                MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 
MHD_USE_ERROR_LOG,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
diff --git a/src/testcurl/https/test_https_get_parallel_threads.c 
b/src/testcurl/https/test_https_get_parallel_threads.c
index 862b9512..f577edd9 100644
--- a/src/testcurl/https/test_https_get_parallel_threads.c
+++ b/src/testcurl/https/test_https_get_parallel_threads.c
@@ -63,7 +63,7 @@ https_transfer_thread_adapter (void *args)
 
   /* time spread incomming requests */
   usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
-  ret = test_https_transfer (cargs->cls,
+  ret = test_https_transfer (cargs->cls, cargs->port,
                              cargs->cipher_suite, cargs->proto_version);
   if (ret == 0)
     return NULL;
@@ -78,12 +78,12 @@ https_transfer_thread_adapter (void *args)
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_single_client (void *cls, const char *cipher_suite,
+test_single_client (void *cls, int port, const char *cipher_suite,
                     int curl_proto_version)
 {
   void *client_thread_ret;
   struct https_test_data client_args =
-    { NULL, cipher_suite, curl_proto_version };
+    { NULL, port, cipher_suite, curl_proto_version };
 
   client_thread_ret = https_transfer_thread_adapter (&client_args);
   if (client_thread_ret != NULL)
@@ -100,7 +100,7 @@ test_single_client (void *cls, const char *cipher_suite,
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_parallel_clients (void *cls, const char *cipher_suite,
+test_parallel_clients (void *cls, int port, const char *cipher_suite,
                        int curl_proto_version)
 {
   int i;
@@ -108,7 +108,7 @@ test_parallel_clients (void *cls, const char *cipher_suite,
   void *client_thread_ret;
   pthread_t client_arr[client_count];
   struct https_test_data client_args =
-    { NULL, cipher_suite, curl_proto_version };
+    { NULL, port, cipher_suite, curl_proto_version };
 
   for (i = 0; i < client_count; ++i)
     {
@@ -138,6 +138,12 @@ main (int argc, char *const *argv)
 {
   unsigned int errorCount = 0;
   const char *ssl_version;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3010;
 
   /* initialize random seed used by curl clients */
   unsigned int iseed = (unsigned int) time (NULL);
@@ -175,7 +181,7 @@ main (int argc, char *const *argv)
 
   errorCount +=
     test_wrap ("multi threaded daemon, single client", &test_single_client,
-               NULL,
+               NULL, port,
                MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION 
| MHD_USE_INTERNAL_POLLING_THREAD,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -183,7 +189,7 @@ main (int argc, char *const *argv)
 
   errorCount +=
     test_wrap ("multi threaded daemon, parallel client",
-               &test_parallel_clients, NULL,
+               &test_parallel_clients, NULL, port,
                MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION 
| MHD_USE_INTERNAL_POLLING_THREAD,
                aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
diff --git a/src/testcurl/https/test_https_get_select.c 
b/src/testcurl/https/test_https_get_select.c
index d3191b8d..df19396e 100644
--- a/src/testcurl/https/test_https_get_select.c
+++ b/src/testcurl/https/test_https_get_select.c
@@ -97,24 +97,39 @@ testExternalGet (int flags)
   time_t start;
   struct timeval tv;
   const char *aes256_sha = "AES256-SHA";
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3030;
 
   multi = NULL;
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS | flags,
-                        1082, NULL, NULL, &ahc_echo, "GET",
+                        port, NULL, NULL, &ahc_echo, "GET",
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);
   if (d == NULL)
     return 256;
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return 32; }
+      port = (int)dinfo->port;
+    }
 
   if (curl_uses_nss_ssl() == 0)
     aes256_sha = "rsa_aes_256_sha";
 
   c = curl_easy_init ();
-  curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1:1082/hello_world";);
+  curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world";);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   /* TLS options */
diff --git a/src/testcurl/https/test_https_multi_daemon.c 
b/src/testcurl/https/test_https_multi_daemon.c
index 99b1bfd4..b1c61ba3 100644
--- a/src/testcurl/https/test_https_multi_daemon.c
+++ b/src/testcurl/https/test_https_multi_daemon.c
@@ -47,13 +47,21 @@ test_concurent_daemon_pair (void *cls,
                            const char *cipher_suite,
                             int proto_version)
 {
-
   int ret;
   struct MHD_Daemon *d1;
   struct MHD_Daemon *d2;
+  int port1, port2;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port1 = port2 = 0;
+  else
+    {
+      port1 = 3050;
+      port2 = 3051;
+    }
 
   d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                         MHD_USE_ERROR_LOG, DEAMON_TEST_PORT,
+                         MHD_USE_ERROR_LOG, port1,
                          NULL, NULL, &http_ahc, NULL,
                          MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                          MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
@@ -64,9 +72,17 @@ test_concurent_daemon_pair (void *cls,
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port1)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d1, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d1); return -1; }
+      port1 = (int)dinfo->port;
+    }
 
   d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                         MHD_USE_ERROR_LOG, DEAMON_TEST_PORT + 1,
+                         MHD_USE_ERROR_LOG, port2,
                          NULL, NULL, &http_ahc, NULL,
                          MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                          MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
@@ -78,16 +94,28 @@ test_concurent_daemon_pair (void *cls,
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port2)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d2, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        {
+          MHD_stop_daemon (d1);
+          MHD_stop_daemon (d2);
+          return -1;
+        }
+      port2 = (int)dinfo->port;
+    }
 
   ret =
-    test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
+    test_daemon_get (NULL, cipher_suite, proto_version, port1, 0);
   ret +=
     test_daemon_get (NULL, cipher_suite, proto_version,
-                     DEAMON_TEST_PORT + 1, 0);
+                     port2, 0);
 
   MHD_stop_daemon (d2);
   ret +=
-    test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
+    test_daemon_get (NULL, cipher_suite, proto_version, port1, 0);
   MHD_stop_daemon (d1);
   return ret;
 }
diff --git a/src/testcurl/https/test_https_session_info.c 
b/src/testcurl/https/test_https_session_info.c
index fe2d0724..eb821240 100644
--- a/src/testcurl/https/test_https_session_info.c
+++ b/src/testcurl/https/test_https_session_info.c
@@ -100,17 +100,21 @@ test_query_session ()
   struct CBC cbc;
   CURLcode errornum;
   char url[256];
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3060;
 
   if (NULL == (cbc.buf = malloc (sizeof (char) * 255)))
     return 16;
   cbc.size = 255;
   cbc.pos = 0;
 
-  gen_test_file_url (url, DEAMON_TEST_PORT);
-
   /* setup test */
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, DEAMON_TEST_PORT,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &query_session_ahc, NULL,
                        MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128",
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -122,6 +126,14 @@ test_query_session ()
       free (cbc.buf);
       return 2;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return 32; }
+      port = (int)dinfo->port;
+    }
 
   const char *aes256_sha = "AES256-SHA";
   if (curl_uses_nss_ssl() == 0)
@@ -129,6 +141,7 @@ test_query_session ()
       aes256_sha = "rsa_aes_256_sha";
     }
 
+  gen_test_file_url (url, port);
   c = curl_easy_init ();
 #if DEBUG_HTTPS_TEST
   curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
@@ -172,6 +185,7 @@ test_query_session ()
 int
 main (int argc, char *const *argv)
 {
+#if LIBCURL_VERSION_NUM >= 0x072200
   unsigned int errorCount = 0;
   const char *ssl_version;
 
@@ -200,10 +214,11 @@ main (int argc, char *const *argv)
     curl_global_cleanup ();
     return 77;
   }
-#if LIBCURL_VERSION_NUM >= 0x072200
   errorCount += test_query_session ();
-#endif
   print_test_result (errorCount, argv[0]);
   curl_global_cleanup ();
   return errorCount != 0 ? 1 : 0;
+#else  /* LIBCURL_VERSION_NUM < 0x072200 */
+  return 77;
+#endif /* LIBCURL_VERSION_NUM < 0x072200 */
 }
diff --git a/src/testcurl/https/test_https_sni.c 
b/src/testcurl/https/test_https_sni.c
index 71805ba8..6c1da540 100644
--- a/src/testcurl/https/test_https_sni.c
+++ b/src/testcurl/https/test_https_sni.c
@@ -180,13 +180,14 @@ sni_callback (gnutls_session_t session,
 
 /* perform a HTTP GET request via SSL/TLS */
 static int
-do_get (const char *url)
+do_get (const char *url, int port)
 {
   CURL *c;
   struct CBC cbc;
   CURLcode errornum;
   size_t len;
   struct curl_slist *dns_info;
+  char buf[256];
 
   len = strlen (test_data);
   if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
@@ -202,6 +203,7 @@ do_get (const char *url)
   curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
 #endif
   curl_easy_setopt (c, CURLOPT_URL, url);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
   curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
   curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
@@ -212,8 +214,10 @@ do_get (const char *url)
   /* TODO merge into send_curl_req */
   curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
   curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 2);
-  dns_info = curl_slist_append (NULL, "host1:4233:127.0.0.1");
-  dns_info = curl_slist_append (dns_info, "host2:4233:127.0.0.1");
+  sprintf(buf, "host1:%d:127.0.0.1", port);
+  dns_info = curl_slist_append (NULL, buf);
+  sprintf(buf, "host2:%d:127.0.0.1", port);
+  dns_info = curl_slist_append (dns_info, buf);
   curl_easy_setopt (c, CURLOPT_RESOLVE, dns_info);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
 
@@ -250,6 +254,12 @@ main (int argc, char *const *argv)
 {
   unsigned int error_count = 0;
   struct MHD_Daemon *d;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3060;
 
 #ifdef MHD_HTTPS_REQUIRE_GRYPT
   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -272,7 +282,7 @@ main (int argc, char *const *argv)
   load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key");
   load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key");
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG,
-                        4233,
+                        port,
                         NULL, NULL,
                         &http_ahc, NULL,
                         MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback,
@@ -282,9 +292,17 @@ main (int argc, char *const *argv)
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
-  if (0 != do_get ("https://host1:4233/";))
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
+  if (0 != do_get ("https://host1/";, port))
     error_count++;
-  if (0 != do_get ("https://host2:4233/";))
+  if (0 != do_get ("https://host2/";, port))
     error_count++;
 
   MHD_stop_daemon (d);
diff --git a/src/testcurl/https/test_https_time_out.c 
b/src/testcurl/https/test_https_time_out.c
index a1908e49..4330334b 100644
--- a/src/testcurl/https/test_https_time_out.c
+++ b/src/testcurl/https/test_https_time_out.c
@@ -47,7 +47,7 @@ extern const char srv_self_signed_cert_pem[];
 static const int TIME_OUT = 3;
 
 static int
-test_tls_session_time_out (gnutls_session_t session)
+test_tls_session_time_out (gnutls_session_t session, int port)
 {
   int ret;
   MHD_socket sd;
@@ -62,7 +62,7 @@ test_tls_session_time_out (gnutls_session_t session)
 
   memset (&sa, '\0', sizeof (struct sockaddr_in));
   sa.sin_family = AF_INET;
-  sa.sin_port = htons (DEAMON_TEST_PORT);
+  sa.sin_port = htons (port);
   sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
 
   gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (intptr_t) sd);
@@ -109,7 +109,12 @@ main (int argc, char *const *argv)
   gnutls_datum_t key;
   gnutls_datum_t cert;
   gnutls_certificate_credentials_t xcred;
+  int port;
 
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3070;
 
 #ifdef MHD_HTTPS_REQUIRE_GRYPT
   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -121,7 +126,7 @@ main (int argc, char *const *argv)
   gnutls_global_set_log_level (11);
 
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, DEAMON_TEST_PORT,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &http_dummy_ahc, NULL,
                         MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -133,13 +138,21 @@ main (int argc, char *const *argv)
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
 
   if (0 != setup_session (&session, &key, &cert, &xcred))
     {
       fprintf (stderr, "failed to setup session\n");
       return 1;
     }
-  errorCount += test_tls_session_time_out (session);
+  errorCount += test_tls_session_time_out (session, port);
   teardown_session (session, &key, &cert, xcred);
 
   print_test_result (errorCount, argv[0]);
diff --git a/src/testcurl/https/test_tls_authentication.c 
b/src/testcurl/https/test_tls_authentication.c
index 20576a61..e3bc2626 100644
--- a/src/testcurl/https/test_tls_authentication.c
+++ b/src/testcurl/https/test_tls_authentication.c
@@ -50,9 +50,15 @@ test_secure_get (void * cls, char *cipher_suite, int 
proto_version)
 {
   int ret;
   struct MHD_Daemon *d;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3070;
 
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, DEAMON_TEST_PORT,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &http_ahc, NULL,
                         MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
@@ -63,8 +69,16 @@ test_secure_get (void * cls, char *cipher_suite, int 
proto_version)
       fprintf (stderr, MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
 
-  ret = test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 
0);
+  ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 0);
 
   MHD_stop_daemon (d);
   return ret;
diff --git a/src/testcurl/https/test_tls_extensions.c 
b/src/testcurl/https/test_tls_extensions.c
index 69deb3a4..a7bb6d4e 100644
--- a/src/testcurl/https/test_tls_extensions.c
+++ b/src/testcurl/https/test_tls_extensions.c
@@ -42,13 +42,14 @@ extern const char srv_self_signed_cert_pem[];
  * Test daemon response to TLS client hello requests containing extensions
  *
  * @param session
+ * @param port
  * @param exten_t - the type of extension being appended to client hello 
request
  * @param ext_count - the number of consecutive extension replicas inserted 
into request
  * @param ext_length - the length of each appended extension
  * @return 0 on successful test completion, -1 otherwise
  */
 static int
-test_hello_extension (gnutls_session_t session, extensions_t exten_t,
+test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
                       int ext_count, int ext_length)
 {
   int i, ret = 0, pos = 0;
@@ -84,7 +85,7 @@ test_hello_extension (gnutls_session_t session, extensions_t 
exten_t,
     }
   memset (&sa, '\0', sizeof (struct sockaddr_in));
   sa.sin_family = AF_INET;
-  sa.sin_port = htons (DEAMON_TEST_PORT);
+  sa.sin_port = htons (port);
   sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
 
   enum MHD_GNUTLS_Protocol hver;
@@ -167,7 +168,7 @@ test_hello_extension (gnutls_session_t session, 
extensions_t exten_t,
 
   gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd);
 
-  if (gen_test_file_url (url, DEAMON_TEST_PORT))
+  if (gen_test_file_url (url, port))
     {
       ret = -1;
       goto cleanup;
@@ -210,11 +211,16 @@ main (int argc, char *const *argv)
   gnutls_datum_t key;
   gnutls_datum_t cert;
   gnutls_certificate_credentials_t xcred;
-
   const int ext_arr[] = {
     GNUTLS_EXTENSION_SERVER_NAME,
     -1
   };
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3080;
 
 #ifdef MHD_HTTPS_REQUIRE_GRYPT
   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -237,7 +243,7 @@ main (int argc, char *const *argv)
     }
 
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
-                        MHD_USE_ERROR_LOG, DEAMON_TEST_PORT,
+                        MHD_USE_ERROR_LOG, port,
                         NULL, NULL, &http_ahc, NULL,
                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                         MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
@@ -248,26 +254,34 @@ main (int argc, char *const *argv)
       fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
       return -1;
     }
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        { MHD_stop_daemon (d); return -1; }
+      port = (int)dinfo->port;
+    }
 
   i = 0;
   setup_session (&session, &key, &cert, &xcred);
-  errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
+  errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16);
   teardown_session (session, &key, &cert, xcred);
 #if 1
   i = 0;
   while (ext_arr[i] != -1)
     {
       setup_session (&session, &key, &cert, &xcred);
-      errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
+      errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16);
       teardown_session (session, &key, &cert, xcred);
 
       setup_session (&session, &key, &cert, &xcred);
-      errorCount += test_hello_extension (session, ext_arr[i], 3, 8);
+      errorCount += test_hello_extension (session, port, ext_arr[i], 3, 8);
       teardown_session (session, &key, &cert, xcred);
 
       /* this test specifically tests the issue raised in CVE-2008-1948 */
       setup_session (&session, &key, &cert, &xcred);
-      errorCount += test_hello_extension (session, ext_arr[i], 6, 0);
+      errorCount += test_hello_extension (session, port, ext_arr[i], 6, 0);
       teardown_session (session, &key, &cert, xcred);
       i++;
     }
diff --git a/src/testcurl/https/test_tls_options.c 
b/src/testcurl/https/test_tls_options.c
index 95f6b3ce..a0f053a0 100644
--- a/src/testcurl/https/test_tls_options.c
+++ b/src/testcurl/https/test_tls_options.c
@@ -43,7 +43,7 @@ int curl_check_version (const char *req_version, ...);
  *
  */
 static int
-test_unmatching_ssl_version (void * cls, const char *cipher_suite,
+test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite,
                              int curl_req_ssl_version)
 {
   struct CBC cbc;
@@ -57,7 +57,7 @@ test_unmatching_ssl_version (void * cls, const char 
*cipher_suite,
   cbc.pos = 0;
 
   char url[255];
-  if (gen_test_file_url (url, DEAMON_TEST_PORT))
+  if (gen_test_file_url (url, port))
     {
       free (cbc.buf);
       fprintf (stderr, "Internal error in gen_test_file_url\n");
@@ -86,6 +86,12 @@ main (int argc, char *const *argv)
   const char *ssl_version;
   int daemon_flags =
     MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | 
MHD_USE_TLS | MHD_USE_ERROR_LOG;
+  int port;
+
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+    port = 3010;
 
 #ifdef MHD_HTTPS_REQUIRE_GRYPT
   gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
@@ -127,7 +133,7 @@ main (int argc, char *const *argv)
 
   if (0 !=
     test_wrap ("TLS1.0-AES-SHA1",
-              &test_https_transfer, NULL, daemon_flags,
+              &test_https_transfer, NULL, port, daemon_flags,
               aes128_sha,
               CURL_SSLVERSION_TLSv1,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -142,7 +148,7 @@ main (int argc, char *const *argv)
           "The following handshake should fail (and print an error 
message)...\n");
   if (0 !=
     test_wrap ("TLS1.0 vs SSL3",
-              &test_unmatching_ssl_version, NULL, daemon_flags,
+              &test_unmatching_ssl_version, NULL, port, daemon_flags,
               aes256_sha,
               CURL_SSLVERSION_SSLv3,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
diff --git a/src/testcurl/https/tls_test_common.c 
b/src/testcurl/https/tls_test_common.c
index 50cc318b..63cb1013 100644
--- a/src/testcurl/https/tls_test_common.c
+++ b/src/testcurl/https/tls_test_common.c
@@ -318,7 +318,7 @@ gen_test_file_url (char *url, int port)
  * test HTTPS file transfer
  */
 int
-test_https_transfer (void *cls, const char *cipher_suite, int proto_version)
+test_https_transfer (void *cls, int port, const char *cipher_suite, int 
proto_version)
 {
   int len;
   int ret = 0;
@@ -334,7 +334,7 @@ test_https_transfer (void *cls, const char *cipher_suite, 
int proto_version)
   cbc.size = len;
   cbc.pos = 0;
 
-  if (gen_test_file_url (url, DEAMON_TEST_PORT))
+  if (gen_test_file_url (url, port))
     {
       ret = -1;
       goto cleanup;
@@ -366,21 +366,33 @@ cleanup:
  * @param d
  * @param daemon_flags
  * @param arg_list
- * @return
+ * @return port number on success or zero on failure
  */
 int
-setup_testcase (struct MHD_Daemon **d, int daemon_flags, va_list arg_list)
+setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list 
arg_list)
 {
-  *d = MHD_start_daemon_va (daemon_flags, DEAMON_TEST_PORT,
+  *d = MHD_start_daemon_va (daemon_flags, port,
                             NULL, NULL, &http_ahc, NULL, arg_list);
 
   if (*d == NULL)
     {
       fprintf (stderr, MHD_E_SERVER_INIT);
-      return -1;
+      return 0;
     }
 
-  return 0;
+  if (0 == port)
+    {
+      const union MHD_DaemonInfo *dinfo;
+      dinfo = MHD_get_daemon_info (*d, MHD_DAEMON_INFO_BIND_PORT);
+      if (NULL == dinfo || 0 == dinfo->port)
+        {
+          MHD_stop_daemon (*d);
+          return 0;
+        }
+      port = (int)dinfo->port;
+    }
+
+  return port;
 }
 
 void
@@ -454,8 +466,9 @@ teardown_session (gnutls_session_t session,
 /* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */
 int
 test_wrap (const char *test_name, int
-           (*test_function) (void * cls, const char *cipher_suite,
+           (*test_function) (void * cls, int port, const char *cipher_suite,
                              int proto_version), void * cls,
+           int port,
            int daemon_flags, const char *cipher_suite, int proto_version, ...)
 {
   int ret;
@@ -463,7 +476,8 @@ test_wrap (const char *test_name, int
   struct MHD_Daemon *d;
 
   va_start (arg_list, proto_version);
-  if (setup_testcase (&d, daemon_flags, arg_list) != 0)
+  port = setup_testcase (&d, port, daemon_flags, arg_list);
+  if (0 == port)
     {
       va_end (arg_list);
       fprintf (stderr, "Failed to setup testcase %s\n", test_name);
@@ -472,7 +486,7 @@ test_wrap (const char *test_name, int
 #if 0
   fprintf (stdout, "running test: %s ", test_name);
 #endif
-  ret = test_function (NULL, cipher_suite, proto_version);
+  ret = test_function (NULL, port, cipher_suite, proto_version);
 #if 0
   if (ret == 0)
     {
diff --git a/src/testcurl/https/tls_test_common.h 
b/src/testcurl/https/tls_test_common.h
index 1d324760..a59c43f4 100644
--- a/src/testcurl/https/tls_test_common.h
+++ b/src/testcurl/https/tls_test_common.h
@@ -32,8 +32,6 @@
 #define DEBUG_HTTPS_TEST 0
 #define CURL_VERBOS_LEVEL 0
 
-#define DEAMON_TEST_PORT 4233
-
 #define test_data "Hello World\n"
 #define ca_cert_file_name "tmp_ca_cert.pem"
 
@@ -51,6 +49,7 @@
 struct https_test_data
 {
   void *cls;
+  int port;
   const char *cipher_suite;
   int proto_version;
 };
@@ -114,10 +113,10 @@ send_curl_req (char *url, struct CBC *cbc, const char 
*cipher_suite,
                int proto_version);
 
 int
-test_https_transfer (void *cls, const char *cipher_suite, int proto_version);
+test_https_transfer (void *cls, int port, const char *cipher_suite, int 
proto_version);
 
 int
-setup_testcase (struct MHD_Daemon **d, int daemon_flags, va_list arg_list);
+setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list 
arg_list);
 
 void teardown_testcase (struct MHD_Daemon *d);
 
@@ -135,7 +134,8 @@ teardown_session (gnutls_session_t session,
 
 int
 test_wrap (const char *test_name, int
-           (*test_function) (void * cls, const char *cipher_suite,
-                             int proto_version), void *test_function_cls,
+           (*test_function) (void * cls, int port, const char *cipher_suite,
+                             int proto_version), void * cls,
+           int port,
            int daemon_flags, const char *cipher_suite, int proto_version, ...);
 #endif /* TLS_TEST_COMMON_H_ */
diff --git a/src/testcurl/test_options.c b/src/testcurl/test_options.c
index 317968e5..004fe615 100644
--- a/src/testcurl/test_options.c
+++ b/src/testcurl/test_options.c
@@ -47,8 +47,8 @@ ahc_echo (void *cls,
   return 0;
 }
 
-int
-test_wrap (char *test_name, int (*test) (void))
+static int
+test_wrap_loc (char *test_name, int (*test) (void))
 {
   int ret;
 
@@ -119,7 +119,7 @@ main (int argc, char *const *argv)
 {
   unsigned int errorCount = 0;
 
-  errorCount += test_wrap ("ip addr option", &test_ip_addr_option);
+  errorCount += test_wrap_loc ("ip addr option", &test_ip_addr_option);
 
   return errorCount != 0;
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]