gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26710 - in gnunet/src: include testing


From: gnunet
Subject: [GNUnet-SVN] r26710 - in gnunet/src: include testing
Date: Mon, 1 Apr 2013 19:54:07 +0200

Author: harsha
Date: 2013-04-01 19:54:06 +0200 (Mon, 01 Apr 2013)
New Revision: 26710

Modified:
   gnunet/src/include/gnunet_testing_lib.h
   gnunet/src/testing/test_testing_peerstartup2.c
   gnunet/src/testing/testing.c
Log:
- only have asynchronous peer stop

Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h     2013-04-01 16:41:10 UTC (rev 
26709)
+++ gnunet/src/include/gnunet_testing_lib.h     2013-04-01 17:54:06 UTC (rev 
26710)
@@ -242,7 +242,9 @@
 
 
 /**
- * Stop the peer. 
+ * Stop the peer. This call is blocking as it kills the peer's main ARM process
+ * by sending a SIGTERM and waits on it.  For asynchronous shutdown of peer, 
see
+ * GNUNET_TESTING_peer_stop_async().
  *
  * @param peer peer to stop
  * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running)
@@ -287,120 +289,35 @@
 /**
  * Callback to inform whether the peer is running or stopped.
  *
- * @param cls the closure from GNUNET_TESTING_peer_configure2()
+ * @param cls the closure given to GNUNET_TESTING_peer_stop_async()
  * @param peer the respective peer whose status is being reported
- * @param success GNUNET_YES if the peer is running; GNUNET_NO if the peer is
- *          not running; GNUNET_SYSERR upon error communicating with the peer's
- *          ARM service
+ * @param success GNUNET_YES if the peer is stopped; GNUNET_SYSERR upon any
+ *          error
  */
-typedef void (*GNUNET_TESTING_PeerStatusCallback) (void *cls, 
-                                                   struct GNUNET_TESTING_Peer *
-                                                   peer,
-                                                   int success);
+typedef void (*GNUNET_TESTING_PeerStopCallback) (void *cls, 
+                                                 struct GNUNET_TESTING_Peer *
+                                                 peer,
+                                                 int success);
 
 
 /**
- * Wrapper over GNUNET_TESTING_peer_configure() to set the
- * GNUNET_TESTING_PeerStatusCallback() for using functions
- * GNUNET_TESTING_peer_start2() and GNUNET_TESTING_peer_stop2()
- *
- * @param system system to use to coordinate resource usage
- * @param cfg configuration to use; will be UPDATED (to reflect needed
- *            changes in port numbers and paths)
- * @param key_number number of the hostkey to use for the peer
- * @param id identifier for the daemon, will be set, can be NULL
- * @param emsg set to freshly allocated error message (set to NULL on 
success), 
- *          can be NULL
- * @param status_cb the status callback to call upon peer start and stop
- * @return handle to the peer, NULL on error
- */
-struct GNUNET_TESTING_Peer *
-GNUNET_TESTING_peer_configure2 (struct GNUNET_TESTING_System *system,
-                                struct GNUNET_CONFIGURATION_Handle *cfg,
-                                uint32_t key_number,
-                                struct GNUNET_PeerIdentity *id,
-                                char **emsg,
-                                GNUNET_TESTING_PeerStatusCallback status_cb,
-                                void *cls);
-
-
-/**
- * Start a peer asynchronously using ARM API.  Peer's startup is signaled
- * through the GNUNET_TESTING_PeerStatusCallback() given to
- * GNUNET_TESTING_peer_configure2().  To use this function the peer must be
- * configured earlier using GNUNET_TESTING_peer_configure2();
- *
- * @param peer the peer to start
- * @param timeout how long to wait before giving up to start the peer
- * @return GNUNET_OK upon successfully giving the request to the ARM API (this
- *           does not mean that the peer is successfully started); 
GNUNET_SYSERR
- *           upon any error.
- */
-int
-GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer,
-                            struct GNUNET_TIME_Relative timeout);
-
-
-/**
  * Stop a peer asynchronously using ARM API.  Peer's shutdown is signaled
- * through the GNUNET_TESTING_PeerStatusCallback() given to
- * GNUNET_TESTING_peer_configure2().  To use this function the peer must be
- * configured earlier using GNUNET_TESTING_peer_configure2();
+ * through the GNUNET_TESTING_PeerStopCallback().
  *
  * @param peer the peer to stop
- * @param timeout how long to wait before giving up to stop the peer
+ * @param cb the callback to signal peer shutdown
+ * @param cb_cls closure for the above callback
  * @return GNUNET_OK upon successfully giving the request to the ARM API (this
  *           does not mean that the peer is successfully stopped); 
GNUNET_SYSERR
  *           upon any error.
  */
 int
-GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer,
-                           struct GNUNET_TIME_Relative timeout);
+GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer,
+                                GNUNET_TESTING_PeerStopCallback cb,
+                                void *cb_cls);
 
 
 /**
- * Start a service at a peer using its ARM service.  To use this function the
- * peer must be configured earlier using GNUNET_TESTING_peer_configure2();
- *
- * @param peer the peer whose service has to be started
- * @param service_name name of the service to start
- * @param timeout how long should the ARM API try to send the request to start
- *          the service
- * @param cont the callback to call with result and status from ARM API
- * @param cont_cls the closure for the above callback
- * @return GNUNET_OK upon successfully queuing the service start request;
- *           GNUNET_SYSERR upon error
- */
-int
-GNUNET_TESTING_peer_service_start (struct GNUNET_TESTING_Peer *peer,
-                                   const char *service_name,
-                                   struct GNUNET_TIME_Relative timeout,
-                                   GNUNET_ARM_ResultCallback cont,
-                                   void *cont_cls);
-
-
-/**
- * Stop a service at a peer using its ARM service.  To use this function the
- * peer must be configured earlier using GNUNET_TESTING_peer_configure2();
- *
- * @param peer the peer whose service has to be stopped
- * @param service_name name of the service to stop
- * @param timeout how long should the ARM API try to send the request to stop
- *          the service
- * @param cont the callback to call with result and status from ARM API
- * @param cont_cls the closure for the above callback
- * @return GNUNET_OK upon successfully queuing the service stop request;
- *           GNUNET_SYSERR upon error
- */
-int 
-GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer,
-                                  const char *service_name,
-                                  struct GNUNET_TIME_Relative timeout,
-                                  GNUNET_ARM_ResultCallback cont,
-                                  void *cont_cls);
-
-
-/**
  * Signature of the 'main' function for a (single-peer) testcase that
  * is run using 'GNUNET_TESTING_peer_run'.
  * 

Modified: gnunet/src/testing/test_testing_peerstartup2.c
===================================================================
--- gnunet/src/testing/test_testing_peerstartup2.c      2013-04-01 16:41:10 UTC 
(rev 26709)
+++ gnunet/src/testing/test_testing_peerstartup2.c      2013-04-01 17:54:06 UTC 
(rev 26710)
@@ -36,12 +36,15 @@
 
 #define FAIL_TEST(cond)                         \
   do {                                          \
-    if ((!(cond)) && (GNUNET_OK == status)) {   \
-      status = GNUNET_SYSERR;                   \
+    if (!(cond)) {                              \
+      GNUNET_break (0);                         \
+      if (GNUNET_OK == status) {                \
+        status = GNUNET_SYSERR;                 \
+      }                                         \
     }                                           \
   } while (0)                                   \
+    
 
-
 /**
  * The status of the test
  */
@@ -103,22 +106,9 @@
  * @param tc the tast context
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct TestingContext *test_ctx = cls;
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
-  GNUNET_assert (NULL != test_ctx);
-  if (NULL != test_ctx->peer)
-  {
-    FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer,
-                                                       
GNUNET_TIME_UNIT_MINUTES));
 
