gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 253/335: fix issues in test logic


From: gnunet
Subject: [libmicrohttpd] 253/335: fix issues in test logic
Date: Sat, 27 Jul 2024 22:02:29 +0200

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

grothoff pushed a commit to tag stf-m2
in repository libmicrohttpd.

commit cd8a44ac179d2b199537fb187cb477ae36770452
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jul 21 17:04:25 2024 +0200

    fix issues in test logic
---
 src/tests/basic/libtest.c             | 29 +++++++++++++++++++++------
 src/tests/basic/libtest.h             | 15 ++++++++++++++
 src/tests/basic/libtest_convenience.c | 37 +++++++++++++++++++++++++++++++++++
 src/tests/basic/test_client_server.c  |  3 +--
 4 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/src/tests/basic/libtest.c b/src/tests/basic/libtest.c
index 8cf70348..d12278c9 100644
--- a/src/tests/basic/libtest.c
+++ b/src/tests/basic/libtest.c
@@ -278,6 +278,10 @@ run_single_client (void *cls)
   struct ClientContext *cc = cls;
   const char *err;
 
+  fprintf (stderr,
+           "Client %u started in phase %s\n",
+           cc->pc.client_id,
+           cc->phase->label);
   err = cc->phase->client_cb (cc->phase->client_cb_cls,
                               &cc->pc);
   if (NULL != err)
@@ -300,6 +304,10 @@ run_single_client (void *cls)
               write (cc->p2,
                      "s",
                      1));
+  fprintf (stderr,
+           "Client %u finished in phase %s\n",
+           cc->pc.client_id,
+           cc->phase->label);
   return NULL;
 }
 
@@ -367,12 +375,20 @@ run_client_phase (const struct MHDT_Phase *phase,
   for (i = phase->timeout_ms - 1; i>0; i--)
   {
     struct timespec ms = {
-      .tv_nsec = 1000 * 1000
+      .tv_nsec = 1000 * 1000,
+      .tv_sec = 1000 // for debugging...
     };
+    struct timespec rem;
     char c;
 
-    nanosleep (&ms,
-               NULL);
+    if (0 != nanosleep (&ms,
+                        &rem))
+    {
+      fprintf (stderr,
+               "nanosleep() interrupted (%s), trying again\n",
+               strerror (errno));
+      i++;
+    }
     /* This is a non-blocking read */
     while (1 == read (p[0],
                       &c,
@@ -537,10 +553,11 @@ MHDT_test (MHDT_ServerSetup ss_cb,
              strerror (errno));
     return 77;
   }
-  // FIXME: start some thread to run the actual server!
-
-  for (i = 0; NULL == phases[i].label; i++)
+  for (i = 0; NULL != phases[i].label; i++)
   {
+    fprintf (stderr,
+             "Running test phase %s\n",
+             phases[i].label);
     if (! run_client_phase (&phases[i],
                             &pc))
     {
diff --git a/src/tests/basic/libtest.h b/src/tests/basic/libtest.h
index 213590fe..2dcc65be 100644
--- a/src/tests/basic/libtest.h
+++ b/src/tests/basic/libtest.h
@@ -314,6 +314,21 @@ typedef void
                      struct MHD_Daemon *d);
 
 
+/**
+ * Function that starts an MHD daemon with the
+ * simple #MHD_daemon_start() method until
+ * a read() against @a finsig succeeds.
+ *
+ * @param cls closure
+ * @param finsig fd to read from to detect termination request
+ * @param[in,out] d daemon to run
+ */
+void
+MHDT_server_run_minimal (void *cls,
+                         int finsig,
+                         struct MHD_Daemon *d);
+
+
 /**
  * Function that runs an MHD daemon in blocking mode until
  * a read() against @a finsig succeeds.
diff --git a/src/tests/basic/libtest_convenience.c 
b/src/tests/basic/libtest_convenience.c
index 85b751cb..d7701b3c 100644
--- a/src/tests/basic/libtest_convenience.c
+++ b/src/tests/basic/libtest_convenience.c
@@ -46,6 +46,38 @@ MHDT_server_setup_minimal (void *cls,
 }
 
 
+void
+MHDT_server_run_minimal (void *cls,
+                         int finsig,
+                         struct MHD_Daemon *d)
+{
+  fd_set r;
+
+  FD_ZERO (&r);
+  FD_SET (finsig, &r);
+  while (1)
+  {
+    if ( (-1 ==
+          select (finsig + 1,
+                  &r,
+                  NULL,
+                  NULL,
+                  NULL)) &&
+         (EAGAIN != errno) )
+    {
+      fprintf (stderr,
+               "Failure waiting on termination signal: %s\n",
+               strerror (errno));
+      break;
+    }
+    if (FD_ISSET (finsig,
+                  &r))
+      break;
+  }
+}
+
+
+#if FUTURE
 void
 MHDT_server_run_blocking (void *cls,
                           int finsig,
@@ -77,6 +109,9 @@ MHDT_server_run_blocking (void *cls,
 }
 
 
+#endif
+
+
 const struct MHD_Action *
 MHDT_server_reply_text (
   void *cls,
@@ -223,6 +258,8 @@ MHDT_server_reply_check_header (
   enum MHD_HTTP_Method method,
   uint_fast64_t upload_size)
 {
+  if (1)
+    return NULL; // force failure...
   // FIXME: actual check logic missing...
   return MHD_action_from_response (
     request,
diff --git a/src/tests/basic/test_client_server.c 
b/src/tests/basic/test_client_server.c
index 349cf94b..20bee6df 100644
--- a/src/tests/basic/test_client_server.c
+++ b/src/tests/basic/test_client_server.c
@@ -38,7 +38,6 @@ main (int argc, char *argv[])
       .client_cb = &MHDT_client_get_root,
       .client_cb_cls = "Hello world",
       .timeout_ms = 5,
-      .num_clients = 10
     },
     // Basic upload
     // HTTP client header
@@ -83,7 +82,7 @@ main (int argc, char *argv[])
   //
   return MHDT_test (&MHDT_server_setup_minimal,
                     NULL,
-                    &MHDT_server_run_blocking,
+                    &MHDT_server_run_minimal,
                     NULL,
                     phases);
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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