gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26702 - gnunet/src/testing


From: gnunet
Subject: [GNUnet-SVN] r26702 - gnunet/src/testing
Date: Sun, 31 Mar 2013 22:03:26 +0200

Author: harsha
Date: 2013-03-31 22:03:26 +0200 (Sun, 31 Mar 2013)
New Revision: 26702

Added:
   gnunet/src/testing/test_testing_peerstartup2.c
Modified:
   gnunet/src/testing/
   gnunet/src/testing/Makefile.am
   gnunet/src/testing/testing.c
Log:
- ARM based peer start stop

Index: gnunet/src/testing
===================================================================
--- gnunet/src/testing  2013-03-31 19:48:11 UTC (rev 26701)
+++ gnunet/src/testing  2013-03-31 20:03:26 UTC (rev 26702)

Property changes on: gnunet/src/testing
___________________________________________________________________
Modified: svn:ignore
## -1,51 +1,9 ##
 test_testing_servicestartup
 test_testing_portreservation
 test_testing_peerstartup
+test_testing_peerstartup2
 gnunet-testing
 gnunet-testing-run-service
-topology_clique.dot
-testing_topo_initial
-test_testing_peergroup
-test_testing_reconnect
-final_topology.dot
-test_testing_topology_stability
-topology_clique.do
-test_testing_2dtorus
-test_testing_topology_none
-test_testing_topology_small_world_torus
-test_testing_topology_small_world_ring
-test_testing_topology_scale_free
-test_testing_topology_ring
-test_testing_topology_line
-test_testing_topology_internat
-test_testing_topology_erdos_renyi
-test_testing_topology_clique_random
-test_testing_topology_clique_minimum
-test_testing_topology_clique_dfs
-test_testing_topology_churn
-test_testing_topology_blacklist
-test_testing_topology_2d_torus
-test_testing_group_remote
-topology.dot
-test_testing_topology_clique
-test_testing_group.gcno
-test_testing_group.gcda
-test_testing_connect.gcno
-test_testing_connect.gcda
-test_testing_group
-test_testing_connect
-test_testing_new_portreservation
-test_testing_new_peerstartup
-test_testing_new_servicestartup
-testing_testbed.gcno
-testing_testbed.gcda
-testing_group.gcno
-testing_group.gcda
-testing.gcno
-testing.gcda
-test_testing.gcno
-test_testing.gcda
-test_testing
 Makefile.in
 Makefile
 .deps
Modified: gnunet/src/testing/Makefile.am
===================================================================
--- gnunet/src/testing/Makefile.am      2013-03-31 19:48:11 UTC (rev 26701)
+++ gnunet/src/testing/Makefile.am      2013-03-31 20:03:26 UTC (rev 26702)
@@ -21,6 +21,7 @@
   testing.c  
 libgnunettesting_la_LIBADD = \
  $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
  $(LTLIBINTL)
 libgnunettesting_la_LDFLAGS = \
  $(GN_LIB_LDFLAGS) \
@@ -53,14 +54,17 @@
 
 check_PROGRAMS = \
  test_testing_portreservation \
+ test_testing_servicestartup \
  test_testing_peerstartup \
- test_testing_servicestartup
+ test_testing_peerstartup2
 
 if ENABLE_TEST_RUN 
 TESTS = \
  test_testing_portreservation \
  test_testing_peerstartup \
+ test_testing_peerstartup2 \
  test_testing_servicestartup
+
 endif
 
 test_testing_portreservation_SOURCES = \
@@ -75,6 +79,12 @@
  $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la
 
+test_testing_peerstartup2_SOURCES = \
+ test_testing_peerstartup2.c
+test_testing_peerstartup2_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
 test_testing_servicestartup_SOURCES = \
  test_testing_servicestartup.c
 test_testing_servicestartup_LDADD = \

