Ejemplo n.º 1
0
int
main (int argc, char *const *argv)
{
  unsigned int errorCount = 0;
  (void)argc;   /* Unused. Silent compiler warning. */

  if (NULL == argv || 0 == argv[0])
    return 99;
  oneone = has_in_name (argv[0], "11");
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    return 2;
  if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS))
    {
      start_time = now();
      errorCount += testInternalPost ();
      fprintf (stderr,
	       oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n",
	       "internal select",
	       (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0));
      GAUGER ("internal select",
	      oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)",
	      (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0),
	      "requests/s");
      start_time = now();
      errorCount += testMultithreadedPost ();
      fprintf (stderr,
	       oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n",
	       "multithreaded post",
	       (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0));
      GAUGER ("Multithreaded select",
	      oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)",
	      (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0),
	      "requests/s");
      start_time = now();
      errorCount += testMultithreadedPoolPost ();
      fprintf (stderr,
	       oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n",
	       "thread with pool",
	       (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0));
      GAUGER ("thread with pool",
	      oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)",
	      (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0),
	      "requests/s");
    }
  start_time = now();
  errorCount += testExternalPost ();
  fprintf (stderr,
	   oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n",
	   "external select",
	   (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0));
  GAUGER ("external select",
	  oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)",
	  (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0),
	  "requests/s");
  if (errorCount != 0)
    fprintf (stderr, "Error (code: %u)\n", errorCount);
  curl_global_cleanup ();
  return errorCount != 0;       /* 0 == pass */
}
int
main (int argc, char *const *argv)
{
  unsigned int errorCount = 0;
  (void)argc;   /* Unused. Silent compiler warning. */

  if (NULL == argv || 0 == argv[0])
    return 99;
  oneone = has_in_name (argv[0], "11");
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    return 2;
  errorCount += testExternalGet ();
  if (errorCount != 0)
    fprintf (stderr, "Error (code: %u)\n", errorCount);
  curl_global_cleanup ();
  return errorCount != 0;       /* 0 == pass */
}
Ejemplo n.º 3
0
int
main (int argc, char *const *argv)
{
  unsigned int errorCount = 0;
  int port = 1130;
  (void)argc;   /* Unused. Silent compiler warning. */

  if (NULL == argv || 0 == argv[0])
    return 99;
  oneone = has_in_name (argv[0], "11");
  if (oneone)
    port += 15;
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    return 2;
  response = MHD_create_response_from_buffer (strlen ("/hello_world"),
					      "/hello_world",
					      MHD_RESPMEM_MUST_COPY);
  errorCount += testExternalGet (port++);
  if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS))
    {
      errorCount += testInternalGet (port++, MHD_USE_AUTO);
      errorCount += testMultithreadedGet (port++, MHD_USE_AUTO);
      errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO);
      errorCount += testInternalGet (port++, 0);
      errorCount += testMultithreadedGet (port++, 0);
      errorCount += testMultithreadedPoolGet (port++, 0);
      if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
	{
	  errorCount += testInternalGet(port++, MHD_USE_POLL);
	  errorCount += testMultithreadedGet(port++, MHD_USE_POLL);
	  errorCount += testMultithreadedPoolGet(port++, MHD_USE_POLL);
	}
      if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
	{
	  errorCount += testInternalGet(port++, MHD_USE_EPOLL);
	  errorCount += testMultithreadedPoolGet(port++, MHD_USE_EPOLL);
	}
    }
  MHD_destroy_response (response);
  if (errorCount != 0)
    fprintf (stderr, "Error (code: %u)\n", errorCount);
  curl_global_cleanup ();
  return errorCount != 0;       /* 0 == pass */
}
Ejemplo n.º 4
0
int
main (int argc, char *const *argv)
{
  unsigned int errorCount = 0;
  (void)argc;   /* Unused. Silent compiler warning. */

  if (NULL == argv || 0 == argv[0])
    return 99;
  oneone = has_in_name (argv[0], "11");
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    return 2;
  if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS))
    {
      errorCount += testInternalPut ();
      errorCount += testMultithreadedPut ();
      errorCount += testMultithreadedPoolPut ();
    }
  errorCount += testExternalPut ();
  if (errorCount != 0)
    fprintf (stderr, "Error (code: %u)\n", errorCount);
  curl_global_cleanup ();
  return errorCount != 0;       /* 0 == pass */
}
Ejemplo n.º 5
0
int
main (int argc,
      char *const *argv)
{
  int error_count = 0;
  int res;

  use_tls_tool = TLS_CLI_NO_TOOL;
  test_tls = has_in_name(argv[0], "_tls");

  if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose"))
    verbose = 1;

  if (test_tls)
    {
#ifdef HTTPS_SUPPORT
      if (has_param(argc, argv, "--use-gnutls-cli"))
        use_tls_tool = TLS_CLI_GNUTLS;
      else if (has_param(argc, argv, "--use-openssl"))
        use_tls_tool = TLS_CLI_OPENSSL;
      else if (has_param(argc, argv, "--use-gnutls-lib"))
        use_tls_tool = TLS_LIB_GNUTLS;
#if defined(HAVE_FORK) && defined(HAVE_WAITPID)
      else if (0 == system ("gnutls-cli --version 1> /dev/null"))
        use_tls_tool = TLS_CLI_GNUTLS;
      else if (0 == system ("openssl version 1> /dev/null"))
        use_tls_tool = TLS_CLI_OPENSSL;
#endif /* HAVE_FORK && HAVE_WAITPID */
      else
        use_tls_tool = TLS_LIB_GNUTLS; /* Should be available as MHD use it. */
      if (verbose)
        {
          switch (use_tls_tool)
          {
            case TLS_CLI_GNUTLS:
              printf ("GnuTLS-CLI will be used for testing.\n");
              break;
            case TLS_CLI_OPENSSL:
              printf ("Command line version of OpenSSL will be used for testing.\n");
              break;
            case TLS_LIB_GNUTLS:
              printf ("GnuTLS library will be used for testing.\n");
              break;
            default:
              abort ();
          }
        }
      if (TLS_LIB_GNUTLS == use_tls_tool && GNUTLS_E_SUCCESS != gnutls_global_init())
        abort ();

#else  /* ! HTTPS_SUPPORT */
      fprintf (stderr, "HTTPS support was disabled by configure.\n");
      return 99;
#endif /* ! HTTPS_SUPPORT */
    }

  /* run tests */
  if (verbose)
    printf ("Starting HTTP \"Upgrade\" tests with %s connections.\n", test_tls ? "TLS" : "plain");
  /* try external select */
  res = test_upgrade (0,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with external select, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with external select.\n");

  /* Try external auto */
  res = test_upgrade (MHD_USE_AUTO,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with external 'auto', return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with external 'auto'.\n");

#ifdef EPOLL_SUPPORT
  res = test_upgrade (MHD_USE_EPOLL,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with external select with EPOLL, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with external select with EPOLL.\n");
#endif

  /* Test thread-per-connection */
  res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with thread per connection, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with thread per connection.\n");

  res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with thread per connection and 'auto', return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with thread per connection and 'auto'.\n");
#ifdef HAVE_POLL
  res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with thread per connection and poll, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with thread per connection and poll.\n");
#endif /* HAVE_POLL */

  /* Test different event loops, with and without thread pool */
  res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal select, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal select.\n");
  res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD,
                      2);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal select with thread pool, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal select with thread pool.\n");
  res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal 'auto' return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal 'auto'.\n");
  res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
                      2);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal 'auto' with thread pool, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal 'auto' with thread pool.\n");
#ifdef HAVE_POLL
  res = test_upgrade (MHD_USE_POLL_INTERNAL_THREAD,
                      0);
  error_count += res;
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal poll, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal poll.\n");
  res = test_upgrade (MHD_USE_POLL_INTERNAL_THREAD,
                      2);
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal poll with thread pool, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal poll with thread pool.\n");
#endif
#ifdef EPOLL_SUPPORT
  res = test_upgrade (MHD_USE_EPOLL_INTERNAL_THREAD,
                      0);
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal epoll, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal epoll.\n");
  res = test_upgrade (MHD_USE_EPOLL_INTERNAL_THREAD,
                      2);
  if (res)
    fprintf (stderr, "FAILED: Upgrade with internal epoll, return code %d.\n", res);
  else if (verbose)
    printf ("PASSED: Upgrade with internal epoll.\n");
#endif
  /* report result */
  if (0 != error_count)
    fprintf (stderr,
             "Error (code: %u)\n",
             error_count);
#ifdef HTTPS_SUPPORT
  if (test_tls && TLS_LIB_GNUTLS == use_tls_tool)
    gnutls_global_deinit();
#endif /* HTTPS_SUPPORT */
  return error_count != 0;       /* 0 == pass */
}
Ejemplo n.º 6
0
int
main (int argc, char *const *argv)
{
  int i;
  time_t start_t, end_t;
  int result = 0;
  MHD_THRD_RTRN_TYPE_ (MHD_THRD_CALL_SPEC_ *test_func)(void* data);
#ifdef MHD_WINSOCK_SOCKETS
  WORD ver_req;
  WSADATA wsa_data;
  int err;
#endif /* MHD_WINSOCK_SOCKETS */
  bool test_poll;

  test_poll = has_in_name(argv[0], "_poll");
  if (!test_poll)
    test_func = &select_thread;
  else
    {
#ifndef HAVE_POLL
      return 77;
#else  /* ! HAVE_POLL */
      test_func = &poll_thread;
#endif /* ! HAVE_POLL */
    }

#ifdef MHD_WINSOCK_SOCKETS
  ver_req = MAKEWORD(2, 2);

  err = WSAStartup(ver_req, &wsa_data);
  if (err != 0 || MAKEWORD(2, 2) != wsa_data.wVersion)
    {
      printf("WSAStartup() failed\n");
      WSACleanup();
      return 99;
    }
#endif /* MHD_WINSOCK_SOCKETS */

  /* try several times to ensure that accidental incoming connection
   * didn't interfere with test results
   */
  for (i = 0; i < 5 && result == 0; i++)
    {
      MHD_thread_handle_ sel_thrd;
      /* fprintf(stdout, "Creating, binding and listening socket...\n"); */
      MHD_socket listen_socket = start_socket_listen (AF_INET);
      if (MHD_INVALID_SOCKET == listen_socket)
        return 99;

      check_err = !0;
      /* fprintf (stdout, "Starting select() thread...\n"); */
#if defined(MHD_USE_POSIX_THREADS)
      if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket))
        {
          MHD_socket_close_chk_ (listen_socket);
          fprintf (stderr, "Can't start thread\n");
          return 99;
        }
#elif defined(MHD_USE_W32_THREADS)
      sel_thrd = (HANDLE)_beginthreadex (NULL, 0, test_func, &listen_socket, 0, NULL);
      if (0 == (sel_thrd))
        {
          MHD_socket_close_chk_ (listen_socket);
          fprintf (stderr, "Can't start select() thread\n");
          return 99;
        }
#else
#error No threading lib available
#endif
      /* fprintf (stdout, "Waiting...\n"); */
      local_sleep(1); /* make sure that select() is started */

      /* fprintf (stdout, "Shutting down socket...\n"); */
      start_t = time (NULL);
      shutdown (listen_socket, SHUT_RDWR);

      /* fprintf (stdout, "Waiting for thread to finish...\n"); */
      if (!MHD_join_thread_(sel_thrd))
        {
          MHD_socket_close_chk_(listen_socket);
          fprintf (stderr, "Can't join select() thread\n");
          return 99;
        }
      if (check_err)
        {
          MHD_socket_close_chk_(listen_socket);
          fprintf (stderr, "Error in waiting thread\n");
          return 99;
        }
      end_t = time (NULL);
      /* fprintf (stdout, "Thread finished.\n"); */
      MHD_socket_close_chk_(listen_socket);

      if (start_t == (time_t)-1 || end_t == (time_t)-1)
        {
          MHD_socket_close_chk_(listen_socket);
          fprintf (stderr, "Can't get current time\n");
          return 99;
        }
      if (end_t - start_t > 3)
        result++;
    }

#ifdef MHD_WINSOCK_SOCKETS
  WSACleanup();
#endif /* MHD_WINSOCK_SOCKETS */

  return result;
}