aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-14 17:06:31 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-14 17:06:31 +0000
commitb9e2512dd31fca0e85e82e5d5e355e027872b47b (patch)
tree74217cbd2e231bb0fbbd0224bb64f346413b5507 /src/testing
parente5035d2c9e05dc738746ee5ef219b2eeb2256d31 (diff)
downloadgnunet-b9e2512dd31fca0e85e82e5d5e355e027872b47b.tar.gz
gnunet-b9e2512dd31fca0e85e82e5d5e355e027872b47b.zip
kill all peers first and wait for them later
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index d534a0051..ce6af991c 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -992,23 +992,62 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
992 992
993 993
994/** 994/**
995 * Stop the peer. 995 * Sends SIGTERM to the peer's main process
996 * 996 *
997 * @param peer peer to stop 997 * @param peer the handle to the peer
998 * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) 998 * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
999 * or upon any error while sending SIGTERM
999 */ 1000 */
1000int 1001int
1001GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) 1002GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
1003{
1004 if (NULL == peer->main_process)
1005 {
1006 GNUNET_break (0);
1007 return GNUNET_SYSERR;
1008 }
1009 return (0 == GNUNET_OS_process_kill (peer->main_process, SIGTERM)) ?
1010 GNUNET_OK : GNUNET_SYSERR;
1011}
1012
1013
1014/**
1015 * Waits for a peer to terminate. The peer's main process will also be destroyed.
1016 *
1017 * @param peer the handle to the peer
1018 * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL
1019 * or upon any error while waiting
1020 */
1021int
1022GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer)
1002{ 1023{
1024 int ret;
1025
1003 if (NULL == peer->main_process) 1026 if (NULL == peer->main_process)
1004 { 1027 {
1005 GNUNET_break (0); 1028 GNUNET_break (0);
1006 return GNUNET_SYSERR; 1029 return GNUNET_SYSERR;
1007 } 1030 }
1008 (void) GNUNET_OS_process_kill (peer->main_process, SIGTERM); 1031 ret = GNUNET_OS_process_wait (peer->main_process);
1009 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process));
1010 GNUNET_OS_process_destroy (peer->main_process); 1032 GNUNET_OS_process_destroy (peer->main_process);
1011 peer->main_process = NULL; 1033 peer->main_process = NULL;
1034 return ret;
1035}
1036
1037
1038/**
1039 * Stop the peer.
1040 *
1041 * @param peer peer to stop
1042 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1043 */
1044int
1045GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1046{
1047 if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill (peer))
1048 return GNUNET_SYSERR;
1049 if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait (peer))
1050 return GNUNET_SYSERR;
1012 return GNUNET_OK; 1051 return GNUNET_OK;
1013} 1052}
1014 1053