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 | 175 |
1 files changed, 121 insertions, 54 deletions
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index 6b0342e51..108e1ac09 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c | |||
@@ -39,28 +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 a received message. | 64 | |
62 | */ | 65 | static struct GNUNET_TESTING_Command block_receive; |
63 | unsigned int message_received; | 66 | |
67 | static struct GNUNET_TESTING_Command connect_peers; | ||
64 | 68 | ||
65 | 69 | ||
66 | /** | 70 | /** |
@@ -85,7 +89,14 @@ static void | |||
85 | handle_test (void *cls, | 89 | handle_test (void *cls, |
86 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 90 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
87 | { | 91 | { |
88 | message_received = GNUNET_YES; | 92 | struct GNUNET_TESTING_AsyncContext *ac; |
93 | |||
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); | ||
89 | } | 100 | } |
90 | 101 | ||
91 | 102 | ||
@@ -96,10 +107,62 @@ handle_test (void *cls, | |||
96 | static void | 107 | static void |
97 | all_peers_started () | 108 | all_peers_started () |
98 | { | 109 | { |
99 | are_all_peers_started = GNUNET_YES; | 110 | struct GNUNET_TESTING_AsyncContext *ac; |
100 | LOG (GNUNET_ERROR_TYPE_ERROR, | 111 | |
101 | "setting are_all_peers_started: %d\n", | 112 | GNUNET_TESTING_get_trait_async_context (&block_send, |
102 | 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); | ||
118 | } | ||
119 | |||
120 | |||
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; | ||
103 | } | 166 | } |
104 | 167 | ||
105 | 168 | ||
@@ -121,7 +184,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
121 | char *local_m) | 184 | char *local_m) |
122 | { | 185 | { |
123 | 186 | ||
124 | unsigned int n_int, m_int, local_m_int, num; | 187 | unsigned int n_int; |
188 | unsigned int m_int; | ||
189 | unsigned int local_m_int; | ||
190 | unsigned int num; | ||
191 | struct TestState *ts = GNUNET_new (struct TestState); | ||
125 | 192 | ||
126 | struct GNUNET_TESTING_NetjailTopology *topology = | 193 | struct GNUNET_TESTING_NetjailTopology *topology = |
127 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); | 194 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); |
@@ -136,18 +203,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
136 | else | 203 | else |
137 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | 204 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; |
138 | 205 | ||
139 | GNUNET_asprintf (&cfgname, | 206 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); |
207 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
208 | "block-receive"); | ||
209 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | ||
210 | "start-peer", | ||
211 | "system-create", | ||
212 | num, | ||
213 | NULL); | ||
214 | |||
215 | GNUNET_asprintf (&ts->cfgname, | ||
140 | "test_transport_api2_tcp_node1.conf"); | 216 | "test_transport_api2_tcp_node1.conf"); |
141 | 217 | ||
142 | LOG (GNUNET_ERROR_TYPE_ERROR, | 218 | LOG (GNUNET_ERROR_TYPE_ERROR, |
143 | "plugin cfgname: %s\n", | 219 | "plugin cfgname: %s\n", |
144 | cfgname); | 220 | ts->cfgname); |
145 | 221 | ||
146 | LOG (GNUNET_ERROR_TYPE_ERROR, | 222 | LOG (GNUNET_ERROR_TYPE_ERROR, |
147 | "node ip: %s\n", | 223 | "node ip: %s\n", |
148 | node_ip); | 224 | node_ip); |
149 | 225 | ||
150 | GNUNET_asprintf (&testdir, | 226 | GNUNET_asprintf (&ts->testdir, |
151 | "%s%s%s", | 227 | "%s%s%s", |
152 | BASE_DIR, | 228 | BASE_DIR, |
153 | m, | 229 | m, |
@@ -163,39 +239,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
163 | 239 | ||
164 | struct GNUNET_TESTING_Command commands[] = { | 240 | struct GNUNET_TESTING_Command commands[] = { |
165 | GNUNET_TESTING_cmd_system_create ("system-create", | 241 | GNUNET_TESTING_cmd_system_create ("system-create", |
166 | testdir), | 242 | ts->testdir), |
167 | GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer", | 243 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", |
168 | "system-create", | 244 | "system-create", |
169 | num, | 245 | num, |
170 | node_ip, | 246 | node_ip, |
171 | handlers, | 247 | handlers, |
172 | cfgname), | 248 | ts->cfgname, |
249 | notify_connect), | ||
173 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | 250 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", |
174 | write_message), | 251 | write_message), |
175 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block", | 252 | block_send, |
176 | &are_all_peers_started), | 253 | connect_peers, |
177 | GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers", | 254 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", |
178 | "start-peer", | 255 | "start-peer", |
179 | "system-create", | 256 | num), |
180 | num, | 257 | block_receive, |
181 | topology), | ||
182 | GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", | ||
183 | "start-peer", | ||
184 | num), | ||
185 | GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", | ||
186 | &message_received), | ||
187 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 258 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
188 | "start-peer"), | 259 | "start-peer"), |
189 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 260 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
190 | "system-create"), | 261 | "system-create") |
191 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", | ||
192 | write_message) | ||
193 | }; | 262 | }; |
194 | 263 | ||
195 | GNUNET_TESTING_run (commands, | 264 | GNUNET_TESTING_run (commands, |
196 | GNUNET_TIME_UNIT_FOREVER_REL, | 265 | GNUNET_TIME_UNIT_FOREVER_REL, |
197 | NULL, /* FIMXE: will crash */ | 266 | &handle_result, |
198 | NULL); | 267 | ts); |
199 | 268 | ||
200 | } | 269 | } |
201 | 270 | ||
@@ -234,8 +303,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls) | |||
234 | struct GNUNET_TESTING_PluginFunctions *api = cls; | 303 | struct GNUNET_TESTING_PluginFunctions *api = cls; |
235 | 304 | ||
236 | GNUNET_free (api); | 305 | GNUNET_free (api); |
237 | GNUNET_free (testdir); | ||
238 | GNUNET_free (cfgname); | ||
239 | return NULL; | 306 | return NULL; |
240 | } | 307 | } |
241 | 308 | ||