diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-14 17:06:31 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-14 17:06:31 +0000 |
commit | b9e2512dd31fca0e85e82e5d5e355e027872b47b (patch) | |
tree | 74217cbd2e231bb0fbbd0224bb64f346413b5507 | |
parent | e5035d2c9e05dc738746ee5ef219b2eeb2256d31 (diff) | |
download | gnunet-b9e2512dd31fca0e85e82e5d5e355e027872b47b.tar.gz gnunet-b9e2512dd31fca0e85e82e5d5e355e027872b47b.zip |
kill all peers first and wait for them later
-rw-r--r-- | src/include/gnunet_testing_lib-new.h | 22 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 11 | ||||
-rw-r--r-- | src/testing/testing.c | 51 |
3 files changed, 76 insertions, 8 deletions
diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h index 97be8211c..bdcd3574d 100644 --- a/src/include/gnunet_testing_lib-new.h +++ b/src/include/gnunet_testing_lib-new.h | |||
@@ -253,6 +253,28 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); | |||
253 | 253 | ||
254 | 254 | ||
255 | /** | 255 | /** |
256 | * Sends SIGTERM to the peer's main process | ||
257 | * | ||
258 | * @param peer the handle to the peer | ||
259 | * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL | ||
260 | * or upon any error while sending SIGTERM | ||
261 | */ | ||
262 | int | ||
263 | GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer); | ||
264 | |||
265 | |||
266 | /** | ||
267 | * Waits for a peer to terminate. The peer's main process will also be destroyed. | ||
268 | * | ||
269 | * @param peer the handle to the peer | ||
270 | * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL | ||
271 | * or upon any error while waiting | ||
272 | */ | ||
273 | int | ||
274 | GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer); | ||
275 | |||
276 | |||
277 | /** | ||
256 | * Signature of the 'main' function for a (single-peer) testcase that | 278 | * Signature of the 'main' function for a (single-peer) testcase that |
257 | * is run using 'GNUNET_TESTING_peer_run'. | 279 | * is run using 'GNUNET_TESTING_peer_run'. |
258 | * | 280 | * |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 9ffdf7812..2b138129a 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -3950,11 +3950,18 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3950 | destroyed by a context which we destroy before */ | 3950 | destroyed by a context which we destroy before */ |
3951 | GNUNET_break (GNUNET_NO == peer_list[id]->destroy_flag); | 3951 | GNUNET_break (GNUNET_NO == peer_list[id]->destroy_flag); |
3952 | /* counter should be zero as we free all contexts before */ | 3952 | /* counter should be zero as we free all contexts before */ |
3953 | GNUNET_break (0 == peer_list[id]->reference_cnt); | 3953 | GNUNET_break (0 == peer_list[id]->reference_cnt); |
3954 | if ( (GNUNET_NO == peer_list[id]->is_remote) | ||
3955 | && (GNUNET_YES == peer_list[id]->details.local.is_running)) | ||
3956 | GNUNET_TESTING_peer_kill (peer_list[id]->details.local.peer); | ||
3957 | } | ||
3958 | for (id = 0; id < peer_list_size; id++) | ||
3959 | if (NULL != peer_list[id]) | ||
3960 | { | ||
3954 | if (GNUNET_NO == peer_list[id]->is_remote) | 3961 | if (GNUNET_NO == peer_list[id]->is_remote) |
3955 | { | 3962 | { |
3956 | if (GNUNET_YES == peer_list[id]->details.local.is_running) | 3963 | if (GNUNET_YES == peer_list[id]->details.local.is_running) |
3957 | GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer); | 3964 | GNUNET_TESTING_peer_wait (peer_list[id]->details.local.peer); |
3958 | GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); | 3965 | GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); |
3959 | GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); | 3966 | GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); |
3960 | } | 3967 | } |
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 | */ |
1000 | int | 1001 | int |
1001 | GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) | 1002 | GNUNET_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 | */ | ||
1021 | int | ||
1022 | GNUNET_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 | */ | ||
1044 | int | ||
1045 | GNUNET_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 | ||