Copied: gnunet/src/testing/test_testing_peerstartup2.c (from rev 26689, 
gnunet/src/testing/test_testing_peerstartup.c)
===================================================================
--- gnunet/src/testing/test_testing_peerstartup2.c                              
(rev 0)
+++ gnunet/src/testing/test_testing_peerstartup2.c      2013-03-31 20:03:26 UTC 
(rev 26702)
@@ -0,0 +1,176 @@
+/*
+      This file is part of GNUnet
+      (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
+
+      GNUnet is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 3, 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
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with GNUnet; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file testing/test_testing_new_peerstartup.c
+ * @brief test case for testing peer startup and shutdown using new testing
+ *          library 
+ * @author Sree Harsha Totakura
+ */
+
+#include "platform.h"
+#include "gnunet_configuration_lib.h"
+#include "gnunet_os_lib.h"
+#include "gnunet_testing_lib.h"
+
+#define LOG(kind,...)                           \
+  GNUNET_log (kind, __VA_ARGS__)
+
+/**
+ * The status of the test
+ */
+int status;
+
+/**
+ * The testing context
+ */
+struct TestingContext
+{
+  /**
+   * The testing system
+   */
+  struct GNUNET_TESTING_System *system;
+  
+  /**
+   * The peer which has been started by the testing system
+   */
+  struct GNUNET_TESTING_Peer *peer;
+
+  /**
+   * The running configuration of the peer
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+};
+
+
+static void
+do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct TestingContext *test_ctx = cls;
+
+  if (NULL != test_ctx->peer)
+    GNUNET_TESTING_peer_destroy (test_ctx->peer);
+  if (NULL != test_ctx->cfg)
+    GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
+  if (NULL != test_ctx->system)
+    GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
+  GNUNET_free (test_ctx);
+  
+}
+
+static void
+peer_stop_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
+{
+  GNUNET_break (GNUNET_NO == success);
+  status = GNUNET_OK;
+  GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
+}
+
+
+/**
+ * Task for shutdown
+ *
+ * @param cls the testing context
+ * @param tc the tast context
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct TestingContext *test_ctx = cls;
+
+  GNUNET_assert (NULL != test_ctx);
+  if (NULL != test_ctx->peer)
+  {
+    GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer,
+                                                          &peer_stop_cb,
+                                                          test_ctx));
+  }
+  else
+    do_shutdown (test_ctx, tc);
+}
+
+static void
+ps_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
+{
+  struct TestingContext *test_ctx = cls;
+
+  GNUNET_break (GNUNET_YES == success);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                &do_shutdown, test_ctx);  
+}
+
+
+/**
+ * Main point of test execution
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct TestingContext *test_ctx;
+  char *emsg;
+  struct GNUNET_PeerIdentity id;
+
+  test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
+  test_ctx->system = 
+      GNUNET_TESTING_system_create ("test-gnunet-testing",
+                                    "127.0.0.1", NULL);
+  emsg = NULL;
+  if (NULL == test_ctx->system)
+    goto end;
+  test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  test_ctx->peer = 
+      GNUNET_TESTING_peer_configure (test_ctx->system,
+                                     test_ctx->cfg,
+                                     0, &id, &emsg);
+  if (NULL == test_ctx->peer)
+  {
+    if (NULL != emsg)
+      printf ("Test failed upon error: %s", emsg);
+    goto end;
+  }
+  if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer,
+                                               &ps_cb, test_ctx))
+    goto end;
+  return;
+  
+ end:
+  GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
+  GNUNET_free_non_null (emsg);
+}
+
+
+int main (int argc, char *argv[])
+{
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  status = GNUNET_SYSERR;
+  if (GNUNET_OK !=
+      GNUNET_PROGRAM_run (argc, argv,
+                          "test_testing_new_peerstartup",
+                          "test case for peerstartup using new testing 
library",
+                          options, &run, NULL))
+    return 1;
+  return (GNUNET_OK == status) ? 0 : 1;
+}
+
+/* end of test_testing_peerstartup.c */

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2013-03-31 19:48:11 UTC (rev 26701)
+++ gnunet/src/testing/testing.c        2013-03-31 20:03:26 UTC (rev 26702)
@@ -31,6 +31,7 @@
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
 #include "gnunet_testing_lib.h"
 
 #define LOG(kind,...)                                           \
@@ -180,6 +181,22 @@
   struct GNUNET_OS_Process *main_process;
 
   /**
+   * The handle to the peer's ARM service
+   */
+  struct GNUNET_ARM_Handle *ah;
+
+  /**
+   * The config of the peer
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  GNUNET_TESTING_PeerStartCallback cb;
+    
+  void *cb_cls;
+  
+  struct GNUNET_ARM_MonitorHandle *mh;
+
+  /**
    * The cached identity of this peer.  Will be populated on call to
    * GNUNET_TESTING_peer_get_identity()
    */
@@ -819,6 +836,8 @@
   GNUNET_asprintf (&default_config, "%s/config", uc.service_home);
   GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
                                          default_config);
+  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
+                                         default_config);
   GNUNET_free (default_config);
   GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME",
                                          uc.service_home);
@@ -876,7 +895,7 @@
     else
       GNUNET_free (emsg_);
     return NULL;
-  }
+  }  
   if (key_number >= system->total_hostkeys)
   {
     GNUNET_asprintf (&emsg_,
@@ -960,6 +979,7 @@
   }
   peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
   peer->cfgfile = config_filename; /* Free in peer_destroy */
+  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
   libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", 
"PREFIX", &peer->main_binary))
   {
@@ -1035,7 +1055,93 @@
 }
 
 
