diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 14:58:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 14:58:37 +0000 |
commit | 4f77ea5b2b3d53a21f70237f8b92a9a2273c21bf (patch) | |
tree | 8f93edb4d6608668822dd2832a734eddc79daac4 /src/transport/test_transport_testing_restart.c | |
parent | c4a3cadf446bdc115a2efb37b10715c2ad8b4575 (diff) | |
download | gnunet-4f77ea5b2b3d53a21f70237f8b92a9a2273c21bf.tar.gz gnunet-4f77ea5b2b3d53a21f70237f8b92a9a2273c21bf.zip |
clean up switch tests
Diffstat (limited to 'src/transport/test_transport_testing_restart.c')
-rw-r--r-- | src/transport/test_transport_testing_restart.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 2f36e080a..2d06bf668 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -21,52 +21,48 @@ | |||
21 | * @file transport/test_transport_testing_restart.c | 21 | * @file transport/test_transport_testing_restart.c |
22 | * @brief test case for transport testing library: | 22 | * @brief test case for transport testing library: |
23 | * start the peer, get the HELLO message, restart and stop the peer | 23 | * start the peer, get the HELLO message, restart and stop the peer |
24 | * | ||
25 | */ | 24 | */ |
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "gnunet_transport_service.h" | 26 | #include "gnunet_transport_service.h" |
28 | #include "transport-testing.h" | 27 | #include "transport-testing.h" |
29 | 28 | ||
30 | /** | ||
31 | * How long until we give up on transmitting the message? | ||
32 | */ | ||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
34 | 30 | ||
35 | struct GNUNET_SCHEDULER_Task * timeout_task; | 31 | |
32 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
36 | 33 | ||
37 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 34 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
38 | 35 | ||
39 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 36 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
37 | |||
38 | static int ret; | ||
40 | 39 | ||
41 | static int ret = 0; | ||
42 | 40 | ||
43 | static void | 41 | static void |
44 | end () | 42 | end () |
45 | { | 43 | { |
46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
47 | 45 | "Stopping peers\n"); | |
48 | if (timeout_task != NULL) | 46 | if (NULL != timeout_task) |
49 | GNUNET_SCHEDULER_cancel (timeout_task); | 47 | GNUNET_SCHEDULER_cancel (timeout_task); |
50 | 48 | if (NULL != p) | |
51 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | 49 | GNUNET_TRANSPORT_TESTING_stop_peer (p); |
52 | GNUNET_TRANSPORT_TESTING_done (tth); | 50 | if (NULL != tth) |
51 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
53 | } | 52 | } |
54 | 53 | ||
54 | |||
55 | static void | 55 | static void |
56 | end_badly () | 56 | end_badly () |
57 | { | 57 | { |
58 | timeout_task = NULL; | 58 | timeout_task = NULL; |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
60 | 60 | "Timeout!\n"); | |
61 | if (NULL != p) | 61 | end (); |
62 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | ||
63 | |||
64 | if (NULL != tth) | ||
65 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
66 | |||
67 | ret = GNUNET_SYSERR; | 62 | ret = GNUNET_SYSERR; |
68 | } | 63 | } |
69 | 64 | ||
65 | |||
70 | static void | 66 | static void |
71 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 67 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
72 | void *cls) | 68 | void *cls) |
@@ -76,7 +72,7 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | |||
76 | p->no, | 72 | p->no, |
77 | GNUNET_i2s (&p->id)); | 73 | GNUNET_i2s (&p->id)); |
78 | ret = 0; | 74 | ret = 0; |
79 | GNUNET_SCHEDULER_add_now (&end, NULL); | 75 | end (); |
80 | } | 76 | } |
81 | 77 | ||
82 | 78 | ||
@@ -84,7 +80,7 @@ static void | |||
84 | restart_task () | 80 | restart_task () |
85 | { | 81 | { |
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
87 | "Peer %u (`%s') restarting, \n", | 83 | "Peer %u (`%s') restarting\n", |
88 | p->no, | 84 | p->no, |
89 | GNUNET_i2s (&p->id)); | 85 | GNUNET_i2s (&p->id)); |
90 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | 86 | GNUNET_TRANSPORT_TESTING_restart_peer (p, |
@@ -94,26 +90,30 @@ restart_task () | |||
94 | 90 | ||
95 | 91 | ||
96 | static void | 92 | static void |
97 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | 93 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
94 | void *cls) | ||
98 | { | 95 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", | 96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
97 | "Peer %u (`%s') successfully started\n", | ||
100 | p->no, | 98 | p->no, |
101 | GNUNET_i2s (&p->id)); | 99 | GNUNET_i2s (&p->id)); |
102 | 100 | GNUNET_SCHEDULER_add_now (&restart_task, | |
103 | GNUNET_SCHEDULER_add_now (&restart_task, NULL); | 101 | NULL); |
104 | } | 102 | } |
105 | 103 | ||
106 | 104 | ||
107 | static void | 105 | static void |
108 | run (void *cls, char *const *args, const char *cfgfile, | 106 | run (void *cls, |
107 | char *const *args, | ||
108 | const char *cfgfile, | ||
109 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 109 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
110 | { | 110 | { |
111 | ret = 1; | 111 | ret = 1; |
112 | tth = GNUNET_TRANSPORT_TESTING_init (); | 112 | tth = GNUNET_TRANSPORT_TESTING_init (); |
113 | GNUNET_assert (NULL != tth); | 113 | GNUNET_assert (NULL != tth); |
114 | 114 | ||
115 | timeout_task = | 115 | timeout_task |
116 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 116 | = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
117 | &end_badly, | 117 | &end_badly, |
118 | NULL); | 118 | NULL); |
119 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, | 119 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, |
@@ -126,33 +126,37 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
126 | NULL); /* closure */ | 126 | NULL); /* closure */ |
127 | if (NULL == p) | 127 | if (NULL == p) |
128 | { | 128 | { |
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
130 | if (timeout_task != NULL) | 130 | "Failed to start peer\n"); |
131 | GNUNET_SCHEDULER_cancel (timeout_task); | 131 | end (); |
132 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 132 | ret = 1; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | |||
136 | int | 137 | int |
137 | main (int argc, char *argv[]) | 138 | main (int argc, |
139 | char *argv[]) | ||
138 | { | 140 | { |
139 | GNUNET_log_setup ("test_transport_testing_restart", | ||
140 | "WARNING", | ||
141 | NULL); | ||
142 | |||
143 | char *const argv_1[] = { "test_transport_testing_restart", | 141 | char *const argv_1[] = { "test_transport_testing_restart", |
144 | "-c", | 142 | "-c", |
145 | "test_transport_api_data.conf", | 143 | "test_transport_api_data.conf", |
146 | NULL | 144 | NULL |
147 | }; | 145 | }; |
148 | |||
149 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 146 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
150 | GNUNET_GETOPT_OPTION_END | 147 | GNUNET_GETOPT_OPTION_END |
151 | }; | 148 | }; |
152 | 149 | ||
153 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | 150 | GNUNET_log_setup ("test_transport_testing_restart", |
154 | "test_transport_testing_restart", "nohelp", options, &run, &ret); | 151 | "WARNING", |
155 | 152 | NULL); | |
153 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, | ||
154 | argv_1, | ||
155 | "test_transport_testing_restart", | ||
156 | "nohelp", | ||
157 | options, | ||
158 | &run, | ||
159 | NULL); | ||
156 | return ret; | 160 | return ret; |
157 | } | 161 | } |
158 | 162 | ||