-  }
-  else
-    do_shutdown (test_ctx, tc);
-}
-
-
 static void
 peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
 {
@@ -127,13 +117,11 @@
   switch (test_ctx->state)
   {
   case PEER_INIT:
-    FAIL_TEST (GNUNET_YES == success);
-    test_ctx->state = PEER_STARTED;
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                  &do_shutdown, test_ctx);
+    FAIL_TEST (0);
     break;
   case PEER_STARTED:
-    FAIL_TEST (GNUNET_NO == success);
+    FAIL_TEST (GNUNET_YES == success);
+    test_ctx->state = PEER_STOPPED;
     GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
     break;
   case PEER_STOPPED:
@@ -143,6 +131,31 @@
 
 
 /**
+ * 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)
+  {
+    FAIL_TEST (GNUNET_OK == 
+               GNUNET_TESTING_peer_stop_async (test_ctx->peer,
+                                               &peer_status_cb,
+                                               test_ctx));
+
+  }
+  else
+    do_shutdown (test_ctx, tc);
+}
+
+
+/**
  * Main point of test execution
  */
 static void
@@ -162,20 +175,20 @@
     goto end;
   test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
   test_ctx->peer = 
-      GNUNET_TESTING_peer_configure2 (test_ctx->system,
-                                      test_ctx->cfg,
-                                      0, &id, &emsg,
-                                      &peer_status_cb,
-                                      test_ctx);
+      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,
-                                               GNUNET_TIME_UNIT_MINUTES))
+  if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer))
     goto end;
+  test_ctx->state = PEER_STARTED;
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                &do_shutdown, test_ctx);
   return;
   
  end:

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2013-04-01 16:41:10 UTC (rev 26709)
+++ gnunet/src/testing/testing.c        2013-04-01 17:54:06 UTC (rev 26710)
@@ -186,15 +186,19 @@
   struct GNUNET_ARM_Handle *ah;
 
   /**
+   * Handle to ARM monitoring
+   */
+  struct GNUNET_ARM_MonitorHandle *mh;
+
+  /**
    * The config of the peer
    */
   struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * The callback to call if asynchronous functions are used for peer/service
-   * start/stop requests
+   * The callback to call asynchronously when a peer is stopped
    */  
