summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2021-05-03 16:33:45 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2021-05-03 16:33:45 +0200
commit5bb2578678064ff4d537fcbc8d9a552a6779892d (patch)
tree9259bc87189b7b9fc4d721a751321bbd4204b964
parentcddca0530fdf461607d6c0af908bb527df6193f2 (diff)
parent49473b425783d156e920a4bafcb01747fefeb175 (diff)
Merge branch 'master' of ssh://gnunet.org/gnunet
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_child_management_lib.h2
-rw-r--r--src/include/gnunet_util_lib.h1
-rw-r--r--src/util/Makefile.am13
-rwxr-xr-xsrc/util/child_management_test.sh2
-rw-r--r--src/util/test_child_management.c177
6 files changed, 194 insertions, 2 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index faef696a7..efbb06d4f 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -25,6 +25,7 @@ gnunetinclude_HEADERS = \
gnunet_block_group_lib.h \
gnunet_block_plugin.h \
gnunet_buffer_lib.h \
+ gnunet_child_management_lib.h \
gnunet_client_lib.h \
gnunet_common.h \
gnunet_constants.h \
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 */