diff options
Diffstat (limited to 'src/lib/testing/testing.h')
-rw-r--r-- | src/lib/testing/testing.h | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/src/lib/testing/testing.h b/src/lib/testing/testing.h new file mode 100644 index 000000000..fbd7d0d34 --- /dev/null +++ b/src/lib/testing/testing.h | |||
@@ -0,0 +1,352 @@ | |||
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 | * @author t3sserakt | ||
23 | */ | ||
24 | #ifndef TESTING_H | ||
25 | #define TESTING_H | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_testing_plugin.h" | ||
28 | |||
29 | GNUNET_NETWORK_STRUCT_BEGIN | ||
30 | |||
31 | /** | ||
32 | * Message send to a child loop to inform the child loop about a barrier being advanced. | ||
33 | */ | ||
34 | struct CommandBarrierCrossable | ||
35 | { | ||
36 | /** | ||
37 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE | ||
38 | */ | ||
39 | struct GNUNET_MessageHeader header; | ||
40 | |||
41 | /* followed by 0-terminated barrier name */ | ||
42 | }; | ||
43 | |||
44 | /** | ||
45 | * Message send by a child loop to inform the master loop how much | ||
46 | * GNUNET_CMDS_BARRIER_REACHED messages the child will send. | ||
47 | */ | ||
48 | struct CommandBarrierAttached | ||
49 | { | ||
50 | /** | ||
51 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED | ||
52 | */ | ||
53 | struct GNUNET_MessageHeader header; | ||
54 | |||
55 | /** | ||
56 | * How often the child loop will reach the barrier. | ||
57 | */ | ||
58 | uint32_t expected_reaches GNUNET_PACKED; | ||
59 | |||
60 | /** | ||
61 | * The number of the node the barrier is running on. | ||
62 | */ | ||
63 | uint32_t node_number GNUNET_PACKED; | ||
64 | |||
65 | /* followed by 0-terminated barrier name */ | ||
66 | }; | ||
67 | |||
68 | struct GNUNET_TESTING_CommandBarrierReached | ||
69 | { | ||
70 | /** | ||
71 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED | ||
72 | */ | ||
73 | struct GNUNET_MessageHeader header; | ||
74 | |||
75 | /** | ||
76 | * The number of the node the barrier is reached. | ||
77 | */ | ||
78 | uint32_t node_number GNUNET_PACKED; | ||
79 | |||
80 | /** | ||
81 | * The number of reach messages which most likely will send. | ||
82 | */ | ||
83 | uint32_t expected_number_of_reached_messages GNUNET_PACKED; | ||
84 | |||
85 | /* followed by 0-terminated barrier name */ | ||
86 | }; | ||
87 | |||
88 | GNUNET_NETWORK_STRUCT_END | ||
89 | |||
90 | /** | ||
91 | * Handle for a plugin. | ||
92 | */ | ||
93 | struct TestcasePlugin | ||
94 | { | ||
95 | /** | ||
96 | * Name of the shared library. | ||
97 | */ | ||
98 | char *library_name; | ||
99 | |||
100 | /** | ||
101 | * Plugin API. | ||
102 | */ | ||
103 | struct GNUNET_TESTING_PluginFunctions *api; | ||
104 | |||
105 | /** | ||
106 | * IP address of the specific node the helper is running for. | ||
107 | * | ||
108 | */ | ||
109 | char *node_ip; | ||
110 | |||
111 | /** | ||
112 | * Name of the test case plugin. | ||
113 | * | ||
114 | */ | ||
115 | char *plugin_name; | ||
116 | |||
117 | /** | ||
118 | * The number of namespaces | ||
119 | * | ||
120 | */ | ||
121 | char *global_n; | ||
122 | |||
123 | /** | ||
124 | * The number of local nodes per namespace. | ||
125 | * | ||
126 | */ | ||
127 | char *local_m; | ||
128 | |||
129 | /** | ||
130 | * The number of the namespace this node is in. | ||
131 | * | ||
132 | */ | ||
133 | char *n; | ||
134 | |||
135 | /** | ||
136 | * The number of the node in the namespace. | ||
137 | * | ||
138 | */ | ||
139 | char *m; | ||
140 | }; | ||
141 | |||
142 | struct CommandListEntry | ||
143 | { | ||
144 | struct CommandListEntry *next; | ||
145 | |||
146 | struct CommandListEntry *prev; | ||
147 | |||
148 | struct GNUNET_TESTING_Command *command; | ||
149 | }; | ||
150 | |||
151 | |||
152 | struct GNUNET_TESTING_Barrier | ||
153 | { | ||
154 | /** | ||
155 | * Pointer to the previous prefix in the DLL. | ||
156 | */ | ||
157 | struct GNUNET_TESTING_Barrier *prev; | ||
158 | |||
159 | /** | ||
160 | * Pointer to the next prefix in the DLL. | ||
161 | */ | ||
162 | struct GNUNET_TESTING_Barrier *next; | ||
163 | |||
164 | /** | ||
165 | * Head of the DLL with local commands the barrier is attached too. | ||
166 | */ | ||
167 | struct CommandListEntry *cmds_head; | ||
168 | |||
169 | /** | ||
170 | * Tail of the DLL with local commands the barrier is attached too. | ||
171 | */ | ||
172 | struct CommandListEntry *cmds_tail; | ||
173 | |||
174 | /** | ||
175 | * Hash map containing the global known nodes which are not natted. | ||
176 | */ | ||
177 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
178 | |||
179 | /** | ||
180 | * Name of the barrier. | ||
181 | */ | ||
182 | const char *name; | ||
183 | |||
184 | /** | ||
185 | * Is this barrier running on the master. | ||
186 | */ | ||
187 | unsigned int running_on_master; | ||
188 | |||
189 | /** | ||
190 | * Number of commands attached to this barrier. | ||
191 | */ | ||
192 | unsigned int expected_reaches; | ||
193 | |||
194 | /** | ||
195 | * Number of commands which reached this barrier. | ||
196 | */ | ||
197 | unsigned int reached; | ||
198 | |||
199 | /** | ||
200 | * Percentage of of commands which need to reach the barrier to change state. | ||
201 | * Can not be used together with to_be_reached; | ||
202 | */ | ||
203 | double percentage_to_be_reached; | ||
204 | |||
205 | /** | ||
206 | * Number of commands which need to reach the barrier to change state. | ||
207 | * Can not be used together with percentage_to_be_reached; | ||
208 | */ | ||
209 | unsigned int number_to_be_reached; | ||
210 | |||
211 | /* | ||
212 | * No barrier locally. Shadow created. Real barrier created elsewhere. | ||
213 | */ | ||
214 | unsigned int shadow; | ||
215 | }; | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Advance internal pointer to next command. | ||
220 | * | ||
221 | * @param cls batch internal state | ||
222 | * @return true if we could advance, false if the batch | ||
223 | * has completed and cannot advance anymore | ||
224 | */ | ||
225 | bool | ||
226 | GNUNET_TESTING_cmd_batch_next_ (void *cls); | ||
227 | |||
228 | |||
229 | /** | ||
230 | * Test if this command is a batch command. | ||
231 | * | ||
232 | * @return false if not, true if it is a batch command | ||
233 | */ | ||
234 | bool | ||
235 | GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd); | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Obtain what command the batch is at. | ||
240 | * | ||
241 | * @return cmd current batch command | ||
242 | */ | ||
243 | struct GNUNET_TESTING_Command * | ||
244 | GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd); | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Set what command the batch should be at. Needed for | ||
249 | * loops. We may want to change this to take a label | ||
250 | * and/or expose it in the public API in the future. | ||
251 | * Not used for now. | ||
252 | * | ||
253 | * @param cmd current batch command | ||
254 | * @param new_ip where to move the IP | ||
255 | */ | ||
256 | void | ||
257 | GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, | ||
258 | unsigned int new_ip); | ||
259 | |||
260 | |||
261 | /** | ||
262 | * This function checks, if a barrier can be crossed, which actually means that | ||
263 | * the cmd representing the barrier is finished. | ||
264 | * | ||
265 | * @param barrier The barrier in question. | ||
266 | * @return GNUNET_YES if we can cross the barrier, GNUNET_NO if not. | ||
267 | */ | ||
268 | unsigned int | ||
269 | GNUNET_TESTING_barrier_crossable (struct GNUNET_TESTING_Barrier *barrier); | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Send Message to a netjail node that a barrier can be crossed. | ||
274 | * | ||
275 | * @param is The interpreter loop. | ||
276 | * @param barrier_name The name of the barrier to cross. | ||
277 | * @param global_node_number The global number of the node to inform. | ||
278 | */ | ||
279 | void | ||
280 | TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, | ||
281 | const char *barrier_name, | ||
282 | unsigned int global_node_number); | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Finish all "barrier reached" comands attached to this barrier. | ||
287 | * | ||
288 | * @param barrier The barrier in question. | ||
289 | */ | ||
290 | void | ||
291 | TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, | ||
292 | const char *barrier_name); | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Send Message to master loop that cmds being attached to a barrier. | ||
297 | * FIXME: Unused function | ||
298 | * | ||
299 | * @param is The interpreter loop. | ||
300 | * @param barrier_name The name of the barrier to attach to. | ||
301 | * @param subnet_number The number of the subnet. | ||
302 | * @param node_number The node to inform. | ||
303 | * @param write_message Callback to write messages to the master loop. | ||
304 | */ | ||
305 | void | ||
306 | GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, | ||
307 | char *barrier_name, | ||
308 | unsigned int global_node_number, | ||
309 | unsigned int expected_reaches, | ||
310 | GNUNET_TESTING_cmd_helper_write_cb write_message); | ||
311 | |||
312 | |||
313 | /** | ||
314 | * Getting a node from a map by global node number. | ||
315 | * FIXME: This is a barrier helper function not related to a command but it is | ||
316 | * implemented in the *_cmd_barrier.c file. | ||
317 | * Maybe move into a separate file like testing_barrier.c; see also can | ||
318 | * barrier advance above | ||
319 | * | ||
320 | * @param nodes The map. | ||
321 | * @param node_number The global node number. | ||
322 | * @return The node. | ||
323 | */ | ||
324 | struct GNUNET_TESTING_NetjailNode * | ||
325 | GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier, | ||
326 | unsigned int node_number); | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Getting a barrier from the interpreter. | ||
331 | * | ||
332 | * @param is The interpreter. | ||
333 | * @param barrier_name The name of the barrier. | ||
334 | * @return The barrier. | ||
335 | */ | ||
336 | struct GNUNET_TESTING_Barrier * | ||
337 | TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, | ||
338 | const char *barrier_name); | ||
339 | |||
340 | |||
341 | /** | ||
342 | * Add a barrier to the loop. | ||
343 | * | ||
344 | * @param is The interpreter. | ||
345 | * @param barrier The barrier to add. | ||
346 | */ | ||
347 | void | ||
348 | TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, | ||
349 | struct GNUNET_TESTING_Barrier *barrier); | ||
350 | |||
351 | |||
352 | #endif | ||