[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 03/04: - added cmds to stop a peer and remove a test environmen
From: |
gnunet |
Subject: |
[gnunet] 03/04: - added cmds to stop a peer and remove a test environment, used in simple send test case plugin |
Date: |
Tue, 24 Aug 2021 11:02:13 +0200 |
This is an automated email from the git hooks/post-receive script.
t3sserakt pushed a commit to branch master
in repository gnunet.
commit 00cbe1e8e09fc2ef567f59de5b4dc14c0562c35f
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Tue Aug 24 10:57:03 2021 +0200
- added cmds to stop a peer and remove a test environment, used in simple
send test case plugin
---
src/testing/Makefile.am | 1 +
src/testing/testing_api_cmd_system_destroy.c | 122 +++++++++++++++
src/transport/Makefile.am | 2 +
.../test_transport_plugin_cmd_simple_send.c | 99 ++++++++++---
src/transport/transport_api_cmd_stop_peer.c | 163 +++++++++++++++++++++
5 files changed, 368 insertions(+), 19 deletions(-)
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 15469a310..c01e9bdbd 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -50,6 +50,7 @@ libgnunettesting_la_SOURCES = \
testing_api_cmd_netjail_stop.c \
testing.c testing.h \
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 \
diff --git a/src/testing/testing_api_cmd_system_destroy.c
b/src/testing/testing_api_cmd_system_destroy.c
new file mode 100644
index 000000000..e94d8dad0
--- /dev/null
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -0,0 +1,122 @@
+/*
+ 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_system_destroy.c
+ * @brief cmd to destroy a testing system handle.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_lib.h"
+
+
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
+struct TestSystemState
+{
+ // Label of the cmd which started the test system.
+ const char *create_label;
+};
+
+
+/**
+ * The run method of this cmd will remove the test environment for a node.
+ *
+ */
+static void
+system_destroy_run (void *cls,
+ const struct GNUNET_TESTING_Command *cmd,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct TestSystemState *tss = cls;
+ const struct GNUNET_TESTING_Command *system_cmd;
+ struct GNUNET_TESTING_System *tl_system;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "system destroy\n");
+
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
+ GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "system destroyed\n");
+}
+
+
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
+static void
+system_destroy_cleanup (void *cls,
+ const struct GNUNET_TESTING_Command *cmd)
+{
+ struct TestSystemState *tss = cls;
+
+ GNUNET_free (tss);
+}
+
+
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
+static int
+system_destroy_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param create_label Label of the cmd which started the test system.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_system_destroy (const char *label,
+ const char *create_label)
+{
+ struct TestSystemState *tss;
+
+ tss = GNUNET_new (struct TestSystemState);
+ tss->create_label = create_label;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = tss,
+ .label = label,
+ .run = &system_destroy_run,
+ .cleanup = &system_destroy_cleanup,
+ .traits = &system_destroy_traits
+ };
+
+ return cmd;
+}
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 0696188c5..afa37bac5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -169,8 +169,10 @@ libgnunettransporttesting_la_LDFLAGS = \
libgnunettransporttesting2_la_SOURCES = \
transport_api_cmd_connecting_peers.c \
transport_api_cmd_start_peer.c \
+ transport_api_cmd_stop_peer.c \
transport_api_cmd_send_simple.c \
transport-testing2.c transport-testing2.h \
+ transport-testing-ng.h \
transport-testing-cmds.h \
transport-testing-filenames2.c \
transport-testing-loggers2.c \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c
b/src/transport/test_transport_plugin_cmd_simple_send.c
index c4f7fcfe3..ac5c01075 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,10 +37,30 @@
#define BASE_DIR "testdir"
-struct GNUNET_MQ_MessageHandler *handlers;
+/**
+ * The name for a specific test environment directory.
+ *
+ */
+char *testdir;
+/**
+ * The name for the configuration file of the specific node.
+ *
+ */
+char *cfgname;
+
+/**
+ * Flag indicating if all peers have been started.
+ *
+ */
unsigned int are_all_peers_started;
+
+/**
+ * Function called to check a message of type
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
static int
check_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -48,6 +68,12 @@ check_test (void *cls,
return GNUNET_OK;
}
+
+/**
+ * Function called to handle a message of type
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -56,6 +82,12 @@ handle_test (void *cls,
"message received\n");
}
+
+/**
+ * Function called to check a message of type
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
static int
check_test2 (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -63,6 +95,12 @@ check_test2 (void *cls,
return GNUNET_OK;
}
+
+/**
+ * Function called to handle a message of type
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
static void
handle_test2 (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -71,6 +109,11 @@ handle_test2 (void *cls,
"message received\n");
}
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via
the plugin api.
+ *
+ */
static void
all_peers_started ()
{
@@ -80,6 +123,17 @@ all_peers_started ()
are_all_peers_started);
}
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
static void
start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *node_ip,
@@ -87,12 +141,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message,
char *router_ip,
char *n,
char *local_m)
{
- char *testdir;
- char *cfgname;
GNUNET_asprintf (&cfgname,
- "%s%s.conf",
- "test_transport_api2_tcp_node",
+ "test_transport_api2_tcp_node%s.conf",
n);
LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -103,12 +154,18 @@ start_testcase (TESTING_CMD_HELPER_write_cb
write_message, char *router_ip,
"node ip: %s\n",
node_ip);
- testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
+ GNUNET_asprintf (&testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
+ 1);
strcpy (testdir, BASE_DIR);
strcat (testdir, m);
- strcat (testdir, n);
+ strcat (testdir, n);*/
struct GNUNET_MQ_MessageHandler handlers[] = {
GNUNET_MQ_hd_var_size (test,
@@ -123,30 +180,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb
write_message, char *router_ip,
};
struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_system_create ("system-create-1",
+ GNUNET_TESTING_cmd_system_create ("system-create",
testdir),
- GNUNET_TRANSPORT_cmd_start_peer ("start-peer-1",
- "system-create-1",
+ GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
+ "system-create",
m,
n,
local_m,
handlers,
cfgname),
- GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
write_message),
- GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
+ GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
&are_all_peers_started),
- GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers-1",
- "start-peer-1",
- "this is useless"),
- GNUNET_TRANSPORT_cmd_send_simple ("send-simple-1",
+ GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
+ "start-peer"),
+ GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
m,
n,
(atoi (n) - 1) * atoi (local_m) + atoi (
m),
- "start-peer-1",
- "this is useless"),
- GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
+ "start-peer"),
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
write_message)
};
@@ -187,6 +246,8 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void
*cls)
struct GNUNET_TESTING_PluginFunctions *api = cls;
GNUNET_free (api);
+ GNUNET_free (testdir);
+ GNUNET_free (cfgname);
return NULL;
}
diff --git a/src/transport/transport_api_cmd_stop_peer.c
b/src/transport/transport_api_cmd_stop_peer.c
new file mode 100644
index 000000000..2277520ec
--- /dev/null
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -0,0 +1,163 @@
+/*
+ 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_stop_peer.c
+ * @brief cmd to stop a peer.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_peerstore_service.h"
+#include "gnunet_transport_core_service.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing-ng.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
+struct StopPeerState
+{
+ // Label of the cmd to start the peer.
+ const char *start_label;
+};
+
+
+/**
+ * The run method of this cmd will stop all services of a peer which were used
to test the transport service.
+ *
+ */
+static void
+stop_peer_run (void *cls,
+ const struct GNUNET_TESTING_Command *cmd,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct StopPeerState *stop_ps = cls;
+ struct StartPeerState *sps;
+ const struct GNUNET_TESTING_Command *start_cmd;
+
+ start_cmd = GNUNET_TESTING_interpreter_lookup_command (stop_ps->start_label);
+ GNUNET_TRANSPORT_get_trait_state (start_cmd,
+ &sps);
+
+ if (NULL != sps->pic)
+ {
+ GNUNET_PEERSTORE_iterate_cancel (sps->pic);
+ sps->pic = NULL;
+ }
+ if (NULL != sps->th)
+ {
+ GNUNET_TRANSPORT_core_disconnect (sps->th);
+ sps->th = NULL;
+ }
+ if (NULL != sps->ah)
+ {
+ GNUNET_TRANSPORT_application_done (sps->ah);
+ sps->ah = NULL;
+ }
+ if (NULL != sps->ph)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting from PEERSTORE service\n");
+ GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
+ sps->ph = NULL;
+ }
+ if (NULL != sps->peer)
+ {
+ if (GNUNET_OK !=
+ GNUNET_TESTING_peer_stop (sps->peer))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing lib failed to stop peer %u (`%s')\n",
+ sps->no,
+ GNUNET_i2s (&sps->id));
+ }
+ GNUNET_TESTING_peer_destroy (sps->peer);
+ sps->peer = NULL;
+ }
+ if (NULL != sps->rh_task)
+ GNUNET_SCHEDULER_cancel (sps->rh_task);
+ sps->rh_task = NULL;
+
+}
+
+
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
+static void
+stop_peer_cleanup (void *cls,
+ const struct GNUNET_TESTING_Command *cmd)
+{
+ struct StopPeerState *sps = cls;
+
+ GNUNET_free (sps);
+}
+
+
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
+static int
+stop_peer_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param start_label Label of the cmd to start the peer.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
+ const char *start_label)
+{
+ struct StopPeerState *sps;
+
+ sps = GNUNET_new (struct StopPeerState);
+ sps->start_label = start_label;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sps,
+ .label = label,
+ .run = &stop_peer_run,
+ .cleanup = &stop_peer_cleanup,
+ .traits = &stop_peer_traits
+ };
+
+ return cmd;
+}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.