diff options
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send_v2.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send_v2.c | 234 |
1 files changed, 0 insertions, 234 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c deleted file mode 100644 index c79b5c7e2..000000000 --- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c +++ /dev/null | |||
@@ -1,234 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/plugin_cmd_simple_send.c | ||
23 | * @brief a plugin to provide the API for running test cases. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_transport_application_service.h" | ||
30 | #include "transport-testing2.h" | ||
31 | #include "transport-testing-cmds.h" | ||
32 | |||
33 | /** | ||
34 | * Generic logging shortcut | ||
35 | */ | ||
36 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | #define BASE_DIR "testdir" | ||
39 | |||
40 | #define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" | ||
41 | |||
42 | /** | ||
43 | * The name for a specific test environment directory. | ||
44 | * | ||
45 | */ | ||
46 | char *testdir; | ||
47 | |||
48 | /** | ||
49 | * The name for the configuration file of the specific node. | ||
50 | * | ||
51 | */ | ||
52 | char *cfgname; | ||
53 | |||
54 | /** | ||
55 | * Flag indicating if all peers have been started. | ||
56 | * | ||
57 | */ | ||
58 | unsigned int are_all_peers_started; | ||
59 | |||
60 | /** | ||
61 | * Flag indicating a received message. | ||
62 | */ | ||
63 | unsigned int message_received; | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being | ||
68 | * received. | ||
69 | * | ||
70 | */ | ||
71 | static int | ||
72 | check_test (void *cls, | ||
73 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
74 | { | ||
75 | return GNUNET_OK; | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE | ||
81 | * being received. | ||
82 | * | ||
83 | */ | ||
84 | static void | ||
85 | handle_test (void *cls, | ||
86 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
87 | { | ||
88 | message_received = GNUNET_YES; | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Callback to set the flag indicating all peers started. Will be called via the plugin api. | ||
94 | * | ||
95 | */ | ||
96 | static void | ||
97 | all_peers_started () | ||
98 | { | ||
99 | are_all_peers_started = GNUNET_YES; | ||
100 | } | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Function to start a local test case. | ||
105 | * | ||
106 | * @param write_message Callback to send a message to the master loop. | ||
107 | * @param router_ip Global address of the network namespace. | ||
108 | * @param node_ip Local address of a node i a network namespace. | ||
109 | * @param m The number of the node in a network namespace. | ||
110 | * @param n The number of the network namespace. | ||
111 | * @param local_m The number of nodes in a network namespace. | ||
112 | */ | ||
113 | static void | ||
114 | start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | ||
115 | char *node_ip, | ||
116 | char *m, | ||
117 | char *n, | ||
118 | char *local_m) | ||
119 | { | ||
120 | |||
121 | unsigned int n_int, m_int, local_m_int, num; | ||
122 | |||
123 | struct GNUNET_TESTING_NetjailTopology *topology = | ||
124 | GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); | ||
125 | |||
126 | sscanf (m, "%u", &m_int); | ||
127 | sscanf (n, "%u", &n_int); | ||
128 | sscanf (local_m, "%u", &local_m_int); | ||
129 | |||
130 | |||
131 | if (0 == m_int) | ||
132 | num = n_int; | ||
133 | else | ||
134 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | ||
135 | |||
136 | GNUNET_asprintf (&cfgname, | ||
137 | "test_transport_api2_tcp_node1.conf"); | ||
138 | |||
139 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
140 | "plugin cfgname: %s\n", | ||
141 | cfgname); | ||
142 | |||
143 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
144 | "node ip: %s\n", | ||
145 | node_ip); | ||
146 | |||
147 | GNUNET_asprintf (&testdir, | ||
148 | "%s%s%s", | ||
149 | BASE_DIR, | ||
150 | m, | ||
151 | n); | ||
152 | |||
153 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
154 | GNUNET_MQ_hd_var_size (test, | ||
155 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | ||
156 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | ||
157 | NULL), | ||
158 | GNUNET_MQ_handler_end () | ||
159 | }; | ||
160 | |||
161 | struct GNUNET_TESTING_Command commands[] = { | ||
162 | GNUNET_TESTING_cmd_system_create ("system-create", | ||
163 | testdir), | ||
164 | GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer", | ||
165 | "system-create", | ||
166 | num, | ||
167 | node_ip, | ||
168 | handlers, | ||
169 | cfgname), | ||
170 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | ||
171 | write_message), | ||
172 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block", | ||
173 | &are_all_peers_started), | ||
174 | GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers", | ||
175 | "start-peer", | ||
176 | "system-create", | ||
177 | num), | ||
178 | GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", | ||
179 | "start-peer", | ||
180 | num), | ||
181 | GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", | ||
182 | &message_received), | ||
183 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | ||
184 | "start-peer"), | ||
185 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | ||
186 | "system-create"), | ||
187 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", | ||
188 | write_message) | ||
189 | }; | ||
190 | |||
191 | GNUNET_TESTING_run (NULL, | ||
192 | commands, | ||
193 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
194 | |||
195 | } | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Entry point for the plugin. | ||
200 | * | ||
201 | * @param cls NULL | ||
202 | * @return the exported block API | ||
203 | */ | ||
204 | void * | ||
205 | libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls) | ||
206 | { | ||
207 | struct GNUNET_TESTING_PluginFunctions *api; | ||
208 | |||
209 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
210 | api->start_testcase = &start_testcase; | ||
211 | api->all_peers_started = &all_peers_started; | ||
212 | return api; | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Exit point from the plugin. | ||
218 | * | ||
219 | * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init | ||
220 | * @return NULL | ||
221 | */ | ||
222 | void * | ||
223 | libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls) | ||
224 | { | ||
225 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
226 | |||
227 | GNUNET_free (api); | ||
228 | GNUNET_free (testdir); | ||
229 | GNUNET_free (cfgname); | ||
230 | return NULL; | ||
231 | } | ||
232 | |||
233 | |||
234 | /* end of plugin_cmd_simple_send.c */ | ||