gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet-gtk] branch master updated: automatically launch re


From: gnunet
Subject: [GNUnet-SVN] [gnunet-gtk] branch master updated: automatically launch required services during transport tests
Date: Thu, 09 Mar 2017 01:23:18 +0100

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

grothoff pushed a commit to branch master
in repository gnunet-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new b3c48577 automatically launch required services during transport tests
b3c48577 is described below

commit b3c485774524f2c4799a46278305070b3a710277
Author: Christian Grothoff <address@hidden>
AuthorDate: Thu Mar 9 01:23:14 2017 +0100

    automatically launch required services during transport tests
---
 src/setup/gnunet-setup-transport-test.c | 120 +++++++++++++++++++++++++++++++-
 src/setup/gnunet-setup.c                |   5 +-
 src/setup/gnunet-setup.h                |   6 ++
 3 files changed, 128 insertions(+), 3 deletions(-)

diff --git a/src/setup/gnunet-setup-transport-test.c 
b/src/setup/gnunet-setup-transport-test.c
index 66f5e80e..a62c4d8e 100644
--- a/src/setup/gnunet-setup-transport-test.c
+++ b/src/setup/gnunet-setup-transport-test.c
@@ -69,6 +69,116 @@ struct TestContext
 
 
 /**
+ * Number of active tests.
+ */
+static unsigned int num_tests;
+
+/**
+ * Handle for NAT service.
+ */
+static struct GNUNET_OS_Process *nat;
+
+/**
+ * Handle for NAT-AUTO service.
+ */
+static struct GNUNET_OS_Process *nat_auto;
+
+/**
+ * Handle for RESOLVER service.
+ */
+static struct GNUNET_OS_Process *resolver;
+
+
+/**
+ * Stop the given process, nicely.
+ *
+ * @param proc process to stop.
+ */
+static void
+stop_service (struct GNUNET_OS_Process *proc)
+{
+  if (NULL == proc)
+    return;
+  GNUNET_break (0 ==
+                GNUNET_OS_process_kill (proc,
+                                        SIGTERM));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_OS_process_wait (proc));
+  GNUNET_OS_process_destroy (proc);
+}
+
+
+/**
+ * Start the given service process.
+ *
+ * @param name name of the service to run
+ * @return handle to the service
+ */
+static struct GNUNET_OS_Process *
+start_service (const char *name)
+{
+  struct GNUNET_OS_Process *proc;
+  char *binary;
+  char *filename;
+  char *path;
+
+  GNUNET_asprintf (&binary,
+                   "gnunet-service-%s",
+                   name);
+  path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
+  GNUNET_asprintf (&filename,
+                   "%s/%s",
+                   path,
+                   binary);
+  GNUNET_free (path);
+  proc = GNUNET_OS_start_process (GNUNET_NO,
+                                  GNUNET_OS_INHERIT_STD_ERR,
+                                  NULL,
+                                  NULL,
+                                  NULL,
+                                  filename,
+                                  binary,
+                                  "-c",
+                                  option_cfg_name,
+                                  NULL);
+  if (NULL == proc)
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                              "exec",
+                              filename);
+  GNUNET_free (binary);
+  GNUNET_free (filename);
+  return proc;
+}
+
+
+/**
+ * Stop the helper services.
+ */
+static void
+stop_services ()
+{
+  stop_service (nat_auto);
+  nat_auto = NULL;
+  stop_service (nat);
+  nat = NULL;
+  stop_service (resolver);
+  resolver = NULL;
+}
+
+
+/**
+ * Start the helper services.
+ */
+static void
+start_services ()
+{
+  resolver = start_service ("resolver");
+  nat = start_service ("nat");
+  nat_auto = start_service ("nat-auto");
+}
+
+
+/**
  * Display the result of the test.
  *
  * @param tc test context
@@ -103,7 +213,10 @@ display_test_result (struct TestContext *tc,
     GNUNET_NAT_AUTO_test_stop (tc->tst);
     tc->tst = NULL;
   }
+  num_tests--;
   GNUNET_free (tc);
+  if (0 == num_tests)
+    stop_services ();
 }
 
 
@@ -138,7 +251,10 @@ shutdown_task (void *cls)
   tc->st = NULL;
   GNUNET_SCHEDULER_cancel (tc->tt);
   GNUNET_NAT_AUTO_test_stop (tc->tst);
+  num_tests--;
   GNUNET_free (tc);
+  if (0 == num_tests)
+    stop_services ();
 }
 
 
@@ -184,8 +300,10 @@ GNUNET_setup_transport_test (const char *section_name,
   struct TestContext *tc;
   GtkWidget *w;
 
-  GNUNET_break (0); // FIXME: launch NAT and RESOLVER service at least first!
+  if (0 == num_tests)
+    start_services ();
   tc = GNUNET_new (struct TestContext);
+  num_tests++;
   tc->success_image = success_image;
   tc->failure_image = failure_image;
   w = GTK_WIDGET (GNUNET_SETUP_get_object (success_image));
diff --git a/src/setup/gnunet-setup.c b/src/setup/gnunet-setup.c
index a2dd6a27..ac37a972 100644
--- a/src/setup/gnunet-setup.c
+++ b/src/setup/gnunet-setup.c
@@ -40,7 +40,7 @@ static struct GNUNET_GTK_MainLoop *ml;
 /**
  * Name of the configuration file.
  */
-static const char *option_cfg_name;
+const char *option_cfg_name;
 
 /**
  * Our configuration.
@@ -332,7 +332,8 @@ write_configuration ()
 
   cfgDefault = GNUNET_CONFIGURATION_create ();
   (void) GNUNET_CONFIGURATION_load (cfgDefault, NULL);  /* load defaults only 
*/
-  ret = GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg,
+  ret = GNUNET_CONFIGURATION_write_diffs (cfgDefault,
+                                          cfg,
                                           option_cfg_name);
   GNUNET_CONFIGURATION_destroy (cfgDefault);
   return ret;
diff --git a/src/setup/gnunet-setup.h b/src/setup/gnunet-setup.h
index fde0b27a..59682fc0 100644
--- a/src/setup/gnunet-setup.h
+++ b/src/setup/gnunet-setup.h
@@ -33,6 +33,12 @@
 
 
 /**
+ * Name of the configuration file.
+ */
+extern const char *option_cfg_name;
+
+
+/**
  * Columns in the gns setup model.
  */
 enum GNUNET_GTK_SETUP_HostlistUrlModelColumns

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]