diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-23 22:52:20 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-23 22:52:20 +0200 |
commit | 8f18cbcaf6025d40fa1d400f5a4e702ad957809a (patch) | |
tree | d6cf2493590f5fd0091c17b6e30bda7ca56fbf9a /src | |
parent | b2cf59bdd77a76cdbeade6e948ca39e1085def35 (diff) | |
download | gnunet-8f18cbcaf6025d40fa1d400f5a4e702ad957809a.tar.gz gnunet-8f18cbcaf6025d40fa1d400f5a4e702ad957809a.zip |
-add first dhtu test skeleton
Diffstat (limited to 'src')
-rw-r--r-- | src/dhtu/Makefile.am | 16 | ||||
-rw-r--r-- | src/dhtu/test_dhtu_ip.c | 77 | ||||
-rw-r--r-- | 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 = \ | |||
39 | $(LTLIBINTL) | 39 | $(LTLIBINTL) |
40 | libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ | 40 | libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ |
41 | $(GN_PLUGIN_LDFLAGS) | 41 | $(GN_PLUGIN_LDFLAGS) |
42 | |||
43 | |||
44 | test_dhtu_ip_SOURCES = \ | ||
45 | test_dhtu_ip.c | ||
46 | test_dhtu_ip_LDADD = \ | ||
47 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
48 | $(top_builddir)/src/util/libgnunetutil.la | ||
49 | |||
50 | check_PROGRAMS = \ | ||
51 | test_dhtu_ip | ||
52 | |||
53 | if ENABLE_TEST_RUN | ||
54 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | ||
55 | TESTS = \ | ||
56 | $(check_PROGRAMS) | ||
57 | 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 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file dhtu/test_dhtu_ip.c | ||
23 | * @brief Test case for the DHTU implementation for IP | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
31 | |||
32 | #define CONFIG_FILE "test_dhtu_ip.conf" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Return value of the test. | ||
37 | * | ||
38 | */ | ||
39 | static int rv; | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Main function to run the test cases. | ||
44 | * | ||
45 | * @param cls not used. | ||
46 | */ | ||
47 | static void | ||
48 | run (void *cls) | ||
49 | { | ||
50 | struct GNUNET_TESTING_Command commands[] = { | ||
51 | GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", | ||
52 | CONFIG_FILE), | ||
53 | GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop", | ||
54 | CONFIG_FILE), | ||
55 | GNUNET_TESTING_cmd_end () | ||
56 | }; | ||
57 | |||
58 | (void) cls; | ||
59 | if (GNUNET_OK != | ||
60 | GNUNET_TESTING_run (NULL, /* config file */ | ||
61 | commands, | ||
62 | TIMEOUT)) | ||
63 | { | ||
64 | GNUNET_break (0); | ||
65 | rv = EXIT_FAILURE; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | |||
70 | int | ||
71 | main (int argc, | ||
72 | char *const *argv) | ||
73 | { | ||
74 | GNUNET_SCHEDULER_run (&run, | ||
75 | NULL); | ||
76 | return rv; | ||
77 | } | ||
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) | |||
91 | 91 | ||
92 | (void) cls; | 92 | (void) cls; |
93 | sig_task = NULL; | 93 | sig_task = NULL; |
94 | |||
95 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
96 | "Received SIGCHLD.\n"); | ||
97 | |||
98 | /* drain pipe */ | 94 | /* drain pipe */ |
99 | pr = GNUNET_DISK_pipe_handle (sigpipe, | 95 | pr = GNUNET_DISK_pipe_handle (sigpipe, |
100 | GNUNET_DISK_PIPE_END_READ); | 96 | GNUNET_DISK_PIPE_END_READ); |
101 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); | 97 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); |
102 | |||
103 | (void) GNUNET_DISK_file_read (pr, | 98 | (void) GNUNET_DISK_file_read (pr, |
104 | buf, | 99 | buf, |
105 | sizeof(buf)); | 100 | sizeof(buf)); |
@@ -159,9 +154,8 @@ sighandler_child_death (void) | |||
159 | } | 154 | } |
160 | 155 | ||
161 | 156 | ||
162 | // void __attribute__ ((constructor)) | ||
163 | static void | 157 | static void |
164 | child_management_start () | 158 | child_management_start (void) |
165 | { | 159 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
167 | "Trying to start child management.\n"); | 161 | "Trying to start child management.\n"); |
@@ -170,19 +164,24 @@ child_management_start () | |||
170 | sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); | 164 | sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); |
171 | GNUNET_assert (sigpipe != NULL); | 165 | GNUNET_assert (sigpipe != NULL); |
172 | shc_chld = | 166 | shc_chld = |
173 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 167 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, |
168 | &sighandler_child_death); | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
175 | "Child management started.\n"); | 170 | "Child management started.\n"); |
176 | } | 171 | } |
177 | 172 | ||
173 | |||
178 | /** | 174 | /** |
179 | * Clean up. | 175 | * Clean up. |
180 | */ | 176 | */ |
181 | // void __attribute__ ((destructor)) | ||
182 | static void | 177 | static void |
183 | child_management_done () | 178 | child_management_done (void) |
184 | { | 179 | { |
185 | GNUNET_assert (NULL == sig_task); | 180 | if (NULL != sig_task) |
181 | { | ||
182 | GNUNET_SCHEDULER_cancel (sig_task); | ||
183 | sig_task = NULL; | ||
184 | } | ||
186 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 185 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
187 | shc_chld = NULL; | 186 | shc_chld = NULL; |
188 | GNUNET_DISK_pipe_close (sigpipe); | 187 | GNUNET_DISK_pipe_close (sigpipe); |
@@ -191,6 +190,7 @@ child_management_done () | |||
191 | "Child management stopped.\n"); | 190 | "Child management stopped.\n"); |
192 | } | 191 | } |
193 | 192 | ||
193 | |||
194 | struct GNUNET_ChildWaitHandle * | 194 | struct GNUNET_ChildWaitHandle * |
195 | GNUNET_wait_child (struct GNUNET_OS_Process *proc, | 195 | GNUNET_wait_child (struct GNUNET_OS_Process *proc, |
196 | GNUNET_ChildCompletedCallback cb, | 196 | GNUNET_ChildCompletedCallback cb, |
@@ -198,9 +198,6 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, | |||
198 | { | 198 | { |
199 | struct GNUNET_ChildWaitHandle *cwh; | 199 | struct GNUNET_ChildWaitHandle *cwh; |
200 | 200 | ||
201 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
202 | "Adding child!\n"); | ||
203 | |||
204 | child_management_start (); | 201 | child_management_start (); |
205 | cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); | 202 | cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); |
206 | cwh->proc = proc; | 203 | cwh->proc = proc; |
@@ -221,23 +218,15 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, | |||
221 | return cwh; | 218 | return cwh; |
222 | } | 219 | } |
223 | 220 | ||
221 | |||
224 | void | 222 | void |
225 | GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) | 223 | GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) |
226 | { | 224 | { |
227 | if ((NULL != cwh_head)) | 225 | GNUNET_CONTAINER_DLL_remove (cwh_head, |
228 | { | 226 | cwh_tail, |
229 | GNUNET_CONTAINER_DLL_remove (cwh_head, | 227 | cwh); |
230 | cwh_tail, | ||
231 | cwh); | ||
232 | } | ||
233 | if (NULL == cwh_head) | ||
234 | { | ||
235 | child_management_done (); | ||
236 | } | ||
237 | if (NULL != sig_task) | ||
238 | { | ||
239 | GNUNET_SCHEDULER_cancel (sig_task); | ||
240 | sig_task = NULL; | ||
241 | } | ||
242 | GNUNET_free (cwh); | 228 | GNUNET_free (cwh); |
229 | if (NULL != cwh_head) | ||
230 | return; | ||
231 | child_management_done (); | ||
243 | } | 232 | } |