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'.
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);
}
/**
- * 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;
}