diff options
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send.c | 195 |
1 files changed, 135 insertions, 60 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index b578219ca..8889f9d06 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c | |||
@@ -37,28 +37,33 @@ | |||
37 | 37 | ||
38 | #define BASE_DIR "testdir" | 38 | #define BASE_DIR "testdir" |
39 | 39 | ||
40 | /** | ||
41 | * The name for a specific test environment directory. | ||
42 | * | ||
43 | */ | ||
44 | char *testdir; | ||
45 | 40 | ||
46 | /** | 41 | struct TestState |
47 | * The name for the configuration file of the specific node. | 42 | { |
48 | * | 43 | /** |
49 | */ | 44 | * Callback to write messages to the master loop. |
50 | char *cfgname; | 45 | * |
46 | */ | ||
47 | TESTING_CMD_HELPER_write_cb write_message; | ||
51 | 48 | ||
52 | /** | 49 | /** |
53 | * Flag indicating if all peers have been started. | 50 | * The name for a specific test environment directory. |
54 | * | 51 | * |
55 | */ | 52 | */ |
56 | unsigned int are_all_peers_started; | 53 | char *testdir; |
57 | 54 | ||
58 | /** | 55 | /** |
59 | * Flag indicating a received message. | 56 | * The name for the configuration file of the specific node. |
60 | */ | 57 | * |
61 | unsigned int message_received; | 58 | */ |
59 | char *cfgname; | ||
60 | }; | ||
61 | |||
62 | static struct GNUNET_TESTING_Command block_send; | ||
63 | |||
64 | static struct GNUNET_TESTING_Command block_receive; | ||
65 | |||
66 | static struct GNUNET_TESTING_Command connect_peers; | ||
62 | 67 | ||
63 | 68 | ||
64 | /** | 69 | /** |
@@ -83,7 +88,14 @@ static void | |||
83 | handle_test (void *cls, | 88 | handle_test (void *cls, |
84 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 89 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
85 | { | 90 | { |
86 | message_received = GNUNET_YES; | 91 | struct GNUNET_TESTING_AsyncContext *ac; |
92 | |||
93 | GNUNET_TESTING_get_trait_async_context (&block_receive, | ||
94 | &ac); | ||
95 | if ((NULL == ac) || (NULL == ac->cont)) | ||
96 | GNUNET_TESTING_async_fail (ac); | ||
97 | else | ||
98 | GNUNET_TESTING_async_finish (ac); | ||
87 | } | 99 | } |
88 | 100 | ||
89 | 101 | ||
@@ -94,7 +106,62 @@ handle_test (void *cls, | |||
94 | static void | 106 | static void |
95 | all_peers_started () | 107 | all_peers_started () |
96 | { | 108 | { |
97 | are_all_peers_started = GNUNET_YES; | 109 | struct GNUNET_TESTING_AsyncContext *ac; |
110 | |||
111 | GNUNET_TESTING_get_trait_async_context (&block_send, | ||
112 | &ac); | ||
113 | if ((NULL == ac) || (NULL == ac->cont)) | ||
114 | GNUNET_TESTING_async_fail (ac); | ||
115 | else | ||
116 | GNUNET_TESTING_async_finish (ac); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Function called with the final result of the test. | ||
122 | * | ||
123 | * @param cls the `struct MainParams` | ||
124 | * @param rv #GNUNET_OK if the test passed | ||
125 | */ | ||
126 | static void | ||
127 | handle_result (void *cls, | ||
128 | enum GNUNET_GenericReturnValue rv) | ||
129 | { | ||
130 | struct TestState *ts = cls; | ||
131 | struct GNUNET_MessageHeader *reply; | ||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "Local test exits with status %d\n", | ||
135 | rv); | ||
136 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); | ||
137 | |||
138 | ts->write_message (reply, | ||
139 | ntohs (reply->size)); | ||
140 | GNUNET_free (ts->testdir); | ||
141 | GNUNET_free (ts->cfgname); | ||
142 | GNUNET_free (ts); | ||
143 | } | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Callback from start peer cmd for signaling a peer got connected. | ||
148 | * | ||
149 | */ | ||
150 | static void * | ||
151 | notify_connect (void *cls, | ||
152 | const struct GNUNET_PeerIdentity *peer, | ||
153 | struct GNUNET_MQ_Handle *mq) | ||
154 | { | ||
155 | struct ConnectPeersState *cps; | ||
156 | |||
157 | GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers, | ||
158 | &cps); | ||
159 | void *ret = NULL; | ||
160 | |||
161 | cps->notify_connect (cps, | ||
162 | peer, | ||
163 | mq); | ||
164 | return ret; | ||
98 | } | 165 | } |
99 | 166 | ||
100 | 167 | ||
@@ -116,24 +183,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
116 | char *local_m) | 183 | char *local_m) |
117 | { | 184 | { |
118 | 185 | ||
119 | GNUNET_asprintf (&cfgname, | 186 | unsigned int n_int; |
120 | "test_transport_api2_tcp_node%s.conf", | 187 | unsigned int m_int; |
121 | "1"); | 188 | unsigned int local_m_int; |
189 | unsigned int num; | ||
190 | struct TestState *ts = GNUNET_new (struct TestState); | ||
191 | struct GNUNET_TESTING_NetjailTopology *topology = | ||
192 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); | ||
193 | |||
194 | if (0 == m_int) | ||
195 | num = n_int; | ||
196 | else | ||
197 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | ||
198 | |||
199 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); | ||
200 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
201 | "block-receive"); | ||
202 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | ||
203 | "start-peer", | ||
204 | "system-create", | ||
205 | num, | ||
206 | NULL); | ||
207 | |||
208 | |||
209 | |||
210 | sscanf (m, "%u", &m_int); | ||
211 | sscanf (n, "%u", &n_int); | ||
212 | sscanf (local_m, "%u", &local_m_int); | ||
213 | |||
214 | GNUNET_asprintf (&ts->cfgname, | ||
215 | "test_transport_api2_tcp_node1.conf"); | ||
122 | 216 | ||
123 | LOG (GNUNET_ERROR_TYPE_ERROR, | 217 | LOG (GNUNET_ERROR_TYPE_ERROR, |
124 | "plugin cfgname: %s\n", | 218 | "plugin cfgname: %s\n", |
125 | cfgname); | 219 | ts->cfgname); |
126 | 220 | ||
127 | LOG (GNUNET_ERROR_TYPE_ERROR, | 221 | LOG (GNUNET_ERROR_TYPE_ERROR, |
128 | "node ip: %s\n", | 222 | "node ip: %s\n", |
129 | node_ip); | 223 | node_ip); |
130 | 224 | ||
131 | LOG (GNUNET_ERROR_TYPE_ERROR, | 225 | GNUNET_asprintf (&ts->testdir, |
132 | "m: %s n: %s\n", | ||
133 | m, | ||
134 | n); | ||
135 | |||
136 | GNUNET_asprintf (&testdir, | ||
137 | "%s%s%s", | 226 | "%s%s%s", |
138 | BASE_DIR, | 227 | BASE_DIR, |
139 | m, | 228 | m, |
@@ -143,50 +232,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
143 | GNUNET_MQ_hd_var_size (test, | 232 | GNUNET_MQ_hd_var_size (test, |
144 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 233 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
145 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | 234 | struct GNUNET_TRANSPORT_TESTING_TestMessage, |
146 | NULL), | 235 | ts), |
147 | GNUNET_MQ_handler_end () | 236 | GNUNET_MQ_handler_end () |
148 | }; | 237 | }; |
149 | 238 | ||
150 | struct GNUNET_TESTING_Command commands[] = { | 239 | struct GNUNET_TESTING_Command commands[] = { |
151 | GNUNET_TESTING_cmd_system_create ("system-create", | 240 | GNUNET_TESTING_cmd_system_create ("system-create", |
152 | testdir), | 241 | ts->testdir), |
153 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", | 242 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", |
154 | "system-create", | 243 | "system-create", |
155 | m, | 244 | num, |
156 | n, | ||
157 | local_m, | ||
158 | node_ip, | 245 | node_ip, |
159 | handlers, | 246 | handlers, |
160 | cfgname), | 247 | ts->cfgname, |
248 | notify_connect), | ||
161 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | 249 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", |
162 | write_message), | 250 | write_message), |
163 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block", | 251 | block_send, |
164 | &are_all_peers_started), | 252 | connect_peers, |
165 | GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | ||
166 | "start-peer", | ||
167 | "system-create", | ||
168 | (atoi (n) - 1) * atoi (local_m) + atoi ( | ||
169 | m)), | ||
170 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", | 253 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", |
171 | m, | 254 | "start-peer", |
172 | n, | 255 | num), |
173 | (atoi (n) - 1) * atoi (local_m) + atoi ( | 256 | block_receive, |
174 | m), | ||
175 | "start-peer"), | ||
176 | GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", | ||
177 | &message_received), | ||
178 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 257 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
179 | "start-peer"), | 258 | "start-peer"), |
180 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 259 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
181 | "system-create"), | 260 | "system-create") |
182 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", | ||
183 | write_message), | ||
184 | GNUNET_TESTING_cmd_end_without_shutdown () | ||
185 | }; | 261 | }; |
186 | 262 | ||
187 | GNUNET_TESTING_run (NULL, | 263 | GNUNET_TESTING_run (commands, |
188 | commands, | 264 | GNUNET_TIME_UNIT_FOREVER_REL, |
189 | GNUNET_TIME_UNIT_FOREVER_REL); | 265 | &handle_result, |
266 | ts); | ||
190 | 267 | ||
191 | } | 268 | } |
192 | 269 | ||
@@ -225,8 +302,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls) | |||
225 | struct GNUNET_TESTING_PluginFunctions *api = cls; | 302 | struct GNUNET_TESTING_PluginFunctions *api = cls; |
226 | 303 | ||
227 | GNUNET_free (api); | 304 | GNUNET_free (api); |
228 | GNUNET_free (testdir); | ||
229 | GNUNET_free (cfgname); | ||
230 | return NULL; | 305 | return NULL; |
231 | } | 306 | } |
232 | 307 | ||