aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_core_testing_lib.h158
-rw-r--r--src/include/gnunet_testing_barrier.h15
-rw-r--r--src/include/gnunet_testing_loop_lib.h679
-rw-r--r--src/include/gnunet_testing_netjail_lib.h2
-rw-r--r--src/include/gnunet_testing_ng_lib.h951
-rw-r--r--src/include/gnunet_testing_plugin.h28
-rw-r--r--src/include/gnunet_transport_testing_ng_lib.h170
-rw-r--r--src/service/core/Makefile.am2
-rw-r--r--src/service/core/core_api_cmd_connecting_peers.c29
-rw-r--r--src/service/core/test_core_plugin_cmd_just_run.c1
-rw-r--r--src/service/dht/gnunet-service-dht.c2
-rw-r--r--src/service/dhtu/testing_dhtu_cmd_send.c10
-rw-r--r--src/service/peerstore/peerstore_api.c1
-rw-r--r--src/service/testing/Makefile.am2
-rw-r--r--src/service/testing/gnunet-cmds-helper.c4
-rw-r--r--src/service/testing/testing.h45
-rw-r--r--src/service/testing/testing_api_cmd_barrier.c62
-rw-r--r--src/service/testing/testing_api_cmd_barrier_reached.c14
-rw-r--r--src/service/testing/testing_api_cmd_batch.c14
-rw-r--r--src/service/testing/testing_api_cmd_netjail_start_cmds_helper.c85
-rw-r--r--src/service/testing/testing_api_loop.c567
-rw-r--r--src/service/testing/testing_api_traits.c6
-rw-r--r--src/service/testing/testing_cmds.h4
-rw-r--r--src/service/transport/Makefile.am2
-rw-r--r--src/service/transport/test_transport_plugin_cmd_nat_upnp.c4
-rw-r--r--src/service/transport/test_transport_plugin_cmd_simple_send.c4
-rw-r--r--src/service/transport/test_transport_plugin_cmd_simple_send_broadcast.c3
-rw-r--r--src/service/transport/test_transport_plugin_cmd_simple_send_dv.c7
-rw-r--r--src/service/transport/test_transport_plugin_cmd_simple_send_performance.c8
-rw-r--r--src/service/transport/test_transport_plugin_cmd_udp_backchannel.c4
-rw-r--r--src/service/transport/testing_api_cmd_start_peer.c (renamed from src/service/testing/testing_api_cmd_start_peer.c)7
-rw-r--r--src/service/transport/testing_api_cmd_stop_peer.c (renamed from src/service/testing/testing_api_cmd_stop_peer.c)2
-rw-r--r--src/service/transport/transport-testing-cmds.h132
-rw-r--r--src/service/transport/transport_api_cmd_backchannel_check.c4
-rw-r--r--src/service/transport/transport_api_cmd_connecting_peers.c18
-rw-r--r--src/service/transport/transport_api_cmd_send_simple.c4
-rw-r--r--src/service/transport/transport_api_cmd_send_simple_performance.c4
-rw-r--r--src/service/transport/transport_api_cmd_start_peer.c14
-rw-r--r--src/service/transport/transport_api_cmd_stop_peer.c4
-rw-r--r--src/service/transport/transport_api_traits.c2
41 files changed, 1563 insertions, 1513 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
37struct 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 */
136struct GNUNET_TESTING_Command
137GNUNET_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
154GNUNET_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
33struct 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 */
37struct GNUNET_TESTING_BarrierListEntry 42struct 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 */
57struct GNUNET_TESTING_BarrierList 63struct 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
106GNUNET_TESTING_cmd_barrier_reached ( 113GNUNET_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 */
56struct GNUNET_TESTING_Interpreter;
57
58/**
59 * State each asynchronous command must have in its closure.
60 */
61struct 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 */
93void
94GNUNET_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 */
102void
103GNUNET_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 */
113typedef 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 */
124typedef 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 */
138typedef 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 */
155struct GNUNET_TESTING_Command
156GNUNET_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 */
167struct 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 */
180void
181GNUNET_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 */
188struct 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.
305const struct GNUNET_TESTING_Command *
306GNUNET_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 */
318const struct GNUNET_TESTING_Command *
319GNUNET_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 */
333const struct GNUNET_TESTING_Command *
334GNUNET_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 */
344void
345GNUNET_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 */
360struct GNUNET_TESTING_Command
361GNUNET_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 */
375const struct GNUNET_TESTING_Command
376GNUNET_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 */
390struct GNUNET_TESTING_Command
391GNUNET_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 */
404typedef 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 */
421struct GNUNET_TESTING_Interpreter *
422GNUNET_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 */
438int
439GNUNET_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 */
452struct GNUNET_TESTING_Command
453GNUNET_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 */
466struct GNUNET_TESTING_Command
467GNUNET_TESTING_cmd_batch (const char *label,
468 struct GNUNET_TESTING_Command *batch);
469
470
471/**
472 * Performance counter.
473 */
474struct 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 */
509struct GNUNET_TESTING_Command
510GNUNET_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 */
524struct 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 */
550struct GNUNET_TESTING_Trait
551GNUNET_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 */
563enum GNUNET_GenericReturnValue
564GNUNET_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
667GNUNET_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
676GNUNET_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
33struct 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
544GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) 543GNUNET_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 */
60struct GNUNET_TESTING_Interpreter;
61
62/**
63 * State each asynchronous command must have in its closure.
64 */
65struct 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 */
99typedef 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 */
110typedef 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 */
124typedef 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 */
141struct GNUNET_TESTING_Command
142GNUNET_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 */
152struct 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.
268const struct GNUNET_TESTING_Command *
269GNUNET_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 */
281const struct GNUNET_TESTING_Command *
282GNUNET_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 */
295const struct GNUNET_TESTING_Command *
296GNUNET_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 */
307const char *
308GNUNET_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 */
317void
318GNUNET_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 */
326void
327GNUNET_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 */
335void
336GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
337
338
339/**
340 * Create command array terminator.
341 *
342 * @return a end-command.
343 */
344struct GNUNET_TESTING_Command
345GNUNET_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 */
360struct GNUNET_TESTING_Command
361GNUNET_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 */
375const struct GNUNET_TESTING_Command
376GNUNET_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 */
390struct GNUNET_TESTING_Command
391GNUNET_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 */
404typedef 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 */
421struct GNUNET_TESTING_Interpreter *
422GNUNET_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 */
438int
439GNUNET_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 */
453enum GNUNET_GenericReturnValue
454GNUNET_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 */
464enum GNUNET_GenericReturnValue
465GNUNET_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 */
477struct GNUNET_TESTING_Command 49struct GNUNET_TESTING_Command
478GNUNET_TESTING_cmd_signal (const char *label, 50GNUNET_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 */
506struct GNUNET_TESTING_Command
507GNUNET_TESTING_cmd_batch (const char *label,
508 struct GNUNET_TESTING_Command *batch);
509
510
511/**
512 * Performance counter.
513 */
514struct 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
551GNUNET_TESTING_cmd_exec_bash_script (const char *label, 77GNUNET_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 */
565struct GNUNET_PeerIdentity *
566GNUNET_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 */
576struct GNUNET_TESTING_Command
577GNUNET_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 */
591struct 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 */
617struct GNUNET_TESTING_Trait
618GNUNET_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 */
631enum GNUNET_GenericReturnValue
632GNUNET_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
641typedef 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 */
649struct 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 */
739struct 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
807struct 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
96GNUNET_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
1032GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
1033
1034GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) 112GNUNET_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
41struct 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
57typedef void 55typedef 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 */
78typedef struct GNUNET_TESTING_Interpreter * 77typedef 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 */
108typedef void 108typedef 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 */
117typedef struct GNUNET_TESTING_BarrierList* 119typedef 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 */
35struct GNUNET_TRANSPORT_ApplicationHandle;
36
37/**
38 * FIXME: what is this?
39 */
40struct GNUNET_TESTING_StartPeerState;
41
42
43// FIXME: breaks naming conventions
44typedef 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?
51struct 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
53struct GNUNET_TESTING_Command 177struct GNUNET_TESTING_Command
54GNUNET_TESTING_cmd_stop_peer (const char *label, 178GNUNET_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 */
69struct GNUNET_TESTING_Command 189struct GNUNET_PeerIdentity *
70GNUNET_CORE_cmd_connect_peers ( 190GNUNET_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
209GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
80 210
81#endif 211#endif
diff --git a/src/service/core/Makefile.am b/src/service/core/Makefile.am
index 482befae9..99506666b 100644
--- a/src/service/core/Makefile.am
+++ b/src/service/core/Makefile.am
@@ -41,6 +41,7 @@ libgnunet_test_core_plugin_cmd_just_run_la_LIBADD = \
41 libgnunetcoretesting.la \ 41 libgnunetcoretesting.la \
42 $(top_builddir)/src/service/transport/libgnunettransportapplication.la \ 42 $(top_builddir)/src/service/transport/libgnunettransportapplication.la \
43 $(top_builddir)/src/service/transport/libgnunettransportcore.la \ 43 $(top_builddir)/src/service/transport/libgnunettransportcore.la \
44 $(top_builddir)/src/service/transport/libgnunettransporttesting2.la \
44 $(top_builddir)/src/service/testing/libgnunettesting.la \ 45 $(top_builddir)/src/service/testing/libgnunettesting.la \
45 $(top_builddir)/src/service/peerstore/libgnunetpeerstore.la \ 46 $(top_builddir)/src/service/peerstore/libgnunetpeerstore.la \
46 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \ 47 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \
@@ -57,6 +58,7 @@ libgnunetcoretesting_la_LIBADD = \
57 $(top_builddir)/src/service/testing/libgnunettesting.la \ 58 $(top_builddir)/src/service/testing/libgnunettesting.la \
58 $(top_builddir)/src/service/arm/libgnunetarm.la \ 59 $(top_builddir)/src/service/arm/libgnunetarm.la \
59 $(top_builddir)/src/service/transport/libgnunettransportapplication.la \ 60 $(top_builddir)/src/service/transport/libgnunettransportapplication.la \
61 $(top_builddir)/src/service/transport/libgnunettransporttesting2.la \
60 $(top_builddir)/src/service/transport/libgnunettransportcore.la \ 62 $(top_builddir)/src/service/transport/libgnunettransportcore.la \
61 $(top_builddir)/src/lib/util/libgnunetutil.la 63 $(top_builddir)/src/lib/util/libgnunetutil.la
62libgnunetcoretesting_la_LDFLAGS = \ 64libgnunetcoretesting_la_LDFLAGS = \
diff --git a/src/service/core/core_api_cmd_connecting_peers.c b/src/service/core/core_api_cmd_connecting_peers.c
index 5a80ee415..97cb8c4a6 100644
--- a/src/service/core/core_api_cmd_connecting_peers.c
+++ b/src/service/core/core_api_cmd_connecting_peers.c
@@ -19,14 +19,14 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing_api_cmd_start_peer.c 22 * @file core_api_cmd_connecting_peers.c
23 * @brief cmd to start a peer. 23 * @brief cmd to start a peer.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_core_testing_lib.h"
29#include "gnunet_testing_netjail_lib.h" 29#include "gnunet_transport_testing_ng_lib.h"
30#include "gnunet_transport_application_service.h" 30#include "gnunet_transport_application_service.h"
31#include "gnunet_transport_core_service.h" 31#include "gnunet_transport_core_service.h"
32 32
@@ -209,15 +209,15 @@ connect_peers_traits (void *cls,
209 209
210 210
211struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
212GNUNET_CORE_cmd_connect_peers (const char *label, 212GNUNET_CORE_cmd_connect_peers (
213 const char *start_peer_label, 213 const char *label,
214 const char *create_label, 214 const char *start_peer_label,
215 uint32_t num, 215 const char *create_label,
216 struct GNUNET_TESTING_NetjailTopology * 216 uint32_t num,
217 topology, 217 struct GNUNET_TESTING_NetjailTopology *topology,
218 unsigned int additional_connects, 218 unsigned int additional_connects,
219 unsigned int wait_for_connect, 219 unsigned int wait_for_connect,
220 struct GNUNET_MQ_MessageHandler *handlers) 220 struct GNUNET_MQ_MessageHandler *handlers)
221{ 221{
222 struct GNUNET_TESTING_ConnectPeersState *cps; 222 struct GNUNET_TESTING_ConnectPeersState *cps;
223 unsigned int node_additional_connects; 223 unsigned int node_additional_connects;
@@ -271,3 +271,8 @@ GNUNET_CORE_cmd_connect_peers (const char *label,
271 &connect_peers_traits, 271 &connect_peers_traits,
272 NULL); 272 NULL);
273} 273}
274
275
276// FIXME: likely not ideally placed here, move to its own file
277GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
278
diff --git a/src/service/core/test_core_plugin_cmd_just_run.c b/src/service/core/test_core_plugin_cmd_just_run.c
index edb458577..3c77c370d 100644
--- a/src/service/core/test_core_plugin_cmd_just_run.c
+++ b/src/service/core/test_core_plugin_cmd_just_run.c
@@ -32,6 +32,7 @@
32#include "gnunet_testing_barrier.h" 32#include "gnunet_testing_barrier.h"
33#include "gnunet_core_service.h" 33#include "gnunet_core_service.h"
34#include "gnunet_transport_testing_ng_lib.h" 34#include "gnunet_transport_testing_ng_lib.h"
35#include "gnunet_core_testing_lib.h"
35 36
36/** 37/**
37 * Generic logging shortcut 38 * Generic logging shortcut
diff --git a/src/service/dht/gnunet-service-dht.c b/src/service/dht/gnunet-service-dht.c
index 0689af9aa..fcf83b0bc 100644
--- a/src/service/dht/gnunet-service-dht.c
+++ b/src/service/dht/gnunet-service-dht.c
@@ -24,8 +24,8 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Nathan Evans 25 * @author Nathan Evans
26 */ 26 */
27#include "gnunet_common.h"
28#include "platform.h" 27#include "platform.h"
28#include "gnunet_common.h"
29#include "gnunet_block_lib.h" 29#include "gnunet_block_lib.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_hello_uri_lib.h" 31#include "gnunet_hello_uri_lib.h"
diff --git a/src/service/dhtu/testing_dhtu_cmd_send.c b/src/service/dhtu/testing_dhtu_cmd_send.c
index 45d166b14..88449659c 100644
--- a/src/service/dhtu/testing_dhtu_cmd_send.c
+++ b/src/service/dhtu/testing_dhtu_cmd_send.c
@@ -88,11 +88,6 @@ send_run (void *cls,
88{ 88{
89 struct SendState *ss = cls; 89 struct SendState *ss = cls;
90 90
91#if 0
92 other_cmd = GNUNET_TESTING_interpreter_lookup_command (ss->other_label);
93 GNUNET_TESTING_get_trait_XXX (other_cmd,
94 &data);
95#endif
96 GNUNET_TESTING_async_finish (&ss->ac); 91 GNUNET_TESTING_async_finish (&ss->ac);
97} 92}
98 93
@@ -112,8 +107,9 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label)
112 .cleanup = &send_cleanup, 107 .cleanup = &send_cleanup,
113 .traits = &send_traits 108 .traits = &send_traits
114 }; 109 };
115 strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH); 110
116 111 GNUNET_TESTING_set_label (&cmd.label,
112 label);
117 return cmd; 113 return cmd;
118 } 114 }
119} 115}
diff --git a/src/service/peerstore/peerstore_api.c b/src/service/peerstore/peerstore_api.c
index cf29925a4..df0e1e226 100644
--- a/src/service/peerstore/peerstore_api.c
+++ b/src/service/peerstore/peerstore_api.c
@@ -23,7 +23,6 @@
23 * @author Omar Tarabai 23 * @author Omar Tarabai
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet_common.h"
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
29#include "gnunet_hello_uri_lib.h" 28#include "gnunet_hello_uri_lib.h"
diff --git a/src/service/testing/Makefile.am b/src/service/testing/Makefile.am
index 9ad48c619..3bad23f95 100644
--- a/src/service/testing/Makefile.am
+++ b/src/service/testing/Makefile.am
@@ -30,8 +30,6 @@ gnunet_cmds_helper_LDADD = $(XLIB) \
30 $(LTLIBINTL) $(Z_LIBS) 30 $(LTLIBINTL) $(Z_LIBS)
31 31
32libgnunettesting_la_SOURCES = \ 32libgnunettesting_la_SOURCES = \
33 testing_api_cmd_stop_peer.c \
34 testing_api_cmd_start_peer.c \
35 testing_api_cmd_exec_bash_script.c \ 33 testing_api_cmd_exec_bash_script.c \
36 testing_api_cmd_barrier.c \ 34 testing_api_cmd_barrier.c \
37 testing_api_cmd_barrier_reached.c \ 35 testing_api_cmd_barrier_reached.c \
diff --git a/src/service/testing/gnunet-cmds-helper.c b/src/service/testing/gnunet-cmds-helper.c
index 4428d4402..d262955cb 100644
--- a/src/service/testing/gnunet-cmds-helper.c
+++ b/src/service/testing/gnunet-cmds-helper.c
@@ -479,8 +479,8 @@ tokenizer_cb (void *cls,
479 LOG (GNUNET_ERROR_TYPE_DEBUG, 479 LOG (GNUNET_ERROR_TYPE_DEBUG,
480 "cross barrier %s\n", 480 "cross barrier %s\n",
481 barrier_name); 481 barrier_name);
482 TST_interpreter_finish_attached_cmds (is, 482 GNUNET_TESTING_finish_barrier_ (is,
483 barrier_name); 483 barrier_name);
484 return GNUNET_OK; 484 return GNUNET_OK;
485 } 485 }
486 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED: 486 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED:
diff --git a/src/service/testing/testing.h b/src/service/testing/testing.h
index fbd7d0d34..43c8ad45a 100644
--- a/src/service/testing/testing.h
+++ b/src/service/testing/testing.h
@@ -263,37 +263,24 @@ GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
263 * the cmd representing the barrier is finished. 263 * the cmd representing the barrier is finished.
264 * 264 *
265 * @param barrier The barrier in question. 265 * @param barrier The barrier in question.
266 * @return GNUNET_YES if we can cross the barrier, GNUNET_NO if not. 266 * @return true if we can cross the barrier, false if not.
267 */ 267 */
268unsigned int 268bool
269GNUNET_TESTING_barrier_crossable (struct GNUNET_TESTING_Barrier *barrier); 269GNUNET_TESTING_barrier_crossable_ (struct GNUNET_TESTING_Barrier *barrier);
270
271
272/**
273 * Send Message to a netjail node that a barrier can be crossed.
274 *
275 * @param is The interpreter loop.
276 * @param barrier_name The name of the barrier to cross.
277 * @param global_node_number The global number of the node to inform.
278 */
279void
280TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
281 const char *barrier_name,
282 unsigned int global_node_number);
283 270
284 271
285/** 272/**
286 * Finish all "barrier reached" comands attached to this barrier. 273 * Finish all "barrier reached" commands attached to this barrier.
287 * 274 *
288 * @param barrier The barrier in question. 275 * @param barrier The barrier in question.
289 */ 276 */
290void 277void
291TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, 278GNUNET_TESTING_finish_barrier_ (struct GNUNET_TESTING_Interpreter *is,
292 const char *barrier_name); 279 const char *barrier_name);
293 280
294 281
295/** 282/**
296 * Send Message to master loop that cmds being attached to a barrier. 283 * Send message to master loop that cmds being attached to a barrier.
297 * FIXME: Unused function 284 * FIXME: Unused function
298 * 285 *
299 * @param is The interpreter loop. 286 * @param is The interpreter loop.
@@ -303,11 +290,11 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
303 * @param write_message Callback to write messages to the master loop. 290 * @param write_message Callback to write messages to the master loop.
304 */ 291 */
305void 292void
306GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, 293GNUNET_TESTING_send_barrier_attach_ (struct GNUNET_TESTING_Interpreter *is,
307 char *barrier_name, 294 const char *barrier_name,
308 unsigned int global_node_number, 295 unsigned int global_node_number,
309 unsigned int expected_reaches, 296 unsigned int expected_reaches,
310 GNUNET_TESTING_cmd_helper_write_cb write_message); 297 GNUNET_TESTING_cmd_helper_write_cb write_message);
311 298
312 299
313/** 300/**
@@ -334,8 +321,8 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier,
334 * @return The barrier. 321 * @return The barrier.
335 */ 322 */
336struct GNUNET_TESTING_Barrier * 323struct GNUNET_TESTING_Barrier *
337TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, 324GNUNET_TESTING_get_barrier_ (struct GNUNET_TESTING_Interpreter *is,
338 const char *barrier_name); 325 const char *barrier_name);
339 326
340 327
341/** 328/**
@@ -345,8 +332,8 @@ TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is,
345 * @param barrier The barrier to add. 332 * @param barrier The barrier to add.
346 */ 333 */
347void 334void
348TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, 335GNUNET_TESTING_add_barrier_ (struct GNUNET_TESTING_Interpreter *is,
349 struct GNUNET_TESTING_Barrier *barrier); 336 struct GNUNET_TESTING_Barrier *barrier);
350 337
351 338
352#endif 339#endif
diff --git a/src/service/testing/testing_api_cmd_barrier.c b/src/service/testing/testing_api_cmd_barrier.c
index c9c43b178..ee074f35b 100644
--- a/src/service/testing/testing_api_cmd_barrier.c
+++ b/src/service/testing/testing_api_cmd_barrier.c
@@ -35,28 +35,31 @@
35 */ 35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 37
38
38struct BarrierState 39struct BarrierState
39{ 40{
40 /* 41 /**
41 * Our barrier. 42 * Our barrier, set to NULL once the barrier is active.
42 */ 43 */
43 struct GNUNET_TESTING_Barrier *barrier; 44 struct GNUNET_TESTING_Barrier *barrier;
44 45
45 /* 46 /**
46 * Our label. 47 * Our label.
47 */ 48 */
48 const char *label; 49 const char *label;
49}; 50};
50 51
52
51// FIXME Unused function 53// FIXME Unused function
52void 54void
53GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, 55GNUNET_TESTING_send_barrier_attach_ (
54 char *barrier_name, 56 struct GNUNET_TESTING_Interpreter *is,
55 unsigned int global_node_number, 57 const char *barrier_name,
56 unsigned int expected_reaches, 58 unsigned int global_node_number,
57 GNUNET_TESTING_cmd_helper_write_cb 59 unsigned int expected_reaches,
58 write_message) 60 GNUNET_TESTING_cmd_helper_write_cb write_message)
59{ 61{
62 // FIXME: avoid useless malloc!
60 struct CommandBarrierAttached *atm = GNUNET_new (struct 63 struct CommandBarrierAttached *atm = GNUNET_new (struct
61 CommandBarrierAttached); 64 CommandBarrierAttached);
62 size_t msg_length = sizeof(struct CommandBarrierAttached); 65 size_t msg_length = sizeof(struct CommandBarrierAttached);
@@ -74,8 +77,8 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is,
74} 77}
75 78
76 79
77unsigned int 80bool
78GNUNET_TESTING_barrier_crossable (struct GNUNET_TESTING_Barrier *barrier) 81GNUNET_TESTING_barrier_crossable_ (struct GNUNET_TESTING_Barrier *barrier)
79{ 82{
80 unsigned int expected_reaches = barrier->expected_reaches; 83 unsigned int expected_reaches = barrier->expected_reaches;
81 unsigned int reached = barrier->reached; 84 unsigned int reached = barrier->reached;
@@ -91,16 +94,10 @@ GNUNET_TESTING_barrier_crossable (struct GNUNET_TESTING_Barrier *barrier)
91 number_to_be_reached, 94 number_to_be_reached,
92 reached); 95 reached);
93 96
94 if (((0 < percentage_to_be_reached) && 97 return ( ( (0 < percentage_to_be_reached) &&
95 (percentage_reached >= percentage_to_be_reached)) || 98 (percentage_reached >= percentage_to_be_reached) ) ||
96 ((0 < number_to_be_reached) && (reached >= number_to_be_reached))) 99 ( (0 < number_to_be_reached) &&
97 { 100 (reached >= number_to_be_reached) ) );
98 return GNUNET_YES;
99 }
100 else
101 {
102 return GNUNET_NO;
103 }
104} 101}
105 102
106 103
@@ -123,7 +120,6 @@ barrier_traits (void *cls,
123 GNUNET_TESTING_trait_end () 120 GNUNET_TESTING_trait_end ()
124 }; 121 };
125 122
126 /* Always return current command. */
127 return GNUNET_TESTING_get_trait (traits, 123 return GNUNET_TESTING_get_trait (traits,
128 ret, 124 ret,
129 trait, 125 trait,
@@ -142,6 +138,7 @@ barrier_cleanup (void *cls)
142{ 138{
143 struct BarrierState *brs = cls; 139 struct BarrierState *brs = cls;
144 140
141 GNUNET_free (brs->barrier);
145 GNUNET_free (brs); 142 GNUNET_free (brs);
146} 143}
147 144
@@ -158,7 +155,9 @@ barrier_run (void *cls,
158{ 155{
159 struct BarrierState *brs = cls; 156 struct BarrierState *brs = cls;
160 157
161 TST_interpreter_add_barrier (is, brs->barrier); 158 GNUNET_TESTING_add_barrier_ (is,
159 brs->barrier);
160 brs->barrier = NULL;
162} 161}
163 162
164 163
@@ -169,11 +168,14 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier,
169 struct GNUNET_HashCode hc; 168 struct GNUNET_HashCode hc;
170 struct GNUNET_ShortHashCode key; 169 struct GNUNET_ShortHashCode key;
171 170
172 GNUNET_CRYPTO_hash (&(node_number), sizeof(node_number), &hc); 171 GNUNET_CRYPTO_hash (&node_number,
172 sizeof(node_number),
173 &hc);
173 memcpy (&key, 174 memcpy (&key,
174 &hc, 175 &hc,
175 sizeof (key)); 176 sizeof (key));
176 return GNUNET_CONTAINER_multishortmap_get (barrier->nodes, &key); 177 return GNUNET_CONTAINER_multishortmap_get (barrier->nodes,
178 &key);
177} 179}
178 180
179 181
@@ -191,8 +193,10 @@ GNUNET_TESTING_cmd_barrier_create (const char *label,
191 barrier->name = label; 193 barrier->name = label;
192 barrier->percentage_to_be_reached = percentage_to_be_reached; 194 barrier->percentage_to_be_reached = percentage_to_be_reached;
193 barrier->number_to_be_reached = number_to_be_reached; 195 barrier->number_to_be_reached = number_to_be_reached;
194 GNUNET_assert ((0 < percentage_to_be_reached && 0 == number_to_be_reached) || 196 GNUNET_assert ((0 < percentage_to_be_reached &&
195 (0 == percentage_to_be_reached && 0 < number_to_be_reached)); 197 0 == number_to_be_reached) ||
198 (0 == percentage_to_be_reached &&
199 0 < number_to_be_reached));
196 bs->barrier = barrier; 200 bs->barrier = barrier;
197 return GNUNET_TESTING_command_new (bs, label, 201 return GNUNET_TESTING_command_new (bs, label,
198 &barrier_run, 202 &barrier_run,
diff --git a/src/service/testing/testing_api_cmd_barrier_reached.c b/src/service/testing/testing_api_cmd_barrier_reached.c
index 161240d4d..54a36b91c 100644
--- a/src/service/testing/testing_api_cmd_barrier_reached.c
+++ b/src/service/testing/testing_api_cmd_barrier_reached.c
@@ -99,22 +99,22 @@ barrier_reached_run (void *cls,
99 struct GNUNET_TESTING_CommandBarrierReached *msg; 99 struct GNUNET_TESTING_CommandBarrierReached *msg;
100 size_t name_len; 100 size_t name_len;
101 101
102 barrier = TST_interpreter_get_barrier (is, brs->barrier_name); 102 barrier = GNUNET_TESTING_get_barrier_ (is,
103 brs->barrier_name);
103 if (NULL == barrier) 104 if (NULL == barrier)
104 { 105 {
105 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); 106 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
106 barrier->name = brs->barrier_name; 107 barrier->name = brs->barrier_name;
107 TST_interpreter_add_barrier (is, barrier); 108 GNUNET_TESTING_add_barrier_ (is,
108 LOG (GNUNET_ERROR_TYPE_DEBUG, 109 barrier);
109 "barrier %s added locally\n",
110 brs->barrier_name);
111 } 110 }
112 barrier->reached++; 111 barrier->reached++;
113 if (GNUNET_TESTING_barrier_crossable (barrier)) 112 if (GNUNET_TESTING_barrier_crossable_ (barrier))
114 { 113 {
115 GNUNET_assert (NULL != cmd); 114 GNUNET_assert (NULL != cmd);
116 cmd->asynchronous_finish = GNUNET_YES; 115 cmd->asynchronous_finish = GNUNET_YES;
117 TST_interpreter_finish_attached_cmds (is, barrier->name); 116 GNUNET_TESTING_finish_barrier_ (is,
117 barrier->name);
118 } 118 }
119 else if (GNUNET_NO == brs->asynchronous_finish) 119 else if (GNUNET_NO == brs->asynchronous_finish)
120 { 120 {
diff --git a/src/service/testing/testing_api_cmd_batch.c b/src/service/testing/testing_api_cmd_batch.c
index 7dc990855..2f1faf288 100644
--- a/src/service/testing/testing_api_cmd_batch.c
+++ b/src/service/testing/testing_api_cmd_batch.c
@@ -41,7 +41,7 @@ struct BatchState
41 /** 41 /**
42 * Our label. 42 * Our label.
43 */ 43 */
44 const char *label; 44 struct GNUNET_TESTING_CommandLabel label;
45 45
46 /** 46 /**
47 * Internal command pointer. 47 * Internal command pointer.
@@ -65,14 +65,14 @@ batch_run (void *cls,
65 if (NULL != bs->batch[bs->batch_ip].run) 65 if (NULL != bs->batch[bs->batch_ip].run)
66 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 66 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
67 "Running batched command: %s\n", 67 "Running batched command: %s\n",
68 bs->batch[bs->batch_ip].label); 68 bs->batch[bs->batch_ip].label.value);
69 69
70 /* hit end command, leap to next top-level command. */ 70 /* hit end command, leap to next top-level command. */
71 if (NULL == bs->batch[bs->batch_ip].run) 71 if (NULL == bs->batch[bs->batch_ip].run)
72 { 72 {
73 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
74 "Exiting from batch: %s\n", 74 "Exiting from batch: %s\n",
75 bs->label); 75 bs->label.value);
76 return; 76 return;
77 } 77 }
78 bs->batch[bs->batch_ip].start_time 78 bs->batch[bs->batch_ip].start_time
@@ -159,7 +159,8 @@ GNUNET_TESTING_cmd_batch (const char *label,
159 unsigned int i; 159 unsigned int i;
160 160
161 bs = GNUNET_new (struct BatchState); 161 bs = GNUNET_new (struct BatchState);
162 bs->label = label; 162 GNUNET_TESTING_set_label (&bs->label,
163 label);
163 /* Get number of commands. */ 164 /* Get number of commands. */
164 for (i = 0; NULL != batch[i].run; i++) 165 for (i = 0; NULL != batch[i].run; i++)
165 /* noop */ 166 /* noop */
@@ -170,7 +171,8 @@ GNUNET_TESTING_cmd_batch (const char *label,
170 memcpy (bs->batch, 171 memcpy (bs->batch,
171 batch, 172 batch,
172 sizeof (struct GNUNET_TESTING_Command) * i); 173 sizeof (struct GNUNET_TESTING_Command) * i);
173 return GNUNET_TESTING_command_new (bs, label, 174 return GNUNET_TESTING_command_new (bs,
175 label,
174 &batch_run, 176 &batch_run,
175 &batch_cleanup, 177 &batch_cleanup,
176 &batch_traits, NULL); 178 &batch_traits, NULL);
@@ -216,8 +218,6 @@ GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
216 218
217 /* sanity checks */ 219 /* sanity checks */
218 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd)); 220 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
219 for (unsigned int i = 0; i < new_ip; i++)
220 GNUNET_assert (NULL != bs->batch[i].label);
221 /* actual logic */ 221 /* actual logic */
222 bs->batch_ip = new_ip; 222 bs->batch_ip = new_ip;
223} 223}
diff --git a/src/service/testing/testing_api_cmd_netjail_start_cmds_helper.c b/src/service/testing/testing_api_cmd_netjail_start_cmds_helper.c
index df6a81cb4..792d7a8cf 100644
--- a/src/service/testing/testing_api_cmd_netjail_start_cmds_helper.c
+++ b/src/service/testing/testing_api_cmd_netjail_start_cmds_helper.c
@@ -353,9 +353,11 @@ barrier_attached (struct NetJailState *ns, const struct
353 353
354 am = (struct CommandBarrierAttached *) message; 354 am = (struct CommandBarrierAttached *) message;
355 barrier_name = (const char *) &am[1]; 355 barrier_name = (const char *) &am[1];
356 barrier = TST_interpreter_get_barrier (ns->is, barrier_name); 356 barrier = GNUNET_TESTING_get_barrier_ (ns->is,
357 barrier_name);
357 GNUNET_assert (NULL != barrier); 358 GNUNET_assert (NULL != barrier);
358 node = GNUNET_TESTING_barrier_get_node (barrier, am->node_number); 359 node = GNUNET_TESTING_barrier_get_node (barrier,
360 am->node_number);
359 if (NULL == node) 361 if (NULL == node)
360 { 362 {
361 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 363 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
@@ -374,18 +376,17 @@ barrier_attached (struct NetJailState *ns, const struct
374 376
375 377
376void 378void
377barrier_reached (struct NetJailState *ns, const struct 379barrier_reached (struct NetJailState *ns,
378 GNUNET_MessageHeader *message) 380 const struct GNUNET_MessageHeader *message)
379{ 381{
380 struct GNUNET_TESTING_Barrier *barrier; 382 struct GNUNET_TESTING_Barrier *barrier;
381 const char *barrier_name; 383 const char *barrier_name;
382 struct GNUNET_TESTING_CommandBarrierReached *rm = (struct 384 const struct GNUNET_TESTING_CommandBarrierReached *rm;
383 GNUNET_TESTING_CommandBarrierReached
384 *) message;
385 385
386 rm = (const struct GNUNET_TESTING_CommandBarrierReached *) message;
386 barrier_name = (const char *) &rm[1]; 387 barrier_name = (const char *) &rm[1];
387 388 barrier = GNUNET_TESTING_get_barrier_ (ns->is,
388 barrier = TST_interpreter_get_barrier (ns->is, barrier_name); 389 barrier_name);
389 GNUNET_assert (NULL != barrier); 390 GNUNET_assert (NULL != barrier);
390 LOG (GNUNET_ERROR_TYPE_DEBUG, 391 LOG (GNUNET_ERROR_TYPE_DEBUG,
391 "barrier %s reached %p %u\n", 392 "barrier %s reached %p %u\n",
@@ -397,12 +398,13 @@ barrier_reached (struct NetJailState *ns, const struct
397 "%u %p\n", 398 "%u %p\n",
398 barrier->reached, 399 barrier->reached,
399 barrier); 400 barrier);
400 if (GNUNET_TESTING_barrier_crossable (barrier)) 401 if (GNUNET_TESTING_barrier_crossable_ (barrier))
401 { 402 {
402 LOG (GNUNET_ERROR_TYPE_DEBUG, 403 LOG (GNUNET_ERROR_TYPE_DEBUG,
403 "%s can be crossed\n", 404 "%s can be crossed\n",
404 barrier_name); 405 barrier_name);
405 TST_interpreter_finish_attached_cmds (ns->is, barrier->name); 406 GNUNET_TESTING_finish_barrier_ (ns->is,
407 barrier->name);
406 } 408 }
407 LOG (GNUNET_ERROR_TYPE_DEBUG, 409 LOG (GNUNET_ERROR_TYPE_DEBUG,
408 "barrier %s reached finished\n", 410 "barrier %s reached finished\n",
@@ -616,10 +618,15 @@ start_helper (struct NetJailState *ns,
616 pid, 618 pid,
617 script_num); 619 script_num);
618 // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data); 620 // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
619 GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); 621 GNUNET_asprintf (&read_file,
622 "%u",
623 *(ns->read_file));
620 624
621 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 625 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
622 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT); 626 GNUNET_asprintf (&script_name,
627 "%s%s",
628 data_dir,
629 NETJAIL_EXEC_SCRIPT);
623 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 630 unsigned int helper_check = GNUNET_OS_check_helper_binary (
624 script_name, 631 script_name,
625 GNUNET_YES, 632 GNUNET_YES,
@@ -634,6 +641,7 @@ start_helper (struct NetJailState *ns,
634 "No SUID for %s!\n", 641 "No SUID for %s!\n",
635 script_name); 642 script_name);
636 GNUNET_TESTING_interpreter_fail (ns->is); 643 GNUNET_TESTING_interpreter_fail (ns->is);
644 // FIXME: why continue here, instead of returning?
637 } 645 }
638 else if (GNUNET_NO == helper_check) 646 else if (GNUNET_NO == helper_check)
639 { 647 {
@@ -672,17 +680,21 @@ start_helper (struct NetJailState *ns,
672 &helper_mst, 680 &helper_mst,
673 &exp_cb, 681 &exp_cb,
674 ns); 682 ns);
675 GNUNET_array_append (ns->helper, ns->n_helper, helper); 683 GNUNET_array_append (ns->helper,
684 ns->n_helper,
685 helper);
676 } 686 }
677 GNUNET_TESTING_add_netjail_helper (ns->is, 687 GNUNET_TESTING_add_netjail_helper_ (ns->is,
678 helper); 688 helper);
679 plugin_name = topology->plugin; 689 plugin_name = topology->plugin;
680 690
681 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 691 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
682 node = NULL; 692 node = NULL;
683 if (0 == n) 693 if (0 == n)
684 { 694 {
685 GNUNET_CRYPTO_hash (&m, sizeof(m), &hc); 695 GNUNET_CRYPTO_hash (&m,
696 sizeof(m),
697 &hc);
686 memcpy (hkey, 698 memcpy (hkey,
687 &hc, 699 &hc,
688 sizeof (*hkey)); 700 sizeof (*hkey));
@@ -732,44 +744,37 @@ start_helper (struct NetJailState *ns,
732 744
733 for (pos = barriers->head; NULL != pos; pos = pos->next) 745 for (pos = barriers->head; NULL != pos; pos = pos->next)
734 { 746 {
735 barrier = TST_interpreter_get_barrier (ns->is, pos->barrier_name); 747 barrier = GNUNET_TESTING_get_barrier_ (ns->is,
748 pos->barrier_name);
736 if (NULL == barrier) 749 if (NULL == barrier)
737 { 750 {
738 LOG (GNUNET_ERROR_TYPE_DEBUG,
739 "barrier %s added\n",
740 pos->barrier_name);
741 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); 751 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
742 barrier->name = pos->barrier_name; 752 barrier->name = pos->barrier_name;
743 barrier->shadow = GNUNET_YES; 753 barrier->shadow = GNUNET_YES;
744 TST_interpreter_add_barrier (ns->is, barrier); 754 GNUNET_TESTING_add_barrier_ (ns->is,
745 755 barrier);
746 LOG (GNUNET_ERROR_TYPE_DEBUG,
747 "%u %p\n",
748 barrier->reached,
749 barrier);
750
751 barrier->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
752 } 756 }
753 LOG (GNUNET_ERROR_TYPE_DEBUG,
754 "barrier %p %s node %u added \n",
755 barrier,
756 pos->barrier_name,
757 node->node_number);
758 barrier_node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 757 barrier_node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
759 barrier_node->node_number = node->node_number; 758 barrier_node->node_number = node->node_number;
760 barrier_node->expected_reaches = pos->expected_reaches; 759 barrier_node->expected_reaches = pos->expected_reaches;
761 barrier->expected_reaches = barrier->expected_reaches 760 barrier->expected_reaches = barrier->expected_reaches
762 + pos->expected_reaches; 761 + pos->expected_reaches;
763 LOG (GNUNET_ERROR_TYPE_DEBUG,
764 "number_to_be_reached %u\n",
765 barrier->number_to_be_reached);
766 if (GNUNET_YES == barrier->shadow) 762 if (GNUNET_YES == barrier->shadow)
767 barrier->number_to_be_reached++; 763 barrier->number_to_be_reached++;
768 LOG (GNUNET_ERROR_TYPE_DEBUG, 764 LOG (GNUNET_ERROR_TYPE_DEBUG,
769 "number_to_be_reached %u\n", 765 "Adding barrier %p %s node %u with reach target %u\n",
766 barrier,
767 pos->barrier_name,
768 node->node_number,
770 barrier->number_to_be_reached); 769 barrier->number_to_be_reached);
771 GNUNET_CRYPTO_hash (&(node->node_number), sizeof(node->node_number), &hc); 770 GNUNET_CRYPTO_hash (&node->node_number,
771 sizeof(node->node_number),
772 &hc);
772 memcpy (&key, &hc, sizeof (key)); 773 memcpy (&key, &hc, sizeof (key));
774 if (NULL == barrier->nodes)
775 barrier->nodes
776 = GNUNET_CONTAINER_multishortmap_create (16,
777 GNUNET_NO);
773 GNUNET_CONTAINER_multishortmap_put (barrier->nodes, 778 GNUNET_CONTAINER_multishortmap_put (barrier->nodes,
774 &key, 779 &key,
775 barrier_node, 780 barrier_node,
@@ -777,9 +782,7 @@ start_helper (struct NetJailState *ns,
777 } 782 }
778 783
779 tbc->plugin = plugin; 784 tbc->plugin = plugin;
780
781 msg = create_helper_init_msg_ (plugin_name); 785 msg = create_helper_init_msg_ (plugin_name);
782
783 tbc->shandle = GNUNET_HELPER_send ( 786 tbc->shandle = GNUNET_HELPER_send (
784 helper, 787 helper,
785 &msg->header, 788 &msg->header,
diff --git a/src/service/testing/testing_api_loop.c b/src/service/testing/testing_api_loop.c
index 559a61c38..beb9b9060 100644
--- a/src/service/testing/testing_api_loop.c
+++ b/src/service/testing/testing_api_loop.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021-2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -50,12 +50,6 @@ struct GNUNET_TESTING_Interpreter
50 struct GNUNET_HELPER_SendHandle *send_handle; 50 struct GNUNET_HELPER_SendHandle *send_handle;
51 51
52 /** 52 /**
53 * Size of the array helper.
54 *
55 */
56 unsigned int n_helper;
57
58 /**
59 * Function to call with the test result. 53 * Function to call with the test result.
60 */ 54 */
61 GNUNET_TESTING_ResultCallback rc; 55 GNUNET_TESTING_ResultCallback rc;
@@ -76,11 +70,6 @@ struct GNUNET_TESTING_Interpreter
76 struct GNUNET_CONTAINER_MultiShortmap *barriers; 70 struct GNUNET_CONTAINER_MultiShortmap *barriers;
77 71
78 /** 72 /**
79 * Number of GNUNET_TESTING_Command in commands.
80 */
81 unsigned int cmds_n;
82
83 /**
84 * Interpreter task (if one is scheduled). 73 * Interpreter task (if one is scheduled).
85 */ 74 */
86 struct GNUNET_SCHEDULER_Task *task; 75 struct GNUNET_SCHEDULER_Task *task;
@@ -96,6 +85,16 @@ struct GNUNET_TESTING_Interpreter
96 struct GNUNET_SCHEDULER_Task *timeout_task; 85 struct GNUNET_SCHEDULER_Task *timeout_task;
97 86
98 /** 87 /**
88 * Number of GNUNET_TESTING_Command in @e commands.
89 */
90 unsigned int cmds_n;
91
92 /**
93 * Size of the array @e helper.
94 */
95 unsigned int n_helper;
96
97 /**
99 * Instruction pointer. Tells #interpreter_run() which instruction to run 98 * Instruction pointer. Tells #interpreter_run() which instruction to run
100 * next. Need (signed) int because it gets -1 when rewinding the 99 * next. Need (signed) int because it gets -1 when rewinding the
101 * interpreter to the first CMD. 100 * interpreter to the first CMD.
@@ -110,31 +109,26 @@ struct GNUNET_TESTING_Interpreter
110 /** 109 /**
111 * Is the interpreter finishing? 110 * Is the interpreter finishing?
112 */ 111 */
113 unsigned int finishing; 112 bool finishing;
114
115};
116
117struct FreeBarrierNodeCbCls
118{
119 /**
120 * The interpreter.
121 */
122 struct GNUNET_TESTING_Interpreter *is;
123 113
124 /**
125 * The barrier from which the nodes are freed..
126 */
127 struct GNUNET_TESTING_Barrier *barrier;
128}; 114};
129 115
130 116
117/**
118 * Lookup command by label.
119 *
120 * @param is interpreter to lookup command in
121 * @param label label of the command to lookup.
122 * @param future true to look into the future, false to look into the past
123 * @return the command, if it is found, or NULL.
124 */
131static const struct GNUNET_TESTING_Command * 125static const struct GNUNET_TESTING_Command *
132get_command (struct GNUNET_TESTING_Interpreter *is, 126get_command (struct GNUNET_TESTING_Interpreter *is,
133 const char *label, 127 const char *label,
134 unsigned int future) 128 bool future)
135{ 129{
136 int start_i = GNUNET_NO == future ? is->ip : is->cmds_n - 1; 130 int start_i = future ? is->cmds_n - 1 : is->ip;
137 int end_i = GNUNET_NO == future ? 0 : is->ip + 1; 131 int end_i = future ? is->ip + 1 : 0;
138 132
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "start_i: %u end_i: %u\n", 134 "start_i: %u end_i: %u\n",
@@ -146,7 +140,6 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
146 "Attempt to lookup command for empty label\n"); 140 "Attempt to lookup command for empty label\n");
147 return NULL; 141 return NULL;
148 } 142 }
149
150 for (int i = start_i; i >= end_i; i--) 143 for (int i = start_i; i >= end_i; i--)
151 { 144 {
152 const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; 145 const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
@@ -154,10 +147,10 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
154 if (NULL != cmd->run) 147 if (NULL != cmd->run)
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "label to compare %s\n", 149 "label to compare %s\n",
157 cmd->label); 150 cmd->label.value);
158 /* Give precedence to top-level commands. */ 151 /* Give precedence to top-level commands. */
159 if ( (NULL != cmd->run) && 152 if ( (NULL != cmd->run) &&
160 (0 == strcmp (cmd->label, 153 (0 == strcmp (cmd->label.value,
161 label)) ) 154 label)) )
162 return cmd; 155 return cmd;
163 156
@@ -181,7 +174,7 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
181 if (current == icmd) 174 if (current == icmd)
182 break; /* do not go past current command */ 175 break; /* do not go past current command */
183 if ( (NULL != icmd->run) && 176 if ( (NULL != icmd->run) &&
184 (0 == strcmp (icmd->label, 177 (0 == strcmp (icmd->label.value,
185 label)) ) 178 label)) )
186 match = icmd; 179 match = icmd;
187 } 180 }
@@ -196,37 +189,25 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
196} 189}
197 190
198 191
199/**
200 * Lookup command by label.
201 * Only future commands are looked up.
202 *
203 * @param is interpreter to lookup command in
204 * @param label label of the command to lookup.
205 * @return the command, if it is found, or NULL.
206 */
207const struct GNUNET_TESTING_Command * 192const struct GNUNET_TESTING_Command *
208GNUNET_TESTING_interpreter_lookup_future_command ( 193GNUNET_TESTING_interpreter_lookup_future_command (
209 struct GNUNET_TESTING_Interpreter *is, 194 struct GNUNET_TESTING_Interpreter *is,
210 const char *label) 195 const char *label)
211{ 196{
212 return get_command (is, label, GNUNET_YES); 197 return get_command (is,
198 label,
199 true);
213} 200}
214 201
215 202
216/**
217 * Lookup command by label.
218 * Only commands from current command to commands in the past are looked up.
219 *
220 * @param is interpreter to lookup command in
221 * @param label label of the command to lookup.
222 * @return the command, if it is found, or NULL.
223 */
224const struct GNUNET_TESTING_Command * 203const struct GNUNET_TESTING_Command *
225GNUNET_TESTING_interpreter_lookup_command ( 204GNUNET_TESTING_interpreter_lookup_command (
226 struct GNUNET_TESTING_Interpreter *is, 205 struct GNUNET_TESTING_Interpreter *is,
227 const char *label) 206 const char *label)
228{ 207{
229 return get_command (is, label, GNUNET_NO); 208 return get_command (is,
209 label,
210 false);
230} 211}
231 212
232 213
@@ -237,14 +218,93 @@ GNUNET_TESTING_interpreter_lookup_command_all (
237{ 218{
238 const struct GNUNET_TESTING_Command *cmd; 219 const struct GNUNET_TESTING_Command *cmd;
239 220
240 cmd = get_command (is, label, GNUNET_NO); 221 cmd = get_command (is,
222 label,
223 false);
241 if (NULL == cmd) 224 if (NULL == cmd)
242 cmd = get_command (is, label, GNUNET_YES); 225 cmd = get_command (is,
226 label,
227 true);
243 return cmd; 228 return cmd;
244} 229}
245 230
246 231
247int 232/**
233 * Continuation function from GNUNET_HELPER_send()
234 *
235 * @param cls closure
236 * @param result #GNUNET_OK on success,
237 * #GNUNET_NO if helper process died
238 * #GNUNET_SYSERR during GNUNET_HELPER_stop()
239 */
240static void
241clear_msg (void *cls,
242 enum GNUNET_GenericReturnValue result)
243{
244 GNUNET_assert (GNUNET_YES == result);
245}
246
247
248/**
249 * Send message to a netjail node that a barrier can be crossed.
250 *
251 * @param is The interpreter loop.
252 * @param barrier_name The name of the barrier to cross.
253 * @param global_node_number The global number of the node to inform.
254 */
255static void
256send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
257 const char *barrier_name,
258 unsigned int global_node_number)
259{
260 struct CommandBarrierCrossable *adm;
261 size_t msg_length;
262 size_t name_len;
263
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "send barrier crossable for barrier `%s'\n",
266 barrier_name);
267 name_len = strlen (barrier_name);
268 msg_length = sizeof(struct CommandBarrierCrossable) + name_len + 1;
269 adm = GNUNET_malloc (msg_length);
270 adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE);
271 adm->header.size = htons ((uint16_t) msg_length);
272 memcpy (&adm[1], barrier_name, name_len);
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "send message of type %u to locals\n",
275 ntohs (adm->header.type));
276 /**
277 FIXME: This should probably be put into a linked list
278 inside is and cleaned up at some point.
279 */
280 is->send_handle = GNUNET_HELPER_send (
281 (struct GNUNET_HELPER_Handle *) is->helper[global_node_number - 1],
282 &adm->header,
283 GNUNET_NO,
284 &clear_msg,
285 NULL);
286 GNUNET_free (adm);
287}
288
289
290/**
291 * Closure for #free_barrier_node_cb().
292 */
293struct FreeBarrierNodeCbCls
294{
295 /**
296 * The interpreter.
297 */
298 struct GNUNET_TESTING_Interpreter *is;
299
300 /**
301 * The barrier from which the nodes are freed..
302 */
303 struct GNUNET_TESTING_Barrier *barrier;
304};
305
306
307static enum GNUNET_GenericReturnValue
248free_barrier_node_cb (void *cls, 308free_barrier_node_cb (void *cls,
249 const struct GNUNET_ShortHashCode *key, 309 const struct GNUNET_ShortHashCode *key,
250 void *value) 310 void *value)
@@ -256,21 +316,41 @@ free_barrier_node_cb (void *cls,
256 316
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
258 "free_barrier_node_cb\n"); 318 "free_barrier_node_cb\n");
259 if (GNUNET_NO == is->finishing) 319 if (! is->finishing)
260 { 320 {
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 send_barrier_crossable (is,
262 "TST_interpreter_send_barrier_crossable\n"); 322 barrier->name,
263 TST_interpreter_send_barrier_crossable (is, 323 node->node_number);
264 barrier->name,
265 node->node_number);
266 } 324 }
267 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove ( 325 GNUNET_assert (GNUNET_YES ==
268 barrier->nodes, key, node)); 326 GNUNET_CONTAINER_multishortmap_remove (
327 barrier->nodes,
328 key,
329 node));
269 return GNUNET_YES; 330 return GNUNET_YES;
270} 331}
271 332
272 333
273static int 334static void
335free_barrier_nodes (struct GNUNET_TESTING_Interpreter *is,
336 struct GNUNET_TESTING_Barrier *barrier)
337{
338 struct FreeBarrierNodeCbCls free_barrier_node_cb_cls = {
339 .barrier = barrier,
340 .is = is
341 };
342
343 if (NULL == barrier->nodes)
344 return;
345 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
346 free_barrier_node_cb,
347 &free_barrier_node_cb_cls);
348 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
349 barrier->nodes = NULL;
350}
351
352
353static enum GNUNET_GenericReturnValue
274free_barriers_cb (void *cls, 354free_barriers_cb (void *cls,
275 const struct GNUNET_ShortHashCode *key, 355 const struct GNUNET_ShortHashCode *key,
276 void *value) 356 void *value)
@@ -278,20 +358,9 @@ free_barriers_cb (void *cls,
278 struct GNUNET_TESTING_Interpreter *is = cls; 358 struct GNUNET_TESTING_Interpreter *is = cls;
279 struct GNUNET_TESTING_Barrier *barrier = value; 359 struct GNUNET_TESTING_Barrier *barrier = value;
280 struct CommandListEntry *pos; 360 struct CommandListEntry *pos;
281 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
282
283 if (NULL != barrier->nodes)
284 {
285 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
286 free_barrier_node_cb_cls->barrier = barrier;
287 free_barrier_node_cb_cls->is = is;
288 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
289 free_barrier_node_cb,
290 free_barrier_node_cb_cls);
291 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
292 barrier->nodes = NULL;
293 }
294 361
362 free_barrier_nodes (is,
363 barrier);
295 while (NULL != (pos = barrier->cmds_head)) 364 while (NULL != (pos = barrier->cmds_head))
296 { 365 {
297 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head, 366 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head,
@@ -305,21 +374,6 @@ free_barriers_cb (void *cls,
305 374
306 375
307/** 376/**
308 * Deleting all barriers create in the context of this interpreter.
309 *
310 * @param is The interpreter.
311 */
312static void
313interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
314{
315 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
316 free_barriers_cb,
317 is);
318 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
319}
320
321
322/**
323 * Finish the test run, return the final result. 377 * Finish the test run, return the final result.
324 * 378 *
325 * @param cls the `struct GNUNET_TESTING_Interpreter` 379 * @param cls the `struct GNUNET_TESTING_Interpreter`
@@ -331,9 +385,9 @@ finish_test (void *cls)
331 struct GNUNET_TESTING_Command *cmd; 385 struct GNUNET_TESTING_Command *cmd;
332 const char *label; 386 const char *label;
333 387
334 is->finishing = GNUNET_YES; 388 is->finishing = true;
335 is->final_task = NULL; 389 is->final_task = NULL;
336 label = is->commands[is->ip].label; 390 label = is->commands[is->ip].label.value;
337 if (NULL == is->commands[is->ip].run) 391 if (NULL == is->commands[is->ip].run)
338 label = "END"; 392 label = "END";
339 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 393 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -346,11 +400,11 @@ finish_test (void *cls)
346 { 400 {
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Cleaning up cmd %s\n", 402 "Cleaning up cmd %s\n",
349 cmd->label); 403 cmd->label.value);
350 cmd->cleanup (cmd->cls); 404 cmd->cleanup (cmd->cls);
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
352 "Cleaned up cmd %s\n", 406 "Cleaned up cmd %s\n",
353 cmd->label); 407 cmd->label.value);
354 } 408 }
355 if (NULL != is->task) 409 if (NULL != is->task)
356 { 410 {
@@ -370,7 +424,10 @@ finish_test (void *cls)
370 GNUNET_free (is->commands); 424 GNUNET_free (is->commands);
371 is->rc (is->rc_cls, 425 is->rc (is->rc_cls,
372 is->result); 426 is->result);
373 interpreter_delete_barriers (is); 427 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
428 free_barriers_cb,
429 is);
430 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
374 GNUNET_free (is->helper); 431 GNUNET_free (is->helper);
375 GNUNET_free (is); 432 GNUNET_free (is);
376} 433}
@@ -432,13 +489,13 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
432 { 489 {
433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 490 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
434 "Failed at command `%s'\n", 491 "Failed at command `%s'\n",
435 cmd->label); 492 cmd->label.value);
436 while (GNUNET_TESTING_cmd_is_batch_ (cmd)) 493 while (GNUNET_TESTING_cmd_is_batch_ (cmd))
437 { 494 {
438 cmd = GNUNET_TESTING_cmd_batch_get_current_ (cmd); 495 cmd = GNUNET_TESTING_cmd_batch_get_current_ (cmd);
439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
440 "Failed in batch at command `%s'\n", 497 "Failed in batch at command `%s'\n",
441 cmd->label); 498 cmd->label.value);
442 } 499 }
443 } 500 }
444 else 501 else
@@ -453,6 +510,33 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
453} 510}
454 511
455 512
513void
514GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac)
515{
516 GNUNET_assert (GNUNET_NO == ac->finished);
517 ac->finished = GNUNET_SYSERR;
518 GNUNET_TESTING_interpreter_fail (ac->is);
519 if (NULL != ac->cont)
520 {
521 ac->cont (ac->cont_cls);
522 ac->cont = NULL;
523 }
524}
525
526
527void
528GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac)
529{
530 GNUNET_assert (GNUNET_NO == ac->finished);
531 ac->finished = GNUNET_OK;
532 if (NULL != ac->cont)
533 {
534 ac->cont (ac->cont_cls);
535 ac->cont = NULL;
536 }
537}
538
539
456/** 540/**
457 * Returns the actual running command. 541 * Returns the actual running command.
458 * 542 *
@@ -468,16 +552,6 @@ GNUNET_TESTING_interpreter_get_current_command (
468} 552}
469 553
470 554
471const char *
472GNUNET_TESTING_interpreter_get_current_label (
473 struct GNUNET_TESTING_Interpreter *is)
474{
475 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
476
477 return cmd->label;
478}
479
480
481/** 555/**
482 * Run the main interpreter loop. 556 * Run the main interpreter loop.
483 * 557 *
@@ -500,7 +574,7 @@ interpreter_run (void *cls)
500 } 574 }
501 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 575 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
502 "Running command `%s'\n", 576 "Running command `%s'\n",
503 cmd->label); 577 cmd->label.value);
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "start time of %p expected 0 is `%" PRIu64 "'\n", 579 "start time of %p expected 0 is `%" PRIu64 "'\n",
506 cmd, 580 cmd,
@@ -508,17 +582,13 @@ interpreter_run (void *cls)
508 cmd->start_time 582 cmd->start_time
509 = cmd->last_req_time 583 = cmd->last_req_time
510 = GNUNET_TIME_absolute_get (); 584 = GNUNET_TIME_absolute_get ();
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 "start time of %p expected something is `%" PRIu64 "'\n",
513 cmd,
514 cmd->start_time.abs_value_us);
515 cmd->num_tries = 1; 585 cmd->num_tries = 1;
516 if (NULL != cmd->ac) 586 if (NULL != cmd->ac)
517 { 587 {
518 cmd->ac->is = is; 588 cmd->ac->is = is;
519 cmd->ac->cont = &interpreter_next; 589 cmd->ac->cont = &interpreter_next;
520 cmd->ac->cont_cls = is; 590 cmd->ac->cont_cls = is;
521 cmd->ac->finished = GNUNET_NO; 591 cmd->ac->finished = false;
522 } 592 }
523 cmd->run (cmd->cls, 593 cmd->run (cmd->cls,
524 is); 594 is);
@@ -553,25 +623,6 @@ do_timeout (void *cls)
553} 623}
554 624
555 625
556enum GNUNET_GenericReturnValue
557GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command)
558{
559 return 0 != command->start_time.abs_value_us && 0 ==
560 command->finish_time.abs_value_us;
561}
562
563
564enum GNUNET_GenericReturnValue
565GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command)
566{
567 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
568 struct GNUNET_TIME_Relative diff = GNUNET_TIME_absolute_get_difference (
569 command->finish_time,
570 now);
571 return 0 < diff.rel_value_us;
572}
573
574
575struct GNUNET_TESTING_Interpreter * 626struct GNUNET_TESTING_Interpreter *
576GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, 627GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
577 struct GNUNET_TIME_Relative timeout, 628 struct GNUNET_TIME_Relative timeout,
@@ -629,17 +680,28 @@ GNUNET_TESTING_command_new (void *cls,
629 680
630 GNUNET_assert (NULL != run); 681 GNUNET_assert (NULL != run);
631 if (NULL != label) 682 if (NULL != label)
632 { 683 GNUNET_TESTING_set_label (&cmd.label,
633 GNUNET_assert (strlen (label) <= 684 label);
634 GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
635 strncpy (cmd.label,
636 label,
637 GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
638 }
639 return cmd; 685 return cmd;
640} 686}
641 687
642 688
689void
690GNUNET_TESTING_set_label (struct GNUNET_TESTING_CommandLabel *label,
691 const char *value)
692{
693 size_t len;
694
695 len = strlen (value);
696 GNUNET_assert (len <=
697 GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
698 memcpy (label->value,
699 value,
700 len + 1);
701}
702
703
704
643struct GNUNET_TESTING_Command 705struct GNUNET_TESTING_Command
644GNUNET_TESTING_cmd_end (void) 706GNUNET_TESTING_cmd_end (void)
645{ 707{
@@ -712,118 +774,101 @@ loop_run (void *cls)
712} 774}
713 775
714 776
715/** 777int
716 * Continuation function from GNUNET_HELPER_send() 778GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
717 * 779 struct GNUNET_TIME_Relative timeout)
718 * @param cls closure
719 * @param result #GNUNET_OK on success,
720 * #GNUNET_NO if helper process died
721 * #GNUNET_SYSERR during GNUNET_HELPER_stop()
722 */
723static void
724clear_msg (void *cls, int result)
725{ 780{
726 GNUNET_assert (GNUNET_YES == result); 781 struct MainParams mp = {
727} 782 .commands = commands,
728 783 .timeout = timeout,
784 .rv = EXIT_SUCCESS
785 };
729 786
730/** 787 GNUNET_SCHEDULER_run (&loop_run,
731 * Adding a helper handle to the interpreter. 788 &mp);
732 * 789 return mp.rv;
733 * @param is The interpreter.
734 * @param helper The helper handle.
735 */
736void
737GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is,
738 const struct GNUNET_HELPER_Handle *helper)
739{
740 GNUNET_array_append (is->helper, is->n_helper, helper);
741} 790}
742 791
743 792
744void 793void
745TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, 794GNUNET_TESTING_add_netjail_helper_ (struct GNUNET_TESTING_Interpreter *is,
746 const char *barrier_name, 795 const struct GNUNET_HELPER_Handle *helper)
747 unsigned int global_node_number)
748{ 796{
749 struct CommandBarrierCrossable *adm; 797 GNUNET_array_append (is->helper,
750 size_t msg_length; 798 is->n_helper,
751 size_t name_len; 799 helper);
752
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 "send barrier name %s barrier_name\n",
755 barrier_name);
756 name_len = strlen (barrier_name);
757 msg_length = sizeof(struct CommandBarrierCrossable) + name_len + 1;
758 adm = GNUNET_malloc (msg_length);
759 adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE);
760 adm->header.size = htons ((uint16_t) msg_length);
761 memcpy (&adm[1], barrier_name, name_len);
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "send message of type %u to locals\n",
764 ntohs (adm->header.type));
765 /**
766 FIXME: This should probably be put into a linked list
767 inside is and cleaned up at some point.
768 */
769 is->send_handle = GNUNET_HELPER_send (
770 (struct GNUNET_HELPER_Handle *) is->helper[global_node_number - 1],
771 &adm->header,
772 GNUNET_NO,
773 &clear_msg,
774 NULL);
775 GNUNET_free (adm);
776} 800}
777 801
778 802
779/**
780 * Getting a barrier from the interpreter.
781 *
782 * @param is The interpreter.
783 * @param barrier_name The name of the barrier.
784 * @return The barrier.
785 */
786struct GNUNET_TESTING_Barrier * 803struct GNUNET_TESTING_Barrier *
787TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, 804GNUNET_TESTING_get_barrier_ (struct GNUNET_TESTING_Interpreter *is,
788 const char *barrier_name) 805 const char *barrier_name)
789{ 806{
790 struct GNUNET_HashCode hc; 807 struct GNUNET_HashCode hc;
791 struct GNUNET_ShortHashCode create_key; 808 struct GNUNET_ShortHashCode create_key;
792 struct GNUNET_TESTING_Barrier *barrier;
793 809
794 GNUNET_CRYPTO_hash (barrier_name, strlen (barrier_name), &hc); 810 GNUNET_CRYPTO_hash (barrier_name,
811 strlen (barrier_name),
812 &hc);
795 memcpy (&create_key, 813 memcpy (&create_key,
796 &hc, 814 &hc,
797 sizeof (create_key)); 815 sizeof (create_key));
798 barrier = GNUNET_CONTAINER_multishortmap_get (is->barriers, &create_key); 816 return GNUNET_CONTAINER_multishortmap_get (is->barriers,
799 return barrier; 817 &create_key);
800} 818}
801 819
802 820
803/** 821/**
804 * Finish all "barrier reached" comands attached to this barrier. 822 * Add a barrier to the interpreter.
805 * 823 *
806 * @param barrier The barrier in question. 824 * @param is The interpreter.
825 * @param barrier The barrier to add.
807 */ 826 */
808void 827void
809TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, 828GNUNET_TESTING_add_barrier_ (struct GNUNET_TESTING_Interpreter *is,
810 const char *barrier_name) 829 struct GNUNET_TESTING_Barrier *barrier)
830{
831 struct GNUNET_HashCode hc;
832 struct GNUNET_ShortHashCode create_key;
833
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Adding barrier %s locally\n",
836 barrier->name);
837 GNUNET_CRYPTO_hash (barrier->name,
838 strlen (barrier->name),
839 &hc);
840 memcpy (&create_key,
841 &hc,
842 sizeof (create_key));
843 GNUNET_CONTAINER_multishortmap_put (is->barriers,
844 &create_key,
845 barrier,
846 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
847}
848
849
850void
851GNUNET_TESTING_finish_barrier_ (struct GNUNET_TESTING_Interpreter *is,
852 const char *barrier_name)
811{ 853{
812 struct CommandListEntry *pos; 854 struct CommandListEntry *pos;
813 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is, 855 struct GNUNET_TESTING_Barrier *barrier;
814 barrier_name);
815 856
816 while (NULL != barrier && NULL != (pos = barrier->cmds_head)) 857 barrier = GNUNET_TESTING_get_barrier_ (is,
858 barrier_name);
859 if (NULL == barrier)
860 return;
861 while (NULL != (pos = barrier->cmds_head))
817 { 862 {
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
819 "command label %s\n", 864 "command label %s\n",
820 pos->command->label); 865 pos->command->label.value);
821 if (GNUNET_NO == pos->command->ac->finished && 866 if ( (GNUNET_NO == pos->command->ac->finished) &&
822 GNUNET_NO == pos->command->asynchronous_finish) 867 (GNUNET_NO == pos->command->asynchronous_finish) )
823 { 868 {
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "command label %s finish\n", 870 "command label %s finish\n",
826 pos->command->label); 871 pos->command->label.value);
827 GNUNET_TESTING_async_finish (pos->command->ac); 872 GNUNET_TESTING_async_finish (pos->command->ac);
828 } 873 }
829 else if (GNUNET_NO == pos->command->ac->finished) 874 else if (GNUNET_NO == pos->command->ac->finished)
@@ -835,95 +880,13 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
835 pos); 880 pos);
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "command entry label %s removed\n", 882 "command entry label %s removed\n",
838 pos->command->label); 883 pos->command->label.value);
839 GNUNET_free (pos); 884 GNUNET_free (pos);
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "command entry freed\n"); 886 "command entry freed\n");
842 } 887 }
843 if (NULL != barrier->nodes) 888 free_barrier_nodes (is,
844 { 889 barrier);
845 struct FreeBarrierNodeCbCls free_barrier_node_cb_cls = {
846 .barrier = barrier,
847 .is = is
848 };
849
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
851 "freeing nodes\n");
852 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
853 &free_barrier_node_cb,
854 &free_barrier_node_cb_cls);
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "nodes freed\n");
857 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
858 barrier->nodes = NULL;
859 }
860}
861
862
863/**
864 * Add a barrier to the loop.
865 *
866 * @param is The interpreter.
867 * @param barrier The barrier to add.
868 */
869void
870TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is,
871 struct GNUNET_TESTING_Barrier *barrier)
872{
873 struct GNUNET_HashCode hc;
874 struct GNUNET_ShortHashCode create_key;
875
876 GNUNET_CRYPTO_hash (barrier->name, strlen (barrier->name), &hc);
877 memcpy (&create_key,
878 &hc,
879 sizeof (create_key));
880 GNUNET_CONTAINER_multishortmap_put (is->barriers,
881 &create_key,
882 barrier,
883 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
884}
885
886
887int
888GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
889 struct GNUNET_TIME_Relative timeout)
890{
891 struct MainParams mp = {
892 .commands = commands,
893 .timeout = timeout,
894 .rv = EXIT_SUCCESS
895 };
896
897 GNUNET_SCHEDULER_run (&loop_run,
898 &mp);
899 return mp.rv;
900}
901
902
903void
904GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac)
905{
906 GNUNET_assert (GNUNET_NO == ac->finished);
907 ac->finished = GNUNET_SYSERR;
908 GNUNET_TESTING_interpreter_fail (ac->is);
909 if (NULL != ac->cont)
910 {
911 ac->cont (ac->cont_cls);
912 ac->cont = NULL;
913 }
914}
915
916
917void
918GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac)
919{
920 GNUNET_assert (GNUNET_NO == ac->finished);
921 ac->finished = GNUNET_OK;
922 if (NULL != ac->cont)
923 {
924 ac->cont (ac->cont_cls);
925 ac->cont = NULL;
926 }
927} 890}
928 891
929 892
diff --git a/src/service/testing/testing_api_traits.c b/src/service/testing/testing_api_traits.c
index ee3edbed0..ddd04ac30 100644
--- a/src/service/testing/testing_api_traits.c
+++ b/src/service/testing/testing_api_traits.c
@@ -32,10 +32,16 @@
32#include "gnunet_testing_netjail_lib.h" 32#include "gnunet_testing_netjail_lib.h"
33 33
34 34
35/* FIXME: move these into respective sub-libs? */
36
35GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT) 37GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
36 38
37GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT) 39GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT)
38 40
41GNUNET_TESTING_LOOP_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
42
43GNUNET_TESTING_LOOP_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT)
44
39GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT) 45GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
40 46
41/** 47/**
diff --git a/src/service/testing/testing_cmds.h b/src/service/testing/testing_cmds.h
index 9c261aab5..f4549477e 100644
--- a/src/service/testing/testing_cmds.h
+++ b/src/service/testing/testing_cmds.h
@@ -136,8 +136,8 @@ GNUNET_TESTING_interpreter_get_current_command (
136 * @param helper The helper handle. 136 * @param helper The helper handle.
137 */ 137 */
138void 138void
139GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is, 139GNUNET_TESTING_add_netjail_helper_ (struct GNUNET_TESTING_Interpreter *is,
140 const struct GNUNET_HELPER_Handle *helper); 140 const struct GNUNET_HELPER_Handle *helper);
141 141
142#endif 142#endif
143/* end of testing_cmds.h */ 143/* end of testing_cmds.h */
diff --git a/src/service/transport/Makefile.am b/src/service/transport/Makefile.am
index e5a3fe9bd..fd1ce535c 100644
--- a/src/service/transport/Makefile.am
+++ b/src/service/transport/Makefile.am
@@ -30,6 +30,8 @@ lib_LTLIBRARIES = \
30 30
31libgnunettransporttesting2_la_SOURCES = \ 31libgnunettransporttesting2_la_SOURCES = \
32 transport_api_traits.c \ 32 transport_api_traits.c \
33 testing_api_cmd_stop_peer.c \
34 testing_api_cmd_start_peer.c \
33 transport_api_cmd_connecting_peers.c \ 35 transport_api_cmd_connecting_peers.c \
34 transport_api_cmd_backchannel_check.c \ 36 transport_api_cmd_backchannel_check.c \
35 transport_api_cmd_start_peer.c \ 37 transport_api_cmd_start_peer.c \
diff --git a/src/service/transport/test_transport_plugin_cmd_nat_upnp.c b/src/service/transport/test_transport_plugin_cmd_nat_upnp.c
index 9d7c5d856..4163ab68b 100644
--- a/src/service/transport/test_transport_plugin_cmd_nat_upnp.c
+++ b/src/service/transport/test_transport_plugin_cmd_nat_upnp.c
@@ -148,8 +148,8 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
148 148
149 cmd = GNUNET_TESTING_interpreter_lookup_command (is, 149 cmd = GNUNET_TESTING_interpreter_lookup_command (is,
150 "connect-peers"); 150 "connect-peers");
151 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, 151 GNUNET_TESTING_get_trait_connect_peer_state (cmd,
152 &cps); 152 &cps);
153 void *ret = NULL; 153 void *ret = NULL;
154 154
155 cps->notify_connect (is, 155 cps->notify_connect (is,
diff --git a/src/service/transport/test_transport_plugin_cmd_simple_send.c b/src/service/transport/test_transport_plugin_cmd_simple_send.c
index c6d75cce4..9f34d4bcc 100644
--- a/src/service/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/service/transport/test_transport_plugin_cmd_simple_send.c
@@ -151,8 +151,8 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
151 151
152 cmd = GNUNET_TESTING_interpreter_lookup_command (is, 152 cmd = GNUNET_TESTING_interpreter_lookup_command (is,
153 "connect-peers"); 153 "connect-peers");
154 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, 154 GNUNET_TESTING_get_trait_connect_peer_state (cmd,
155 &cps); 155 &cps);
156 void *ret = NULL; 156 void *ret = NULL;
157 157
158 cps->notify_connect (is, 158 cps->notify_connect (is,
diff --git a/src/service/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/service/transport/test_transport_plugin_cmd_simple_send_broadcast.c
index d2870ab34..a63b6e926 100644
--- a/src/service/transport/test_transport_plugin_cmd_simple_send_broadcast.c
+++ b/src/service/transport/test_transport_plugin_cmd_simple_send_broadcast.c
@@ -154,10 +154,8 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
154 154
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "notify_connect\n"); 156 "notify_connect\n");
157
158 GNUNET_TESTING_get_trait_async_context (&connect_peers, 157 GNUNET_TESTING_get_trait_async_context (&connect_peers,
159 &ac); 158 &ac);
160
161 if (NULL != ac->is) 159 if (NULL != ac->is)
162 { 160 {
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -172,7 +170,6 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
172 { 170 {
173 cmd = GNUNET_TESTING_interpreter_lookup_future_command (is, 171 cmd = GNUNET_TESTING_interpreter_lookup_future_command (is,
174 "connect-peers"); 172 "connect-peers");
175
176 LOG (GNUNET_ERROR_TYPE_DEBUG, 173 LOG (GNUNET_ERROR_TYPE_DEBUG,
177 "block state %s\n", 174 "block state %s\n",
178 cmd->label); 175 cmd->label);
diff --git a/src/service/transport/test_transport_plugin_cmd_simple_send_dv.c b/src/service/transport/test_transport_plugin_cmd_simple_send_dv.c
index d35672cd9..695344287 100644
--- a/src/service/transport/test_transport_plugin_cmd_simple_send_dv.c
+++ b/src/service/transport/test_transport_plugin_cmd_simple_send_dv.c
@@ -91,11 +91,10 @@ handle_test (void *cls,
91 struct GNUNET_TRANSPORT_CoreHandle *ch; 91 struct GNUNET_TRANSPORT_CoreHandle *ch;
92 const struct GNUNET_TESTING_StartPeerState *sps; 92 const struct GNUNET_TESTING_StartPeerState *sps;
93 93
94 94 GNUNET_TESTING_get_trait_state (&start_peer,
95 GNUNET_TRANSPORT_get_trait_state (&start_peer,
96 &sps); 95 &sps);
97 ch = sps->th; 96 ch = sps->th;
98 GNUNET_TRANSPORT_get_trait_connected_peers_map (&start_peer, 97 GNUNET_TESTING_get_trait_connected_peers_map (&start_peer,
99 &connected_peers_map); 98 &connected_peers_map);
100 99
101 if (NULL != connected_peers_map) 100 if (NULL != connected_peers_map)
@@ -211,7 +210,7 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
211 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is, 210 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
212 "connect-peers"); 211 "connect-peers");
213 // FIXME: check return value! 212 // FIXME: check return value!
214 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, 213 GNUNET_TESTING_get_trait_connect_peer_state (cmd,
215 &cps); 214 &cps);
216 cps->notify_connect (is, 215 cps->notify_connect (is,
217 peer); 216 peer);
diff --git a/src/service/transport/test_transport_plugin_cmd_simple_send_performance.c b/src/service/transport/test_transport_plugin_cmd_simple_send_performance.c
index 2baa7b5b4..d44eab9e1 100644
--- a/src/service/transport/test_transport_plugin_cmd_simple_send_performance.c
+++ b/src/service/transport/test_transport_plugin_cmd_simple_send_performance.c
@@ -114,8 +114,8 @@ handle_test (void *cls,
114 const struct GNUNET_TESTING_StartPeerState *sps; 114 const struct GNUNET_TESTING_StartPeerState *sps;
115 115
116 116
117 GNUNET_TRANSPORT_get_trait_state (&start_peer, 117 GNUNET_TESTING_get_trait_state (&start_peer,
118 &sps); 118 &sps);
119 ch = sps->th; 119 ch = sps->th;
120 num = ntohl (message->num); 120 num = ntohl (message->num);
121 GNUNET_TESTING_get_trait_async_context (&block_receive, 121 GNUNET_TESTING_get_trait_async_context (&block_receive,
@@ -254,8 +254,8 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
254 254
255 cmd = GNUNET_TESTING_interpreter_lookup_command (is, 255 cmd = GNUNET_TESTING_interpreter_lookup_command (is,
256 "connect-peers"); 256 "connect-peers");
257 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, 257 GNUNET_TESTING_get_trait_connect_peer_state (cmd,
258 &cps); 258 &cps);
259 void *ret = NULL; 259 void *ret = NULL;
260 260
261 cps->notify_connect (is, 261 cps->notify_connect (is,
diff --git a/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
index 378caf7df..15677eca8 100644
--- a/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -146,8 +146,8 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
146{ 146{
147 const struct ConnectPeersState *cps; 147 const struct ConnectPeersState *cps;
148 148
149 GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers, 149 GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
150 &cps); 150 &cps);
151 void *ret = NULL; 151 void *ret = NULL;
152 152
153 cps->notify_connect (is, 153 cps->notify_connect (is,
diff --git a/src/service/testing/testing_api_cmd_start_peer.c b/src/service/transport/testing_api_cmd_start_peer.c
index cd4536131..3932be74b 100644
--- a/src/service/testing/testing_api_cmd_start_peer.c
+++ b/src/service/transport/testing_api_cmd_start_peer.c
@@ -25,9 +25,10 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "testing_cmds.h" 28#include "transport-testing-cmds.h"
29#include "gnunet_testing_ng_lib.h" 29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_netjail_lib.h" 30#include "gnunet_transport_testing_ng_lib.h"
31
31 32
32/** 33/**
33 * Generic logging shortcut 34 * Generic logging shortcut
@@ -246,8 +247,6 @@ start_peer_traits (void *cls,
246 sps->connected_peers_map; 247 sps->connected_peers_map;
247 char *hello = sps->hello; 248 char *hello = sps->hello;
248 size_t hello_size = sps->hello_size; 249 size_t hello_size = sps->hello_size;
249
250
251 struct GNUNET_TESTING_Trait traits[] = { 250 struct GNUNET_TESTING_Trait traits[] = {
252 GNUNET_TESTING_make_trait_application_handle ((const void *) ah), 251 GNUNET_TESTING_make_trait_application_handle ((const void *) ah),
253 GNUNET_TESTING_make_trait_peer_id ((const void *) id), 252 GNUNET_TESTING_make_trait_peer_id ((const void *) id),
diff --git a/src/service/testing/testing_api_cmd_stop_peer.c b/src/service/transport/testing_api_cmd_stop_peer.c
index 2cbf978c6..76a63e319 100644
--- a/src/service/testing/testing_api_cmd_stop_peer.c
+++ b/src/service/transport/testing_api_cmd_stop_peer.c
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h" 29#include "gnunet_transport_testing_ng_lib.h"
30 30
31/** 31/**
32 * Generic logging shortcut 32 * Generic logging shortcut
diff --git a/src/service/transport/transport-testing-cmds.h b/src/service/transport/transport-testing-cmds.h
index 6b6fcf4f1..057f6ea14 100644
--- a/src/service/transport/transport-testing-cmds.h
+++ b/src/service/transport/transport-testing-cmds.h
@@ -26,8 +26,84 @@
26 */ 26 */
27#ifndef TRANSPORT_TESTING_CMDS_H 27#ifndef TRANSPORT_TESTING_CMDS_H
28#define TRANSPORT_TESTING_CMDS_H 28#define TRANSPORT_TESTING_CMDS_H
29
29#include "gnunet_testing_ng_lib.h" 30#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_plugin.h" 31#include "gnunet_transport_testing_ng_lib.h"
32
33
34/**
35 * Struct to store information needed in callbacks.
36 *
37 */
38// FIXME: breaks naming conventions! Needed public?
39struct ConnectPeersState
40{
41 /**
42 * Context for our asynchronous completion.
43 */
44 struct GNUNET_TESTING_AsyncContext ac;
45
46 GNUNET_TESTING_notify_connect_cb notify_connect;
47
48 /**
49 * The testing system of this node.
50 */
51 const struct GNUNET_TESTING_System *tl_system;
52
53 // Label of the cmd which started the test system.
54 const char *create_label;
55
56 /**
57 * Number globally identifying the node.
58 *
59 */
60 uint32_t num;
61
62 /**
63 * Label of the cmd to start a peer.
64 *
65 */
66 const char *start_peer_label;
67
68 /**
69 * The topology of the test setup.
70 */
71 struct GNUNET_TESTING_NetjailTopology *topology;
72
73 /**
74 * Connections to other peers.
75 */
76 struct GNUNET_TESTING_NodeConnection *node_connections_head;
77
78 struct GNUNET_TESTING_Interpreter *is;
79
80 /**
81 * Number of connections.
82 */
83 unsigned int con_num;
84
85 /**
86 * Number of additional connects this cmd will wait for not triggered by this cmd.
87 */
88 unsigned int additional_connects;
89
90 /**
91 * Number of connections we already have a notification for.
92 */
93 unsigned int con_num_notified;
94
95 /**
96 * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
97 */
98 unsigned int additional_connects_notified;
99
100 /**
101 * Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
102 */
103 unsigned int wait_for_connect;
104};
105
106
31 107
32typedef void * 108typedef void *
33(*GNUNET_TRANSPORT_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is, 109(*GNUNET_TRANSPORT_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
@@ -183,62 +259,14 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
183 topology); 259 topology);
184 260
185 261
186/**
187 * Create headers for a trait with name @a name for
188 * statically allocated data of type @a type.
189 */
190#define GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT(name,type) \
191 enum GNUNET_GenericReturnValue \
192 GNUNET_TRANSPORT_get_trait_ ## name ( \
193 const struct GNUNET_TESTING_Command *cmd, \
194 type **ret); \
195 struct GNUNET_TESTING_Trait \
196 GNUNET_TRANSPORT_make_trait_ ## name ( \
197 type * value);
198
199
200/**
201 * Create C implementation for a trait with name @a name for statically
202 * allocated data of type @a type.
203 */
204#define GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
205 enum GNUNET_GenericReturnValue \
206 GNUNET_TRANSPORT_get_trait_ ## name ( \
207 const struct GNUNET_TESTING_Command *cmd, \
208 type **ret) \
209 { \
210 if (NULL == cmd->traits) return GNUNET_SYSERR; \
211 return cmd->traits (cmd->cls, \
212 (const void **) ret, \
213 GNUNET_S (name), \
214 0); \
215 } \
216 struct GNUNET_TESTING_Trait \
217 GNUNET_TRANSPORT_make_trait_ ## name ( \
218 type * value) \
219 { \
220 struct GNUNET_TESTING_Trait ret = { \
221 .trait_name = GNUNET_S (name), \
222 .ptr = (const void *) value \
223 }; \
224 return ret; \
225 }
226
227 262
228/** 263/**
229 * Call #op on all simple traits. 264 * Call #op on all simple traits.
230 */ 265 */
231#define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \ 266#define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \
232 op (peer_id, const struct GNUNET_PeerIdentity) \ 267 op (connect_peer_state, const struct ConnectPeersState)
233 op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ 268
234 op (hello_size, const size_t) \ 269GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
235 op (hello, const char) \
236 op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \
237 op (connect_peer_state, const struct ConnectPeersState) \
238 op (state, const struct GNUNET_TESTING_StartPeerState) \
239 op (broadcast, const enum GNUNET_GenericReturnValue)
240
241GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT)
242 270
243 271
244#endif 272#endif
diff --git a/src/service/transport/transport_api_cmd_backchannel_check.c b/src/service/transport/transport_api_cmd_backchannel_check.c
index 388001496..0b57ddabd 100644
--- a/src/service/transport/transport_api_cmd_backchannel_check.c
+++ b/src/service/transport/transport_api_cmd_backchannel_check.c
@@ -417,8 +417,8 @@ backchannel_check_run (void *cls,
417 417
418 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 418 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
419 cs->start_peer_label); 419 cs->start_peer_label);
420 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 420 GNUNET_TESTING_get_trait_application_handle (peer1_cmd,
421 &ah); 421 &ah);
422 422
423 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 423 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
424 cs->create_label); 424 cs->create_label);
diff --git a/src/service/transport/transport_api_cmd_connecting_peers.c b/src/service/transport/transport_api_cmd_connecting_peers.c
index e38d5b860..8498efa42 100644
--- a/src/service/transport/transport_api_cmd_connecting_peers.c
+++ b/src/service/transport/transport_api_cmd_connecting_peers.c
@@ -26,9 +26,9 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h" 29#include "gnunet_transport_testing_ng_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "transport-testing-cmds.h" 30#include "transport-testing-cmds.h"
31#include "gnunet_transport_application_service.h"
32 32
33/** 33/**
34 * Generic logging shortcut 34 * Generic logging shortcut
@@ -67,8 +67,8 @@ connect_peers_run (void *cls,
67 { 67 {
68 LOG (GNUNET_ERROR_TYPE_DEBUG, 68 LOG (GNUNET_ERROR_TYPE_DEBUG,
69 "Wait for connect.\n"); 69 "Wait for connect.\n");
70 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 70 GNUNET_TESTING_get_trait_application_handle (peer1_cmd,
71 &ah); 71 &ah);
72 } 72 }
73 else 73 else
74 { 74 {
@@ -78,8 +78,8 @@ connect_peers_run (void *cls,
78 &ah); 78 &ah);
79 } 79 }
80 80
81 GNUNET_TRANSPORT_get_trait_broadcast (peer1_cmd, 81 GNUNET_TESTING_get_trait_broadcast (peer1_cmd,
82 &broadcast); 82 &broadcast);
83 83
84 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 84 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
85 cps->create_label); 85 cps->create_label);
@@ -249,7 +249,7 @@ connect_peers_traits (void *cls,
249{ 249{
250 struct ConnectPeersState *cps = cls; 250 struct ConnectPeersState *cps = cls;
251 struct GNUNET_TESTING_Trait traits[] = { 251 struct GNUNET_TESTING_Trait traits[] = {
252 GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps), 252 GNUNET_TESTING_make_trait_connect_peer_state ((const void *) cps),
253 GNUNET_TESTING_trait_end () 253 GNUNET_TESTING_trait_end ()
254 }; 254 };
255 return GNUNET_TESTING_get_trait (traits, 255 return GNUNET_TESTING_get_trait (traits,
@@ -307,3 +307,7 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
307 &connect_peers_traits, 307 &connect_peers_traits,
308 NULL); 308 NULL);
309} 309}
310
311
312// FIXME: likely not ideally placed here, move to its own file
313GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
diff --git a/src/service/transport/transport_api_cmd_send_simple.c b/src/service/transport/transport_api_cmd_send_simple.c
index 2671727c0..4013a1556 100644
--- a/src/service/transport/transport_api_cmd_send_simple.c
+++ b/src/service/transport/transport_api_cmd_send_simple.c
@@ -122,8 +122,8 @@ send_simple_run (void *cls,
122 122
123 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 123 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
124 sss->start_peer_label); 124 sss->start_peer_label);
125 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 125 GNUNET_TESTING_get_trait_connected_peers_map (peer1_cmd,
126 &connected_peers_map); 126 &connected_peers_map);
127 127
128 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 128 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
129 sss->create_label); 129 sss->create_label);
diff --git a/src/service/transport/transport_api_cmd_send_simple_performance.c b/src/service/transport/transport_api_cmd_send_simple_performance.c
index 7ce3b8bf7..d6581c4e1 100644
--- a/src/service/transport/transport_api_cmd_send_simple_performance.c
+++ b/src/service/transport/transport_api_cmd_send_simple_performance.c
@@ -173,8 +173,8 @@ send_simple_run (void *cls,
173 173
174 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 174 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
175 sss->start_peer_label); 175 sss->start_peer_label);
176 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 176 GNUNET_TESTING_get_trait_connected_peers_map (peer1_cmd,
177 &connected_peers_map); 177 &connected_peers_map);
178 178
179 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 179 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
180 sss->create_label); 180 sss->create_label);
diff --git a/src/service/transport/transport_api_cmd_start_peer.c b/src/service/transport/transport_api_cmd_start_peer.c
index 54e204a21..642478109 100644
--- a/src/service/transport/transport_api_cmd_start_peer.c
+++ b/src/service/transport/transport_api_cmd_start_peer.c
@@ -420,15 +420,15 @@ start_peer_traits (void *cls,
420 420
421 421
422 struct GNUNET_TESTING_Trait traits[] = { 422 struct GNUNET_TESTING_Trait traits[] = {
423 GNUNET_TRANSPORT_make_trait_application_handle ((const void *) ah), 423 GNUNET_TESTING_make_trait_application_handle ((const void *) ah),
424 GNUNET_TRANSPORT_make_trait_peer_id ((const void *) id), 424 GNUNET_TESTING_make_trait_peer_id ((const void *) id),
425 GNUNET_TRANSPORT_make_trait_connected_peers_map ((const 425 GNUNET_TESTING_make_trait_connected_peers_map ((const
426 void *) 426 void *)
427 connected_peers_map), 427 connected_peers_map),
428 GNUNET_TRANSPORT_make_trait_hello ((const void *) hello), 428 GNUNET_TESTING_make_trait_hello ((const void *) hello),
429 GNUNET_TRANSPORT_make_trait_hello_size ((const void *) hello_size), 429 GNUNET_TESTING_make_trait_hello_size ((const void *) hello_size),
430 GNUNET_TRANSPORT_make_trait_state ((const void *) sps), 430 GNUNET_TESTING_make_trait_state ((const void *) sps),
431 GNUNET_TRANSPORT_make_trait_broadcast ((const void *) &sps->broadcast), 431 GNUNET_TESTING_make_trait_broadcast ((const void *) &sps->broadcast),
432 GNUNET_TESTING_trait_end () 432 GNUNET_TESTING_trait_end ()
433 }; 433 };
434 434
diff --git a/src/service/transport/transport_api_cmd_stop_peer.c b/src/service/transport/transport_api_cmd_stop_peer.c
index 795a2f0f3..cd6863711 100644
--- a/src/service/transport/transport_api_cmd_stop_peer.c
+++ b/src/service/transport/transport_api_cmd_stop_peer.c
@@ -63,8 +63,8 @@ stop_peer_run (void *cls,
63 63
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
65 stop_ps->start_label); 65 stop_ps->start_label);
66 GNUNET_TRANSPORT_get_trait_state (start_cmd, 66 GNUNET_TESTING_get_trait_state (start_cmd,
67 &sps); 67 &sps);
68 68
69 if (NULL != sps->pic) 69 if (NULL != sps->pic)
70 { 70 {
diff --git a/src/service/transport/transport_api_traits.c b/src/service/transport/transport_api_traits.c
index 7e66cc3d1..78f306019 100644
--- a/src/service/transport/transport_api_traits.c
+++ b/src/service/transport/transport_api_traits.c
@@ -29,4 +29,4 @@
29#include "transport-testing-cmds.h" 29#include "transport-testing-cmds.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31 31
32GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT) 32GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)