diff options
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_udp_backchannel.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_udp_backchannel.c | 177 |
1 files changed, 118 insertions, 59 deletions
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index e2e0b258b..b0ca37447 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c | |||
@@ -39,34 +39,32 @@ | |||
39 | 39 | ||
40 | #define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf" | 40 | #define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf" |
41 | 41 | ||
42 | /** | 42 | struct TestState |
43 | * The name for a specific test environment directory. | 43 | { |
44 | * | 44 | /** |
45 | */ | 45 | * Callback to write messages to the master loop. |
46 | char *testdir; | 46 | * |
47 | */ | ||
48 | TESTING_CMD_HELPER_write_cb write_message; | ||
47 | 49 | ||
48 | /** | 50 | /** |
49 | * The name for the configuration file of the specific node. | 51 | * The name for a specific test environment directory. |
50 | * | 52 | * |
51 | */ | 53 | */ |
52 | char *cfgname; | 54 | char *testdir; |
53 | 55 | ||
54 | /** | 56 | /** |
55 | * Flag indicating if all peers have been started. | 57 | * The name for the configuration file of the specific node. |
56 | * | 58 | * |
57 | */ | 59 | */ |
58 | unsigned int are_all_peers_started; | 60 | char *cfgname; |
61 | }; | ||
59 | 62 | ||
60 | /** | 63 | static struct GNUNET_TESTING_Command block_send; |
61 | * Flag indicating if all local tests are prepared to finish. | ||
62 | * | ||
63 | */ | ||
64 | unsigned int are_all_local_tests_prepared; | ||
65 | 64 | ||
66 | /** | 65 | static struct GNUNET_TESTING_Command block_receive; |
67 | * Flag indicating a received message. | 66 | |
68 | */ | 67 | static struct GNUNET_TESTING_Command connect_peers; |
69 | unsigned int message_received; | ||
70 | 68 | ||
71 | 69 | ||
72 | /** | 70 | /** |
@@ -91,9 +89,14 @@ static void | |||
91 | handle_test (void *cls, | 89 | handle_test (void *cls, |
92 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 90 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
93 | { | 91 | { |
94 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 92 | struct GNUNET_TESTING_AsyncContext *ac; |
95 | "Message received.\n"); | 93 | |
96 | message_received = GNUNET_YES; | 94 | GNUNET_TESTING_get_trait_async_context (&block_receive, |
95 | &ac); | ||
96 | if ((NULL == ac) || (NULL == ac->cont)) | ||
97 | GNUNET_TESTING_async_fail (ac); | ||
98 | else | ||
99 | GNUNET_TESTING_async_finish (ac); | ||
97 | } | 100 | } |
98 | 101 | ||
99 | 102 | ||
@@ -104,14 +107,65 @@ handle_test (void *cls, | |||
104 | static void | 107 | static void |
105 | all_peers_started () | 108 | all_peers_started () |
106 | { | 109 | { |
107 | are_all_peers_started = GNUNET_YES; | 110 | struct GNUNET_TESTING_AsyncContext *ac; |
108 | LOG (GNUNET_ERROR_TYPE_ERROR, | 111 | |
109 | "setting are_all_peers_started: %d\n", | 112 | GNUNET_TESTING_get_trait_async_context (&block_send, |
110 | are_all_peers_started); | 113 | &ac); |
114 | if ((NULL == ac) || (NULL == ac->cont)) | ||
115 | GNUNET_TESTING_async_fail (ac); | ||
116 | else | ||
117 | GNUNET_TESTING_async_finish (ac); | ||
111 | } | 118 | } |
112 | 119 | ||
113 | 120 | ||
114 | /** | 121 | /** |
122 | * Function called with the final result of the test. | ||
123 | * | ||
124 | * @param cls the `struct MainParams` | ||
125 | * @param rv #GNUNET_OK if the test passed | ||
126 | */ | ||
127 | static void | ||
128 | handle_result (void *cls, | ||
129 | enum GNUNET_GenericReturnValue rv) | ||
130 | { | ||
131 | struct TestState *ts = cls; | ||
132 | struct GNUNET_MessageHeader *reply; | ||
133 | |||
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
135 | "Local test exits with status %d\n", | ||
136 | rv); | ||
137 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); | ||
138 | |||
139 | ts->write_message (reply, | ||
140 | ntohs (reply->size)); | ||
141 | GNUNET_free (ts->testdir); | ||
142 | GNUNET_free (ts->cfgname); | ||
143 | GNUNET_free (ts); | ||
144 | } | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Callback from start peer cmd for signaling a peer got connected. | ||
149 | * | ||
150 | */ | ||
151 | static void * | ||
152 | notify_connect (void *cls, | ||
153 | const struct GNUNET_PeerIdentity *peer, | ||
154 | struct GNUNET_MQ_Handle *mq) | ||
155 | { | ||
156 | struct ConnectPeersState *cps; | ||
157 | |||
158 | GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, | ||
159 | &cps); | ||
160 | void *ret = NULL; | ||
161 | |||
162 | cps->notify_connect (cps, | ||
163 | peer, | ||
164 | mq); | ||
165 | return ret; | ||
166 | } | ||
167 | |||
168 | /** | ||
115 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. | 169 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. |
116 | */ | 170 | */ |
117 | static void | 171 | static void |
@@ -120,7 +174,6 @@ all_local_tests_prepared () | |||
120 | are_all_local_tests_prepared = GNUNET_YES; | 174 | are_all_local_tests_prepared = GNUNET_YES; |
121 | } | 175 | } |
122 | 176 | ||
123 | |||
124 | /** | 177 | /** |
125 | * Function to start a local test case. | 178 | * Function to start a local test case. |
126 | * | 179 | * |
@@ -139,7 +192,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
139 | char *local_m) | 192 | char *local_m) |
140 | { | 193 | { |
141 | 194 | ||
142 | unsigned int n_int, m_int, local_m_int, num; | 195 | unsigned int n_int; |
196 | unsigned int m_int; | ||
197 | unsigned int local_m_int; | ||
198 | unsigned int num; | ||
199 | struct TestState *ts = GNUNET_new (struct TestState); | ||
143 | 200 | ||
144 | struct GNUNET_TESTING_NetjailTopology *topology = | 201 | struct GNUNET_TESTING_NetjailTopology *topology = |
145 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); | 202 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); |
@@ -154,18 +211,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
154 | else | 211 | else |
155 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | 212 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; |
156 | 213 | ||
157 | GNUNET_asprintf (&cfgname, | 214 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); |
215 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
216 | "block-receive"); | ||
217 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | ||
218 | "start-peer", | ||
219 | "system-create", | ||
220 | num, | ||
221 | NULL); | ||
222 | |||
223 | GNUNET_asprintf (&ts->cfgname, | ||
158 | "test_transport_api2_tcp_node1.conf"); | 224 | "test_transport_api2_tcp_node1.conf"); |
159 | 225 | ||
160 | LOG (GNUNET_ERROR_TYPE_ERROR, | 226 | LOG (GNUNET_ERROR_TYPE_ERROR, |
161 | "plugin cfgname: %s\n", | 227 | "plugin cfgname: %s\n", |
162 | cfgname); | 228 | ts->cfgname); |
163 | 229 | ||
164 | LOG (GNUNET_ERROR_TYPE_ERROR, | 230 | LOG (GNUNET_ERROR_TYPE_ERROR, |
165 | "node ip: %s\n", | 231 | "node ip: %s\n", |
166 | node_ip); | 232 | node_ip); |
167 | 233 | ||
168 | GNUNET_asprintf (&testdir, | 234 | GNUNET_asprintf (&ts->testdir, |
169 | "%s%s%s", | 235 | "%s%s%s", |
170 | BASE_DIR, | 236 | BASE_DIR, |
171 | m, | 237 | m, |
@@ -181,22 +247,18 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
181 | 247 | ||
182 | struct GNUNET_TESTING_Command commands[] = { | 248 | struct GNUNET_TESTING_Command commands[] = { |
183 | GNUNET_TESTING_cmd_system_create ("system-create", | 249 | GNUNET_TESTING_cmd_system_create ("system-create", |
184 | testdir), | 250 | ts->testdir), |
185 | GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer", | 251 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", |
186 | "system-create", | 252 | "system-create", |
187 | num, | 253 | num, |
188 | node_ip, | 254 | node_ip, |
189 | handlers, | 255 | handlers, |
190 | cfgname), | 256 | ts->cfgname, |
257 | notify_connect), | ||
191 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | 258 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", |
192 | write_message), | 259 | write_message), |
193 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block", | 260 | block_send, |
194 | &are_all_peers_started), | 261 | connect_peers, |
195 | GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers", | ||
196 | "start-peer", | ||
197 | "system-create", | ||
198 | num, | ||
199 | topology), | ||
200 | GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check", | 262 | GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check", |
201 | "start-peer", | 263 | "start-peer", |
202 | "system-create", | 264 | "system-create", |
@@ -207,18 +269,17 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
207 | GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared", | 269 | GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared", |
208 | write_message, | 270 | write_message, |
209 | &are_all_local_tests_prepared), | 271 | &are_all_local_tests_prepared), |
272 | block_receive, | ||
210 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 273 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
211 | "start-peer"), | 274 | "start-peer"), |
212 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 275 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
213 | "system-create"), | 276 | "system-create") |
214 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", | ||
215 | write_message), | ||
216 | GNUNET_TESTING_cmd_end_without_shutdown () | ||
217 | }; | 277 | }; |
218 | 278 | ||
219 | GNUNET_TESTING_run (NULL, | 279 | GNUNET_TESTING_run (commands, |
220 | commands, | 280 | GNUNET_TIME_UNIT_FOREVER_REL, |
221 | GNUNET_TIME_UNIT_FOREVER_REL); | 281 | &handle_result, |
282 | ts); | ||
222 | 283 | ||
223 | } | 284 | } |
224 | 285 | ||
@@ -258,8 +319,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls) | |||
258 | struct GNUNET_TESTING_PluginFunctions *api = cls; | 319 | struct GNUNET_TESTING_PluginFunctions *api = cls; |
259 | 320 | ||
260 | GNUNET_free (api); | 321 | GNUNET_free (api); |
261 | GNUNET_free (testdir); | ||
262 | GNUNET_free (cfgname); | ||
263 | return NULL; | 322 | return NULL; |
264 | } | 323 | } |
265 | 324 | ||