diff options
author | t3sserakt <t3ss@posteo.de> | 2021-10-28 16:13:47 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-10-28 16:13:47 +0200 |
commit | 6fb788ca2ec44837ea10a36be7fd0030fb08955b (patch) | |
tree | cba4a385aa8ab914d02db9a702f6c6230aa89a2a /src/transport/test_transport_plugin_cmd_simple_send.c | |
parent | 1609d627e509043a946f611d7589105cfae2364d (diff) | |
download | gnunet-6fb788ca2ec44837ea10a36be7fd0030fb08955b.tar.gz gnunet-6fb788ca2ec44837ea10a36be7fd0030fb08955b.zip |
- fixed coverity issues
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send.c | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index f0b47084b..c374fc2d0 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c | |||
@@ -58,6 +58,11 @@ struct TestState | |||
58 | * | 58 | * |
59 | */ | 59 | */ |
60 | char *cfgname; | 60 | char *cfgname; |
61 | |||
62 | /** | ||
63 | * The complete topology information. | ||
64 | */ | ||
65 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
61 | }; | 66 | }; |
62 | 67 | ||
63 | static struct GNUNET_TESTING_Command block_send; | 68 | static struct GNUNET_TESTING_Command block_send; |
@@ -66,6 +71,8 @@ static struct GNUNET_TESTING_Command block_receive; | |||
66 | 71 | ||
67 | static struct GNUNET_TESTING_Command connect_peers; | 72 | static struct GNUNET_TESTING_Command connect_peers; |
68 | 73 | ||
74 | static struct GNUNET_TESTING_Command local_prepared; | ||
75 | |||
69 | 76 | ||
70 | /** | 77 | /** |
71 | * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being | 78 | * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being |
@@ -93,7 +100,8 @@ handle_test (void *cls, | |||
93 | 100 | ||
94 | GNUNET_TESTING_get_trait_async_context (&block_receive, | 101 | GNUNET_TESTING_get_trait_async_context (&block_receive, |
95 | &ac); | 102 | &ac); |
96 | if ((NULL == ac) || (NULL == ac->cont)) | 103 | GNUNET_assert (NULL != ac); |
104 | if (NULL == ac->cont) | ||
97 | GNUNET_TESTING_async_fail (ac); | 105 | GNUNET_TESTING_async_fail (ac); |
98 | else | 106 | else |
99 | GNUNET_TESTING_async_finish (ac); | 107 | GNUNET_TESTING_async_finish (ac); |
@@ -111,7 +119,8 @@ all_peers_started () | |||
111 | 119 | ||
112 | GNUNET_TESTING_get_trait_async_context (&block_send, | 120 | GNUNET_TESTING_get_trait_async_context (&block_send, |
113 | &ac); | 121 | &ac); |
114 | if ((NULL == ac) || (NULL == ac->cont)) | 122 | GNUNET_assert (NULL != ac); |
123 | if (NULL == ac->cont) | ||
115 | GNUNET_TESTING_async_fail (ac); | 124 | GNUNET_TESTING_async_fail (ac); |
116 | else | 125 | else |
117 | GNUNET_TESTING_async_finish (ac); | 126 | GNUNET_TESTING_async_finish (ac); |
@@ -136,10 +145,15 @@ handle_result (void *cls, | |||
136 | rv); | 145 | rv); |
137 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); | 146 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); |
138 | 147 | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
149 | "message prepared\n"); | ||
139 | ts->write_message (reply, | 150 | ts->write_message (reply, |
140 | ntohs (reply->size)); | 151 | ntohs (reply->size)); |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
153 | "message send\n"); | ||
141 | GNUNET_free (ts->testdir); | 154 | GNUNET_free (ts->testdir); |
142 | GNUNET_free (ts->cfgname); | 155 | GNUNET_free (ts->cfgname); |
156 | GNUNET_TESTING_free_topology (ts->topology); | ||
143 | GNUNET_free (ts); | 157 | GNUNET_free (ts); |
144 | } | 158 | } |
145 | 159 | ||
@@ -167,6 +181,24 @@ notify_connect (void *cls, | |||
167 | 181 | ||
168 | 182 | ||
169 | /** | 183 | /** |
184 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. | ||
185 | */ | ||
186 | static void | ||
187 | all_local_tests_prepared () | ||
188 | { | ||
189 | struct LocalPreparedState *lfs; | ||
190 | |||
191 | GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, | ||
192 | &lfs); | ||
193 | GNUNET_assert (NULL != &lfs->ac); | ||
194 | if (NULL == lfs->ac.cont) | ||
195 | GNUNET_TESTING_async_fail (&lfs->ac); | ||
196 | else | ||
197 | GNUNET_TESTING_async_finish (&lfs->ac); | ||
198 | } | ||
199 | |||
200 | |||
201 | /** | ||
170 | * Function to start a local test case. | 202 | * Function to start a local test case. |
171 | * | 203 | * |
172 | * @param write_message Callback to send a message to the master loop. | 204 | * @param write_message Callback to send a message to the master loop. |
@@ -192,8 +224,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
192 | struct GNUNET_TESTING_NetjailTopology *topology = | 224 | struct GNUNET_TESTING_NetjailTopology *topology = |
193 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); | 225 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); |
194 | 226 | ||
195 | if (0 == m_int) | 227 | ts->topology = topology; |
196 | num = n_int; | 228 | |
229 | sscanf (m, "%u", &m_int); | ||
230 | sscanf (n, "%u", &n_int); | ||
231 | sscanf (local_m, "%u", &local_m_int); | ||
232 | |||
233 | if (0 == n_int) | ||
234 | num = m_int; | ||
197 | else | 235 | else |
198 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | 236 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; |
199 | 237 | ||
@@ -205,13 +243,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
205 | "system-create", | 243 | "system-create", |
206 | num, | 244 | num, |
207 | topology); | 245 | topology); |
246 | local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( | ||
247 | "local-test-prepared", | ||
248 | write_message); | ||
208 | 249 | ||
209 | 250 | ||
210 | |||
211 | sscanf (m, "%u", &m_int); | ||
212 | sscanf (n, "%u", &n_int); | ||
213 | sscanf (local_m, "%u", &local_m_int); | ||
214 | |||
215 | GNUNET_asprintf (&ts->cfgname, | 251 | GNUNET_asprintf (&ts->cfgname, |
216 | "test_transport_api2_tcp_node1.conf"); | 252 | "test_transport_api2_tcp_node1.conf"); |
217 | 253 | ||
@@ -253,8 +289,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
253 | connect_peers, | 289 | connect_peers, |
254 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", | 290 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", |
255 | "start-peer", | 291 | "start-peer", |
256 | num), | 292 | "system-create", |
293 | num, | ||
294 | topology), | ||
257 | block_receive, | 295 | block_receive, |
296 | local_prepared, | ||
258 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | 297 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", |
259 | "start-peer"), | 298 | "start-peer"), |
260 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | 299 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", |
@@ -262,6 +301,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
262 | GNUNET_TESTING_cmd_end () | 301 | GNUNET_TESTING_cmd_end () |
263 | }; | 302 | }; |
264 | 303 | ||
304 | ts->write_message = write_message; | ||
305 | |||
265 | GNUNET_TESTING_run (commands, | 306 | GNUNET_TESTING_run (commands, |
266 | GNUNET_TIME_UNIT_FOREVER_REL, | 307 | GNUNET_TIME_UNIT_FOREVER_REL, |
267 | &handle_result, | 308 | &handle_result, |
@@ -288,6 +329,7 @@ libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls) | |||
288 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | 329 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); |
289 | api->start_testcase = &start_testcase; | 330 | api->start_testcase = &start_testcase; |
290 | api->all_peers_started = &all_peers_started; | 331 | api->all_peers_started = &all_peers_started; |
332 | api->all_local_tests_prepared = all_local_tests_prepared; | ||
291 | return api; | 333 | return api; |
292 | } | 334 | } |
293 | 335 | ||