Home | History | Annotate | Download | only in testcurl
      1 /*
      2      This file is part of libmicrohttpd
      3      Copyright (C) 2011 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 test_start_stop.c
     23  * @brief  test for #1901 (start+stop)
     24  * @author Christian Grothoff
     25  */
     26 #include "MHD_config.h"
     27 #include "platform.h"
     28 #include <curl/curl.h>
     29 #include <microhttpd.h>
     30 
     31 #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2
     32 #undef CPU_COUNT
     33 #endif
     34 #if !defined(CPU_COUNT)
     35 #define CPU_COUNT 2
     36 #endif
     37 
     38 
     39 static int
     40 ahc_echo (void *cls,
     41           struct MHD_Connection *connection,
     42           const char *url,
     43           const char *method,
     44           const char *version,
     45           const char *upload_data, size_t *upload_data_size,
     46           void **unused)
     47 {
     48   return MHD_NO;
     49 }
     50 
     51 
     52 static int
     53 testInternalGet (int poll_flag)
     54 {
     55   struct MHD_Daemon *d;
     56 
     57   d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
     58                         11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
     59   if (d == NULL)
     60     return 1;
     61   MHD_stop_daemon (d);
     62   return 0;
     63 }
     64 
     65 static int
     66 testMultithreadedGet (int poll_flag)
     67 {
     68   struct MHD_Daemon *d;
     69 
     70   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG  | poll_flag,
     71                         1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
     72   if (d == NULL)
     73     return 2;
     74   MHD_stop_daemon (d);
     75   return 0;
     76 }
     77 
     78 static int
     79 testMultithreadedPoolGet (int poll_flag)
     80 {
     81   struct MHD_Daemon *d;
     82 
     83   d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
     84                         1081, NULL, NULL, &ahc_echo, "GET",
     85                         MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
     86   if (d == NULL)
     87     return 4;
     88   MHD_stop_daemon (d);
     89   return 0;
     90 }
     91 
     92 static int
     93 testExternalGet ()
     94 {
     95   struct MHD_Daemon *d;
     96 
     97   d = MHD_start_daemon (MHD_USE_DEBUG,
     98                         1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
     99   if (d == NULL)
    100     return 8;
    101   MHD_stop_daemon (d);
    102   return 0;
    103 }
    104 
    105 
    106 int
    107 main (int argc, char *const *argv)
    108 {
    109   unsigned int errorCount = 0;
    110 
    111   errorCount += testInternalGet (0);
    112   errorCount += testMultithreadedGet (0);
    113   errorCount += testMultithreadedPoolGet (0);
    114   errorCount += testExternalGet ();
    115   if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
    116     {
    117       errorCount += testInternalGet(MHD_USE_POLL);
    118       errorCount += testMultithreadedGet(MHD_USE_POLL);
    119       errorCount += testMultithreadedPoolGet(MHD_USE_POLL);
    120     }
    121   if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
    122     {
    123       errorCount += testInternalGet(MHD_USE_EPOLL_LINUX_ONLY);
    124       errorCount += testMultithreadedPoolGet(MHD_USE_EPOLL_LINUX_ONLY);
    125     }
    126   if (errorCount != 0)
    127     fprintf (stderr, "Error (code: %u)\n", errorCount);
    128   return errorCount != 0;       /* 0 == pass */
    129 }
    130