summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-11-09 17:38:47 +0100
committert3sserakt <t3ss@posteo.de>2021-11-09 17:43:25 +0100
commit8cd4dadfb9ebd4db232fda79d5c4353eacb15690 (patch)
treea063e52d71d1b6611371f6c129c6ae1b0215cf99 /src/testing
parent6fb788ca2ec44837ea10a36be7fd0030fb08955b (diff)
- moved global netjail methods to its own header file.dev/t3ss/tng
- added configuration by string in test skript instead of config file. - moved netjail scripts to contrib/netjail and install them into the share/gnunet directory.
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am40
-rw-r--r--src/testing/gnunet-cmds-helper.c41
-rw-r--r--src/testing/test_testing_api_cmd_netjail.c87
-rw-r--r--src/testing/test_testing_hello_world.c68
-rw-r--r--src/testing/test_testing_plugin_testcmd.c123
-rw-r--r--src/testing/test_testing_topology.c44
-rw-r--r--src/testing/testing.c99
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c107
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c1
-rw-r--r--src/testing/testing_api_cmd_finish.c2
-rw-r--r--src/testing/testing_api_cmd_hello_world.c126
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c161
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c1
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c1
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c43
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c187
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c77
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c14
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c1
-rw-r--r--src/testing/testing_api_cmd_system_create.c1
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c1
21 files changed, 262 insertions, 963 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 3daa29e1e..a9a1b5a02 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -18,9 +18,6 @@ libexec_PROGRAMS = \
plugindir = $(libdir)/gnunet
-plugin_LTLIBRARIES = \
- libgnunet_test_testing_plugin_testcmd.la
-
lib_LTLIBRARIES = \
libgnunettesting.la
@@ -31,25 +28,12 @@ gnunet_cmds_helper_LDADD = $(XLIB) \
libgnunettesting.la \
$(LTLIBINTL) $(Z_LIBS)
-libgnunet_test_testing_plugin_testcmd_la_SOURCES = \
- test_testing_plugin_testcmd.c
-libgnunet_test_testing_plugin_testcmd_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
- libgnunettesting.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(LTLIBINTL)
-libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
-
libgnunettesting_la_SOURCES = \
testing_api_cmd_end.c \
testing_api_cmd_finish.c \
testing_api_cmd_local_test_finished.c \
testing_api_cmd_local_test_prepared.c \
testing_api_cmd_send_peer_ready.c \
- testing_api_cmd_block_until_all_peers_started.c \
testing_api_cmd_block_until_external_trigger.c \
testing_api_cmd_netjail_start.c \
testing_api_cmd_netjail_start_testsystem.c \
@@ -59,8 +43,6 @@ libgnunettesting_la_SOURCES = \
testing_api_cmd_system_create.c \
testing_api_cmd_system_destroy.c \
testing_api_cmd_batch.c \
- testing_api_cmd_hello_world.c \
- testing_api_cmd_hello_world_birth.c \
testing_api_loop.c \
testing_api_trait_cmd.c \
testing_api_trait_process.c \
@@ -94,8 +76,6 @@ list_keys_LDADD = \
check_PROGRAMS = \
- test_testing_api_cmd_netjail \
- test_testing_hello_world \
test_testing_portreservation \
test_testing_servicestartup \
test_testing_peerstartup \
@@ -105,32 +85,12 @@ check_PROGRAMS = \
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 = \
- test_testing_api_cmd_netjail \
- test_testing_hello_world \
test_testing_portreservation \
test_testing_peerstartup \
test_testing_peerstartup2 \
test_testing_servicestartup
endif
-#test_testing_topology_SOURCES = \
-# test_testing_topology.c
-#test_testing_topology_LDADD = \
-# libgnunettesting.la \
-# $(top_builddir)/src/util/libgnunetutil.la
-
-test_testing_api_cmd_netjail_SOURCES = \
- test_testing_api_cmd_netjail.c
-test_testing_api_cmd_netjail_LDADD = \
- libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-test_testing_hello_world_SOURCES = \
- test_testing_hello_world.c
-test_testing_hello_world_LDADD = \
- libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
test_testing_portreservation_SOURCES = \
test_testing_portreservation.c
test_testing_portreservation_LDADD = \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 4aeccb115..f90cc3cc4 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -142,6 +142,16 @@ struct NodeIdentifier
*
*/
char *local_m;
+
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
+
+ /**
+ * String with topology data or name of topology file.
+ */
+ char *topology_data;
};
/**
@@ -402,7 +412,8 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
strcat (node_ip, plugin->m);
plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
- plugin->n, plugin->local_m);
+ plugin->n, plugin->local_m, ni->topology_data,
+ ni->read_file);
GNUNET_free (binary);
@@ -559,6 +570,10 @@ main (int argc, char **argv)
struct GNUNET_GETOPT_CommandLineOption options[] =
{ GNUNET_GETOPT_OPTION_END };
int ret;
+ int i;
+ size_t topology_data_length = 0;
+ unsigned int read_file;
+ char cr[1] = "\n";
GNUNET_log_setup ("gnunet-cmds-helper",
"DEBUG",
@@ -569,6 +584,30 @@ main (int argc, char **argv)
ni->m = argv[3];
ni->n = argv[4];
+ sscanf (argv[5], "%u", &read_file);
+
+ if (1 == read_file)
+ ni->topology_data = argv[6];
+ else
+ {
+ for (i = 6; i<argc; i++)
+ topology_data_length += strlen (argv[i]) + 1;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "topo data length %lu\n",
+ topology_data_length);
+ ni->topology_data = GNUNET_malloc (topology_data_length);
+ for (i = 6; i<argc; i++)
+ {
+ strcat (ni->topology_data, argv[i]);
+ strcat (ni->topology_data, cr);
+ }
+ }
+ ni->read_file = &read_file;
+ ni->topology_data[topology_data_length - 1] = '\0';
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "topo data %s\n",
+ ni->topology_data);
+
status = GNUNET_OK;
if (NULL ==
(sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
diff --git a/src/testing/test_testing_api_cmd_netjail.c b/src/testing/test_testing_api_cmd_netjail.c
deleted file mode 100644
index aeddfb7c9..000000000
--- a/src/testing/test_testing_api_cmd_netjail.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- 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 testing/test_testbed_api_cmd_netjail.c
- * @brief Test case executing a script in a network name space.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-
-
-/**
- * Return value of the test.
- *
- */
-static unsigned int rv = 0;
-
-
-/**
- * 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 ("netjail-start-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
- "2",
- "2",
- "libgnunet_plugin_testcmd",
- &rv),
- GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
- "netjail-start-testbed-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_end ()
- };
-
- GNUNET_TESTING_run (NULL,
- commands,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
-
-
-int
-main (int argc,
- char *const *argv)
-{
- int rv = 0;
-
- GNUNET_log_setup ("test-netjail",
- "DEBUG",
- NULL);
- GNUNET_SCHEDULER_run (&run,
- NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test finished!\n");
- return rv;
-}
diff --git a/src/testing/test_testing_hello_world.c b/src/testing/test_testing_hello_world.c
deleted file mode 100644
index 6300e26a4..000000000
--- a/src/testing/test_testing_hello_world.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- 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 testing/test_testing_hello_world.c
- * @brief hello world test case
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-
-/**
- * Main function to run the test cases.
- *
- * @param cls not used.
- *
- */
-static void
-run (void *cls)
-{
- (void *) cls;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-
- struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
- &now),
- GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
- GNUNET_TESTING_cmd_end ()
- };
-
- GNUNET_TESTING_run (NULL,
- commands,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
-
-int
-main (int argc,
- char *const *argv)
-{
- int rv = 0;
-
- GNUNET_log_setup ("test-hello-world",
- "DEBUG",
- NULL);
-
- GNUNET_SCHEDULER_run (&run,
- NULL);
-
- return rv;
-}
diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c
deleted file mode 100644
index 32e2b38a7..000000000
--- a/src/testing/test_testing_plugin_testcmd.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- 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 testbed/plugin_testcmd.c
- * @brief a plugin to provide the API for running test cases.
- * @author t3sserakt
- *
- * // FIXME: too verbose, no logic to return final status, will segv!
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-
-// FIXME: bad global!
-unsigned int are_all_peers_started;
-
-
-static void
-all_peers_started ()
-{
- are_all_peers_started = GNUNET_YES;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "setting are_all_peers_started: %d\n",
- are_all_peers_started);
-}
-
-
-static void
-start_testcase (TESTING_CMD_HELPER_write_cb write_message,
- char *router_ip,
- char *node_ip,
- char *n,
- char *m,
- char *local_m)
-{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 6!\n");
-
- are_all_peers_started = GNUNET_NO;
-
- struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
- &now),
- GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
- GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
- write_message),
- GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
- &are_all_peers_started),
- GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
- write_message)
- };
-
- GNUNET_TESTING_run (commands,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, /* FIXME: pass continuation! */
- NULL);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 7!\n");
-
-}
-
-
-/**
- * Entry point for the plugin.
- *
- * @param cls NULL
- * @return the exported block API
- */
-void *
-libgnunet_plugin_testcmd_init (void *cls)
-{
- struct GNUNET_TESTING_PluginFunctions *api;
-
- api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
- api->start_testcase = &start_testcase;
- api->all_peers_started = &all_peers_started;
- return api;
-}
-
-
-/**
- * Exit point from the plugin.
- *
- * @param cls the return value from #libgnunet_plugin_block_test_init
- * @return NULL
- */
-void *
-libgnunet_plugin_testcmd_done (void *cls)
-{
- struct GNUNET_TESTING_PluginFunctions *api = cls;
-
- GNUNET_free (api);
- return NULL;
-}
-
-
-
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
deleted file mode 100644
index cfc91e609..000000000
--- a/src/testing/test_testing_topology.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- 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 testbed/plugin_testcmd.c
- * @brief a plugin to provide the API for running test cases.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
-
-int
-main (int argc,
- char *const *argv)
-{
- GNUNET_log_setup ("test-topology",
- "DEBUG",
- NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Test\n");
- GNUNET_TESTING_get_topo_from_file ("topo.conf");
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Test2\n");
-}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 02cedc744..4ccf93c6b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -33,7 +33,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
-#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -2102,6 +2102,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
struct GNUNET_HashCode hc;
struct GNUNET_TESTING_NetjailNamespace *namespace;
unsigned int namespace_n, node_m;
+ struct GNUNET_TESTING_NodeConnection *node_connections = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"gaga 1\n");
@@ -2121,6 +2122,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
sizeof (*hkey));
node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
hkey);
+ node_connections = node->node_connections_head;
}
else
{
@@ -2147,10 +2149,11 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
sizeof (*hkey));
node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
hkey);
+ node_connections = node->node_connections_head;
}
GNUNET_free (hkey);
- return node->node_connections_head;
+ return node_connections;
}
@@ -2355,16 +2358,14 @@ GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
/**
- * Getting the topology from file.
+ * Parse the topology data.
*
- * @param filename The name of the topology file.
+ * @param data The topology data.
* @return The GNUNET_TESTING_NetjailTopology
*/
struct GNUNET_TESTING_NetjailTopology *
-GNUNET_TESTING_get_topo_from_file (const char *filename)
+GNUNET_TESTING_get_topo_from_string (char *data)
{
- uint64_t fs;
- char *data;
char *token;
char *key = NULL;
unsigned int out;
@@ -2379,36 +2380,9 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
struct GNUNET_ShortHashCode *hkey;
struct GNUNET_HashCode hc;
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s not found\n"),
- filename);
- return NULL;
- }
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s has no data\n"),
- filename);
- return NULL;
- }
- data = GNUNET_malloc (fs);
- if (fs != GNUNET_DISK_fn_read (filename, data, fs))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s cannot be read\n"),
- filename);
- GNUNET_free (data);
- return NULL;
- }
-
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "data: %s\n",
+ "data %s\n",
data);
-
- data[fs] = '\0';
token = strtok_r (data, "\n", &rest);
topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology);
topo->map_namespaces =
@@ -2626,7 +2600,62 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
node_connections (token, node);
}
token = strtok_r (NULL, "\n", &rest);
+ if (NULL != token)
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Next token %s\n",
+ token);
+ }
+
+ return topo;
+}
+
+
+/**
+ * Getting the topology from file.
+ *
+ * @param filename The name of the topology file.
+ * @return The GNUNET_TESTING_NetjailTopology
+ */
+struct GNUNET_TESTING_NetjailTopology *
+GNUNET_TESTING_get_topo_from_file (const char *filename)
+{
+ uint64_t fs;
+ char *data;
+ struct GNUNET_TESTING_NetjailTopology *topo;
+
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s not found\n"),
+ filename);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s has no data\n"),
+ filename);
+ return NULL;
}
+ data = GNUNET_malloc (fs);
+ if (fs != GNUNET_DISK_fn_read (filename, data, fs))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s cannot be read\n"),
+ filename);
+ GNUNET_free (data);
+ return NULL;
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "data: %s\n",
+ data);
+
+ data[fs] = '\0';
+
+ topo = GNUNET_TESTING_get_topo_from_string (data);
+
GNUNET_free (data);
return topo;
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
deleted file mode 100644
index 763713e15..000000000
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- 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 testing_api_cmd_block_until_all_peers_started.c
- * @brief cmd to block the interpreter loop until all peers started.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-/**
- * Struct with information for callbacks.
- *
- */
-struct BlockState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- /**
- * Flag to indicate if all peers have started.
- *
- */
- unsigned int *all_peers_started;
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-block_until_all_peers_started_cleanup (void *cls)
-{
- struct BlockState *bs = cls;
-
- GNUNET_free (bs);
-}
-
-
-/**
- * This function does nothing but to start the cmd.
- *
- */
-static void
-block_until_all_peers_started_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "block_until_all_peers_started_run!\n");
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param all_peers_started Flag which will be set from outside.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
- unsigned int *
- all_peers_started)
-{
- struct BlockState *bs;
-
- bs = GNUNET_new (struct BlockState);
- bs->all_peers_started = all_peers_started;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = label,
- .run = &block_until_all_peers_started_run,
- .ac = &bs->ac,
- .cleanup = &block_until_all_peers_started_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index aeb9ffda3..7ff554280 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
/**
* Generic logging shortcut
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c
index 3ac0871a5..47199d3d6 100644
--- a/src/testing/testing_api_cmd_finish.c
+++ b/src/testing/testing_api_cmd_finish.c
@@ -25,6 +25,8 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+
/**
* Struct to use for command-specific context information closure of a command waiting
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
deleted file mode 100644
index 73dcd6dff..000000000
--- a/src/testing/testing_api_cmd_hello_world.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- 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 testing/testing_api_cmd_hello_world.c
- * @brief implementation of a hello world command.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-
-struct HelloWorldState
-{
- char *message;
- const char *birthLabel;
-};
-
-
-/**
- *
- *
- * @param cls closure
- */
-static void
-hello_world_cleanup (void *cls)
-{
- struct HelloWorldState *hs = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Cleaning up message %s\n",
- hs->message);
- GNUNET_free (hs);
-}
-
-
-/**
- *
- *
- * @param cls closure.
- * @param[out] ret result
- * @param trait name of the trait.
- * @param index index number of the object to offer.
- * @return #GNUNET_OK on success.
- */
-static enum GNUNET_GenericReturnValue
-hello_world_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_NO;
-}
-
-
-/**
-* Run the "hello world" CMD.
-*
-* @param cls closure.
-* @param is interpreter state.
-*/
-static void
-hello_world_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct HelloWorldState *hs = cls;
- const struct GNUNET_TESTING_Command *birth_cmd;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%s\n",
- hs->message);
- birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- hs->birthLabel);
- GNUNET_TESTING_get_trait_what_am_i (birth_cmd,
- &hs->message);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Now I am a %s\n",
- hs->message);
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param message initial message.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world (const char *label,
- const char *birthLabel,
- char *message)
-{
- struct HelloWorldState *hs;
-
- hs = GNUNET_new (struct HelloWorldState);
- hs->message = "Hello World, I was nobody!";
- hs->birthLabel = birthLabel;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = hs,
- .label = label,
- .run = &hello_world_run,
- .cleanup = &hello_world_cleanup,
- .traits = &hello_world_traits
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
deleted file mode 100644
index 8415b99f0..000000000
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- 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 testing/testing_api_cmd_hello_world.c
- * @brief implementation of a hello world command.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-struct HelloWorldBirthState
-{
- struct GNUNET_TIME_Absolute *date;
- char *what_am_i;
-};
-
-/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-hello_world_birth_cleanup (void *cls)
-{
- struct HelloWorldBirthState *hbs = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Finished birth of %s\n",
- hbs->what_am_i);
-}
-
-
-/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
-static int
-hello_world_birth_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct HelloWorldBirthState *hbs = cls;
- const char *what_am_i = hbs->what_am_i;
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "what_am_i",
- .ptr = (const void *) what_am_i,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
-* Run the "hello world" CMD.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-hello_world_birth_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct HelloWorldBirthState *hbs = cls;
- struct GNUNET_TIME_Relative relative;
-
- relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
- GNUNET_TIME_absolute_get ());
-
- if (0 == relative.rel_value_us % 10)
- {
- hbs->what_am_i = "creature!";
- }
- else if (0 == relative.rel_value_us % 2)
- {
- hbs->what_am_i = "girl!";
- }
- else
- {
- hbs->what_am_i = "boy!";
- }
-}
-
-
-/**
- * Offer data from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
- char **what_am_i)
-{
- return cmd->traits (cmd->cls,
- (const void **) what_am_i,
- "what_am_i",
- (unsigned int) 0);
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param now when the command was started.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world_birth (const char *label,
- struct GNUNET_TIME_Absolute *now)
-{
- struct HelloWorldBirthState *hbs;
-
- hbs = GNUNET_new (struct HelloWorldBirthState);
- hbs->date = now;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = hbs,
- .label = label,
- .run = &hello_world_birth_run,
- .cleanup = &hello_world_birth_cleanup,
- .traits = &hello_world_birth_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 8f8a8230c..709c6b62f 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
/**
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 2554d6fec..9dc7dfa9a 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
/**
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 35fb90f3c..2ff70c33e 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -26,8 +26,11 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
-#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
+#define NETJAIL_START_SCRIPT "netjail_start.sh"
+
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
/**
* Struct to hold information for callbacks.
@@ -53,6 +56,10 @@ struct NetJailState
*/
char *topology_config;
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
};
@@ -70,11 +77,15 @@ netjail_start_cleanup (void *cls)
if (NULL != ns->cwh)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cancel child\n");
GNUNET_wait_child_cancel (ns->cwh);
ns->cwh = NULL;
}
if (NULL != ns->start_proc)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Kill process\n");
GNUNET_assert (0 ==
GNUNET_OS_process_kill (ns->start_proc,
SIGKILL));
@@ -100,6 +111,7 @@ child_completed_callback (void *cls,
GNUNET_OS_process_destroy (ns->start_proc);
ns->start_proc = NULL;
+ ns->cwh = NULL;
if (0 == exit_code)
{
GNUNET_TESTING_async_finish (&ns->ac);
@@ -127,20 +139,28 @@ netjail_start_run (void *cls,
struct NetJailState *ns = cls;
char pid[15];
enum GNUNET_GenericReturnValue helper_check;
+ char *data_dir;
+ char *script_name;
+ char *read_file;
+
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
- // FIXME: NETJAIL_START_SCRIPT like this is bad,
- // use location from share/gnunet/ of installed
- // binary in case libgnunettesting is used as a lib!
helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_START_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "script_name %s\n",
+ script_name);
+
if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_START_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
return;
}
@@ -148,7 +168,7 @@ netjail_start_run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_START_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
return;
}
@@ -159,9 +179,10 @@ netjail_start_run (void *cls,
getpid ());
{
char *const script_argv[] = {
- NETJAIL_START_SCRIPT,
+ script_name,
ns->topology_config,
pid,
+ read_file,
NULL
};
@@ -170,7 +191,7 @@ netjail_start_run (void *cls,
NULL,
NULL,
NULL,
- NETJAIL_START_SCRIPT,
+ script_name,
script_argv);
}
ns->cwh = GNUNET_wait_child (ns->start_proc,
@@ -189,12 +210,14 @@ netjail_start_run (void *cls,
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *topology_config)
+ char *topology_config,
+ unsigned int *read_file)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
+ ns->read_file = read_file;
{
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index c3598d174..89c193de5 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -25,9 +25,10 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
-#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
+#define NETJAIL_EXEC_SCRIPT "netjail_exec.sh"
/**
* Generic logging shortcut
@@ -83,18 +84,6 @@ struct NetJailState
struct GNUNET_TESTING_NetjailTopology *topology;
/**
- * Head of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_head;
-
- /**
- * Tail of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_tail;
-
- /**
* Array with handles of helper processes.
*/
struct GNUNET_HELPER_Handle **helper;
@@ -123,27 +112,6 @@ struct NetJailState
*/
unsigned int known;
- /**
- * The send handle for the helper
- */
- // struct GNUNET_HELPER_SendHandle **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
-
- /**
- * The messages send to the helper.
- */
- struct GNUNET_MessageHeader **msg;
-
- /**
- * Size of the array NetJailState#msg.
- *
- */
- unsigned int n_msg;
/**
* Number of test environments started.
@@ -176,16 +144,14 @@ struct NetJailState
char *plugin_name;
/**
- * HEAD of the DLL containing TestingSystemCount.
- *
+ * Shall we read the topology from file, or from a string.
*/
- struct TestingSystemCount *tbcs_head;
+ unsigned int *read_file;
/**
- * TAIL of the DLL containing TestingSystemCount.
- *
+ * String with topology data or name of topology file.
*/
- struct TestingSystemCount *tbcs_tail;
+ char *topology_data;
};
/**
@@ -207,13 +173,7 @@ struct TestingSystemCount
/**
* The send handle for the helper
*/
- struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
+ struct GNUNET_HELPER_SendHandle *shandle;
/**
* The number of the test environment.
@@ -226,6 +186,11 @@ struct TestingSystemCount
*
*/
struct NetJailState *ns;
+
+ /**
+ * The messages send to the helper.
+ */
+ struct GNUNET_MessageHeader *msg;
};
/**
@@ -237,24 +202,7 @@ static void
netjail_exec_cleanup (void *cls)
{
struct NetJailState *ns = cls;
- struct HelperMessage *message_pos;
- struct TestingSystemCount *tbc_pos;
- while (NULL != (message_pos = ns->hp_messages_head))
- {
- GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
- ns->hp_messages_tail,
- message_pos);
- GNUNET_free (message_pos);
- }
- while (NULL != (tbc_pos = ns->tbcs_head))
- {
- GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
- ns->tbcs_tail,
- tbc_pos);
- GNUNET_free (tbc_pos);
- }
- GNUNET_TESTING_free_topology (ns->topology);
GNUNET_free (ns);
}
@@ -271,7 +219,6 @@ netjail_exec_traits (void *cls,
{
struct NetJailState *ns = cls;
struct GNUNET_HELPER_Handle **helper = ns->helper;
- struct HelperMessage *hp_messages_head = ns->hp_messages_head;
struct GNUNET_TESTING_Trait traits[] = {
@@ -280,11 +227,6 @@ netjail_exec_traits (void *cls,
.trait_name = "helper_handles",
.ptr = (const void *) helper,
},
- {
- .index = 1,
- .trait_name = "hp_msgs_head",
- .ptr = (const void *) hp_messages_head,
- },
GNUNET_TESTING_trait_end ()
};
@@ -327,12 +269,12 @@ static void
clear_msg (void *cls, int result)
{
struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
- GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
- tbc->shandle = NULL;// [tbc->count - 1] = NULL;
- GNUNET_free (ns->msg[tbc->count - 1]);
- ns->msg[tbc->count - 1] = NULL;
+ GNUNET_assert (NULL != tbc->shandle);
+ GNUNET_free (tbc->shandle);
+ tbc->shandle = NULL;
+ GNUNET_free (tbc->msg);
+ tbc->msg = NULL;
}
@@ -361,7 +303,7 @@ send_message_to_locals (
helper = ns->helper[tbc->count - 1];// - total_number];
- GNUNET_array_append (ns->msg, ns->n_msg, header);
+
struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
helper,
@@ -427,7 +369,7 @@ static int
helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
{
// struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = cls;// tbc->ns;
+ struct NetJailState *ns = cls;
struct HelperMessage *hp_msg;
unsigned int total_number = ns->local_m * ns->global_n + ns->known;
// uint16_t message_type = ntohs (message->type);
@@ -543,11 +485,8 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
}
else
{
- hp_msg = GNUNET_new (struct HelperMessage);
- hp_msg->bytes_msg = message->size;
- memcpy (&hp_msg[1], message, message->size);
- GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
- hp_msg);
+ // We received a message we can not handle.
+ GNUNET_assert (0);
}
@@ -629,6 +568,7 @@ start_helper (struct NetJailState *ns,
char *known_char;
char *node_id;
char *plugin;
+ char *read_file;
pid_t pid;
unsigned int script_num;
struct GNUNET_ShortHashCode *hkey;
@@ -636,6 +576,9 @@ start_helper (struct NetJailState *ns,
struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
struct GNUNET_TESTING_NetjailNode *node;
struct GNUNET_TESTING_NetjailNamespace *namespace;
+ char *data_dir;
+ char *script_name;
+ char *topology_data;
if (0 == n)
@@ -652,47 +595,31 @@ start_helper (struct NetJailState *ns,
GNUNET_asprintf (&node_id, "%06x-%08x\n",
pid,
script_num);
+ // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
-
- char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
- m_char,
- n_char,
- GNUNET_OS_get_libexec_binary_path (
- HELPER_CMDS_BINARY),
- global_n_char,
- local_m_char,
- node_id,
- NULL};
-
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT);
unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_EXEC_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
- if (0 == n)
- tbc->count = m;
- else
- tbc->count = (n - 1) * ns->local_m + m + ns->known;
-
- GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
- ns->tbcs_tail,
- tbc);
-
if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_EXEC_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (ns->is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_EXEC_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (ns->is);
}
@@ -705,17 +632,29 @@ start_helper (struct NetJailState *ns,
ns->local_m,
ns->global_n,
ns->known);
+ {
+ char *const script_argv[] = {script_name,
+ m_char,
+ n_char,
+ GNUNET_OS_get_libexec_binary_path (
+ HELPER_CMDS_BINARY),
+ global_n_char,
+ local_m_char,
+ node_id,
+ read_file,
+ ns->topology_data,
+ NULL};
+ helper = GNUNET_HELPER_start (
+ GNUNET_YES,
+ script_name,
+ script_argv,
+ &helper_mst,
+ &exp_cb,
+ ns);
+ GNUNET_array_append (ns->helper, ns->n_helper, helper);
+ }
- GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
- GNUNET_YES,
- NETJAIL_EXEC_SCRIPT,
- script_argv,
- &helper_mst,
- &exp_cb,
- ns));
-
- helper = ns->helper[tbc->count - 1];
-
+ tbc->count = ns->n_helper;
hkey = GNUNET_new (struct GNUNET_ShortHashCode);
plugin = topology->plugin;
@@ -767,8 +706,6 @@ start_helper (struct NetJailState *ns,
msg = create_helper_init_msg_ (plugin);
- GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
-
// GNUNET_array_append (tbc->shandle, tbc->n_shandle,
tbc->shandle = GNUNET_HELPER_send (
helper,
@@ -825,24 +762,28 @@ netjail_exec_run (void *cls,
* Create command.
*
* @param label Name for the command.
- * @param topology_config Configuration file for the test topology.
+ * @param topology The complete topology information.
+ * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
+ * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- const char *topology_config)
+GNUNET_TESTING_cmd_netjail_start_testing_system (
+ const char *label,
+ struct GNUNET_TESTING_NetjailTopology *topology,
+ unsigned int *read_file,
+ char *topology_data)
{
struct NetJailState *ns;
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
ns = GNUNET_new (struct NetJailState);
ns->local_m = topology->nodes_m;
ns->global_n = topology->namespaces_n;
ns->known = topology->nodes_x;
ns->plugin_name = topology->plugin;
ns->topology = topology;
+ ns->read_file = read_file;
+ ns->topology_data = topology_data;
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 5033272a3..e3bf7da62 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -26,12 +26,10 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
-#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
-
-// Child Wait handle
-static struct GNUNET_ChildWaitHandle *cwh;
+#define NETJAIL_STOP_SCRIPT "netjail_stop.sh"
/**
* Struct to hold information for callbacks.
@@ -44,6 +42,9 @@ struct NetJailState
*/
struct GNUNET_TESTING_AsyncContext ac;
+ // Child Wait handle
+ struct GNUNET_ChildWaitHandle *cwh;
+
/**
* Configuration file for the test topology.
*/
@@ -54,6 +55,11 @@ struct NetJailState
*/
struct GNUNET_OS_Process *stop_proc;
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
+
};
@@ -66,10 +72,10 @@ netjail_stop_cleanup (void *cls)
{
struct NetJailState *ns = cls;
- if (NULL != cwh)
+ if (NULL != ns->cwh)
{
- GNUNET_wait_child_cancel (cwh);
- cwh = NULL;
+ GNUNET_wait_child_cancel (ns->cwh);
+ ns->cwh = NULL;
}
if (NULL != ns->stop_proc)
{
@@ -95,7 +101,7 @@ child_completed_callback (void *cls,
{
struct NetJailState *ns = cls;
- cwh = NULL; // WTF? globals!?!?!
+ ns->cwh = NULL;
GNUNET_OS_process_destroy (ns->stop_proc);
ns->stop_proc = NULL;
if (0 == exit_code)
@@ -121,16 +127,16 @@ netjail_stop_run (void *cls,
{
struct NetJailState *ns = cls;
char *pid;
+ char *data_dir;
+ char *script_name;
+ char *read_file;
- GNUNET_asprintf (&pid,
- "%u",
- getpid ());
- char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
- ns->topology_config,
- pid,
- NULL};
+
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_STOP_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
@@ -138,39 +144,50 @@ netjail_stop_run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_STOP_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_STOP_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
}
- ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_STOP_SCRIPT,
- script_argv);
-
- cwh = GNUNET_wait_child (ns->stop_proc,
- &child_completed_callback,
- ns);
- GNUNET_break (NULL != cwh);
+ GNUNET_asprintf (&pid,
+ "%u",
+ getpid ());
+ {
+ char *const script_argv[] = {script_name,
+ ns->topology_config,
+ pid,
+ read_file,
+ NULL};
+ ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
+ NULL,
+ NULL,
+ NULL,
+ script_name,
+ script_argv);
+ }
+ ns->cwh = GNUNET_wait_child (ns->stop_proc,
+ &child_completed_callback,
+ ns);
+ GNUNET_break (NULL != ns->cwh);
}
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *topology_config)
+ char *topology_config,
+ unsigned int *read_file)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
+ ns->read_file = read_file;
{
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index e37e955be..4b52878c4 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
@@ -70,7 +71,6 @@ stop_testing_system_cleanup (void *cls)
{
struct StopHelperState *shs = cls;
- GNUNET_TESTING_free_topology (shs->topology);
GNUNET_free (shs);
}
@@ -124,19 +124,17 @@ stop_testing_system_run (void *cls,
*
* @param label name for command.
* @param helper_start_label label of the cmd to start the test system.
- * @param topology_config Configuration file for the test topology.
+ * @param topology The complete topology information.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system (const char *label,
- const char *helper_start_label,
- const char *topology_config)
+GNUNET_TESTING_cmd_stop_testing_system (
+ const char *label,
+ const char *helper_start_label,
+ struct GNUNET_TESTING_NetjailTopology *topology)
{
struct StopHelperState *shs;
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
shs = GNUNET_new (struct StopHelperState);
shs->helper_start_label = helper_start_label;
shs->local_m = topology->nodes_m;
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 8eef1d8f1..5bbabce51 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 820adf1bd..275132684 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_testing_lib.h"
/**
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index 338123d91..cdfc65d53 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_testing_lib.h"