aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
committert3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
commitd64ac269856744b9bab170964e1d6f36896ecc55 (patch)
treeed5aa79b91fe3cf9388433a5611581b7ce3b846c /src/transport/test_transport_plugin_cmd_simple_send.c
parent003910fc614cd347919707d1bf3c37a939978459 (diff)
downloadgnunet-d64ac269856744b9bab170964e1d6f36896ecc55.tar.gz
gnunet-d64ac269856744b9bab170964e1d6f36896ecc55.zip
removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c192
1 files changed, 134 insertions, 58 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 21167415d..5384bf24d 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,28 +37,34 @@
37 37
38#define BASE_DIR "testdir" 38#define BASE_DIR "testdir"
39 39
40/** 40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45 41
46/** 42struct TestState
47 * The name for the configuration file of the specific node. 43{
48 * 44 /**
49 */ 45 * Callback to write messages to the master loop.
50char *cfgname; 46 *
47 */
48 TESTING_CMD_HELPER_write_cb write_message;
51 49
52/** 50 /**
53 * Flag indicating if all peers have been started. 51 * The name for a specific test environment directory.
54 * 52 *
55 */ 53 */
56unsigned int are_all_peers_started; 54 char *testdir;
57 55
58/** 56 /**
59 * Flag indicating a received message. 57 * The name for the configuration file of the specific node.
60 */ 58 *
61unsigned int message_received; 59 */
60 char *cfgname;
61};
62
63static struct GNUNET_TESTING_Command block_send;
64
65static struct GNUNET_TESTING_Command block_receive;
66
67static struct GNUNET_TESTING_Command connect_peers;
62 68
63 69
64/** 70/**
@@ -83,7 +89,14 @@ static void
83handle_test (void *cls, 89handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 90 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{ 91{
86 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);
87} 100}
88 101
89 102
@@ -94,7 +107,62 @@ handle_test (void *cls,
94static void 107static void
95all_peers_started () 108all_peers_started ()
96{ 109{
97 are_all_peers_started = GNUNET_YES; 110 struct GNUNET_TESTING_AsyncContext *ac;
111
112 GNUNET_TESTING_get_trait_async_context (&block_send,
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 */
127static void
128handle_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 */
151static void *
152notify_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;
98} 166}
99 167
100 168
@@ -116,24 +184,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
116 char *local_m) 184 char *local_m)
117{ 185{
118 186
119 GNUNET_asprintf (&cfgname, 187 unsigned int n_int;
120 "test_transport_api2_tcp_node%s.conf", 188 unsigned int m_int;
121 "1"); 189 unsigned int local_m_int;
190 unsigned int num;
191 struct TestState *ts = GNUNET_new (struct TestState);
192 struct GNUNET_TESTING_NetjailTopology *topology =
193 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
194
195 if (0 == m_int)
196 num = n_int;
197 else
198 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
199
200 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
201 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
202 "block-receive");
203 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
204 "start-peer",
205 "system-create",
206 num,
207 NULL);
208
209
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,
216 "test_transport_api2_tcp_node1.conf");
122 217
123 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "plugin cfgname: %s\n", 219 "plugin cfgname: %s\n",
125 cfgname); 220 ts->cfgname);
126 221
127 LOG (GNUNET_ERROR_TYPE_ERROR, 222 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "node ip: %s\n", 223 "node ip: %s\n",
129 node_ip); 224 node_ip);
130 225
131 LOG (GNUNET_ERROR_TYPE_ERROR, 226 GNUNET_asprintf (&ts->testdir,
132 "m: %s n: %s\n",
133 m,
134 n);
135
136 GNUNET_asprintf (&testdir,
137 "%s%s%s", 227 "%s%s%s",
138 BASE_DIR, 228 BASE_DIR,
139 m, 229 m,
@@ -143,50 +233,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
143 GNUNET_MQ_hd_var_size (test, 233 GNUNET_MQ_hd_var_size (test,
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 234 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
145 struct GNUNET_TRANSPORT_TESTING_TestMessage, 235 struct GNUNET_TRANSPORT_TESTING_TestMessage,
146 NULL), 236 ts),
147 GNUNET_MQ_handler_end () 237 GNUNET_MQ_handler_end ()
148 }; 238 };
149 239
150 struct GNUNET_TESTING_Command commands[] = { 240 struct GNUNET_TESTING_Command commands[] = {
151 GNUNET_TESTING_cmd_system_create ("system-create", 241 GNUNET_TESTING_cmd_system_create ("system-create",
152 testdir), 242 ts->testdir),
153 GNUNET_TRANSPORT_cmd_start_peer ("start-peer", 243 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
154 "system-create", 244 "system-create",
155 m, 245 num,
156 n,
157 local_m,
158 node_ip, 246 node_ip,
159 handlers, 247 handlers,
160 cfgname), 248 ts->cfgname,
249 notify_connect),
161 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 250 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
162 write_message), 251 write_message),
163 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 252 block_send,
164 &are_all_peers_started), 253 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", 254 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
171 m, 255 "start-peer",
172 n, 256 num),
173 (atoi (n) - 1) * atoi (local_m) + atoi ( 257 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", 258 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
179 "start-peer"), 259 "start-peer"),
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 260 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"), 261 "system-create")
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message)
184 }; 262 };
185 263
186 GNUNET_TESTING_run (commands, 264 GNUNET_TESTING_run (commands,
187 GNUNET_TIME_UNIT_FOREVER_REL, 265 GNUNET_TIME_UNIT_FOREVER_REL,
188 NULL, /* FIXME: will crash */ 266 &handle_result,
189 NULL); 267 ts);
190 268
191} 269}
192 270
@@ -221,8 +299,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
221 struct GNUNET_TESTING_PluginFunctions *api = cls; 299 struct GNUNET_TESTING_PluginFunctions *api = cls;
222 300
223 GNUNET_free (api); 301 GNUNET_free (api);
224 GNUNET_free (testdir);
225 GNUNET_free (cfgname);
226 return NULL; 302 return NULL;
227} 303}
228 304