gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r24970 - in gnunet/src: include testbed testing
Date: Wed, 14 Nov 2012 18:06:31 +0100

Author: harsha
Date: 2012-11-14 18:06:31 +0100 (Wed, 14 Nov 2012)
New Revision: 24970

Modified:
   gnunet/src/include/gnunet_testing_lib-new.h
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testing/testing.c
Log:
kill all peers first and wait for them later

Modified: gnunet/src/include/gnunet_testing_lib-new.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib-new.h 2012-11-14 16:00:54 UTC (rev 
24969)
+++ gnunet/src/include/gnunet_testing_lib-new.h 2012-11-14 17:06:31 UTC (rev 
24970)
@@ -253,6 +253,28 @@
 
 
 /**
+ * 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'.
  * 

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-11-14 16:00:54 UTC (rev 
24969)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-11-14 17:06:31 UTC (rev 
24970)
@@ -3950,11 +3950,18 @@
          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);
       }

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2012-11-14 16:00:54 UTC (rev 24969)
+++ gnunet/src/testing/testing.c        2012-11-14 17:06:31 UTC (rev 24970)
@@ -992,23 +992,62 @@
 
 
 /**
- * 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;
   }
-  (void) GNUNET_OS_process_kill (peer->main_process, SIGTERM);
-  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process));
+  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;
+  }
+  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;
 }
 




reply via email to

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