-  GNUNET_TESTING_PeerStatusCallback cb;
+  GNUNET_TESTING_PeerStopCallback cb;
   
   /**
    * The closure for the above callback
@@ -518,25 +522,6 @@
 
 
 /**
- * Reserve a SERVICEHOME path for a peer.
- *
- * @param system system to use for reservation tracking
- * @return NULL on error, otherwise fresh unique path to use
- *         as the servicehome for the peer; must be freed by the caller
- */
-// static 
-char *
-reserve_path (struct GNUNET_TESTING_System *system)
-{
-  char *reserved_path;
-
-  GNUNET_asprintf (&reserved_path,
-                   "%s/%u", system->tmppath, system->path_counter++);
-  return reserved_path;
-}            
-
-
-/**
  * Testing includes a number of pre-created hostkeys for
  * faster peer startup.  This function can be used to
  * access the n-th key of those pre-created hostkeys; note
@@ -984,6 +969,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))
   {
@@ -1001,46 +987,6 @@
 
 
 /**
- * Wrapper over GNUNET_TESTING_peer_configure() to set the
- * GNUNET_TESTING_PeerStatusCallback() for using functions
- * GNUNET_TESTING_peer_start2() and GNUNET_TESTING_peer_stop2()
- *
- * @param system system to use to coordinate resource usage
- * @param cfg configuration to use; will be UPDATED (to reflect needed
- *            changes in port numbers and paths)
- * @param key_number number of the hostkey to use for the peer
- * @param id identifier for the daemon, will be set, can be NULL
- * @param emsg set to freshly allocated error message (set to NULL on 
success), 
- *          can be NULL
- * @param status_cb the status callback to call upon peer start and stop
- * @return handle to the peer, NULL on error
- */
-struct GNUNET_TESTING_Peer *
-GNUNET_TESTING_peer_configure2 (struct GNUNET_TESTING_System *system,
-                                struct GNUNET_CONFIGURATION_Handle *cfg,
-                                uint32_t key_number,
-                                struct GNUNET_PeerIdentity *id,
-                                char **emsg,
-                                GNUNET_TESTING_PeerStatusCallback status_cb,
-                                void *cls)
-{
-  struct GNUNET_TESTING_Peer *peer;
-  
-  peer = GNUNET_TESTING_peer_configure (system,
-                                        cfg,
-                                        key_number,
-                                        id,
-                                        emsg);
-  if (NULL == peer)
-    return NULL;
-  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  peer->cb = status_cb;
-  peer->cb_cls = cls;
-  return peer;
-}
-
-
-/**
  * Obtain the peer identity from a peer handle.
  *
  * @param peer peer handle for which we want the peer's identity
@@ -1159,56 +1105,6 @@
                                        
 
 /**
- * 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);  
-}
-
-
-/**
- * Start a peer asynchronously using ARM API.  Peer's startup is signaled
- * through the GNUNET_TESTING_PeerStatusCallback() given to
- * GNUNET_TESTING_peer_configure2().  To use this function the peer must be
- * configured earlier using GNUNET_TESTING_peer_configure2();
- *
- * @param peer the peer to start
- * @param timeout how long to wait before giving up to start the peer
- * @return GNUNET_OK upon successfully giving the request to the ARM API (this
- *           does not mean that the peer is successfully started); 
GNUNET_SYSERR
- *           upon any error.
- */
-int
-GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer,
-                            struct GNUNET_TIME_Relative timeout)
-{
-  if (NULL != peer->ah)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  GNUNET_assert (NULL != peer->cb);
-  GNUNET_assert (NULL != peer->cfg);
-  peer->ah = GNUNET_ARM_connect (peer->cfg, &conn_status, peer);
-  if (NULL == peer->ah)
-    return GNUNET_SYSERR;
-  GNUNET_TESTING_peer_service_start (peer, "arm", timeout, NULL, NULL);
-  return GNUNET_OK;
-}
-
-
-
-/**
  * Sends SIGTERM to the peer's main process
  *
  * @param peer the handle to the peer
@@ -1270,25 +1166,59 @@
 
 
 /**
+ * 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
+disconn_status (void *cls, struct GNUNET_ARM_Handle *arm, 
+                int connected)
+{
+  struct GNUNET_TESTING_Peer *peer = cls;
+
+  if (GNUNET_SYSERR == connected)
+  {
+    peer->cb (peer->cb_cls, peer, connected);
+    return;
+  }
+  if (GNUNET_YES == connected)
+  {
+    GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer));
+    return;
+  }
+  GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer));
+  GNUNET_ARM_disconnect_and_free (peer->ah);
+  peer->ah = NULL;
+  peer->cb (peer->cb_cls, peer, GNUNET_YES);
+}
+
+
+/**
  * Stop a peer asynchronously using ARM API.  Peer's shutdown is signaled
- * through the GNUNET_TESTING_PeerStatusCallback() given to
- * GNUNET_TESTING_peer_configure2().  To use this function the peer must be
- * configured earlier using GNUNET_TESTING_peer_configure2();
+ * through the GNUNET_TESTING_PeerStopCallback().
  *
  * @param peer the peer to stop
- * @param timeout how long to wait before giving up to stop the peer
+ * @param cb the callback to signal peer shutdown
+ * @param cb_cls closure for the above callback
  * @return GNUNET_OK upon successfully giving the request to the ARM API (this
  *           does not mean that the peer is successfully stopped); 
GNUNET_SYSERR
  *           upon any error.
  */
 int
-GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer,
-                           struct GNUNET_TIME_Relative timeout)
+GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer,
+                                GNUNET_TESTING_PeerStopCallback cb,
+                                void *cb_cls)
 {
+  if (NULL == peer->main_process)
+    return GNUNET_SYSERR;  
+  peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
   if (NULL == peer->ah)
     return GNUNET_SYSERR;
-  GNUNET_assert (NULL != peer->cb);
-  GNUNET_TESTING_peer_service_stop (peer, "arm", timeout, NULL, NULL);
+  peer->cb = cb;
+  peer->cb_cls = cb_cls;
   return GNUNET_OK;
 }
 
@@ -1307,6 +1237,8 @@
     GNUNET_TESTING_peer_stop (peer);
   if (NULL != peer->ah)
     GNUNET_ARM_disconnect_and_free (peer->ah);
+  if (NULL != peer->mh)
+    GNUNET_ARM_monitor_disconnect_and_free (peer->mh);
   GNUNET_free (peer->cfgfile);
   if (NULL != peer->cfg)
     GNUNET_CONFIGURATION_destroy (peer->cfg);




reply via email to

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