gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 01/02: -add first dhtu test skeleton


From: gnunet
Subject: [gnunet] 01/02: -add first dhtu test skeleton
Date: Thu, 23 Sep 2021 22:52:53 +0200

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

grothoff pushed a commit to branch master
in repository gnunet.

commit 8f18cbcaf6025d40fa1d400f5a4e702ad957809a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Sep 23 22:52:20 2021 +0200

    -add first dhtu test skeleton
---
 src/dhtu/Makefile.am        | 16 ++++++++++
 src/dhtu/test_dhtu_ip.c     | 77 +++++++++++++++++++++++++++++++++++++++++++++
 src/util/child_management.c | 47 +++++++++++----------------
 3 files changed, 111 insertions(+), 29 deletions(-)

diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am
index 33c31dd6c..61ca84ee3 100644
--- a/src/dhtu/Makefile.am
+++ b/src/dhtu/Makefile.am
@@ -39,3 +39,19 @@ libgnunet_plugin_dhtu_gnunet_la_LIBADD = \
   $(LTLIBINTL)
 libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \
  $(GN_PLUGIN_LDFLAGS)
+
+
+test_dhtu_ip_SOURCES = \
+ test_dhtu_ip.c
+test_dhtu_ip_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
+check_PROGRAMS = \
+ test_dhtu_ip
+
+if ENABLE_TEST_RUN
+AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export 
PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset 
XDG_CONFIG_HOME;
+TESTS = \
+ $(check_PROGRAMS)
+endif
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
new file mode 100644
index 000000000..f350905b8
--- /dev/null
+++ b/src/dhtu/test_dhtu_ip.c
@@ -0,0 +1,77 @@
+/*
+      This file is part of GNUnet
+      Copyright (C) 2021 GNUnet e.V.
+
+      GNUnet is free software: you can redistribute it and/or modify it
+      under the terms of the GNU Affero General Public License as published
+      by the Free Software Foundation, either version 3 of the License,
+      or (at your option) any later version.
+
+      GNUnet is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      Affero General Public License for more details.
+
+      You should have received a copy of the GNU Affero General Public License
+      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file dhtu/test_dhtu_ip.c
+ * @brief Test case for the DHTU implementation for IP
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+
+#define CONFIG_FILE "test_dhtu_ip.conf"
+
+
+/**
+ * Return value of the test.
+ *
+ */
+static int rv;
+
+
+/**
+ * Main function to run the test cases.
+ *
+ * @param cls not used.
+ */
+static void
+run (void *cls)
+{
+  struct GNUNET_TESTING_Command commands[] = {
+    GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
+                                         CONFIG_FILE),
+    GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
+                                        CONFIG_FILE),
+    GNUNET_TESTING_cmd_end ()
+  };
+
+  (void) cls;
+  if (GNUNET_OK !=
+      GNUNET_TESTING_run (NULL, /* config file */
+                          commands,
+                          TIMEOUT))
+  {
+    GNUNET_break (0);
+    rv = EXIT_FAILURE;
+  }
+}
+
+
+int
+main (int argc,
+      char *const *argv)
+{
+  GNUNET_SCHEDULER_run (&run,
+                        NULL);
+  return rv;
+}
diff --git a/src/util/child_management.c b/src/util/child_management.c
index 3afd682b9..4ef42dba2 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -91,15 +91,10 @@ maint_child_death (void *cls)
 
   (void) cls;
   sig_task = NULL;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Received SIGCHLD.\n");
-
   /* drain pipe */
   pr = GNUNET_DISK_pipe_handle (sigpipe,
                                 GNUNET_DISK_PIPE_END_READ);
   GNUNET_assert (! GNUNET_DISK_handle_invalid (pr));
-
   (void) GNUNET_DISK_file_read (pr,
                                 buf,
                                 sizeof(buf));
@@ -159,9 +154,8 @@ sighandler_child_death (void)
 }
 
 
-// void __attribute__ ((constructor))
 static void
-child_management_start ()
+child_management_start (void)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Trying to start child management.\n");
@@ -170,19 +164,24 @@ child_management_start ()
   sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
   GNUNET_assert (sigpipe != NULL);
   shc_chld =
-    GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
+    GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
+                                   &sighandler_child_death);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Child management started.\n");
 }
 
+
 /**
  * Clean up.
  */
-// void __attribute__ ((destructor))
 static void
-child_management_done ()
+child_management_done (void)
 {
-  GNUNET_assert (NULL == sig_task);
+  if (NULL != sig_task)
+  {
+    GNUNET_SCHEDULER_cancel (sig_task);
+    sig_task = NULL;
+  }
   GNUNET_SIGNAL_handler_uninstall (shc_chld);
   shc_chld = NULL;
   GNUNET_DISK_pipe_close (sigpipe);
@@ -191,6 +190,7 @@ child_management_done ()
               "Child management stopped.\n");
 }
 
+
 struct GNUNET_ChildWaitHandle *
 GNUNET_wait_child (struct GNUNET_OS_Process *proc,
                    GNUNET_ChildCompletedCallback cb,
@@ -198,9 +198,6 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
 {
   struct GNUNET_ChildWaitHandle *cwh;
 
-  LOG (GNUNET_ERROR_TYPE_ERROR,
-       "Adding child!\n");
-
   child_management_start ();
   cwh = GNUNET_new (struct GNUNET_ChildWaitHandle);
   cwh->proc = proc;
@@ -221,23 +218,15 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
   return cwh;
 }
 
+
 void
 GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
 {
-  if ((NULL != cwh_head))
-  {
-    GNUNET_CONTAINER_DLL_remove (cwh_head,
-                                 cwh_tail,
-                                 cwh);
-  }
-  if (NULL == cwh_head)
-  {
-    child_management_done ();
-  }
-  if (NULL != sig_task)
-  {
-    GNUNET_SCHEDULER_cancel (sig_task);
-    sig_task = NULL;
-  }
+  GNUNET_CONTAINER_DLL_remove (cwh_head,
+                               cwh_tail,
+                               cwh);
   GNUNET_free (cwh);
+  if (NULL != cwh_head)
+    return;
+  child_management_done ();
 }

-- 
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]