kill all peers first and wait for them later
authorSree Harsha Totakura <totakura@in.tum.de>
Wed, 14 Nov 2012 17:06:31 +0000 (17:06 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Wed, 14 Nov 2012 17:06:31 +0000 (17:06 +0000)
src/include/gnunet_testing_lib-new.h
src/testbed/gnunet-service-testbed.c
src/testing/testing.c

index 97be8211c166ad852668753be5c0077665f36c58..bdcd3574d74a168893f29c3cb950c5962f2e3cb3 100644 (file)
@@ -252,6 +252,28 @@ void
 GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer);
 
 
+/**
+ * Sends SIGTERM to the peer's main process
+ *
+ * @param peer the handle to the peer
+ * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
+ *           or upon any error while sending SIGTERM
+ */
+int
+GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer);
+
+
+/**
+ * Waits for a peer to terminate. The peer's main process will also be destroyed.
+ *
+ * @param peer the handle to the peer
+ * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
+ *           or upon any error while waiting
+ */
+int
+GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer);
+
+
 /**
  * Signature of the 'main' function for a (single-peer) testcase that
  * is run using 'GNUNET_TESTING_peer_run'.
index 9ffdf78120e692cd1e636d8c7e2f885e7c17e8db..2b138129aa0dbd4623c1b24d6c92d5e81227b3d7 100644 (file)
@@ -3950,11 +3950,18 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
          destroyed by a context which we destroy before */
       GNUNET_break (GNUNET_NO == peer_list[id]->destroy_flag);
       /* counter should be zero as we free all contexts before */
-      GNUNET_break (0 == peer_list[id]->reference_cnt);
+      GNUNET_break (0 == peer_list[id]->reference_cnt);      
+      if ( (GNUNET_NO == peer_list[id]->is_remote)
+           && (GNUNET_YES == peer_list[id]->details.local.is_running))
+        GNUNET_TESTING_peer_kill (peer_list[id]->details.local.peer);
+    }
+  for (id = 0; id < peer_list_size; id++)
+    if (NULL != peer_list[id])
+    {
       if (GNUNET_NO == peer_list[id]->is_remote)
       {
        if (GNUNET_YES == peer_list[id]->details.local.is_running)
-         GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer);
+         GNUNET_TESTING_peer_wait (peer_list[id]->details.local.peer);
         GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
         GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
       }
index d534a0051669c34edf18fc81dd30b914ddc700b0..ce6af991c9c4589c0fd764df68d38090e51ac889 100644 (file)
@@ -992,23 +992,62 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
 
 
 /**
- * Stop the peer. 
+ * Sends SIGTERM to the peer's main process
  *
- * @param peer peer to stop
- * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running)
+ * @param peer the handle to the peer
+ * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
+ *           or upon any error while sending SIGTERM
  */
 int
-GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
+GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
+{
+  if (NULL == peer->main_process)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return (0 == GNUNET_OS_process_kill (peer->main_process, SIGTERM)) ?
+      GNUNET_OK : GNUNET_SYSERR;
+}
+
+
+/**
+ * Waits for a peer to terminate. The peer's main process will also be destroyed.
+ *
+ * @param peer the handle to the peer
+ * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
+ *           or upon any error while waiting
+ */
+int
+GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer)
 {
+  int ret;
+
   if (NULL == peer->main_process)
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
-  (void) GNUNET_OS_process_kill (peer->main_process, SIGTERM);
-  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process));
+  ret = GNUNET_OS_process_wait (peer->main_process);
   GNUNET_OS_process_destroy (peer->main_process);
   peer->main_process = NULL;
+  return ret;
+}
+
+
+/**
+ * Stop the peer. 
+ *
+ * @param peer peer to stop
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
+{
+  if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill (peer))
+    return GNUNET_SYSERR;
+  if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait (peer))
+    return GNUNET_SYSERR;
   return GNUNET_OK;
 }