aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2022-12-07 12:42:31 +0100
committert3sserakt <t3ss@posteo.de>2022-12-07 12:42:31 +0100
commit34e1c58cb39a649c9a4c551681cedf19807b85f0 (patch)
tree79ea7222958c3ae086b2b2367f22cb66936ad045 /src/include
parent8804d3efd5bccce3a5d7638a5fcb33450ade2f07 (diff)
downloadgnunet-34e1c58cb39a649c9a4c551681cedf19807b85f0.tar.gz
gnunet-34e1c58cb39a649c9a4c551681cedf19807b85f0.zip
- added configuration to be able to start executables on a router node
- added barrier functionality
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_protocols.h8
-rw-r--r--src/include/gnunet_testing_barrier.h272
-rw-r--r--src/include/gnunet_testing_netjail_lib.h62
-rw-r--r--src/include/gnunet_testing_ng_lib.h68
-rw-r--r--src/include/gnunet_testing_plugin.h10
6 files changed, 395 insertions, 26 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index bda1a012b..0f091b615 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -117,6 +117,7 @@ gnunetinclude_HEADERS = \
117 gnunet_strings_lib.h \ 117 gnunet_strings_lib.h \
118 gnunet_testbed_service.h \ 118 gnunet_testbed_service.h \
119 gnunet_testbed_logger_service.h \ 119 gnunet_testbed_logger_service.h \
120 gnunet_testing_barrier.h \
120 gnunet_testing_lib.h \ 121 gnunet_testing_lib.h \
121 gnunet_testing_plugin.h \ 122 gnunet_testing_plugin.h \
122 gnunet_testing_ng_lib.h \ 123 gnunet_testing_ng_lib.h \
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 509c97fb2..8f857e86c 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -3601,6 +3601,14 @@ extern "C" {
3601 3601
3602#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706 3602#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706
3603 3603
3604#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED 1707
3605
3606#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACH 1708
3607
3608#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED 1709
3609
3610#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED 1710
3611
3604/*********************************************************************************/ 3612/*********************************************************************************/
3605 3613
3606/*********************************************************************************/ 3614/*********************************************************************************/
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h
new file mode 100644
index 000000000..4a3d87ec7
--- /dev/null
+++ b/src/include/gnunet_testing_barrier.h
@@ -0,0 +1,272 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2022 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 include/gnunet_testing_barrier.h
23 * @brief API to manage barriers.
24 * @author t3sserakt
25 */
26
27#ifndef GNUNET_TESTING_BARRIER_LIB_H
28#define GNUNET_TESTING_BARRIER_LIB_H
29
30#include "gnunet_testing_lib.h"
31#include "gnunet_testing_netjail_lib.h"
32
33struct GNUNET_TESTING_Barrier
34{
35 /**
36 * Pointer to the previous prefix in the DLL.
37 */
38 struct GNUNET_TESTING_Barrier *prev;
39
40 /**
41 * Pointer to the next prefix in the DLL.
42 */
43 struct GNUNET_TESTING_Barrier *next;
44
45 /**
46 * Head of the DLL with local commands the barrier is attached too.
47 */
48 struct GNUNET_TESTING_Command *cmds_head;
49
50 /**
51 * Tail of the DLL with local commands the barrier is attached too.
52 */
53 struct GNUNET_TESTING_Command *cmds_tail;
54
55 /**
56 * Hash map containing the global known nodes which are not natted.
57 */
58 struct GNUNET_CONTAINER_MultiShortmap *nodes;
59
60 /**
61 * Name of the barrier.
62 */
63 const char *name;
64
65 /**
66 * Is this barrier running on the master.
67 */
68 unsigned int running_on_master;
69
70 /**
71 * Number of commands attached to this barrier.
72 */
73 unsigned int expected_reaches;
74
75 /**
76 * Number of commands which reached this barrier.
77 */
78 unsigned int reached;
79
80 /**
81 * Percentage of of commands which need to reach the barrier to change state.
82 * Can not be used together with to_be_reached;
83 */
84 double percentage_to_be_reached;
85
86 /**
87 * Number of commands which need to reach the barrier to change state.
88 * Can not be used together with percentage_to_be_reached;
89 */
90 unsigned int number_to_be_reached;
91
92 /*
93 * No barrier locally. Shadow created. Real barrier created elsewhere.
94 */
95 unsigned int shadow;
96};
97
98/**
99 * Message send to a child loop to inform the child loop about a barrier being advanced.
100 */
101struct GNUNET_TESTING_CommandBarrierAdvanced
102{
103 /**
104 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED
105 */
106 struct GNUNET_MessageHeader header;
107
108 /**
109 * The name of the barrier.
110 */
111 const char *barrier_name;
112};
113
114/**
115 * Message send by a child loop to inform the master loop how much
116 * GNUNET_CMDS_BARRIER_REACHED messages the child will send.
117 */
118struct GNUNET_TESTING_CommandBarrierAttached
119{
120 /**
121 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED
122 */
123 struct GNUNET_MessageHeader header;
124
125 /**
126 * The name of the barrier.
127 */
128 const char *barrier_name;
129
130 /**
131 * How often the child loop will reach the barrier.
132 */
133 unsigned int expected_reaches;
134
135 /**
136 * The number of the node the barrier is running on.
137 */
138 unsigned int node_number;
139};
140
141
142struct GNUNET_TESTING_CommandBarrierReached
143{
144 /**
145 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
146 */
147 struct GNUNET_MessageHeader header;
148
149 /**
150 * The name of the barrier.
151 */
152 const char *barrier_name;
153
154 /**
155 * The number of the node the barrier is reached.
156 */
157 unsigned int node_number;
158
159 /**
160 * The number of reach messages which most likely will send.
161 */
162 unsigned int expected_number_of_reached_messages;
163};
164
165
166/**
167 * Adding a node to the map of nodes of a barrier.
168 *
169 * @param nodes Map of nodes.
170 * @param node The node to add.
171 */
172void
173GNUNET_TESTING_barrier_add_node (struct GNUNET_CONTAINER_MultiShortmap *nodes,
174 struct GNUNET_TESTING_NetjailNode *node);
175
176
177struct GNUNET_TESTING_Command
178GNUNET_TESTING_cmd_barrier_create (
179 const char *label,
180 double percentage_to_be_reached,
181 unsigned int number_to_be_reached);
182
183
184// Wait for barrier to be reached by all;
185// async version implies reached but does not
186// wait on other peers to reach it.
187/**
188 * Create command.
189 *
190 * @param label name for command.
191 * @param barrier_label The name of the barrier we wait for and which will be reached.
192 * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL.
193 * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL.
194 * @param node_number The global numer of the node the cmd runs on.
195 * @param running_on_master Is this cmd running on the master loop.
196 * @param write_message Callback to write messages to the master loop.
197 * @return command.
198 */
199struct GNUNET_TESTING_Command
200GNUNET_TESTING_cmd_barrier_reached (
201 const char *label,
202 const char *barrier_label,
203 unsigned int asynchronous_finish,
204 unsigned int node_number,
205 unsigned int running_on_master,
206 TESTING_CMD_HELPER_write_cb write_message);
207
208
209/**
210 * Can we advance the barrier?
211 *
212 * @param barrier The barrier in question.
213 * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not.
214 */
215unsigned int
216GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier);
217
218
219/**
220 * Send Message to netjail nodes that a barrier can be advanced.
221 *
222 * @param is The interpreter loop.
223 * @param barrier_name The name of the barrier to advance.
224 * @param global_node_number The global number of the node to inform.
225 */
226void
227GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is,
228 const char *barrier_name,
229 unsigned int global_node_number);
230
231
232/**
233 * Finish all "barrier reached" comands attached to this barrier.
234 *
235 * @param barrier The barrier in question.
236 */
237void
238GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
239 struct GNUNET_TESTING_Barrier *barrier);
240
241
242/**
243 * Send Message to master loop that cmds being attached to a barrier.
244 *
245 * @param is The interpreter loop.
246 * @param barrier_name The name of the barrier to advance.
247 * @param subnet_number The number of the subnet.
248 * @param node_number The node to inform.
249 * @param write_message Callback to write messages to the master loop.
250 */
251void
252GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is,
253 char *barrier_name,
254 unsigned int global_node_number,
255 unsigned int expected_reaches,
256 TESTING_CMD_HELPER_write_cb write_message);
257
258
259/**
260 * Getting a node from a map by global node number.
261 *
262 * @param nodes The map.
263 * @param node_number The global node number.
264 * @return The node.
265 */
266struct GNUNET_TESTING_NetjailNode *
267GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes,
268 unsigned int node_number);
269
270
271#endif
272/* end of testing_barrier.h */
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
index f736e1b42..4f52f5af0 100644
--- a/src/include/gnunet_testing_netjail_lib.h
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -145,6 +145,16 @@ struct GNUNET_TESTING_NodeConnection
145struct GNUNET_TESTING_NetjailNode 145struct GNUNET_TESTING_NetjailNode
146{ 146{
147 /** 147 /**
148 * Head of the DLL with the connections which shall be established to other nodes.
149 */
150 struct GNUNET_TESTING_NodeConnection *node_connections_head;
151
152 /**
153 * Tail of the DLL with the connections which shall be established to other nodes.
154 */
155 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
156
157 /**
148 * Plugin for the test case to be run on this node. 158 * Plugin for the test case to be run on this node.
149 */ 159 */
150 char *plugin; 160 char *plugin;
@@ -165,19 +175,19 @@ struct GNUNET_TESTING_NetjailNode
165 unsigned int node_n; 175 unsigned int node_n;
166 176
167 /** 177 /**
168 * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value. 178 * The overall number of the node in the whole test system.
169 */ 179 */
170 unsigned int additional_connects; 180 unsigned int node_number;
171 181
172 /** 182 /**
173 * Head of the DLL with the connections which shall be established to other nodes. 183 * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value.
174 */ 184 */
175 struct GNUNET_TESTING_NodeConnection *node_connections_head; 185 unsigned int additional_connects;
176 186
177 /** 187 /**
178 * Tail of the DLL with the connections which shall be established to other nodes. 188 * The number of cmds waiting for a specific barrier.
179 */ 189 */
180 struct GNUNET_TESTING_NodeConnection *node_connections_tail; 190 unsigned int expected_reaches;
181}; 191};
182 192
183 193
@@ -275,6 +285,17 @@ GNUNET_TESTING_get_additional_connects (unsigned int num,
275 struct GNUNET_TESTING_NetjailTopology * 285 struct GNUNET_TESTING_NetjailTopology *
276 topology); 286 topology);
277 287
288/**
289 * Get a node from the topology.
290 *
291 * @param num The specific node we want the connections for.
292 * @param topology The topology we get the connections from.
293 * @return The connections of the node.
294 */
295struct GNUNET_TESTING_NetjailNode *
296GNUNET_TESTING_get_node (unsigned int num,
297 struct GNUNET_TESTING_NetjailTopology *topology);
298
278 299
279/** 300/**
280 * Get the connections to other nodes for a specific node. 301 * Get the connections to other nodes for a specific node.
@@ -323,6 +344,16 @@ GNUNET_TESTING_calculate_num (struct
323struct TestState 344struct TestState
324{ 345{
325 /** 346 /**
347 * The head of the DLL with barriers of the test case.
348 */
349 struct GNUNET_TESTING_Barrier *barriers_head;
350
351 /**
352 * The tail of the DLL with barriers of the test case.
353 */
354 struct GNUNET_TESTING_Barrier *barriers_tail;
355
356 /**
326 * Callback to write messages to the master loop. 357 * Callback to write messages to the master loop.
327 * 358 *
328 */ 359 */
@@ -480,25 +511,6 @@ GNUNET_TESTING_send_local_test_finished_msg ();
480 511
481 512
482struct GNUNET_TESTING_Command 513struct GNUNET_TESTING_Command
483GNUNET_TESTING_cmd_barrier_create (
484 const char *label);
485
486
487struct GNUNET_TESTING_Command
488GNUNET_TESTING_cmd_barrier_setup_finished (
489 const char *label);
490
491
492// Wait for barrier to be reached by all;
493// async version implies reached but does not
494// wait on other peers to reach it.
495struct GNUNET_TESTING_Command
496GNUNET_TESTING_cmd_barrier_reached (
497 const char *label,
498 const char *barrier_label);
499
500
501struct GNUNET_TESTING_Command
502GNUNET_TESTING_cmd_block_until_all_peers_started ( 514GNUNET_TESTING_cmd_block_until_all_peers_started (
503 const char *label, 515 const char *label,
504 unsigned int *all_peers_started); 516 unsigned int *all_peers_started);
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index d810a5342..9a6c82d90 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -194,6 +194,16 @@ struct GNUNET_TESTING_Command
194 struct GNUNET_TIME_Relative default_timeout; 194 struct GNUNET_TIME_Relative default_timeout;
195 195
196 /** 196 /**
197 * Pointer to the previous command in the DLL.
198 */
199 struct GNUNET_TESTING_Command *prev;
200
201 /**
202 * Pointer to the next command in the DLL.
203 */
204 struct GNUNET_TESTING_Command *next;
205
206 /**
197 * How often did we try to execute this command? (In case it is a request 207 * How often did we try to execute this command? (In case it is a request
198 * that is repated.) Note that a command must have some built-in retry 208 * that is repated.) Note that a command must have some built-in retry
199 * mechanism for this value to be useful. 209 * mechanism for this value to be useful.
@@ -362,8 +372,9 @@ typedef void
362 * @param timeout how long to wait for each command to execute 372 * @param timeout how long to wait for each command to execute
363 * @param rc function to call with the final result 373 * @param rc function to call with the final result
364 * @param rc_cls closure for @a rc 374 * @param rc_cls closure for @a rc
375 * @return The interpreter.
365 */ 376 */
366void 377struct GNUNET_TESTING_Interpreter *
367GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, 378GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
368 struct GNUNET_TIME_Relative timeout, 379 struct GNUNET_TIME_Relative timeout,
369 GNUNET_TESTING_ResultCallback rc, 380 GNUNET_TESTING_ResultCallback rc,
@@ -396,11 +407,66 @@ int
396GNUNET_TESTING_has_in_name (const char *prog, 407GNUNET_TESTING_has_in_name (const char *prog,
397 const char *marker); 408 const char *marker);
398 409
410/**
411 * Deleting all barriers create in the context of this interpreter.
412 *
413 * @param is The interpreter.
414 */
415void
416GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is);
417
418
419/**
420 * Getting a barrier from the interpreter.
421 *
422 * @param is The interpreter.
423 * @param barrier_name The name of the barrier.
424 * @return The barrier.
425 */
426struct GNUNET_TESTING_Barrier *
427GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is,
428 const char *barrier_name);
429
430
431/**
432 * Add a barrier to the loop.
433 *
434 * @param is The interpreter.
435 * @param barrier The barrier to add.
436 */
437void
438GNUNET_TESTING_barrier_add (struct GNUNET_TESTING_Interpreter *is,
439 struct GNUNET_TESTING_Barrier *barrier);
440
399 441
400/* ************** Specific interpreter commands ************ */ 442/* ************** Specific interpreter commands ************ */
401 443
402 444
403/** 445/**
446 * Adding a helper handle to the interpreter.
447 *
448 * @param is The interpreter.
449 * @param helper The helper handle.
450 */
451void
452GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is,
453 const struct GNUNET_HELPER_Handle *helper);
454
455
456/**
457 * Send Message to netjail nodes that a barrier can be advanced.
458 *
459 * @param is The interpreter.
460 * @param global_node_number The node to inform.
461 * @param header The message to send.
462 */
463void
464GNUNET_TESTING_send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is,
465 unsigned int global_node_number,
466 struct GNUNET_MessageHeader *header);
467
468
469/**
404 * Returns the actual running command. 470 * Returns the actual running command.
405 * 471 *
406 * @param is Global state of the interpreter, used by a command 472 * @param is Global state of the interpreter, used by a command
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 9d0ef269d..28b505976 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -62,6 +62,12 @@ typedef void
62typedef void 62typedef void
63(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) (); 63(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) ();
64 64
65typedef void
66(*GNUNET_TESTING_PLUGIN_BARRIER_ADVANCED) (const char *barrier_name);
67
68typedef struct GNUNET_TESTING_Barrier *
69(*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) ();
70
65 71
66struct GNUNET_TESTING_PluginFunctions 72struct GNUNET_TESTING_PluginFunctions
67{ 73{
@@ -70,11 +76,15 @@ struct GNUNET_TESTING_PluginFunctions
70 */ 76 */
71 void *cls; 77 void *cls;
72 78
79 GNUNET_TESTING_PLUGIN_BARRIER_ADVANCED barrier_advanced;
80
73 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase; 81 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
74 82
75 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started; 83 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
76 84
77 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared; 85 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared;
86
87 GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS get_waiting_for_barriers;
78}; 88};
79 89
80#if 0 /* keep Emacsens' auto-indent happy */ 90#if 0 /* keep Emacsens' auto-indent happy */