diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/Makefile.am | 2 | ||||
-rw-r--r-- | src/include/gnunet_core_testing_lib.h | 158 | ||||
-rw-r--r-- | src/include/gnunet_testing_barrier.h | 15 | ||||
-rw-r--r-- | src/include/gnunet_testing_loop_lib.h | 679 | ||||
-rw-r--r-- | src/include/gnunet_testing_netjail_lib.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 951 | ||||
-rw-r--r-- | src/include/gnunet_testing_plugin.h | 28 | ||||
-rw-r--r-- | src/include/gnunet_transport_testing_ng_lib.h | 170 |
8 files changed, 1031 insertions, 974 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index cf8c49cf1..5e4582ec2 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -33,6 +33,7 @@ gnunetinclude_HEADERS = \ | |||
33 | gnunet_container_lib.h \ | 33 | gnunet_container_lib.h \ |
34 | gnunet_conversation_service.h \ | 34 | gnunet_conversation_service.h \ |
35 | gnunet_core_service.h \ | 35 | gnunet_core_service.h \ |
36 | gnunet_core_testing_lib.h \ | ||
36 | gnunet_crypto_lib.h \ | 37 | gnunet_crypto_lib.h \ |
37 | gnunet_curl_lib.h \ | 38 | gnunet_curl_lib.h \ |
38 | gnunet_datacache_lib.h \ | 39 | gnunet_datacache_lib.h \ |
@@ -114,6 +115,7 @@ gnunetinclude_HEADERS = \ | |||
114 | gnunet_testing_lib.h \ | 115 | gnunet_testing_lib.h \ |
115 | gnunet_testing_plugin.h \ | 116 | gnunet_testing_plugin.h \ |
116 | gnunet_testing_ng_lib.h \ | 117 | gnunet_testing_ng_lib.h \ |
118 | gnunet_testing_loop_lib.h \ | ||
117 | gnunet_testing_netjail_lib.h \ | 119 | gnunet_testing_netjail_lib.h \ |
118 | gnunet_time_lib.h \ | 120 | gnunet_time_lib.h \ |
119 | gnunet_transport_application_service.h \ | 121 | gnunet_transport_application_service.h \ |
diff --git a/src/include/gnunet_core_testing_lib.h b/src/include/gnunet_core_testing_lib.h new file mode 100644 index 000000000..afb71b2cf --- /dev/null +++ b/src/include/gnunet_core_testing_lib.h | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021-2023 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 | * @brief API for cmds working with core sub system provided by libgnunetcoretesting | ||
23 | * @author t3sserakt | ||
24 | */ | ||
25 | #ifndef GNUNET_CORE_TESTING_LIB_H | ||
26 | #define GNUNET_CORE_TESTING_LIB_H | ||
27 | |||
28 | |||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_ng_lib.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Struct to store information needed in callbacks. | ||
35 | */ | ||
36 | // FIXME: breaks naming conventions | ||
37 | struct GNUNET_TESTING_ConnectPeersState | ||
38 | { | ||
39 | /** | ||
40 | * Receive callback | ||
41 | */ | ||
42 | struct GNUNET_MQ_MessageHandler *handlers; | ||
43 | |||
44 | /** | ||
45 | * A map with struct GNUNET_MQ_Handle values for each peer this peer | ||
46 | * is connected to. | ||
47 | */ | ||
48 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
49 | |||
50 | /** | ||
51 | * Handle for transport. | ||
52 | */ | ||
53 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
54 | |||
55 | /** | ||
56 | * Core handle. | ||
57 | */ | ||
58 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
59 | |||
60 | /** | ||
61 | * Context for our asynchronous completion. | ||
62 | */ | ||
63 | struct GNUNET_TESTING_AsyncContext ac; | ||
64 | |||
65 | /** | ||
66 | * The testing system of this node. | ||
67 | */ | ||
68 | const struct GNUNET_TESTING_System *tl_system; | ||
69 | |||
70 | // Label of the cmd which started the test system. | ||
71 | const char *create_label; | ||
72 | |||
73 | /** | ||
74 | * Number globally identifying the node. | ||
75 | * | ||
76 | */ | ||
77 | uint32_t num; | ||
78 | |||
79 | /** | ||
80 | * Label of the cmd to start a peer. | ||
81 | * | ||
82 | */ | ||
83 | const char *start_peer_label; | ||
84 | |||
85 | /** | ||
86 | * The topology of the test setup. | ||
87 | */ | ||
88 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
89 | |||
90 | /** | ||
91 | * Connections to other peers. | ||
92 | */ | ||
93 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
94 | |||
95 | struct GNUNET_TESTING_Interpreter *is; | ||
96 | |||
97 | /** | ||
98 | * Number of connections. | ||
99 | */ | ||
100 | unsigned int con_num; | ||
101 | |||
102 | /** | ||
103 | * Number of additional connects this cmd will wait for not triggered by this cmd. | ||
104 | */ | ||
105 | unsigned int additional_connects; | ||
106 | |||
107 | /** | ||
108 | * Number of connections we already have a notification for. | ||
109 | */ | ||
110 | unsigned int con_num_notified; | ||
111 | |||
112 | /** | ||
113 | * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for. | ||
114 | */ | ||
115 | unsigned int additional_connects_notified; | ||
116 | |||
117 | /** | ||
118 | * Flag indicating, whether the command is waiting for peers to connect that are configured to connect. | ||
119 | */ | ||
120 | unsigned int wait_for_connect; | ||
121 | }; | ||
122 | |||
123 | |||
124 | /** | ||
125 | * FIXME: document properly! | ||
126 | * Create command | ||
127 | * | ||
128 | * @param label name for command | ||
129 | * @param start_peer_label Label of the cmd to start a peer. | ||
130 | * @param create_label Label of the cmd which started the test system. | ||
131 | * @param num Number globally identifying the node. | ||
132 | * @param topology The topology for the test setup. | ||
133 | * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd. | ||
134 | * @return command. | ||
135 | */ | ||
136 | struct GNUNET_TESTING_Command | ||
137 | GNUNET_CORE_cmd_connect_peers ( | ||
138 | const char *label, | ||
139 | const char *start_peer_label, | ||
140 | const char *create_label, | ||
141 | uint32_t num, | ||
142 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
143 | unsigned int additional_connects, | ||
144 | unsigned int wait_for_connect, | ||
145 | struct GNUNET_MQ_MessageHandler *handlers); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Call #op on all simple traits. | ||
150 | */ | ||
151 | #define GNUNET_CORE_TESTING_SIMPLE_TRAITS(op) \ | ||
152 | op (connect_peer_state, const struct GNUNET_TESTING_ConnectPeersState) | ||
153 | |||
154 | GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
155 | |||
156 | |||
157 | |||
158 | #endif | ||
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h index 4384dd055..b0f4e1c03 100644 --- a/src/include/gnunet_testing_barrier.h +++ b/src/include/gnunet_testing_barrier.h | |||
@@ -29,10 +29,15 @@ | |||
29 | 29 | ||
30 | #include "gnunet_testing_plugin.h" | 30 | #include "gnunet_testing_plugin.h" |
31 | 31 | ||
32 | |||
33 | struct GNUNET_TESTING_Barrier; | ||
34 | |||
35 | |||
32 | #define GNUNET_TESTING_BARRIER_MAX 32 | 36 | #define GNUNET_TESTING_BARRIER_MAX 32 |
33 | 37 | ||
34 | /** | 38 | /** |
35 | * An entry for a barrier list | 39 | * An entry for a barrier list |
40 | * FIXME: why is this in the public API!??! | ||
36 | */ | 41 | */ |
37 | struct GNUNET_TESTING_BarrierListEntry | 42 | struct GNUNET_TESTING_BarrierListEntry |
38 | { | 43 | { |
@@ -53,6 +58,7 @@ struct GNUNET_TESTING_BarrierListEntry | |||
53 | 58 | ||
54 | /** | 59 | /** |
55 | * A list to hold barriers provided by plugins | 60 | * A list to hold barriers provided by plugins |
61 | * FIXME: why is this in the public API!??! | ||
56 | */ | 62 | */ |
57 | struct GNUNET_TESTING_BarrierList | 63 | struct GNUNET_TESTING_BarrierList |
58 | { | 64 | { |
@@ -87,6 +93,7 @@ GNUNET_TESTING_cmd_barrier_create ( | |||
87 | double percentage_to_be_reached, | 93 | double percentage_to_be_reached, |
88 | unsigned int number_to_be_reached); | 94 | unsigned int number_to_be_reached); |
89 | 95 | ||
96 | |||
90 | /** | 97 | /** |
91 | * If this command is executed the the process is signaling the master process | 98 | * If this command is executed the the process is signaling the master process |
92 | * that it reached a barrier. If this command is synchronous it will block. | 99 | * that it reached a barrier. If this command is synchronous it will block. |
@@ -96,7 +103,7 @@ GNUNET_TESTING_cmd_barrier_create ( | |||
96 | * | 103 | * |
97 | * @param label name for command. | 104 | * @param label name for command. |
98 | * @param barrier_label The name of the barrier we waited for and which was reached. | 105 | * @param barrier_label The name of the barrier we waited for and which was reached. |
99 | * @param asynchronous_finish If GNUNET_YES this command will not block. | 106 | * @param asynchronous_finish If #GNUNET_YES this command will not block. |
100 | * @param node_number The global number of the node the cmd runs on. | 107 | * @param node_number The global number of the node the cmd runs on. |
101 | * @param running_on_master Is this cmd running on the master loop? | 108 | * @param running_on_master Is this cmd running on the master loop? |
102 | * @param write_message Callback to write messages to the master loop. | 109 | * @param write_message Callback to write messages to the master loop. |
@@ -106,10 +113,10 @@ struct GNUNET_TESTING_Command | |||
106 | GNUNET_TESTING_cmd_barrier_reached ( | 113 | GNUNET_TESTING_cmd_barrier_reached ( |
107 | const char *label, | 114 | const char *label, |
108 | const char *barrier_label, | 115 | const char *barrier_label, |
109 | unsigned int asynchronous_finish, | 116 | unsigned int asynchronous_finish, /* FIXME: why not a bool? */ |
110 | unsigned int node_number, | 117 | unsigned int node_number, |
111 | unsigned int running_on_master, | 118 | unsigned int running_on_master, /* FIXME: why not a bool? */ |
112 | GNUNET_TESTING_cmd_helper_write_cb write_message); | 119 | GNUNET_TESTING_cmd_helper_write_cb write_message); /* FIXME: no 'cls' closure argument!? */ |
113 | 120 | ||
114 | #endif | 121 | #endif |
115 | /* end of testing_barrier.h */ | 122 | /* end of testing_barrier.h */ |
diff --git a/src/include/gnunet_testing_loop_lib.h b/src/include/gnunet_testing_loop_lib.h new file mode 100644 index 000000000..e4a7653e8 --- /dev/null +++ b/src/include/gnunet_testing_loop_lib.h | |||
@@ -0,0 +1,679 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021, 2023 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 | * @brief Central interpreter and command loop for writing an interpreter to test asynchronous systems | ||
23 | * @author Christian Grothoff <christian@grothoff.org> | ||
24 | * @author Marcello Stanisci | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #ifndef GNUNET_TESTING_LOOP_LIB_H | ||
28 | #define GNUNET_TESTING_LOOP_LIB_H | ||
29 | |||
30 | /** | ||
31 | * Maximum length of label in command | ||
32 | */ | ||
33 | #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 | ||
34 | |||
35 | /* ********************* Helper functions ********************* */ | ||
36 | |||
37 | /** | ||
38 | * Print failing line number and trigger shutdown. Useful | ||
39 | * quite any time after the command "run" method has been called. | ||
40 | */ | ||
41 | #define GNUNET_TESTING_FAIL(is) \ | ||
42 | do \ | ||
43 | { \ | ||
44 | GNUNET_break (0); \ | ||
45 | GNUNET_TESTING_interpreter_fail (is); \ | ||
46 | return; \ | ||
47 | } while (0) | ||
48 | |||
49 | |||
50 | /* ******************* Generic interpreter logic ************ */ | ||
51 | |||
52 | /** | ||
53 | * Global state of the interpreter, used by a command | ||
54 | * to access information about other commands. | ||
55 | */ | ||
56 | struct GNUNET_TESTING_Interpreter; | ||
57 | |||
58 | /** | ||
59 | * State each asynchronous command must have in its closure. | ||
60 | */ | ||
61 | struct GNUNET_TESTING_AsyncContext | ||
62 | { | ||
63 | |||
64 | /** | ||
65 | * Interpreter we are part of. | ||
66 | */ | ||
67 | struct GNUNET_TESTING_Interpreter *is; // FIXME: Why needed? When available? | ||
68 | |||
69 | /** | ||
70 | * Function to call when done. | ||
71 | */ | ||
72 | GNUNET_SCHEDULER_TaskCallback cont; | ||
73 | |||
74 | /** | ||
75 | * Closure for @e cont. | ||
76 | */ | ||
77 | void *cont_cls; | ||
78 | |||
79 | /** | ||
80 | * Indication if the command finished (#GNUNET_OK). | ||
81 | * #GNUNET_NO if it did not finish, | ||
82 | * #GNUNET_SYSERR if it failed. | ||
83 | */ | ||
84 | enum GNUNET_GenericReturnValue finished; | ||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * The asynchronous command of @a ac has failed. | ||
90 | * | ||
91 | * @param ac command-specific context | ||
92 | */ | ||
93 | void | ||
94 | GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac); | ||
95 | |||
96 | |||
97 | /** | ||
98 | * The asynchronous command of @a ac has finished. | ||
99 | * | ||
100 | * @param ac command-specific context | ||
101 | */ | ||
102 | void | ||
103 | GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac); | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Signature of a function used to start executing a command | ||
108 | * of a test. | ||
109 | * | ||
110 | * @param cls closure | ||
111 | * @param is interpreter running the command | ||
112 | */ | ||
113 | typedef void | ||
114 | (*GNUNET_TESTING_CommandRunRoutine)(void *cls, | ||
115 | struct GNUNET_TESTING_Interpreter *is); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Signature of a function used to clean up resources allocated | ||
120 | * by a command. | ||
121 | * | ||
122 | * @param cls closure | ||
123 | */ | ||
124 | typedef void | ||
125 | (*GNUNET_TESTING_CommandCleanupRoutine)(void *cls); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Signature of a function used to extract traits exposed by a | ||
130 | * command. | ||
131 | * | ||
132 | * @param cls closure | ||
133 | * @param[out] ret where to return the trait data | ||
134 | * @param trait name of the trait to return | ||
135 | * @param index index of the trait (for traits that are indexed) | ||
136 | * @return #GNUNET_OK on success | ||
137 | */ | ||
138 | typedef enum GNUNET_GenericReturnValue | ||
139 | (*GNUNET_TESTING_CommandGetTraits) (void *cls, | ||
140 | const void **ret, | ||
141 | const char *trait, | ||
142 | unsigned int index); | ||
143 | |||
144 | /** | ||
145 | * Create a new command | ||
146 | * | ||
147 | * @param cls the closure | ||
148 | * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
149 | * @param run the run routing | ||
150 | * @param cleanup the cleanup function | ||
151 | * @param traits the traits function (optional) | ||
152 | * @param the async context | ||
153 | * @return the command the function cannot fail | ||
154 | */ | ||
155 | struct GNUNET_TESTING_Command | ||
156 | GNUNET_TESTING_command_new (void *cls, | ||
157 | const char *label, | ||
158 | GNUNET_TESTING_CommandRunRoutine run, | ||
159 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
160 | GNUNET_TESTING_CommandGetTraits traits, | ||
161 | struct GNUNET_TESTING_AsyncContext *ac); | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Structure with storage space for a label. | ||
166 | */ | ||
167 | struct GNUNET_TESTING_CommandLabel | ||
168 | { | ||
169 | char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1]; | ||
170 | }; | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Set @a label to @a value. Asserts that @a value is | ||
175 | * not longer than #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH. | ||
176 | * | ||
177 | * @param[out] label label to initialize | ||
178 | * @param value value to store into @a label | ||
179 | */ | ||
180 | void | ||
181 | GNUNET_TESTING_set_label (struct GNUNET_TESTING_CommandLabel *label, | ||
182 | const char *value); | ||
183 | |||
184 | |||
185 | /** | ||
186 | * A command to be run by the interpreter. | ||
187 | */ | ||
188 | struct GNUNET_TESTING_Command | ||
189 | { | ||
190 | /** | ||
191 | * Closure for all commands with command-specific context information. | ||
192 | */ | ||
193 | void *cls; | ||
194 | |||
195 | /** | ||
196 | * Label for the command. | ||
197 | */ | ||
198 | struct GNUNET_TESTING_CommandLabel label; | ||
199 | |||
200 | /** | ||
201 | * Runs the command. Note that upon return, the interpreter | ||
202 | * will not automatically run the next command, as the command | ||
203 | * may continue asynchronously in other scheduler tasks. Thus, | ||
204 | * the command must ensure to eventually call | ||
205 | * #GNUNET_TESTING_interpreter_next() or | ||
206 | * #GNUNET_TESTING_interpreter_fail(). | ||
207 | * | ||
208 | * If this function creates some asynchronous activity, it should | ||
209 | * initialize @e finish to a function that can be used to wait for | ||
210 | * the asynchronous activity to terminate. | ||
211 | * | ||
212 | * @param cls closure | ||
213 | * @param is interpreter state | ||
214 | */ | ||
215 | GNUNET_TESTING_CommandRunRoutine run; | ||
216 | |||
217 | /** | ||
218 | * Pointer to the asynchronous context in the command's | ||
219 | * closure. Used by the | ||
220 | * #GNUNET_TESTING_async_finish() and | ||
221 | * #GNUNET_TESTING_async_fail() functions. | ||
222 | * | ||
223 | * Must be NULL if a command is synchronous. | ||
224 | */ | ||
225 | struct GNUNET_TESTING_AsyncContext *ac; | ||
226 | |||
227 | /** | ||
228 | * Clean up after the command. Run during forced termination | ||
229 | * (CTRL-C) or test failure or test success. | ||
230 | * | ||
231 | * @param cls closure | ||
232 | */ | ||
233 | GNUNET_TESTING_CommandCleanupRoutine cleanup; | ||
234 | |||
235 | /** | ||
236 | * Extract information from a command that is useful for other | ||
237 | * commands. Can be NULL if a command has no traits. | ||
238 | * | ||
239 | * @param cls closure | ||
240 | * @param[out] ret result (could be anything) | ||
241 | * @param trait name of the trait | ||
242 | * @param index index number of the object to extract. | ||
243 | * @return #GNUNET_OK on success, | ||
244 | * #GNUNET_NO if no trait was found | ||
245 | */ | ||
246 | GNUNET_TESTING_CommandGetTraits traits; | ||
247 | |||
248 | /** | ||
249 | * When did the execution of this command start? | ||
250 | */ | ||
251 | struct GNUNET_TIME_Absolute start_time; | ||
252 | |||
253 | /** | ||
254 | * When did the execution of this command finish? | ||
255 | */ | ||
256 | struct GNUNET_TIME_Absolute finish_time; | ||
257 | |||
258 | /** | ||
259 | * When did we start the last run of this command? Delta to @e finish_time | ||
260 | * gives the latency for the last successful run. Useful in case @e | ||
261 | * num_tries was positive and the command was run multiple times. In that | ||
262 | * case, the @e start_time gives the time when we first tried to run the | ||
263 | * command, so the difference between @e start_time and @e finish_time would | ||
264 | * be the time all of the @e num_tries took, while the delta to @e | ||
265 | * last_req_time is the time the last (successful) execution took. | ||
266 | */ | ||
267 | struct GNUNET_TIME_Absolute last_req_time; | ||
268 | |||
269 | /** | ||
270 | * In case @e asynchronous_finish is true, how long should we wait for this | ||
271 | * command to complete? If @e finish did not complete after this amount of | ||
272 | * time, the interpreter will fail. Should be set generously to ensure | ||
273 | * tests do not fail on slow systems. | ||
274 | */ | ||
275 | struct GNUNET_TIME_Relative default_timeout; | ||
276 | |||
277 | /** | ||
278 | * How often did we try to execute this command? (In case it is a request | ||
279 | * that is repated.) Note that a command must have some built-in retry | ||
280 | * mechanism for this value to be useful. | ||
281 | */ | ||
282 | unsigned int num_tries; | ||
283 | |||
284 | /** | ||
285 | * If "true", the interpreter should not immediately call | ||
286 | * @e finish, even if @e finish is non-NULL. Otherwise, | ||
287 | * #GNUNET_TESTING_cmd_finish() must be used | ||
288 | * to ensure that a command actually completed. | ||
289 | */ | ||
290 | bool asynchronous_finish; | ||
291 | |||
292 | }; | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Lookup command by label. | ||
297 | * Only future commands are looked up. | ||
298 | * | ||
299 | * @param is interpreter to lookup command in | ||
300 | * @param label label of the command to lookup. | ||
301 | * @return the command, if it is found, or NULL. | ||
302 | * @deprecated (still in use in a very odd way) | ||
303 | */ | ||
304 | // FIXME: think harder about whether this is actually needed, likely not. | ||
305 | const struct GNUNET_TESTING_Command * | ||
306 | GNUNET_TESTING_interpreter_lookup_future_command ( | ||
307 | struct GNUNET_TESTING_Interpreter *is, | ||
308 | const char *label); | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Lookup command by label. | ||
313 | * | ||
314 | * @param is interpreter to lookup command in | ||
315 | * @param label label of the command to lookup. | ||
316 | * @return the command, if it is found, or NULL. | ||
317 | */ | ||
318 | const struct GNUNET_TESTING_Command * | ||
319 | GNUNET_TESTING_interpreter_lookup_command ( | ||
320 | struct GNUNET_TESTING_Interpreter *is, | ||
321 | const char *label); | ||
322 | |||
323 | |||
324 | /** | ||
325 | * Lookup command by label. | ||
326 | * All commands, first into the past, then into the future are looked up. | ||
327 | * | ||
328 | * @param is interpreter to lookup command in | ||
329 | * @param label label of the command to lookup. | ||
330 | * @return the command, if it is found, or NULL. | ||
331 | * @deprecated (still in use in a very odd way) | ||
332 | */ | ||
333 | const struct GNUNET_TESTING_Command * | ||
334 | GNUNET_TESTING_interpreter_lookup_command_all ( | ||
335 | struct GNUNET_TESTING_Interpreter *is, | ||
336 | const char *label); | ||
337 | |||
338 | |||
339 | /** | ||
340 | * Current command failed, clean up and fail the test case. | ||
341 | * | ||
342 | * @param is interpreter state. | ||
343 | */ | ||
344 | void | ||
345 | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Turn asynchronous command into non-blocking command by setting | ||
350 | * asynchronous_finish to true. Modifies (and then returns) @a cmd simply | ||
351 | * setting the bit. By default, most commands are blocking, and by wrapping | ||
352 | * the command construction in this function a blocking command can be turned | ||
353 | * into an asynchronous command where the interpreter continues after | ||
354 | * initiating the asynchronous action. Does nothing if the command is | ||
355 | * fundamentally synchronous. | ||
356 | * | ||
357 | * @param[in,out] cmd command to make non-blocking | ||
358 | * @return a finish-command. | ||
359 | */ | ||
360 | struct GNUNET_TESTING_Command | ||
361 | GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); | ||
362 | |||
363 | |||
364 | /** | ||
365 | * Create (synchronous) command that waits for another command to finish. | ||
366 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
367 | * the test case. | ||
368 | * | ||
369 | * @param finish_label label for this command | ||
370 | * @param cmd_ref reference to a previous command which we should | ||
371 | * wait for (call `finish()` on) | ||
372 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
373 | * @return a finish-command. | ||
374 | */ | ||
375 | const struct GNUNET_TESTING_Command | ||
376 | GNUNET_TESTING_cmd_finish (const char *finish_label, | ||
377 | const char *cmd_ref, | ||
378 | struct GNUNET_TIME_Relative timeout); | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Make the instruction pointer point to @a target_label | ||
383 | * only if @a counter is greater than zero. | ||
384 | * | ||
385 | * @param label command label | ||
386 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
387 | * must be before the current instruction | ||
388 | * @param counter counts how many times the rewinding is to happen. | ||
389 | */ | ||
390 | struct GNUNET_TESTING_Command | ||
391 | GNUNET_TESTING_cmd_rewind_ip (const char *label, | ||
392 | const char *target_label, | ||
393 | unsigned int counter); | ||
394 | |||
395 | |||
396 | /** | ||
397 | * Function called with the final result of the test. | ||
398 | * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g. | ||
399 | * GNUNET_EC_TESTING_*) | ||
400 | * | ||
401 | * @param cls closure | ||
402 | * @param rv #GNUNET_OK if the test passed | ||
403 | */ | ||
404 | typedef void | ||
405 | (*GNUNET_TESTING_ResultCallback)(void *cls, | ||
406 | enum GNUNET_GenericReturnValue rv); | ||
407 | |||
408 | |||
409 | /** | ||
410 | * Run the testsuite. Note, CMDs are copied into | ||
411 | * the interpreter state because they are _usually_ | ||
412 | * defined into the "run" method that returns after | ||
413 | * having scheduled the test interpreter. | ||
414 | * | ||
415 | * @param commands the array of command to execute | ||
416 | * @param timeout how long to wait for each command to execute | ||
417 | * @param rc function to call with the final result | ||
418 | * @param rc_cls closure for @a rc | ||
419 | * @return The interpreter. | ||
420 | */ | ||
421 | struct GNUNET_TESTING_Interpreter * | ||
422 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, | ||
423 | struct GNUNET_TIME_Relative timeout, | ||
424 | GNUNET_TESTING_ResultCallback rc, | ||
425 | void *rc_cls); | ||
426 | |||
427 | |||
428 | /** | ||
429 | * Start a GNUnet scheduler event loop and | ||
430 | * run the testsuite. Return 0 upon success. | ||
431 | * Expected to be called directly from main(). | ||
432 | * FIXME: Why is this commands array here not const? | ||
433 | * | ||
434 | * @param commands the list of command to execute | ||
435 | * @param timeout how long to wait for each command to execute | ||
436 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure | ||
437 | */ | ||
438 | int | ||
439 | GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, | ||
440 | struct GNUNET_TIME_Relative timeout); | ||
441 | |||
442 | |||
443 | |||
444 | /* ************** Fundamental interpreter commands ************ */ | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Create command array terminator. | ||
449 | * | ||
450 | * @return a end-command. | ||
451 | */ | ||
452 | struct GNUNET_TESTING_Command | ||
453 | GNUNET_TESTING_cmd_end (void); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Create a "batch" command. Such command takes a end_CMD-terminated array of | ||
458 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
459 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
460 | * CMD. | ||
461 | * | ||
462 | * @param label the command label. | ||
463 | * @param batch array of CMDs to execute. | ||
464 | * @return the command. | ||
465 | */ | ||
466 | struct GNUNET_TESTING_Command | ||
467 | GNUNET_TESTING_cmd_batch (const char *label, | ||
468 | struct GNUNET_TESTING_Command *batch); | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Performance counter. | ||
473 | */ | ||
474 | struct GNUNET_TESTING_Timer | ||
475 | { | ||
476 | /** | ||
477 | * For which type of commands. | ||
478 | */ | ||
479 | const char *prefix; | ||
480 | |||
481 | /** | ||
482 | * Total time spend in all commands of this type. | ||
483 | */ | ||
484 | struct GNUNET_TIME_Relative total_duration; | ||
485 | |||
486 | /** | ||
487 | * Total time spend waiting for the *successful* exeuction | ||
488 | * in all commands of this type. | ||
489 | */ | ||
490 | struct GNUNET_TIME_Relative success_latency; | ||
491 | |||
492 | /** | ||
493 | * Number of commands summed up. | ||
494 | */ | ||
495 | unsigned int num_commands; | ||
496 | |||
497 | /** | ||
498 | * Number of retries summed up. | ||
499 | */ | ||
500 | unsigned int num_retries; | ||
501 | }; | ||
502 | |||
503 | /** | ||
504 | * Obtain performance data from the interpreter. | ||
505 | * | ||
506 | * @param[in,out] timers what commands (by label) to obtain runtimes for | ||
507 | * @return the command | ||
508 | */ | ||
509 | struct GNUNET_TESTING_Command | ||
510 | GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers); | ||
511 | |||
512 | |||
513 | /* *** Generic trait logic for implementing traits ********* */ | ||
514 | |||
515 | /** | ||
516 | * A `struct GNUNET_TESTING_Trait` can be used to exchange data between cmds. | ||
517 | * | ||
518 | * Therefor the cmd which like to provide data to other cmds has to implement | ||
519 | * the trait function, where an array of traits is defined with the help of the | ||
520 | * #GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the | ||
521 | * #GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make | ||
522 | * use of the macros. | ||
523 | */ | ||
524 | struct GNUNET_TESTING_Trait | ||
525 | { | ||
526 | /** | ||
527 | * Index number associated with the trait. This gives the | ||
528 | * possibility to have _multiple_ traits on offer under the | ||
529 | * same name. | ||
530 | */ | ||
531 | unsigned int index; | ||
532 | |||
533 | /** | ||
534 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
535 | */ | ||
536 | const char *trait_name; | ||
537 | |||
538 | /** | ||
539 | * Pointer to the piece of data to offer. | ||
540 | */ | ||
541 | const void *ptr; | ||
542 | }; | ||
543 | |||
544 | |||
545 | /** | ||
546 | * "end" of traits array. Because traits are offered into arrays, this type | ||
547 | * of trait is used to mark the end of such arrays; useful when iterating over | ||
548 | * those. | ||
549 | */ | ||
550 | struct GNUNET_TESTING_Trait | ||
551 | GNUNET_TESTING_trait_end (void); | ||
552 | |||
553 | |||
554 | /** | ||
555 | * Obtain value of a trait from a command. | ||
556 | * | ||
557 | * @param traits the array of all the traits. | ||
558 | * @param[out] ret where to store the result. | ||
559 | * @param trait type of the trait to extract. | ||
560 | * @param index index number of the trait to extract. | ||
561 | * @return #GNUNET_OK when the trait is found. | ||
562 | */ | ||
563 | enum GNUNET_GenericReturnValue | ||
564 | GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | ||
565 | const void **ret, | ||
566 | const char *trait, | ||
567 | unsigned int index); | ||
568 | |||
569 | |||
570 | |||
571 | /** | ||
572 | * Create headers for a trait with name @a name for | ||
573 | * statically allocated data of type @a type. | ||
574 | */ | ||
575 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \ | ||
576 | enum GNUNET_GenericReturnValue \ | ||
577 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
578 | const struct GNUNET_TESTING_Command *cmd, \ | ||
579 | type **ret); \ | ||
580 | struct GNUNET_TESTING_Trait \ | ||
581 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
582 | type * value); | ||
583 | |||
584 | |||
585 | /** | ||
586 | * Create C implementation for a trait with name @a name for statically | ||
587 | * allocated data of type @a type. | ||
588 | */ | ||
589 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ | ||
590 | enum GNUNET_GenericReturnValue \ | ||
591 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
592 | const struct GNUNET_TESTING_Command *cmd, \ | ||
593 | type * *ret) \ | ||
594 | { \ | ||
595 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
596 | return cmd->traits (cmd->cls, \ | ||
597 | (const void **) ret, \ | ||
598 | GNUNET_S (name), \ | ||
599 | 0); \ | ||
600 | } \ | ||
601 | struct GNUNET_TESTING_Trait \ | ||
602 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
603 | type * value) \ | ||
604 | { \ | ||
605 | struct GNUNET_TESTING_Trait ret = { \ | ||
606 | .trait_name = GNUNET_S (name), \ | ||
607 | .ptr = (const void *) value \ | ||
608 | }; \ | ||
609 | return ret; \ | ||
610 | } | ||
611 | |||
612 | |||
613 | /** | ||
614 | * Create headers for a trait with name @a name for | ||
615 | * statically allocated data of type @a type. | ||
616 | */ | ||
617 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \ | ||
618 | enum GNUNET_GenericReturnValue \ | ||
619 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
620 | const struct GNUNET_TESTING_Command *cmd, \ | ||
621 | unsigned int index, \ | ||
622 | type **ret); \ | ||
623 | struct GNUNET_TESTING_Trait \ | ||
624 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
625 | unsigned int index, \ | ||
626 | type *value); | ||
627 | |||
628 | |||
629 | /** | ||
630 | * Create C implementation for a trait with name @a name for statically | ||
631 | * allocated data of type @a type. | ||
632 | */ | ||
633 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \ | ||
634 | enum GNUNET_GenericReturnValue \ | ||
635 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
636 | const struct GNUNET_TESTING_Command *cmd, \ | ||
637 | unsigned int index, \ | ||
638 | type * *ret) \ | ||
639 | { \ | ||
640 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
641 | return cmd->traits (cmd->cls, \ | ||
642 | (const void **) ret, \ | ||
643 | GNUNET_S (name), \ | ||
644 | index); \ | ||
645 | } \ | ||
646 | struct GNUNET_TESTING_Trait \ | ||
647 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
648 | unsigned int index, \ | ||
649 | type * value) \ | ||
650 | { \ | ||
651 | struct GNUNET_TESTING_Trait ret = { \ | ||
652 | .index = index, \ | ||
653 | .trait_name = GNUNET_S (name), \ | ||
654 | .ptr = (const void *) value \ | ||
655 | }; \ | ||
656 | return ret; \ | ||
657 | } | ||
658 | |||
659 | |||
660 | /** | ||
661 | * Call #op on all simple traits needed by loop logic. | ||
662 | */ | ||
663 | #define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op) \ | ||
664 | op (batch_cmds, struct GNUNET_TESTING_Command *) | ||
665 | |||
666 | |||
667 | GNUNET_TESTING_LOOP_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
668 | |||
669 | |||
670 | /** | ||
671 | * Call #op on all indexed traits needed by loop logic. | ||
672 | */ | ||
673 | #define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op) \ | ||
674 | op (cmd, const struct GNUNET_TESTING_Command) | ||
675 | |||
676 | GNUNET_TESTING_LOOP_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) | ||
677 | |||
678 | |||
679 | #endif | ||
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h index 9d016b33a..0d58e0f62 100644 --- a/src/include/gnunet_testing_netjail_lib.h +++ b/src/include/gnunet_testing_netjail_lib.h | |||
@@ -30,7 +30,6 @@ | |||
30 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_ng_lib.h" |
31 | #include "gnunet_testing_plugin.h" | 31 | #include "gnunet_testing_plugin.h" |
32 | 32 | ||
33 | struct GNUNET_TESTING_AsyncContext; | ||
34 | 33 | ||
35 | /** | 34 | /** |
36 | * Router of a netjail subnet. | 35 | * Router of a netjail subnet. |
@@ -543,4 +542,5 @@ GNUNET_TESTING_cmd_start_peer (const char *label, | |||
543 | 542 | ||
544 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | 543 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) |
545 | 544 | ||
545 | |||
546 | #endif | 546 | #endif |
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 991eddbe4..7b19a0ab4 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @brief API for writing an interpreter to test GNUnet components | 22 | * @brief Meta-header for next-generation testing logic |
23 | * @author Christian Grothoff <christian@grothoff.org> | 23 | * @author Christian Grothoff <christian@grothoff.org> |
24 | * @author Marcello Stanisci | 24 | * @author Marcello Stanisci |
25 | * @author t3sserakt | 25 | * @author t3sserakt |
@@ -29,440 +29,13 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_testing_lib.h" | ||
33 | |||
34 | /** | ||
35 | * Maximum length of label in command | ||
36 | */ | ||
37 | #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 | ||
38 | |||
39 | /* ********************* Helper functions ********************* */ | ||
40 | |||
41 | /** | ||
42 | * Print failing line number and trigger shutdown. Useful | ||
43 | * quite any time after the command "run" method has been called. | ||
44 | */ | ||
45 | #define GNUNET_TESTING_FAIL(is) \ | ||
46 | do \ | ||
47 | { \ | ||
48 | GNUNET_break (0); \ | ||
49 | GNUNET_TESTING_interpreter_fail (is); \ | ||
50 | return; \ | ||
51 | } while (0) | ||
52 | |||
53 | |||
54 | /* ******************* Generic interpreter logic ************ */ | ||
55 | |||
56 | /** | ||
57 | * Global state of the interpreter, used by a command | ||
58 | * to access information about other commands. | ||
59 | */ | ||
60 | struct GNUNET_TESTING_Interpreter; | ||
61 | |||
62 | /** | ||
63 | * State each asynchronous command must have in its closure. | ||
64 | */ | ||
65 | struct GNUNET_TESTING_AsyncContext | ||
66 | { | ||
67 | |||
68 | /** | ||
69 | * Interpreter we are part of. | ||
70 | */ | ||
71 | struct GNUNET_TESTING_Interpreter *is; // Why needed? When available? | ||
72 | |||
73 | /** | ||
74 | * Function to call when done. | ||
75 | */ | ||
76 | GNUNET_SCHEDULER_TaskCallback cont; | ||
77 | |||
78 | /** | ||
79 | * Closure for @e cont. | ||
80 | */ | ||
81 | void *cont_cls; | ||
82 | |||
83 | /** | ||
84 | * Indication if the command finished (#GNUNET_OK). | ||
85 | * #GNUNET_NO if it did not finish, | ||
86 | * #GNUNET_SYSERR if it failed. | ||
87 | */ | ||
88 | enum GNUNET_GenericReturnValue finished; | ||
89 | }; | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Signature of a function used to start executing a command | ||
94 | * of a test. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param is interpreter running the command | ||
98 | */ | ||
99 | typedef void | ||
100 | (*GNUNET_TESTING_CommandRunRoutine)(void *cls, | ||
101 | struct GNUNET_TESTING_Interpreter *is); | ||
102 | |||
103 | |||
104 | /** | ||
105 | * Signature of a function used to clean up resources allocated | ||
106 | * by a command. | ||
107 | * | ||
108 | * @param cls closure | ||
109 | */ | ||
110 | typedef void | ||
111 | (*GNUNET_TESTING_CommandCleanupRoutine)(void *cls); | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Signature of a function used to extract traits exposed by a | ||
116 | * command. | ||
117 | * | ||
118 | * @param cls closure | ||
119 | * @param[out] ret where to return the trait data | ||
120 | * @param trait name of the trait to return | ||
121 | * @param index index of the trait (for traits that are indexed) | ||
122 | * @return #GNUNET_OK on success | ||
123 | */ | ||
124 | typedef enum GNUNET_GenericReturnValue | ||
125 | (*GNUNET_TESTING_CommandGetTraits) (void *cls, | ||
126 | const void **ret, | ||
127 | const char *trait, | ||
128 | unsigned int index); | ||
129 | |||
130 | /** | ||
131 | * Create a new command | ||
132 | * | ||
133 | * @param cls the closure | ||
134 | * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
135 | * @param run the run routing | ||
136 | * @param cleanup the cleanup function | ||
137 | * @param traits the traits function (optional) | ||
138 | * @param the async context | ||
139 | * @return the command the function cannot fail | ||
140 | */ | ||
141 | struct GNUNET_TESTING_Command | ||
142 | GNUNET_TESTING_command_new (void *cls, | ||
143 | const char *label, | ||
144 | GNUNET_TESTING_CommandRunRoutine run, | ||
145 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
146 | GNUNET_TESTING_CommandGetTraits traits, | ||
147 | struct GNUNET_TESTING_AsyncContext *ac); | ||
148 | |||
149 | /** | ||
150 | * A command to be run by the interpreter. | ||
151 | */ | ||
152 | struct GNUNET_TESTING_Command | ||
153 | { | ||
154 | /** | ||
155 | * Closure for all commands with command-specific context information. | ||
156 | */ | ||
157 | void *cls; | ||
158 | |||
159 | /** | ||
160 | * Label for the command. | ||
161 | */ | ||
162 | char label[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1]; | ||
163 | |||
164 | /** | ||
165 | * Runs the command. Note that upon return, the interpreter | ||
166 | * will not automatically run the next command, as the command | ||
167 | * may continue asynchronously in other scheduler tasks. Thus, | ||
168 | * the command must ensure to eventually call | ||
169 | * #GNUNET_TESTING_interpreter_next() or | ||
170 | * #GNUNET_TESTING_interpreter_fail(). | ||
171 | * | ||
172 | * If this function creates some asynchronous activity, it should | ||
173 | * initialize @e finish to a function that can be used to wait for | ||
174 | * the asynchronous activity to terminate. | ||
175 | * | ||
176 | * @param cls closure | ||
177 | * @param is interpreter state | ||
178 | */ | ||
179 | GNUNET_TESTING_CommandRunRoutine run; | ||
180 | |||
181 | /** | ||
182 | * Pointer to the asynchronous context in the command's | ||
183 | * closure. Used by the | ||
184 | * #GNUNET_TESTING_async_finish() and | ||
185 | * #GNUNET_TESTING_async_fail() functions. | ||
186 | * | ||
187 | * Must be NULL if a command is synchronous. | ||
188 | */ | ||
189 | struct GNUNET_TESTING_AsyncContext *ac; | ||
190 | |||
191 | /** | ||
192 | * Clean up after the command. Run during forced termination | ||
193 | * (CTRL-C) or test failure or test success. | ||
194 | * | ||
195 | * @param cls closure | ||
196 | */ | ||
197 | GNUNET_TESTING_CommandCleanupRoutine cleanup; | ||
198 | |||
199 | /** | ||
200 | * Extract information from a command that is useful for other | ||
201 | * commands. Can be NULL if a command has no traits. | ||
202 | * | ||
203 | * @param cls closure | ||
204 | * @param[out] ret result (could be anything) | ||
205 | * @param trait name of the trait | ||
206 | * @param index index number of the object to extract. | ||
207 | * @return #GNUNET_OK on success, | ||
208 | * #GNUNET_NO if no trait was found | ||
209 | */ | ||
210 | GNUNET_TESTING_CommandGetTraits traits; | ||
211 | |||
212 | /** | ||
213 | * When did the execution of this command start? | ||
214 | */ | ||
215 | struct GNUNET_TIME_Absolute start_time; | ||
216 | |||
217 | /** | ||
218 | * When did the execution of this command finish? | ||
219 | */ | ||
220 | struct GNUNET_TIME_Absolute finish_time; | ||
221 | |||
222 | /** | ||
223 | * When did we start the last run of this command? Delta to @e finish_time | ||
224 | * gives the latency for the last successful run. Useful in case @e | ||
225 | * num_tries was positive and the command was run multiple times. In that | ||
226 | * case, the @e start_time gives the time when we first tried to run the | ||
227 | * command, so the difference between @e start_time and @e finish_time would | ||
228 | * be the time all of the @e num_tries took, while the delta to @e | ||
229 | * last_req_time is the time the last (successful) execution took. | ||
230 | */ | ||
231 | struct GNUNET_TIME_Absolute last_req_time; | ||
232 | |||
233 | /** | ||
234 | * In case @e asynchronous_finish is true, how long should we wait for this | ||
235 | * command to complete? If @e finish did not complete after this amount of | ||
236 | * time, the interpreter will fail. Should be set generously to ensure | ||
237 | * tests do not fail on slow systems. | ||
238 | */ | ||
239 | struct GNUNET_TIME_Relative default_timeout; | ||
240 | |||
241 | /** | ||
242 | * How often did we try to execute this command? (In case it is a request | ||
243 | * that is repated.) Note that a command must have some built-in retry | ||
244 | * mechanism for this value to be useful. | ||
245 | */ | ||
246 | unsigned int num_tries; | ||
247 | |||
248 | /** | ||
249 | * If "true", the interpreter should not immediately call | ||
250 | * @e finish, even if @e finish is non-NULL. Otherwise, | ||
251 | * #GNUNET_TESTING_cmd_finish() must be used | ||
252 | * to ensure that a command actually completed. | ||
253 | */ | ||
254 | bool asynchronous_finish; | ||
255 | |||
256 | }; | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Lookup command by label. | ||
261 | * Only future commands are looked up. | ||
262 | * | ||
263 | * @param is interpreter to lookup command in | ||
264 | * @param label label of the command to lookup. | ||
265 | * @return the command, if it is found, or NULL. | ||
266 | */ | ||
267 | // FIXME: think harder about whether this is actually needed, likely not. | ||
268 | const struct GNUNET_TESTING_Command * | ||
269 | GNUNET_TESTING_interpreter_lookup_future_command ( | ||
270 | struct GNUNET_TESTING_Interpreter *is, | ||
271 | const char *label); | ||
272 | |||
273 | |||
274 | /** | ||
275 | * Lookup command by label. | ||
276 | * | ||
277 | * @param is interpreter to lookup command in | ||
278 | * @param label label of the command to lookup. | ||
279 | * @return the command, if it is found, or NULL. | ||
280 | */ | ||
281 | const struct GNUNET_TESTING_Command * | ||
282 | GNUNET_TESTING_interpreter_lookup_command ( | ||
283 | struct GNUNET_TESTING_Interpreter *is, | ||
284 | const char *label); | ||
285 | |||
286 | |||
287 | /** | ||
288 | * Lookup command by label. | ||
289 | * All commands, first into the past, then into the future are looked up. | ||
290 | * | ||
291 | * @param is interpreter to lookup command in | ||
292 | * @param label label of the command to lookup. | ||
293 | * @return the command, if it is found, or NULL. | ||
294 | */ | ||
295 | const struct GNUNET_TESTING_Command * | ||
296 | GNUNET_TESTING_interpreter_lookup_command_all ( | ||
297 | struct GNUNET_TESTING_Interpreter *is, | ||
298 | const char *label); | ||
299 | |||
300 | |||
301 | /** | ||
302 | * Obtain label of the command being now run. | ||
303 | * | ||
304 | * @param is interpreter state. | ||
305 | * @return the label. | ||
306 | */ | ||
307 | const char * | ||
308 | GNUNET_TESTING_interpreter_get_current_label ( | ||
309 | struct GNUNET_TESTING_Interpreter *is); | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Current command failed, clean up and fail the test case. | ||
314 | * | ||
315 | * @param is interpreter state. | ||
316 | */ | ||
317 | void | ||
318 | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); | ||
319 | |||
320 | |||
321 | /** | ||
322 | * The asynchronous command of @a ac has failed. | ||
323 | * | ||
324 | * @param ac command-specific context | ||
325 | */ | ||
326 | void | ||
327 | GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac); | ||
328 | |||
329 | |||
330 | /** | ||
331 | * The asynchronous command of @a ac has finished. | ||
332 | * | ||
333 | * @param ac command-specific context | ||
334 | */ | ||
335 | void | ||
336 | GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac); | ||
337 | |||
338 | |||
339 | /** | ||
340 | * Create command array terminator. | ||
341 | * | ||
342 | * @return a end-command. | ||
343 | */ | ||
344 | struct GNUNET_TESTING_Command | ||
345 | GNUNET_TESTING_cmd_end (void); | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Turn asynchronous command into non blocking command by setting | ||
350 | * asynchronous_finish to true. Modifies (and then returns) @a cmd simply | ||
351 | * setting the bit. By default, most commands are blocking, and by wrapping | ||
352 | * the command construction in this function a blocking command can be turned | ||
353 | * into an asynchronous command where the interpreter continues after | ||
354 | * initiating the asynchronous action. Does nothing if the command is | ||
355 | * fundamentally synchronous. | ||
356 | * | ||
357 | * @param cmd command to make synchronous. | ||
358 | * @return a finish-command. | ||
359 | */ | ||
360 | struct GNUNET_TESTING_Command | ||
361 | GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); | ||
362 | |||
363 | |||
364 | /** | ||
365 | * Create (synchronous) command that waits for another command to finish. | ||
366 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
367 | * the test case. | ||
368 | * | ||
369 | * @param finish_label label for this command | ||
370 | * @param cmd_ref reference to a previous command which we should | ||
371 | * wait for (call `finish()` on) | ||
372 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
373 | * @return a finish-command. | ||
374 | */ | ||
375 | const struct GNUNET_TESTING_Command | ||
376 | GNUNET_TESTING_cmd_finish (const char *finish_label, | ||
377 | const char *cmd_ref, | ||
378 | struct GNUNET_TIME_Relative timeout); | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Make the instruction pointer point to @a target_label | ||
383 | * only if @a counter is greater than zero. | ||
384 | * | ||
385 | * @param label command label | ||
386 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
387 | * must be before the current instruction | ||
388 | * @param counter counts how many times the rewinding is to happen. | ||
389 | */ | ||
390 | struct GNUNET_TESTING_Command | ||
391 | GNUNET_TESTING_cmd_rewind_ip (const char *label, | ||
392 | const char *target_label, | ||
393 | unsigned int counter); | ||
394 | |||
395 | |||
396 | /** | ||
397 | * Function called with the final result of the test. | ||
398 | * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g. | ||
399 | * GNUNET_EC_TESTING_*) | ||
400 | * | ||
401 | * @param cls closure | ||
402 | * @param rv #GNUNET_OK if the test passed | ||
403 | */ | ||
404 | typedef void | ||
405 | (*GNUNET_TESTING_ResultCallback)(void *cls, | ||
406 | enum GNUNET_GenericReturnValue rv); | ||
407 | |||
408 | |||
409 | /** | ||
410 | * Run the testsuite. Note, CMDs are copied into | ||
411 | * the interpreter state because they are _usually_ | ||
412 | * defined into the "run" method that returns after | ||
413 | * having scheduled the test interpreter. | ||
414 | * | ||
415 | * @param commands the array of command to execute | ||
416 | * @param timeout how long to wait for each command to execute | ||
417 | * @param rc function to call with the final result | ||
418 | * @param rc_cls closure for @a rc | ||
419 | * @return The interpreter. | ||
420 | */ | ||
421 | struct GNUNET_TESTING_Interpreter * | ||
422 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, | ||
423 | struct GNUNET_TIME_Relative timeout, | ||
424 | GNUNET_TESTING_ResultCallback rc, | ||
425 | void *rc_cls); | ||
426 | |||
427 | |||
428 | /** | ||
429 | * Start a GNUnet scheduler event loop and | ||
430 | * run the testsuite. Return 0 upon success. | ||
431 | * Expected to be called directly from main(). | ||
432 | * FIXME: Why is this commands array here not const? | ||
433 | * | ||
434 | * @param commands the list of command to execute | ||
435 | * @param timeout how long to wait for each command to execute | ||
436 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure | ||
437 | */ | ||
438 | int | ||
439 | GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, | ||
440 | struct GNUNET_TIME_Relative timeout); | ||
441 | |||
442 | |||
443 | /* ************** Specific interpreter commands ************ */ | ||
444 | |||
445 | 32 | ||
446 | /** | 33 | /* FIXME: legacy test header, to be removed!! */ |
447 | * Check if the command is running. | 34 | #include "gnunet_testing_lib.h" |
448 | * FIXME: Unused function. | ||
449 | * | ||
450 | * @param command The command to check. | ||
451 | * @return #GNUNET_NO if the command is not running, #GNUNET_YES if it is running. | ||
452 | */ | ||
453 | enum GNUNET_GenericReturnValue | ||
454 | GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command); | ||
455 | 35 | ||
456 | 36 | #include "gnunet_testing_plugin.h" | |
457 | /** | 37 | #include "gnunet_testing_loop_lib.h" |
458 | * Check if a command is finished. | 38 | #include "gnunet_testing_netjail_lib.h" |
459 | * FIXME: Unused function | ||
460 | * | ||
461 | * @param command The command to check. | ||
462 | * @return #GNUNET_NO if the command is not finished, #GNUNET_YES if it is finished. | ||
463 | */ | ||
464 | enum GNUNET_GenericReturnValue | ||
465 | GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command); | ||
466 | 39 | ||
467 | 40 | ||
468 | /** | 41 | /** |
@@ -470,14 +43,12 @@ GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command); | |||
470 | * | 43 | * |
471 | * @param label command label. | 44 | * @param label command label. |
472 | * @param process_label label of a command that has a process trait | 45 | * @param process_label label of a command that has a process trait |
473 | * @param process_index index of the process trait at @a process_label // FIXME: enum? needed? | ||
474 | * @param signal signal to send to @a process. | 46 | * @param signal signal to send to @a process. |
475 | * @return the command. | 47 | * @return the command. |
476 | */ | 48 | */ |
477 | struct GNUNET_TESTING_Command | 49 | struct GNUNET_TESTING_Command |
478 | GNUNET_TESTING_cmd_signal (const char *label, | 50 | GNUNET_TESTING_cmd_signal (const char *label, |
479 | const char *process_label, | 51 | const char *process_label, |
480 | unsigned int process_index, | ||
481 | int signal); | 52 | int signal); |
482 | 53 | ||
483 | 54 | ||
@@ -494,55 +65,10 @@ GNUNET_TESTING_cmd_sleep (const char *label, | |||
494 | 65 | ||
495 | 66 | ||
496 | /** | 67 | /** |
497 | * Create a "batch" command. Such command takes a end_CMD-terminated array of | ||
498 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
499 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
500 | * CMD. | ||
501 | * | ||
502 | * @param label the command label. | ||
503 | * @param batch array of CMDs to execute. | ||
504 | * @return the command. | ||
505 | */ | ||
506 | struct GNUNET_TESTING_Command | ||
507 | GNUNET_TESTING_cmd_batch (const char *label, | ||
508 | struct GNUNET_TESTING_Command *batch); | ||
509 | |||
510 | |||
511 | /** | ||
512 | * Performance counter. | ||
513 | */ | ||
514 | struct GNUNET_TESTING_Timer | ||
515 | { | ||
516 | /** | ||
517 | * For which type of commands. | ||
518 | */ | ||
519 | const char *prefix; | ||
520 | |||
521 | /** | ||
522 | * Total time spend in all commands of this type. | ||
523 | */ | ||
524 | struct GNUNET_TIME_Relative total_duration; | ||
525 | |||
526 | /** | ||
527 | * Total time spend waiting for the *successful* exeuction | ||
528 | * in all commands of this type. | ||
529 | */ | ||
530 | struct GNUNET_TIME_Relative success_latency; | ||
531 | |||
532 | /** | ||
533 | * Number of commands summed up. | ||
534 | */ | ||
535 | unsigned int num_commands; | ||
536 | |||
537 | /** | ||
538 | * Number of retries summed up. | ||
539 | */ | ||
540 | unsigned int num_retries; | ||
541 | }; | ||
542 | |||
543 | /** | ||
544 | * Command to execute a script synchronously. | 68 | * Command to execute a script synchronously. |
545 | * | 69 | * |
70 | * FIXME: is this accurate? How is this limited to BASH scripts or even scripts? | ||
71 | * | ||
546 | * @param label Label of the command. | 72 | * @param label Label of the command. |
547 | * @param script The name of the script. | 73 | * @param script The name of the script. |
548 | * @param script_argv The arguments of the script. | 74 | * @param script_argv The arguments of the script. |
@@ -551,486 +77,39 @@ const struct GNUNET_TESTING_Command | |||
551 | GNUNET_TESTING_cmd_exec_bash_script (const char *label, | 77 | GNUNET_TESTING_cmd_exec_bash_script (const char *label, |
552 | const char *script, | 78 | const char *script, |
553 | char *const script_argv[], | 79 | char *const script_argv[], |
80 | // FIXME: wtf are these two args here for!? | ||
554 | int argc, | 81 | int argc, |
555 | GNUNET_ChildCompletedCallback cb); | 82 | GNUNET_ChildCompletedCallback cb); |
556 | 83 | ||
557 | 84 | ||
558 | /** | ||
559 | * Retrieve peer identity from the test system with the unique node id. | ||
560 | * | ||
561 | * @param num The unique node id. | ||
562 | * @param tl_system The test system. | ||
563 | * @return The peer identity wrapping the public key. | ||
564 | */ | ||
565 | struct GNUNET_PeerIdentity * | ||
566 | GNUNET_TESTING_get_peer (unsigned int num, | ||
567 | const struct GNUNET_TESTING_System *tl_system); | ||
568 | 85 | ||
569 | 86 | /* ****** Specific traits needed by this component ******* */ | |
570 | /** | ||
571 | * Obtain performance data from the interpreter. | ||
572 | * | ||
573 | * @param[in,out] timers what commands (by label) to obtain runtimes for | ||
574 | * @return the command | ||
575 | */ | ||
576 | struct GNUNET_TESTING_Command | ||
577 | GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers); | ||
578 | |||
579 | |||
580 | /* *** Generic trait logic for implementing traits ********* */ | ||
581 | |||
582 | /** | ||
583 | * A struct GNUNET_TESTING_Trait can be used to exchange data between cmds. | ||
584 | * | ||
585 | * Therefor the cmd which like to provide data to other cmds has to implement | ||
586 | * the trait function, where an array of traits is defined with the help of the | ||
587 | * GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the | ||
588 | * GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make | ||
589 | * use of the macros. | ||
590 | */ | ||
591 | struct GNUNET_TESTING_Trait | ||
592 | { | ||
593 | /** | ||
594 | * Index number associated with the trait. This gives the | ||
595 | * possibility to have _multiple_ traits on offer under the | ||
596 | * same name. | ||
597 | */ | ||
598 | unsigned int index; | ||
599 | |||
600 | /** | ||
601 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
602 | */ | ||
603 | const char *trait_name; | ||
604 | |||
605 | /** | ||
606 | * Pointer to the piece of data to offer. | ||
607 | */ | ||
608 | const void *ptr; | ||
609 | }; | ||
610 | |||
611 | |||
612 | /** | ||
613 | * "end" trait. Because traits are offered into arrays, | ||
614 | * this type of trait is used to mark the end of such arrays; | ||
615 | * useful when iterating over those. | ||
616 | */ | ||
617 | struct GNUNET_TESTING_Trait | ||
618 | GNUNET_TESTING_trait_end (void); | ||
619 | |||
620 | |||
621 | /** | ||
622 | * Extract a trait. | ||
623 | * FIXME: Naming. This is something like "contains trait". | ||
624 | * | ||
625 | * @param traits the array of all the traits. | ||
626 | * @param[out] ret where to store the result. | ||
627 | * @param trait type of the trait to extract. | ||
628 | * @param index index number of the trait to extract. | ||
629 | * @return #GNUNET_OK when the trait is found. | ||
630 | */ | ||
631 | enum GNUNET_GenericReturnValue | ||
632 | GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | ||
633 | const void **ret, | ||
634 | const char *trait, | ||
635 | unsigned int index); | ||
636 | |||
637 | |||
638 | /* ****** Specific traits supported by this component ******* */ | ||
639 | |||
640 | |||
641 | typedef void * | ||
642 | (*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is, | ||
643 | const struct GNUNET_PeerIdentity *peer); | ||
644 | |||
645 | /** | ||
646 | * Struct to store information needed in callbacks. | ||
647 | * | ||
648 | */ | ||
649 | struct GNUNET_TESTING_ConnectPeersState | ||
650 | { | ||
651 | /** | ||
652 | * Receive callback | ||
653 | */ | ||
654 | struct GNUNET_MQ_MessageHandler *handlers; | ||
655 | |||
656 | /** | ||
657 | * A map with struct GNUNET_MQ_Handle values for each peer this peer | ||
658 | * is connected to. | ||
659 | */ | ||
660 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
661 | |||
662 | /** | ||
663 | * Handle for transport. | ||
664 | */ | ||
665 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
666 | |||
667 | /** | ||
668 | * Core handle. | ||
669 | */ | ||
670 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
671 | |||
672 | /** | ||
673 | * Context for our asynchronous completion. | ||
674 | */ | ||
675 | struct GNUNET_TESTING_AsyncContext ac; | ||
676 | |||
677 | /** | ||
678 | * The testing system of this node. | ||
679 | */ | ||
680 | const struct GNUNET_TESTING_System *tl_system; | ||
681 | |||
682 | // Label of the cmd which started the test system. | ||
683 | const char *create_label; | ||
684 | |||
685 | /** | ||
686 | * Number globally identifying the node. | ||
687 | * | ||
688 | */ | ||
689 | uint32_t num; | ||
690 | |||
691 | /** | ||
692 | * Label of the cmd to start a peer. | ||
693 | * | ||
694 | */ | ||
695 | const char *start_peer_label; | ||
696 | |||
697 | /** | ||
698 | * The topology of the test setup. | ||
699 | */ | ||
700 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
701 | |||
702 | /** | ||
703 | * Connections to other peers. | ||
704 | */ | ||
705 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
706 | |||
707 | struct GNUNET_TESTING_Interpreter *is; | ||
708 | |||
709 | /** | ||
710 | * Number of connections. | ||
711 | */ | ||
712 | unsigned int con_num; | ||
713 | |||
714 | /** | ||
715 | * Number of additional connects this cmd will wait for not triggered by this cmd. | ||
716 | */ | ||
717 | unsigned int additional_connects; | ||
718 | |||
719 | /** | ||
720 | * Number of connections we already have a notification for. | ||
721 | */ | ||
722 | unsigned int con_num_notified; | ||
723 | |||
724 | /** | ||
725 | * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for. | ||
726 | */ | ||
727 | unsigned int additional_connects_notified; | ||
728 | |||
729 | /** | ||
730 | * Flag indicating, whether the command is waiting for peers to connect that are configured to connect. | ||
731 | */ | ||
732 | unsigned int wait_for_connect; | ||
733 | }; | ||
734 | |||
735 | /** | ||
736 | * Struct to store information needed in callbacks. | ||
737 | * | ||
738 | */ | ||
739 | struct ConnectPeersState | ||
740 | { | ||
741 | /** | ||
742 | * Context for our asynchronous completion. | ||
743 | */ | ||
744 | struct GNUNET_TESTING_AsyncContext ac; | ||
745 | |||
746 | GNUNET_TESTING_notify_connect_cb notify_connect; | ||
747 | |||
748 | /** | ||
749 | * The testing system of this node. | ||
750 | */ | ||
751 | const struct GNUNET_TESTING_System *tl_system; | ||
752 | |||
753 | // Label of the cmd which started the test system. | ||
754 | const char *create_label; | ||
755 | |||
756 | /** | ||
757 | * Number globally identifying the node. | ||
758 | * | ||
759 | */ | ||
760 | uint32_t num; | ||
761 | |||
762 | /** | ||
763 | * Label of the cmd to start a peer. | ||
764 | * | ||
765 | */ | ||
766 | const char *start_peer_label; | ||
767 | |||
768 | /** | ||
769 | * The topology of the test setup. | ||
770 | */ | ||
771 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
772 | |||
773 | /** | ||
774 | * Connections to other peers. | ||
775 | */ | ||
776 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
777 | |||
778 | struct GNUNET_TESTING_Interpreter *is; | ||
779 | |||
780 | /** | ||
781 | * Number of connections. | ||
782 | */ | ||
783 | unsigned int con_num; | ||
784 | |||
785 | /** | ||
786 | * Number of additional connects this cmd will wait for not triggered by this cmd. | ||
787 | */ | ||
788 | unsigned int additional_connects; | ||
789 | |||
790 | /** | ||
791 | * Number of connections we already have a notification for. | ||
792 | */ | ||
793 | unsigned int con_num_notified; | ||
794 | |||
795 | /** | ||
796 | * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for. | ||
797 | */ | ||
798 | unsigned int additional_connects_notified; | ||
799 | |||
800 | /** | ||
801 | * Flag indicating, whether the command is waiting for peers to connect that are configured to connect. | ||
802 | */ | ||
803 | unsigned int wait_for_connect; | ||
804 | }; | ||
805 | |||
806 | |||
807 | struct GNUNET_TESTING_StartPeerState | ||
808 | { | ||
809 | /** | ||
810 | * Context for our asynchronous completion. | ||
811 | */ | ||
812 | struct GNUNET_TESTING_AsyncContext ac; | ||
813 | |||
814 | /** | ||
815 | * The ip of a node. | ||
816 | */ | ||
817 | char *node_ip; | ||
818 | |||
819 | /** | ||
820 | * Receive callback | ||
821 | */ | ||
822 | struct GNUNET_MQ_MessageHandler *handlers; | ||
823 | |||
824 | /** | ||
825 | * GNUnet configuration file used to start a peer. | ||
826 | */ | ||
827 | char *cfgname; | ||
828 | |||
829 | /** | ||
830 | * Peer's configuration | ||
831 | */ | ||
832 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
833 | |||
834 | /** | ||
835 | * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure. | ||
836 | */ | ||
837 | struct GNUNET_TESTING_Peer *peer; | ||
838 | |||
839 | /** | ||
840 | * Peer identity | ||
841 | */ | ||
842 | struct GNUNET_PeerIdentity id; | ||
843 | |||
844 | /** | ||
845 | * Peer's transport service handle | ||
846 | */ | ||
847 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
848 | |||
849 | /** | ||
850 | * Application handle | ||
851 | */ | ||
852 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
853 | |||
854 | /** | ||
855 | * Peer's PEERSTORE Handle | ||
856 | */ | ||
857 | struct GNUNET_PEERSTORE_Handle *ph; | ||
858 | |||
859 | /** | ||
860 | * Hello get task | ||
861 | */ | ||
862 | struct GNUNET_SCHEDULER_Task *rh_task; | ||
863 | |||
864 | /** | ||
865 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
866 | */ | ||
867 | struct GNUNET_PEERSTORE_IterateContext *pic; | ||
868 | |||
869 | /** | ||
870 | * Hello | ||
871 | */ | ||
872 | char *hello; | ||
873 | |||
874 | /** | ||
875 | * Hello size | ||
876 | */ | ||
877 | size_t hello_size; | ||
878 | |||
879 | /** | ||
880 | * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create. | ||
881 | */ | ||
882 | char *system_label; | ||
883 | |||
884 | /** | ||
885 | * An unique number to identify the peer | ||
886 | */ | ||
887 | unsigned int no; | ||
888 | |||
889 | /** | ||
890 | * A map with struct GNUNET_MQ_Handle values for each peer this peer | ||
891 | * is connected to. | ||
892 | */ | ||
893 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
894 | |||
895 | /** | ||
896 | * Test setup for this peer. | ||
897 | */ | ||
898 | const struct GNUNET_TESTING_System *tl_system; | ||
899 | |||
900 | /** | ||
901 | * Callback which is called on neighbour connect events. | ||
902 | */ | ||
903 | GNUNET_TESTING_notify_connect_cb notify_connect; | ||
904 | |||
905 | /** | ||
906 | * Flag indicating, if udp broadcast should be switched on. | ||
907 | */ | ||
908 | enum GNUNET_GenericReturnValue broadcast; | ||
909 | }; | ||
910 | |||
911 | |||
912 | /** | ||
913 | * Create headers for a trait with name @a name for | ||
914 | * statically allocated data of type @a type. | ||
915 | */ | ||
916 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \ | ||
917 | enum GNUNET_GenericReturnValue \ | ||
918 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
919 | const struct GNUNET_TESTING_Command *cmd, \ | ||
920 | type **ret); \ | ||
921 | struct GNUNET_TESTING_Trait \ | ||
922 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
923 | type * value); | ||
924 | |||
925 | |||
926 | /** | ||
927 | * Create C implementation for a trait with name @a name for statically | ||
928 | * allocated data of type @a type. | ||
929 | */ | ||
930 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ | ||
931 | enum GNUNET_GenericReturnValue \ | ||
932 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
933 | const struct GNUNET_TESTING_Command *cmd, \ | ||
934 | type * *ret) \ | ||
935 | { \ | ||
936 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
937 | return cmd->traits (cmd->cls, \ | ||
938 | (const void **) ret, \ | ||
939 | GNUNET_S (name), \ | ||
940 | 0); \ | ||
941 | } \ | ||
942 | struct GNUNET_TESTING_Trait \ | ||
943 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
944 | type * value) \ | ||
945 | { \ | ||
946 | struct GNUNET_TESTING_Trait ret = { \ | ||
947 | .trait_name = GNUNET_S (name), \ | ||
948 | .ptr = (const void *) value \ | ||
949 | }; \ | ||
950 | return ret; \ | ||
951 | } | ||
952 | |||
953 | |||
954 | /** | ||
955 | * Create headers for a trait with name @a name for | ||
956 | * statically allocated data of type @a type. | ||
957 | */ | ||
958 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \ | ||
959 | enum GNUNET_GenericReturnValue \ | ||
960 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
961 | const struct GNUNET_TESTING_Command *cmd, \ | ||
962 | unsigned int index, \ | ||
963 | type **ret); \ | ||
964 | struct GNUNET_TESTING_Trait \ | ||
965 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
966 | unsigned int index, \ | ||
967 | type *value); | ||
968 | |||
969 | |||
970 | /** | ||
971 | * Create C implementation for a trait with name @a name for statically | ||
972 | * allocated data of type @a type. | ||
973 | */ | ||
974 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \ | ||
975 | enum GNUNET_GenericReturnValue \ | ||
976 | GNUNET_TESTING_get_trait_ ## name ( \ | ||
977 | const struct GNUNET_TESTING_Command *cmd, \ | ||
978 | unsigned int index, \ | ||
979 | type * *ret) \ | ||
980 | { \ | ||
981 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
982 | return cmd->traits (cmd->cls, \ | ||
983 | (const void **) ret, \ | ||
984 | GNUNET_S (name), \ | ||
985 | index); \ | ||
986 | } \ | ||
987 | struct GNUNET_TESTING_Trait \ | ||
988 | GNUNET_TESTING_make_trait_ ## name ( \ | ||
989 | unsigned int index, \ | ||
990 | type * value) \ | ||
991 | { \ | ||
992 | struct GNUNET_TESTING_Trait ret = { \ | ||
993 | .index = index, \ | ||
994 | .trait_name = GNUNET_S (name), \ | ||
995 | .ptr = (const void *) value \ | ||
996 | }; \ | ||
997 | return ret; \ | ||
998 | } | ||
999 | 87 | ||
1000 | 88 | ||
1001 | /** | 89 | /** |
1002 | * Call #op on all simple traits. | 90 | * Call #op on all simple traits. |
1003 | */ | 91 | */ |
1004 | #define GNUNET_TESTING_SIMPLE_TRAITS(op) \ | 92 | #define GNUNET_TESTING_SIMPLE_TRAITS(op) \ |
1005 | op (batch_cmds, struct GNUNET_TESTING_Command *) \ | 93 | op (process, struct GNUNET_OS_Process *) |
1006 | op (process, struct GNUNET_OS_Process *) \ | 94 | |
1007 | op (peer_id, const struct GNUNET_PeerIdentity) \ | ||
1008 | op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ | ||
1009 | op (hello_size, const size_t) \ | ||
1010 | op (hello, const char) \ | ||
1011 | op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \ | ||
1012 | op (connect_peer_state, const struct GNUNET_TESTING_ConnectPeersState) \ | ||
1013 | op (state, const struct GNUNET_TESTING_StartPeerState) \ | ||
1014 | op (broadcast, const enum GNUNET_GenericReturnValue) | ||
1015 | 95 | ||
96 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
1016 | 97 | ||
1017 | /** | 98 | /** |
1018 | * Call #op on all indexed traits. | 99 | * Call #op on all indexed traits. |
1019 | */ | 100 | */ |
1020 | #define GNUNET_TESTING_INDEXED_TRAITS(op) \ | 101 | #define GNUNET_TESTING_INDEXED_TRAITS(op) \ |
1021 | op (uint32, const uint32_t) \ | 102 | op (uint32, const uint32_t) \ |
1022 | op (uint64, const uint64_t) \ | 103 | op (uint64, const uint64_t) \ |
1023 | op (int64, const int64_t) \ | 104 | op (int64, const int64_t) \ |
1024 | op (uint, const unsigned int) \ | 105 | op (uint, const unsigned int) \ |
1025 | op (string, const char) \ | 106 | op (string, const char) \ |
1026 | op (cmd, const struct GNUNET_TESTING_Command) \ | ||
1027 | op (uuid, const struct GNUNET_Uuid) \ | 107 | op (uuid, const struct GNUNET_Uuid) \ |
1028 | op (time, const struct GNUNET_TIME_Absolute) \ | 108 | op (time, const struct GNUNET_TIME_Absolute) \ |
1029 | op (absolute_time, const struct GNUNET_TIME_Absolute) \ | 109 | op (absolute_time, const struct GNUNET_TIME_Absolute) \ |
1030 | op (relative_time, const struct GNUNET_TIME_Relative) | 110 | op (relative_time, const struct GNUNET_TIME_Relative) |
1031 | 111 | ||
1032 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
1033 | |||
1034 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) | 112 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) |
1035 | 113 | ||
114 | |||
1036 | #endif | 115 | #endif |
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h index d6a3560ef..b030bc8a8 100644 --- a/src/include/gnunet_testing_plugin.h +++ b/src/include/gnunet_testing_plugin.h | |||
@@ -38,8 +38,6 @@ extern "C" | |||
38 | #endif | 38 | #endif |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | struct GNUNET_TESTING_Barrier; | ||
42 | |||
43 | 41 | ||
44 | /** | 42 | /** |
45 | * Callback function to write messages from the helper process running on a netjail node to the master process. | 43 | * Callback function to write messages from the helper process running on a netjail node to the master process. |
@@ -57,6 +55,7 @@ typedef void | |||
57 | typedef void | 55 | typedef void |
58 | (*GNUNET_TESTING_cmd_helper_finish_cb) (); | 56 | (*GNUNET_TESTING_cmd_helper_finish_cb) (); |
59 | 57 | ||
58 | |||
60 | /** | 59 | /** |
61 | * Function to be implemented for each test case plugin which starts the test case on a netjail node. | 60 | * Function to be implemented for each test case plugin which starts the test case on a netjail node. |
62 | * | 61 | * |
@@ -76,17 +75,17 @@ typedef void | |||
76 | * @return Returns The struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node. | 75 | * @return Returns The struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node. |
77 | */ | 76 | */ |
78 | typedef struct GNUNET_TESTING_Interpreter * | 77 | typedef struct GNUNET_TESTING_Interpreter * |
79 | (*GNUNET_TESTING_PLUGIN_StartTestCase) (GNUNET_TESTING_cmd_helper_write_cb | 78 | (*GNUNET_TESTING_PLUGIN_StartTestCase) ( |
80 | write_message, | 79 | GNUNET_TESTING_cmd_helper_write_cb write_message, |
81 | const char *router_ip, | 80 | const char *router_ip, |
82 | const char *node_ip, | 81 | const char *node_ip, |
83 | const char *n, | 82 | const char *n, |
84 | const char *m, | 83 | const char *m, |
85 | const char *local_m, | 84 | const char *local_m, |
86 | const char *topology_data, | 85 | const char *topology_data, |
87 | unsigned int *read_file, | 86 | unsigned int *read_file, |
88 | GNUNET_TESTING_cmd_helper_finish_cb | 87 | GNUNET_TESTING_cmd_helper_finish_cb |
89 | finish_cb); | 88 | finish_cb); |
90 | 89 | ||
91 | /** | 90 | /** |
92 | * DEPRECATED | 91 | * DEPRECATED |
@@ -104,15 +103,18 @@ typedef void | |||
104 | * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED. This will finish the blocking command | 103 | * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED. This will finish the blocking command |
105 | * GNUNET_TESTING_cmd_local_test_prepared which was execute right after the command | 104 | * GNUNET_TESTING_cmd_local_test_prepared which was execute right after the command |
106 | * GNUNET_TRANSPORT_cmd_connect_peers. | 105 | * GNUNET_TRANSPORT_cmd_connect_peers. |
106 | * FIXME: do not use ALL CAPS | ||
107 | */ | 107 | */ |
108 | typedef void | 108 | typedef void |
109 | (*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) (); | 109 | (*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) (); |
110 | 110 | ||
111 | |||
111 | /** | 112 | /** |
112 | * This function returns a struct GNUNET_TESTING_BarrierList, which is a list of all barriers | 113 | * This function returns a struct GNUNET_TESTING_BarrierList, which is a list of all barriers |
113 | * this test case will wait for. | 114 | * this test case will wait for. |
114 | * | 115 | * |
115 | * @return A struct GNUNET_TESTING_BarrierList. | 116 | * @return A struct GNUNET_TESTING_BarrierList. |
117 | * FIXME: do not use ALL CAPS | ||
116 | */ | 118 | */ |
117 | typedef struct GNUNET_TESTING_BarrierList* | 119 | typedef struct GNUNET_TESTING_BarrierList* |
118 | (*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void); | 120 | (*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void); |
diff --git a/src/include/gnunet_transport_testing_ng_lib.h b/src/include/gnunet_transport_testing_ng_lib.h index 72ec11eaf..b11fe6373 100644 --- a/src/include/gnunet_transport_testing_ng_lib.h +++ b/src/include/gnunet_transport_testing_ng_lib.h | |||
@@ -27,7 +27,131 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_ng_lib.h" |
31 | |||
32 | /** | ||
33 | * Application handle; FIXME: what exactly is this? | ||
34 | */ | ||
35 | struct GNUNET_TRANSPORT_ApplicationHandle; | ||
36 | |||
37 | /** | ||
38 | * FIXME: what is this? | ||
39 | */ | ||
40 | struct GNUNET_TESTING_StartPeerState; | ||
41 | |||
42 | |||
43 | // FIXME: breaks naming conventions | ||
44 | typedef void * | ||
45 | (*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is, | ||
46 | const struct GNUNET_PeerIdentity *peer); | ||
47 | |||
48 | |||
49 | |||
50 | // FIXME: breaks naming conventions! Needed public? | ||
51 | struct GNUNET_TESTING_StartPeerState | ||
52 | { | ||
53 | /** | ||
54 | * Context for our asynchronous completion. | ||
55 | */ | ||
56 | struct GNUNET_TESTING_AsyncContext ac; | ||
57 | |||
58 | /** | ||
59 | * The ip of a node. | ||
60 | */ | ||
61 | char *node_ip; | ||
62 | |||
63 | /** | ||
64 | * Receive callback | ||
65 | */ | ||
66 | struct GNUNET_MQ_MessageHandler *handlers; | ||
67 | |||
68 | /** | ||
69 | * GNUnet configuration file used to start a peer. | ||
70 | */ | ||
71 | char *cfgname; | ||
72 | |||
73 | /** | ||
74 | * Peer's configuration | ||
75 | */ | ||
76 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
77 | |||
78 | /** | ||
79 | * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure. | ||
80 | */ | ||
81 | struct GNUNET_TESTING_Peer *peer; | ||
82 | |||
83 | /** | ||
84 | * Peer identity | ||
85 | */ | ||
86 | struct GNUNET_PeerIdentity id; | ||
87 | |||
88 | /** | ||
89 | * Peer's transport service handle | ||
90 | */ | ||
91 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
92 | |||
93 | /** | ||
94 | * Application handle | ||
95 | */ | ||
96 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
97 | |||
98 | /** | ||
99 | * Peer's PEERSTORE Handle | ||
100 | */ | ||
101 | struct GNUNET_PEERSTORE_Handle *ph; | ||
102 | |||
103 | /** | ||
104 | * Hello get task | ||
105 | */ | ||
106 | struct GNUNET_SCHEDULER_Task *rh_task; | ||
107 | |||
108 | /** | ||
109 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
110 | */ | ||
111 | struct GNUNET_PEERSTORE_IterateContext *pic; | ||
112 | |||
113 | /** | ||
114 | * Hello | ||
115 | */ | ||
116 | char *hello; | ||
117 | |||
118 | /** | ||
119 | * Hello size | ||
120 | */ | ||
121 | size_t hello_size; | ||
122 | |||
123 | /** | ||
124 | * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create. | ||
125 | */ | ||
126 | char *system_label; | ||
127 | |||
128 | /** | ||
129 | * An unique number to identify the peer | ||
130 | */ | ||
131 | unsigned int no; | ||
132 | |||
133 | /** | ||
134 | * A map with struct GNUNET_MQ_Handle values for each peer this peer | ||
135 | * is connected to. | ||
136 | */ | ||
137 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
138 | |||
139 | /** | ||
140 | * Test setup for this peer. | ||
141 | */ | ||
142 | const struct GNUNET_TESTING_System *tl_system; | ||
143 | |||
144 | /** | ||
145 | * Callback which is called on neighbour connect events. | ||
146 | */ | ||
147 | GNUNET_TESTING_notify_connect_cb notify_connect; | ||
148 | |||
149 | /** | ||
150 | * Flag indicating, if udp broadcast should be switched on. | ||
151 | */ | ||
152 | enum GNUNET_GenericReturnValue broadcast; | ||
153 | }; | ||
154 | |||
31 | 155 | ||
32 | 156 | ||
33 | /** | 157 | /** |
@@ -52,30 +176,36 @@ GNUNET_TESTING_cmd_start_peer (const char *label, | |||
52 | 176 | ||
53 | struct GNUNET_TESTING_Command | 177 | struct GNUNET_TESTING_Command |
54 | GNUNET_TESTING_cmd_stop_peer (const char *label, | 178 | GNUNET_TESTING_cmd_stop_peer (const char *label, |
55 | const char *start_label); | 179 | const char *start_label); |
56 | 180 | ||
57 | 181 | ||
58 | /** | 182 | /** |
59 | * Create command | 183 | * Retrieve peer identity from the test system with the unique node id. |
60 | * | 184 | * |
61 | * @param label name for command | 185 | * @param num The unique node id. |
62 | * @param start_peer_label Label of the cmd to start a peer. | 186 | * @param tl_system The test system. |
63 | * @param create_label Label of the cmd which started the test system. | 187 | * @return The peer identity wrapping the public key. |
64 | * @param num Number globally identifying the node. | ||
65 | * @param topology The topology for the test setup. | ||
66 | * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd. | ||
67 | * @return command. | ||
68 | */ | 188 | */ |
69 | struct GNUNET_TESTING_Command | 189 | struct GNUNET_PeerIdentity * |
70 | GNUNET_CORE_cmd_connect_peers ( | 190 | GNUNET_TESTING_get_peer (unsigned int num, |
71 | const char *label, | 191 | const struct GNUNET_TESTING_System *tl_system); |
72 | const char *start_peer_label, | 192 | |
73 | const char *create_label, | 193 | |
74 | uint32_t num, | 194 | |
75 | struct GNUNET_TESTING_NetjailTopology *topology, | 195 | |
76 | unsigned int additional_connects, | 196 | /** |
77 | unsigned int wait_for_connect, | 197 | * Call #op on all simple traits. |
78 | struct GNUNET_MQ_MessageHandler *handlers); | 198 | */ |
199 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op) \ | ||
200 | op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ | ||
201 | op (peer_id, const struct GNUNET_PeerIdentity) \ | ||
202 | op (hello_size, const size_t) \ | ||
203 | op (hello, const char) \ | ||
204 | op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \ | ||
205 | op (state, const struct GNUNET_TESTING_StartPeerState) \ | ||
206 | op (broadcast, const enum GNUNET_GenericReturnValue) | ||
207 | |||
79 | 208 | ||
209 | GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
80 | 210 | ||
81 | #endif | 211 | #endif |