+void
+GNUNET_TESTING_peer_service_start (struct GNUNET_TESTING_Peer *peer,
+                                   const char *service_name,
+                                   GNUNET_ARM_ResultCallback cont,
+                                   void *cont_cls)
+{
+  GNUNET_ARM_request_service_start (peer->ah,
+                                    service_name,
+                                    GNUNET_OS_INHERIT_STD_ALL,
+                                    GNUNET_TIME_UNIT_MINUTES, 
+                                    cont,
+                                    cont_cls);
+
+}
+
+
+void GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer,
+                                        const char *service_name,
+                                        GNUNET_ARM_ResultCallback cont,
+                                       void *cont_cls)
+{
+  GNUNET_ARM_request_service_stop (peer->ah, service_name,
+                                   GNUNET_TIME_UNIT_MINUTES,
+                                   cont, cont_cls);
+}
+                                       
+static void
+arm_start_result_cb (void *cls, 
+                     struct GNUNET_ARM_Handle *arm, 
+                     enum GNUNET_ARM_RequestStatus rs,
+                     const char *service, 
+                     enum GNUNET_ARM_Result result)
+{
+  struct GNUNET_TESTING_Peer *peer = cls;
+
+  if ((GNUNET_ARM_REQUEST_SENT_OK != rs)
+      || ! ((GNUNET_ARM_RESULT_STARTING == result)
+            || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result)
+            || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)))
+  {
+    peer->cb (peer->cb_cls, peer, GNUNET_NO);
+    return;
+  }
+  peer->cb (peer->cb_cls, peer, GNUNET_OK);
+}
+
 /**
+ * Function called whenever we connect to or disconnect from ARM.
+ *
+ * @param cls closure
+ * @param arm handle to the ARM connection
+ * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
+ *                  GNUNET_SYSERR on error.
+ */
+static void
+conn_status (void *cls, struct GNUNET_ARM_Handle *arm, 
+            int connected)
+{
+  struct GNUNET_TESTING_Peer *peer = cls;
+
+  peer->cb (peer->cb_cls, peer, connected);  
+}
+
+
+int
+GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer,
+                            GNUNET_TESTING_PeerStartCallback cb,
+                            void *cb_cls)
+{
+  if (NULL != peer->ah)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  GNUNET_assert (NULL != (peer->cb = cb));
+  peer->cb_cls = cb_cls;
+  peer->ah = GNUNET_ARM_connect (peer->cfg, &conn_status, peer);
+  if (NULL == peer->ah)
+    return GNUNET_SYSERR;
+  //GNUNET_TESTING_peer_service_start (peer, "arm", &arm_start_result_cb, 
peer);
+  GNUNET_TESTING_peer_service_start (peer, "arm", NULL, NULL);
+  return GNUNET_OK;
+}
+
+
+
+/**
  * Sends SIGTERM to the peer's main process
  *
  * @param peer the handle to the peer
@@ -1094,8 +1200,62 @@
     return GNUNET_SYSERR;
   return GNUNET_OK;
 }
+                                       
+static void
+arm_stop_result_cb (void *cls, 
+                     struct GNUNET_ARM_Handle *arm, 
+                     enum GNUNET_ARM_RequestStatus rs,
+                     const char *service, 
+                     enum GNUNET_ARM_Result result)
+{
+  struct GNUNET_TESTING_Peer *peer = cls;
+  
+  if ((GNUNET_ARM_REQUEST_SENT_OK != rs)
+      || ! ((GNUNET_ARM_RESULT_STOPPED == result)
+            || (GNUNET_ARM_RESULT_STOPPING == result)
+            || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result)
+            || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)))
+  {
+    peer->cb (peer->cb_cls, peer, GNUNET_NO);
+    return;
+  }
+  peer->cb (peer->cb_cls, peer, GNUNET_OK);
+}
 
 
+static void 
+arm_service_monitor (void *cls,
+                 struct GNUNET_ARM_MonitorHandle *arm,
+                 const char *service, 
+                 enum GNUNET_ARM_ServiceStatus status)
+{
+  struct GNUNET_TESTING_Peer *peer = cls;
+  
+  peer->mh = arm;
+  if (GNUNET_ARM_SERVICE_STOPPED != status)
+    return;
+  if (0 != strcasecmp (service, "arm"))
+    return;
+  peer->cb (peer->cb_cls, peer, GNUNET_OK);
+}
+
+
+int
+GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer,
+                           GNUNET_TESTING_PeerStartCallback cb,
+                           void *cb_cls)
+{
+  if (NULL == peer->ah)
+    return GNUNET_SYSERR;
+  GNUNET_assert (NULL != (peer->cb = cb));
+  peer->cb_cls = cb_cls;
+  /* if (NULL == peer->mh) */
+  /*   peer->mh = GNUNET_ARM_monitor (peer->cfg, &arm_service_monitor, peer); 
*/
+  GNUNET_TESTING_peer_service_stop (peer, "arm", NULL, NULL);
+  return GNUNET_OK;
+}
+
+
 /**
  * Destroy the peer.  Releases resources locked during peer configuration.
  * If the peer is still running, it will be stopped AND a warning will be
@@ -1107,11 +1267,13 @@
 GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
 {
   if (NULL != peer->main_process)
-  {
-    GNUNET_break (0);
     GNUNET_TESTING_peer_stop (peer);
-  }
+  if (NULL != peer->mh)
+    GNUNET_ARM_monitor_disconnect_and_free (peer->mh);
+  if (NULL != peer->ah)
+    GNUNET_ARM_disconnect_and_free (peer->ah);
   GNUNET_free (peer->cfgfile);
+  GNUNET_CONFIGURATION_destroy (peer->cfg);
   GNUNET_free (peer->main_binary);
   GNUNET_free (peer->args);
   GNUNET_free_non_null (peer->id);




reply via email to

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