gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: migrate test as well, integrate child_ma


From: gnunet
Subject: [gnunet] branch master updated: migrate test as well, integrate child_management with libgnunetutil
Date: Mon, 03 May 2021 16:24:14 +0200

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 53a6e5487 migrate test as well, integrate child_management with 
libgnunetutil
53a6e5487 is described below

commit 53a6e5487f38be5b71c22978f2d400956c3c04c9
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 3 16:22:02 2021 +0200

    migrate test as well, integrate child_management with libgnunetutil
---
 src/include/gnunet_child_management_lib.h |   2 +-
 src/include/gnunet_util_lib.h             |   1 +
 src/util/Makefile.am                      |  13 ++-
 src/util/child_management_test.sh         |   2 +
 src/util/test_child_management.c          | 177 ++++++++++++++++++++++++++++++
 5 files changed, 193 insertions(+), 2 deletions(-)

diff --git a/src/include/gnunet_child_management_lib.h 
b/src/include/gnunet_child_management_lib.h
index 465f71f0e..a35b37865 100644
--- a/src/include/gnunet_child_management_lib.h
+++ b/src/include/gnunet_child_management_lib.h
@@ -19,7 +19,7 @@
  */
 
 /**
- * @file include/anastasis_util_lib.h
+ * @file include/gnunet_child_management_lib.h
  * @brief GNUnet child management api
  * @author Christian Grothoff
  * @author Dominik Meister
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 5e790550f..3acd4cb9b 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -84,6 +84,7 @@ extern "C"
 #include "gnunet_tun_lib.h"
 #include "gnunet_dnsstub_lib.h"
 #include "gnunet_dnsparser_lib.h"
+#include "gnunet_child_management_lib.h"
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 09620aee0..9c1fb01a4 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -43,6 +43,7 @@ libgnunetutil_la_SOURCES = \
   $(BENCHMARK) \
   bio.c \
   buffer.c \
+  child_management.c \
   client.c \
   common_allocation.c \
   common_endian.c \
@@ -271,6 +272,7 @@ check_SCRIPTS = \
 
 check_PROGRAMS = \
  test_bio \
+ test_child_management \
  test_client.nc \
  $(TEST_CLIENT_UNIX_NC) \
  test_common_allocation \
@@ -323,6 +325,14 @@ check_PROGRAMS = \
  test_common_logging_runtime_loglevels
 
 
+test_child_management_SOURCES = \
+  test_child_management.c
+test_child_management_LDADD = \
+  libgnunetutil.la \
+  $(XLIB)
+
+
+
 # Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart
 # sequential execution order for them
 TEST_EXTENSIONS = .nc
@@ -650,4 +660,5 @@ EXTRA_DIST = \
   test_program_data.conf \
   test_resolver_api_data.conf \
   test_service_data.conf \
-  test_speedup_data.conf
+  test_speedup_data.conf \
+  child_management_test.sh
diff --git a/src/util/child_management_test.sh 
b/src/util/child_management_test.sh
new file mode 100755
index 000000000..a35b865f3
--- /dev/null
+++ b/src/util/child_management_test.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+echo "$1$2" >> child_management_test.txt
diff --git a/src/util/test_child_management.c b/src/util/test_child_management.c
new file mode 100644
index 000000000..62c143420
--- /dev/null
+++ b/src/util/test_child_management.c
@@ -0,0 +1,177 @@
+/*
+  This file is part of GNUnet
+  Copyright (C) 2014-2021 GNUnet e.V.
+
+  GNUNET is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 3, 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 General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with GNUNET; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file lib/test_child_management.c
+ * @brief testcase to test the child management
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+
+
+static struct GNUNET_ChildWaitHandle *cwh;
+
+static int global_ret;
+
+static struct GNUNET_OS_Process *pid;
+
+
+static void
+child_completed_callback (void *cls,
+                          enum GNUNET_OS_ProcessStatusType type,
+                          long unsigned int exit_code)
+{
+  cwh = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Process extided with code: %lu \n",
+              exit_code);
+  FILE *file;
+  char code[9];
+
+  file = fopen ("child_management_test.txt", "r");
+  if (NULL == file)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "could not find file: child_management_test.txt in %s:%u\n",
+                __FILE__,
+                __LINE__);
+    global_ret = 1;
+    return;
+  }
+  if (0 == fscanf (file,
+                   "%8s",
+                   code))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "could not read file: child_management_test.txt in %s:%u\n",
+                __FILE__,
+                __LINE__);
+    global_ret = 1;
+    return;
+  }
+
+  if (0 != strcmp ("12345678", code))
+  {
+    global_ret = 1;
+    return;
+  }
+  GNUNET_OS_process_destroy (pid);
+  pid = NULL;
+  GNUNET_break (0 == unlink ("child_management_test.txt"));
+  GNUNET_SCHEDULER_shutdown ();
+  global_ret = 0;
+}
+
+
+static void
+do_shutdown (void *cls)
+{
+  if (NULL != cwh)
+  {
+    GNUNET_wait_child_cancel (cwh);
+    cwh = NULL;
+  }
+  if (NULL != pid)
+  {
+    GNUNET_assert (0 ==
+                   GNUNET_OS_process_kill (pid,
+                                           SIGKILL));
+    GNUNET_assert (GNUNET_OK ==
+                   GNUNET_OS_process_wait (pid));
+    GNUNET_OS_process_destroy (pid);
+    pid = NULL;
+  }
+}
+
+
+static void
+test_child_management (void *cls)
+{
+  const char *command = "./child_management_test.sh";
+  struct GNUNET_DISK_PipeHandle *p;
+  struct GNUNET_DISK_FileHandle *out;
+
+  (void) cls;
+  p = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
+  if (NULL == p)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                         "pipe");
+    global_ret = 2;
+    return;
+  }
+  pid = GNUNET_OS_start_process (0,
+                                 p,
+                                 NULL,
+                                 NULL,
+                                 command,
+                                 command,
+                                 "1234",
+                                 "5678",
+                                 NULL);
+  if (NULL == pid)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                         "fork");
+    GNUNET_break (GNUNET_OK ==
+                  GNUNET_DISK_pipe_close (p));
+    global_ret = 1;
+    return;
+  }
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_pipe_close_end (p,
+                                            GNUNET_DISK_PIPE_END_READ));
+  out = GNUNET_DISK_pipe_detach_end (p,
+                                     GNUNET_DISK_PIPE_END_WRITE);
+  GNUNET_assert (NULL != out);
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_pipe_close (p));
+
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                 NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Alright");
+  cwh = GNUNET_wait_child (pid,
+                           &child_completed_callback,
+                           cls);
+  GNUNET_break (NULL != cwh);
+  GNUNET_assert (5 ==
+                 GNUNET_DISK_file_write (out,
+                                         "Hello",
+                                         5));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_file_close (out));
+}
+
+
+int
+main (int argc,
+      const char *const argv[])
+{
+  GNUNET_log_setup (argv[0],
+                    "DEBUG",
+                    NULL);
+  GNUNET_SCHEDULER_run (&test_child_management,
+                        NULL);
+  return global_ret;
+}
+
+
+/* end of test_anastasis_child_management.c */

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