gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 21/40: NEWS: Moved code to testing to have more generic test se


From: gnunet
Subject: [gnunet] 21/40: NEWS: Moved code to testing to have more generic test setup, which can be used not only from within transport.
Date: Thu, 05 Oct 2023 08:57:24 +0200

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

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit 02a1fdad33c37bf39d4bdbe4c535fcf4c6ed0cc4
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Mon Oct 2 18:04:28 2023 +0200

    NEWS: Moved code to testing to have more generic test setup, which can be 
used not only from within transport.
---
 src/include/Makefile.am                       |   3 +-
 src/include/gnunet_transport_testing_ng_lib.h |  81 ++++++++++++++++
 src/testing/Makefile.am                       |  11 ++-
 src/testing/test_testing_start_with_config.c  | 121 ++++++++++++++++++++++++
 src/testing/testing_api_cmd_start_peer.c      |  84 +----------------
 src/testing/testing_api_cmd_stop_peer.c       | 130 ++++++++++++++++++++++++++
 6 files changed, 344 insertions(+), 86 deletions(-)

diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 8519883c9..70828b92d 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -133,7 +133,8 @@ gnunetinclude_HEADERS = \
   gnunet_transport_hello_service.h \
   gnunet_transport_manipulation_service.h \
   gnunet_transport_monitor_service.h \
-  gnunet_transport_plugin.h \
+  gnunet_transport_plugin.h  \
+  gnunet_transport_testing_ng_lib.h \
   gnunet_tun_lib.h \
   gnunet_uri_lib.h \
   gnunet_util_lib.h \
diff --git a/src/include/gnunet_transport_testing_ng_lib.h 
b/src/include/gnunet_transport_testing_ng_lib.h
new file mode 100644
index 000000000..72ec11eaf
--- /dev/null
+++ b/src/include/gnunet_transport_testing_ng_lib.h
@@ -0,0 +1,81 @@
+/*
+      This file is part of GNUnet
+      Copyright (C) 2021-2023 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
+ */
+
+/**
+ * @brief API for cmds working with transport sub system.
+ * @author t3sserakt
+ */
+#ifndef GNUNET_TRANSPORT_TESTING_NG_LIB_H
+#define GNUNET_TRANSPORT_TESTING_NG_LIB_H
+
+
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param system_label Label of the cmd to setup a test environment.
+ * @param no Decimal number representing the last byte of the IP address of 
this peer.
+ * @param node_ip The IP address of this node.
+ * @param cfgname Configuration file name for this peer.
+ * @param broadcast Flag indicating, if broadcast should be switched on.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_start_peer (const char *label,
+                               const char *system_label,
+                               uint32_t no,
+                               const char *node_ip,
+                               const char *cfgname,
+                               unsigned int broadcast);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_stop_peer (const char *label,
+                                const char *start_label);
+
+
+/**
+ * Create command
+ *
+ * @param label name for command
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_label Label of the cmd which started the test system.
+ * @param num Number globally identifying the node.
+ * @param topology The topology for the test setup.
+ * @param additional_connects Number of additional connects this cmd will wait 
for not triggered by this cmd.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_CORE_cmd_connect_peers (
+  const char *label,
+  const char *start_peer_label,
+  const char *create_label,
+  uint32_t num,
+  struct GNUNET_TESTING_NetjailTopology *topology,
+  unsigned int additional_connects,
+  unsigned int wait_for_connect,
+  struct GNUNET_MQ_MessageHandler *handlers);
+
+
+#endif
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index b40706707..e0b63f05e 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -14,6 +14,7 @@ dist_pkgcfg_DATA = \
   testing.conf
 
 libexec_PROGRAMS = \
+ test_testing_start_with_config \
   gnunet-cmds-helper
 
 plugindir = $(libdir)/gnunet
@@ -29,6 +30,7 @@ gnunet_cmds_helper_LDADD = $(XLIB) \
  $(LTLIBINTL) $(Z_LIBS)
 
 libgnunettesting_la_SOURCES = \
+  testing_api_cmd_stop_peer.c \
   testing_api_cmd_start_peer.c \
   testing_api_cmd_exec_bash_script.c \
   testing_api_cmd_barrier.c \
@@ -51,8 +53,6 @@ libgnunettesting_la_SOURCES = \
 libgnunettesting_la_LIBADD = \
  $(top_builddir)/src/arm/libgnunetarm.la \
  $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/transport/libgnunettransportapplication.la \
-$(top_builddir)/src/peerstore/libgnunetpeerstore.la \
  $(LTLIBINTL)
 libgnunettesting_la_LDFLAGS = \
  $(GN_LIB_LDFLAGS) \
@@ -94,6 +94,13 @@ check_PROGRAMS = \
 #  test_testing_servicestartup
 # endif
 
+test_testing_start_with_config_SOURCES = \
+ test_testing_start_with_config.c
+test_testing_start_with_config_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/hello/libgnunethello.la 
+
 test_testing_portreservation_SOURCES = \
  test_testing_portreservation.c
 test_testing_portreservation_LDADD = \
diff --git a/src/testing/test_testing_start_with_config.c 
b/src/testing/test_testing_start_with_config.c
new file mode 100644
index 000000000..a2c692dbc
--- /dev/null
+++ b/src/testing/test_testing_start_with_config.c
@@ -0,0 +1,121 @@
+/*
+      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 transport/test_transport_start_with_config.c
+ * @brief Generic program to start testcases in an configurable topology.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "gnunet_util_lib.h"
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
+
+
+int
+main (int argc,
+      char *const *argv)
+{
+  char *topology_data;
+  char *topology_data_script;
+  struct GNUNET_TESTING_NetjailTopology *topology;
+  unsigned int read_file = GNUNET_YES;
+  int ret;
+  char *rest = NULL;
+  char *token;
+  size_t single_line_len;
+  size_t data_len;
+
+  GNUNET_log_setup ("test-netjail",
+                    "INFO",
+                    NULL);
+
+  if (0 == strcmp ("-s", argv[1]))
+  {
+    data_len = strlen (argv[2]);
+    topology_data = GNUNET_malloc (data_len);
+    topology_data_script = GNUNET_malloc (data_len);
+    token = strtok_r (argv[2], "\n", &rest);
+    while (NULL != token)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "token1 %s\n",
+                  token);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "token2 %s\n",
+                  token);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "topology_data %s\n",
+                  topology_data);
+      strcat (topology_data_script, token);
+      strcat (topology_data_script, " ");
+      strcat (topology_data, token);
+      strcat (topology_data, "\n");
+      token = strtok_r (NULL, "\n", &rest);
+    }
+    single_line_len = strlen (topology_data);
+    topology_data_script [single_line_len - 1] = '\0';
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "read from string\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "topology_data %s\n",
+                topology_data);
+    read_file = GNUNET_NO;
+    topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+  }
+  else
+  {
+    topology_data = argv[1];
+    topology_data_script = argv[1];
+    topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+  }
+
+  struct GNUNET_TESTING_Command commands[] = {
+    GNUNET_TESTING_cmd_netjail_start ("netjail-start",
+                                      topology_data_script,
+                                      &read_file),
+    GNUNET_TESTING_cmd_netjail_start_cmds_helper ("netjail-start-testbed",
+                                                     topology,
+                                                     &read_file,
+                                                     topology_data_script,
+                                                     TIMEOUT),
+    GNUNET_TESTING_cmd_stop_cmds_helper ("stop-testbed",
+                                            "netjail-start-testbed",
+                                            topology),
+    GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
+                                     topology_data_script,
+                                     &read_file),
+    GNUNET_TESTING_cmd_end ()
+  };
+
+  ret = GNUNET_TESTING_main (commands,
+                             TIMEOUT);
+
+  if (0 == strcmp ("-s", argv[1]))
+  {
+    GNUNET_free (topology_data_script);
+    GNUNET_free (topology_data);
+  }
+  GNUNET_TESTING_free_topology (topology);
+
+  return ret;
+}
diff --git a/src/testing/testing_api_cmd_start_peer.c 
b/src/testing/testing_api_cmd_start_peer.c
index f6b471be4..e2a2c0fbf 100644
--- a/src/testing/testing_api_cmd_start_peer.c
+++ b/src/testing/testing_api_cmd_start_peer.c
@@ -28,9 +28,6 @@
 #include "testing_cmds.h"
 #include "gnunet_testing_ng_lib.h"
 #include "gnunet_testing_netjail_lib.h"
-#include "gnunet_peerstore_service.h"
-#include "gnunet_transport_core_service.h"
-#include "gnunet_transport_application_service.h"
 
 /**
  * Generic logging shortcut
@@ -38,61 +35,6 @@
 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
 
 
-static void
-retrieve_hello (void *cls);
-
-
-/**
- * Callback delivering the hello of this peer from peerstore.
- *
- */
-static void
-hello_iter_cb (void *cb_cls,
-               const struct GNUNET_PEERSTORE_Record *record,
-               const char *emsg)
-{
-  struct GNUNET_TESTING_StartPeerState *sps = cb_cls;
-  if (NULL == record)
-  {
-    sps->pic = NULL;
-    sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
-    return;
-  }
-  // Check record type et al?
-  sps->hello_size = record->value_size;
-  sps->hello = GNUNET_malloc (sps->hello_size);
-  memcpy (sps->hello, record->value, sps->hello_size);
-  sps->hello[sps->hello_size - 1] = '\0';
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Our hello %s\n",
-       sps->hello);
-  GNUNET_PEERSTORE_iterate_cancel (sps->pic);
-  sps->pic = NULL;
-  GNUNET_TESTING_async_finish (&sps->ac);
-}
-
-
-/**
- * Function to start the retrieval task to retrieve the hello of this peer
- * from the peerstore.
- *
- */
-static void
-retrieve_hello (void *cls)
-{
-  struct GNUNET_TESTING_StartPeerState *sps = cls;
-  sps->rh_task = NULL;
-  sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
-                                       "transport",
-                                       &sps->id,
-                                       GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
-                                       hello_iter_cb,
-                                       sps);
-
-}
-
-
 /**
  * The run method of this cmd will start all services of a peer to test the 
transport service.
  *
@@ -254,30 +196,6 @@ start_peer_run (void *cls,
        sps->no,
        GNUNET_i2s_full (&sps->id));
 
-  sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
-  if (NULL == sps->ph)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         "Failed to connect to peerstore service for peer `%s': `%s'\n",
-         sps->cfgname,
-         emsg);
-    GNUNET_free (emsg);
-    GNUNET_TESTING_interpreter_fail (is);
-    return;
-  }
-
-  sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
-  if (NULL == sps->ah)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         "Failed to initialize the TRANSPORT application suggestion client 
handle for peer `%s': `%s'\n",
-         sps->cfgname,
-         emsg);
-    GNUNET_free (emsg);
-    GNUNET_TESTING_interpreter_fail (is);
-    return;
-  }
-  sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
   GNUNET_free (home);
   GNUNET_free (transport_unix_path);
   GNUNET_free (tcp_communicator_unix_path);
@@ -376,5 +294,5 @@ GNUNET_TESTING_cmd_start_peer (const char *label,
                                      &start_peer_run,
                                      &start_peer_cleanup,
                                      &start_peer_traits,
-                                     &sps->ac);
+                                     NULL);
 }
diff --git a/src/testing/testing_api_cmd_stop_peer.c 
b/src/testing/testing_api_cmd_stop_peer.c
new file mode 100644
index 000000000..2cbf978c6
--- /dev/null
+++ b/src/testing/testing_api_cmd_stop_peer.c
@@ -0,0 +1,130 @@
+/*
+      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_testing_netjail_lib.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,
+               struct GNUNET_TESTING_Interpreter *is)
+{
+  struct StopPeerState *stop_ps = cls;
+  const struct GNUNET_TESTING_StartPeerState *sps;
+  const struct GNUNET_TESTING_Command *start_cmd;
+
+  start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+                                                         stop_ps->start_label);
+  GNUNET_TESTING_get_trait_state (start_cmd,
+                                    &sps);
+  
+  if (NULL != sps->peer)
+  {
+    if (GNUNET_OK !=
+        GNUNET_TESTING_peer_stop (sps->peer))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           "Testing lib failed to stop peer %u (`%s')\n",
+           sps->no,
+           GNUNET_i2s (&sps->id));
+    }
+    GNUNET_TESTING_peer_destroy (sps->peer);
+  }
+  if (NULL != sps->rh_task)
+    GNUNET_SCHEDULER_cancel (sps->rh_task);
+}
+
+
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
+static void
+stop_peer_cleanup (void *cls)
+{
+  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_TESTING_cmd_stop_peer (const char *label,
+                                const char *start_label)
+{
+  struct StopPeerState *sps;
+
+  sps = GNUNET_new (struct StopPeerState);
+  sps->start_label = start_label;
+  return GNUNET_TESTING_command_new (sps,
+                                     label,
+                                     &stop_peer_run,
+                                     &stop_peer_cleanup,
+                                     &stop_peer_traits,
+                                     NULL);
+}

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