aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c60
-rw-r--r--src/include/gnunet_testing_ng_lib.h81
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c56
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c57
-rw-r--r--src/testing/testing_api_cmd_finish.c112
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c34
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c62
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c31
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c8
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c55
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c45
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c64
-rw-r--r--src/testing/testing_api_loop.c53
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c49
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c24
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c48
-rw-r--r--src/transport/transport_api_cmd_start_peer.c42
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c1
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c1
19 files changed, 288 insertions, 595 deletions
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index 129a31205..e620e329e 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -34,16 +34,10 @@ struct SendState
34{ 34{
35 35
36 /** 36 /**
37 * Function to call when done. 37 * Mandatory context for async commands.
38 */ 38 */
39 GNUNET_SCHEDULER_TaskCallback cont; 39 struct GNUNET_TESTING_AsyncContext ac;
40 40
41 /**
42 * Closure for @e cont.
43 */
44 void *cont_cls;
45
46 enum GNUNET_GenericReturnValue finished;
47}; 41};
48 42
49 43
@@ -98,56 +92,10 @@ send_run (void *cls,
98 GNUNET_TESTING_get_trait_XXX (other_cmd, 92 GNUNET_TESTING_get_trait_XXX (other_cmd,
99 &data); 93 &data);
100#endif 94#endif
101 ss->finished = GNUNET_OK; 95 GNUNET_TESTING_async_finish (&ss->ac);
102} 96}
103 97
104 98
105/**
106 * This function checks the flag NetJailState#finished, if this cmd finished.
107 *
108 * @param cls a `struct SendState`
109 * @param cont function to call upon completion, can be NULL
110 * @param cont_cls closure for @a cont
111 * @return
112 * #GNUNET_NO if the command is still running and @a cont will be called later
113 * #GNUNET_OK if the command completed successfully and @a cont was called
114 * #GNUNET_SYSERR if the operation @a cont was NOT called
115 */
116static enum GNUNET_GenericReturnValue
117send_finish (void *cls,
118 GNUNET_SCHEDULER_TaskCallback cont,
119 void *cont_cls)
120{
121 struct SendState *ss = cls;
122
123 switch (ss->finished)
124 {
125 case GNUNET_OK:
126 cont (cont_cls);
127 break;
128 case GNUNET_SYSERR:
129 GNUNET_break (0);
130 break;
131 case GNUNET_NO:
132 if (NULL != ss->cont)
133 {
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 ss->cont = cont;
138 ss->cont_cls = cont_cls;
139 break;
140 }
141 return ss->finished;
142}
143
144
145/**
146 * Create 'send' command.
147 *
148 * @param label name for command.
149 * @return command.
150 */
151struct GNUNET_TESTING_Command 99struct GNUNET_TESTING_Command
152GNUNET_TESTING_DHTU_cmd_send (const char *label) 100GNUNET_TESTING_DHTU_cmd_send (const char *label)
153{ 101{
@@ -160,7 +108,7 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label)
160 .cls = ss, 108 .cls = ss,
161 .label = label, 109 .label = label,
162 .run = &send_run, 110 .run = &send_run,
163 .finish = &send_finish, 111 .ac = &ss->ac,
164 .cleanup = &send_cleanup, 112 .cleanup = &send_cleanup,
165 .traits = &send_traits 113 .traits = &send_traits
166 }; 114 };
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 4ef9aac18..0cab64504 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -82,7 +82,7 @@ enum GNUNET_TESTING_NODE_TYPE
82}; 82};
83 83
84 84
85 // FIXME: this does not belong here! 85// FIXME: this does not belong here!
86struct GNUNET_TESTING_ADDRESS_PREFIX 86struct GNUNET_TESTING_ADDRESS_PREFIX
87{ 87{
88 /** 88 /**
@@ -261,6 +261,36 @@ struct GNUNET_TESTING_NetjailTopology
261struct GNUNET_TESTING_Interpreter; 261struct GNUNET_TESTING_Interpreter;
262 262
263/** 263/**
264 * State each asynchronous command must have in its closure.
265 */
266struct GNUNET_TESTING_AsyncContext
267{
268
269 /**
270 * Interpreter we are part of.
271 */
272 struct GNUNET_TESTING_Interpreter *is;
273
274 /**
275 * Function to call when done.
276 */
277 GNUNET_SCHEDULER_TaskCallback cont;
278
279 /**
280 * Closure for @e cont.
281 */
282 void *cont_cls;
283
284 /**
285 * Indication if the command finished (#GNUNET_OK).
286 * #GNUNET_NO if it is still running,
287 * #GNUNET_SYSERR if it failed.
288 */
289 enum GNUNET_GenericReturnValue finished;
290};
291
292
293/**
264 * A command to be run by the interpreter. 294 * A command to be run by the interpreter.
265 */ 295 */
266struct GNUNET_TESTING_Command 296struct GNUNET_TESTING_Command
@@ -296,27 +326,14 @@ struct GNUNET_TESTING_Command
296 struct GNUNET_TESTING_Interpreter *is); 326 struct GNUNET_TESTING_Interpreter *is);
297 327
298 /** 328 /**
299 * FIXME: logic is basically always the same! 329 * Pointer to the asynchronous context in the command's
300 * => Refactor API to avoid duplication! 330 * closure. Used by the
331 * #GNUNET_TESTING_async_finish() and
332 * #GNUNET_TESTING_async_fail() functions.
301 * 333 *
302 * Wait for any asynchronous execution of @e run to conclude, 334 * Must be NULL if a command is synchronous.
303 * then call finish_cont. Finish may only be called once per command.
304 *
305 * This member may be NULL if this command is a synchronous command,
306 * and also should be set to NULL once the command has finished.
307 *
308 * @param cls closure
309 * @param cont function to call upon completion, can be NULL
310 * @param cont_cls closure for @a cont
311 * @return
312 * #GNUNET_NO if the command is still running and @a cont will be called later
313 * #GNUNET_OK if the command completed successfully and @a cont was called
314 * #GNUNET_SYSERR if the operation @a cont was NOT called
315 */ 335 */
316 enum GNUNET_GenericReturnValue 336 struct GNUNET_TESTING_AsyncContext *ac;
317 (*finish)(void *cls,
318 GNUNET_SCHEDULER_TaskCallback cont,
319 void *cont_cls);
320 337
321 /** 338 /**
322 * Clean up after the command. Run during forced termination 339 * Clean up after the command. Run during forced termination
@@ -328,11 +345,8 @@ struct GNUNET_TESTING_Command
328 (*cleanup)(void *cls); 345 (*cleanup)(void *cls);
329 346
330 /** 347 /**
331 * FIXME: logic is often the same!
332 * => Think about refactoring API to reduce duplication!
333 *
334 * Extract information from a command that is useful for other 348 * Extract information from a command that is useful for other
335 * commands. 349 * commands. Can be NULL if a command has no traits.
336 * 350 *
337 * @param cls closure 351 * @param cls closure
338 * @param[out] ret result (could be anything) 352 * @param[out] ret result (could be anything)
@@ -428,6 +442,24 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
428 442
429 443
430/** 444/**
445 * The asynchronous command of @a ac has failed.
446 *
447 * @param ac command-specific context
448 */
449void
450GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
451
452
453/**
454 * The asynchronous command of @a ac has finished.
455 *
456 * @param ac command-specific context
457 */
458void
459GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
460
461
462/**
431 * Create command array terminator. 463 * Create command array terminator.
432 * 464 *
433 * @return a end-command. 465 * @return a end-command.
@@ -1116,7 +1148,6 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
1116 const char *topology_config); 1148 const char *topology_config);
1117 1149
1118 1150
1119
1120// FIXME: document! 1151// FIXME: document!
1121enum GNUNET_GenericReturnValue 1152enum GNUNET_GenericReturnValue
1122GNUNET_TESTING_get_trait_helper_handles (const struct 1153GNUNET_TESTING_get_trait_helper_handles (const struct
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
index fb51c1066..8a47a7ce0 100644
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c
@@ -47,20 +47,6 @@ struct BlockState
47 47
48 48
49/** 49/**
50 * Trait function of this cmd does nothing.
51 *
52 */
53static int
54block_until_all_peers_started_traits (void *cls,
55 const void **ret,
56 const char *trait,
57 unsigned int index)
58{
59 return GNUNET_OK;
60}
61
62
63/**
64 * The cleanup function of this cmd frees resources the cmd allocated. 50 * The cleanup function of this cmd frees resources the cmd allocated.
65 * 51 *
66 */ 52 */
@@ -87,27 +73,6 @@ block_until_all_peers_started_run (void *cls,
87 73
88 74
89/** 75/**
90 * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
91 *
92 */
93static int
94block_until_all_peers_started_finish (void *cls,
95 GNUNET_SCHEDULER_TaskCallback cont,
96 void *cont_cls)
97{
98 struct BlockState *bs = cls;
99 unsigned int *ret = bs->all_peers_started;
100
101 if (GNUNET_YES == *ret)
102 {
103 cont (cont_cls);
104 }
105
106 return *ret;
107}
108
109
110/**
111 * Create command. 76 * Create command.
112 * 77 *
113 * @param label name for command. 78 * @param label name for command.
@@ -123,15 +88,14 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
123 88
124 bs = GNUNET_new (struct BlockState); 89 bs = GNUNET_new (struct BlockState);
125 bs->all_peers_started = all_peers_started; 90 bs->all_peers_started = all_peers_started;
126 91 {
127 struct GNUNET_TESTING_Command cmd = { 92 struct GNUNET_TESTING_Command cmd = {
128 .cls = bs, 93 .cls = bs,
129 .label = label, 94 .label = label,
130 .run = &block_until_all_peers_started_run, 95 .run = &block_until_all_peers_started_run,
131 .finish = &block_until_all_peers_started_finish, 96 .cleanup = &block_until_all_peers_started_cleanup
132 .cleanup = &block_until_all_peers_started_cleanup, 97 };
133 .traits = &block_until_all_peers_started_traits 98
134 }; 99 return cmd;
135 100 }
136 return cmd;
137} 101}
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index d69040b75..b416fa595 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -40,27 +40,12 @@ struct BlockState
40{ 40{
41 /** 41 /**
42 * Flag to indicate if all peers have started. 42 * Flag to indicate if all peers have started.
43 *
44 */ 43 */
45 unsigned int *stop_blocking; 44 unsigned int *stop_blocking;
46}; 45};
47 46
48 47
49/** 48/**
50 * Trait function of this cmd does nothing.
51 *
52 */
53static int
54block_until_all_peers_started_traits (void *cls,
55 const void **ret,
56 const char *trait,
57 unsigned int index)
58{
59 return GNUNET_NO;
60}
61
62
63/**
64 * The cleanup function of this cmd frees resources the cmd allocated. 49 * The cleanup function of this cmd frees resources the cmd allocated.
65 * 50 *
66 */ 51 */
@@ -87,27 +72,6 @@ block_until_all_peers_started_run (void *cls,
87 72
88 73
89/** 74/**
90 * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
91 *
92 */
93static int
94block_until_all_peers_started_finish (void *cls,
95 GNUNET_SCHEDULER_TaskCallback cont,
96 void *cont_cls)
97{
98 struct BlockState *bs = cls;
99 unsigned int *ret = bs->stop_blocking;
100
101 if (GNUNET_YES == *ret)
102 {
103 cont (cont_cls);
104 }
105
106 return *ret;
107}
108
109
110/**
111 * Create command. 75 * Create command.
112 * 76 *
113 * @param label name for command. 77 * @param label name for command.
@@ -123,15 +87,14 @@ GNUNET_TESTING_cmd_block_until_external_trigger (const char *label,
123 87
124 bs = GNUNET_new (struct BlockState); 88 bs = GNUNET_new (struct BlockState);
125 bs->stop_blocking = stop_blocking; 89 bs->stop_blocking = stop_blocking;
126 90 {
127 struct GNUNET_TESTING_Command cmd = { 91 struct GNUNET_TESTING_Command cmd = {
128 .cls = bs, 92 .cls = bs,
129 .label = label, 93 .label = label,
130 .run = &block_until_all_peers_started_run, 94 .run = &block_until_all_peers_started_run,
131 .finish = &block_until_all_peers_started_finish, 95 .cleanup = &block_until_all_peers_started_cleanup,
132 .cleanup = &block_until_all_peers_started_cleanup, 96 };
133 .traits = &block_until_all_peers_started_traits 97
134 }; 98 return cmd;
135 99 }
136 return cmd;
137} 100}
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c
index 2bcefd803..3ac0871a5 100644
--- a/src/testing/testing_api_cmd_finish.c
+++ b/src/testing/testing_api_cmd_finish.c
@@ -48,34 +48,23 @@ struct FinishState
48 struct GNUNET_SCHEDULER_Task *finish_task; 48 struct GNUNET_SCHEDULER_Task *finish_task;
49 49
50 /** 50 /**
51 * Interpreter we are part of.
52 */
53 struct GNUNET_TESTING_Interpreter *is;
54
55 /**
56 * Function to call when done. 51 * Function to call when done.
57 */ 52 */
58 GNUNET_SCHEDULER_TaskCallback cont; 53 struct GNUNET_TESTING_AsyncContext ac;
59
60 /**
61 * Closure for @e cont.
62 */
63 void *cont_cls;
64 54
65 /** 55 /**
66 * How long to wait until finish fails hard? 56 * How long to wait until finish fails hard?
67 */ 57 */
68 struct GNUNET_TIME_Relative timeout; 58 struct GNUNET_TIME_Relative timeout;
69 59
70 /**
71 * Set to #GNUNET_OK if the @a async_label command finished on time
72 */
73 enum GNUNET_GenericReturnValue finished;
74
75}; 60};
76 61
77 62
78/** 63/**
64 * Function called when the command we are waiting on
65 * is finished. Hence we are finished, too.
66 *
67 * @param cls a `struct FinishState` being notified
79 */ 68 */
80static void 69static void
81done_finish (void *cls) 70done_finish (void *cls)
@@ -84,15 +73,15 @@ done_finish (void *cls)
84 73
85 GNUNET_SCHEDULER_cancel (finish_state->finish_task); 74 GNUNET_SCHEDULER_cancel (finish_state->finish_task);
86 finish_state->finish_task = NULL; 75 finish_state->finish_task = NULL;
87 finish_state->finished = GNUNET_YES; 76 GNUNET_TESTING_async_finish (&finish_state->ac);
88 if (NULL != finish_state->cont)
89 {
90 finish_state->cont (finish_state->cont_cls);
91 }
92} 77}
93 78
94 79
95/** 80/**
81 * Function triggered if the command we are waiting
82 * for did not complete on time.
83 *
84 * @param cls our `struct FinishState`
96 */ 85 */
97static void 86static void
98timeout_finish (void *cls) 87timeout_finish (void *cls)
@@ -103,8 +92,7 @@ timeout_finish (void *cls)
103 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
104 "Timeout waiting for command `%s' to finish\n", 93 "Timeout waiting for command `%s' to finish\n",
105 finish_state->async_label); 94 finish_state->async_label);
106 finish_state->finished = GNUNET_SYSERR; 95 GNUNET_TESTING_async_fail (&finish_state->ac);
107 GNUNET_TESTING_interpreter_fail (finish_state->is);
108} 96}
109 97
110 98
@@ -114,13 +102,13 @@ timeout_finish (void *cls)
114 * 102 *
115 */ 103 */
116static void 104static void
117run_finish_on_ref (void *cls, 105run_finish (void *cls,
118 struct GNUNET_TESTING_Interpreter *is) 106 struct GNUNET_TESTING_Interpreter *is)
119{ 107{
120 struct FinishState *finish_state = cls; 108 struct FinishState *finish_state = cls;
121 const struct GNUNET_TESTING_Command *async_cmd; 109 const struct GNUNET_TESTING_Command *async_cmd;
110 struct GNUNET_TESTING_AsyncContext *aac;
122 111
123 finish_state->is = is;
124 async_cmd 112 async_cmd
125 = GNUNET_TESTING_interpreter_lookup_command (is, 113 = GNUNET_TESTING_interpreter_lookup_command (is,
126 finish_state->async_label); 114 finish_state->async_label);
@@ -132,7 +120,7 @@ run_finish_on_ref (void *cls,
132 GNUNET_TESTING_interpreter_fail (is); 120 GNUNET_TESTING_interpreter_fail (is);
133 return; 121 return;
134 } 122 }
135 if ( (NULL == async_cmd->finish) || 123 if ( (NULL == (aac = async_cmd->ac)) ||
136 (! async_cmd->asynchronous_finish) ) 124 (! async_cmd->asynchronous_finish) )
137 { 125 {
138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -141,71 +129,40 @@ run_finish_on_ref (void *cls,
141 GNUNET_TESTING_interpreter_fail (is); 129 GNUNET_TESTING_interpreter_fail (is);
142 return; 130 return;
143 } 131 }
132 if (GNUNET_NO != aac->finished)
133 {
134 /* Command is already finished, so are we! */
135 GNUNET_TESTING_async_finish (&finish_state->ac);
136 return;
137 }
144 finish_state->finish_task 138 finish_state->finish_task
145 = GNUNET_SCHEDULER_add_delayed (finish_state->timeout, 139 = GNUNET_SCHEDULER_add_delayed (finish_state->timeout,
146 &timeout_finish, 140 &timeout_finish,
147 finish_state); 141 finish_state);
148 async_cmd->finish (async_cmd->cls, 142 aac->cont = &done_finish;
149 &done_finish, 143 aac->cont_cls = finish_state;
150 finish_state);
151} 144}
152 145
153 146
154/** 147/**
155 * Wait for any asynchronous execution of @e run to conclude, 148 * Cleanup state of a finish command.
156 * then call finish_cont. Finish may only be called once per command.
157 * 149 *
158 * This member may be NULL if this command is a synchronous command, 150 * @param cls a `struct FinishState` to clean up
159 * and also should be set to NULL once the command has finished.
160 *
161 * @param cls closure
162 * @param cont function to call upon completion, can be NULL
163 * @param cont_cls closure for @a cont
164 * @return
165 * #GNUNET_NO if the command is still running and @a cont will be called later
166 * #GNUNET_OK if the command completed successfully and @a cont was called
167 * #GNUNET_SYSERR if the operation @a cont was NOT called
168 */ 151 */
169static enum GNUNET_GenericReturnValue 152static void
170finish_finish_on_ref (void *cls, 153cleanup_finish (void *cls)
171 GNUNET_SCHEDULER_TaskCallback cont,
172 void *cont_cls)
173{ 154{
174 struct FinishState *finish_state = cls; 155 struct FinishState *finish_state = cls;
175 156
176 switch (finish_state->finished) 157 if (NULL != finish_state->finish_task)
177 { 158 {
178 case GNUNET_OK: 159 GNUNET_SCHEDULER_cancel (finish_state->finish_task);
179 cont (cont_cls); 160 finish_state->finish_task = NULL;
180 break;
181 case GNUNET_SYSERR:
182 GNUNET_break (0);
183 break;
184 case GNUNET_NO:
185 if (NULL != finish_state->cont)
186 {
187 GNUNET_break (0);
188 return GNUNET_SYSERR;
189 }
190 finish_state->cont = cont;
191 finish_state->cont_cls = cont_cls;
192 break;
193 } 161 }
194 return finish_state->finished; 162 GNUNET_free (finish_state);
195} 163}
196 164
197 165
198/**
199 * Create (synchronous) command that waits for another command to finish.
200 * If @a cmd_ref did not finish after @a timeout, this command will fail
201 * the test case.
202 *
203 * @param finish_label label for this command
204 * @param cmd_ref reference to a previous command which we should
205 * wait for (call `finish()` on)
206 * @param timeout how long to wait at most for @a cmd_ref to finish
207 * @return a finish-command.
208 */
209const struct GNUNET_TESTING_Command 166const struct GNUNET_TESTING_Command
210GNUNET_TESTING_cmd_finish (const char *finish_label, 167GNUNET_TESTING_cmd_finish (const char *finish_label,
211 const char *cmd_ref, 168 const char *cmd_ref,
@@ -220,8 +177,9 @@ GNUNET_TESTING_cmd_finish (const char *finish_label,
220 struct GNUNET_TESTING_Command cmd = { 177 struct GNUNET_TESTING_Command cmd = {
221 .cls = finish_state, 178 .cls = finish_state,
222 .label = finish_label, 179 .label = finish_label,
223 .run = &run_finish_on_ref, 180 .run = &run_finish,
224 .finish = &finish_finish_on_ref 181 .ac = &finish_state->ac,
182 .cleanup = &cleanup_finish
225 }; 183 };
226 184
227 return cmd; 185 return cmd;
@@ -234,7 +192,7 @@ GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd)
234{ 192{
235 /* do not permit this function to be used on 193 /* do not permit this function to be used on
236 a finish command! */ 194 a finish command! */
237 GNUNET_assert (cmd.run != &run_finish_on_ref); 195 GNUNET_assert (cmd.run != &run_finish);
238 cmd.asynchronous_finish = true; 196 cmd.asynchronous_finish = true;
239 return cmd; 197 return cmd;
240} 198}
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index da4aff80f..0e7e214dc 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -40,6 +40,7 @@
40 */ 40 */
41struct LocalFinishedState 41struct LocalFinishedState
42{ 42{
43
43 /** 44 /**
44 * Callback to write messages to the master loop. 45 * Callback to write messages to the master loop.
45 * 46 *
@@ -55,20 +56,6 @@ struct LocalFinishedState
55 56
56 57
57/** 58/**
58 * Trait function of this cmd does nothing.
59 *
60 */
61static enum GNUNET_GenericReturnValue
62local_test_finished_traits (void *cls,
63 const void **ret,
64 const char *trait,
65 unsigned int index)
66{
67 return GNUNET_NO;
68}
69
70
71/**
72 * The cleanup function of this cmd frees resources the cmd allocated. 59 * The cleanup function of this cmd frees resources the cmd allocated.
73 * 60 *
74 */ 61 */
@@ -105,23 +92,6 @@ local_test_finished_run (void *cls,
105 92
106 93
107/** 94/**
108 * This finish function will stop the local loop without shutting down the
109 * scheduler, because we do not call the continuation, which is the
110 * interpreter_next method.
111 *
112 */
113static enum GNUNET_GenericReturnValue
114local_test_finished_finish (void *cls,
115 GNUNET_SCHEDULER_TaskCallback cont,
116 void *cont_cls)
117{
118 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "Stopping local loop\n");
120 return GNUNET_YES;
121}
122
123
124/**
125 * Create command. 95 * Create command.
126 * 96 *
127 * @param label name for command. 97 * @param label name for command.
@@ -142,9 +112,7 @@ GNUNET_TESTING_cmd_local_test_finished (
142 .cls = lfs, 112 .cls = lfs,
143 .label = label, 113 .label = label,
144 .run = &local_test_finished_run, 114 .run = &local_test_finished_run,
145 .finish = &local_test_finished_finish,
146 .cleanup = &local_test_finished_cleanup, 115 .cleanup = &local_test_finished_cleanup,
147 .traits = &local_test_finished_traits
148 }; 116 };
149 117
150 return cmd; 118 return cmd;
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 1815b64d2..4b5592524 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -35,6 +35,11 @@
35 */ 35 */
36struct NetJailState 36struct NetJailState
37{ 37{
38 /**
39 * Context for our asynchronous completion.
40 */
41 struct GNUNET_TESTING_AsyncContext ac;
42
38 // Child Wait handle 43 // Child Wait handle
39 struct GNUNET_ChildWaitHandle *cwh; 44 struct GNUNET_ChildWaitHandle *cwh;
40 45
@@ -67,7 +72,6 @@ netjail_start_cleanup (void *cls)
67 72
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
69 "netjail_start_cleanup!\n"); 74 "netjail_start_cleanup!\n");
70
71 if (NULL != ns->cwh) 75 if (NULL != ns->cwh)
72 { 76 {
73 GNUNET_wait_child_cancel (ns->cwh); 77 GNUNET_wait_child_cancel (ns->cwh);
@@ -88,20 +92,6 @@ netjail_start_cleanup (void *cls)
88 92
89 93
90/** 94/**
91 * Trait function of this cmd does nothing.
92 *
93 */
94static enum GNUNET_GenericReturnValue
95netjail_start_traits (void *cls,
96 const void **ret,
97 const char *trait,
98 unsigned int index)
99{
100 return GNUNET_NO;
101}
102
103
104/**
105 * Callback which will be called if the setup script finished. 95 * Callback which will be called if the setup script finished.
106 * 96 *
107 */ 97 */
@@ -112,18 +102,18 @@ child_completed_callback (void *cls,
112{ 102{
113 struct NetJailState *ns = cls; 103 struct NetJailState *ns = cls;
114 104
105 GNUNET_OS_process_destroy (ns->start_proc);
106 ns->start_proc = NULL;
115 if (0 == exit_code) 107 if (0 == exit_code)
116 { 108 {
117 ns->finished = GNUNET_YES; 109 GNUNET_TESTING_async_finish (&ns->ac);
118 } 110 }
119 else 111 else
120 { 112 {
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
122 "Child completed with an error!\n"); 114 "Child completed with an error!\n");
123 ns->finished = GNUNET_SYSERR; 115 GNUNET_TESTING_async_fail (&ns->ac);
124 } 116 }
125 GNUNET_OS_process_destroy (ns->start_proc);
126 ns->start_proc = NULL;
127} 117}
128 118
129 119
@@ -138,10 +128,12 @@ netjail_start_run (void *cls,
138 struct GNUNET_TESTING_Interpreter *is) 128 struct GNUNET_TESTING_Interpreter *is)
139{ 129{
140 struct NetJailState *ns = cls; 130 struct NetJailState *ns = cls;
141 char *const script_argv[] = {NETJAIL_START_SCRIPT, 131 char *const script_argv[] = {
142 ns->local_m, 132 NETJAIL_START_SCRIPT,
143 ns->global_n, 133 ns->local_m,
144 NULL}; 134 ns->global_n,
135 NULL
136 };
145 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 137 unsigned int helper_check = GNUNET_OS_check_helper_binary (
146 NETJAIL_START_SCRIPT, 138 NETJAIL_START_SCRIPT,
147 GNUNET_YES, 139 GNUNET_YES,
@@ -177,25 +169,6 @@ netjail_start_run (void *cls,
177 169
178 170
179/** 171/**
180 * This function checks the flag NetJailState#finished, if this cmd finished.
181 *
182 */
183static enum GNUNET_GenericReturnValue
184netjail_start_finish (void *cls,
185 GNUNET_SCHEDULER_TaskCallback cont,
186 void *cont_cls)
187{
188 struct NetJailState *ns = cls;
189
190 if (ns->finished)
191 {
192 cont (cont_cls);
193 }
194 return ns->finished;
195}
196
197
198/**
199 * Create command. 172 * Create command.
200 * 173 *
201 * @param label name for command. 174 * @param label name for command.
@@ -218,9 +191,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
218 .cls = ns, 191 .cls = ns,
219 .label = label, 192 .label = label,
220 .run = &netjail_start_run, 193 .run = &netjail_start_run,
221 .finish = &netjail_start_finish, 194 .ac = &ns->ac,
222 .cleanup = &netjail_start_cleanup, 195 .cleanup = &netjail_start_cleanup
223 .traits = &netjail_start_traits
224 }; 196 };
225 197
226 return cmd; 198 return cmd;
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 1222ae54b..4224a5736 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -62,6 +62,11 @@ struct HelperMessage
62struct NetJailState 62struct NetJailState
63{ 63{
64 /** 64 /**
65 * Context for our asynchronous completion.
66 */
67 struct GNUNET_TESTING_AsyncContext ac;
68
69 /**
65 * Pointer to the return value of the test. 70 * Pointer to the return value of the test.
66 * 71 *
67 */ 72 */
@@ -399,14 +404,16 @@ start_helper (struct NetJailState *ns, struct
399 struct GNUNET_HELPER_Handle *helper; 404 struct GNUNET_HELPER_Handle *helper;
400 struct GNUNET_CMDS_HelperInit *msg; 405 struct GNUNET_CMDS_HelperInit *msg;
401 struct TestingSystemCount *tbc; 406 struct TestingSystemCount *tbc;
402 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 407 char *const script_argv[] = {
403 m_char, 408 NETJAIL_EXEC_SCRIPT,
404 n_char, 409 m_char,
405 GNUNET_OS_get_libexec_binary_path ( 410 n_char,
406 HELPER_CMDS_BINARY), 411 GNUNET_OS_get_libexec_binary_path (
407 ns->global_n, 412 HELPER_CMDS_BINARY),
408 ns->local_m, 413 ns->global_n,
409 NULL}; 414 ns->local_m,
415 NULL
416 };
410 unsigned int m = atoi (m_char); 417 unsigned int m = atoi (m_char);
411 unsigned int n = atoi (n_char); 418 unsigned int n = atoi (n_char);
412 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 419 unsigned int helper_check = GNUNET_OS_check_helper_binary (
@@ -436,8 +443,9 @@ start_helper (struct NetJailState *ns, struct
436 NETJAIL_EXEC_SCRIPT); 443 NETJAIL_EXEC_SCRIPT);
437 *ns->rv = 1; 444 *ns->rv = 1;
438 } 445 }
439 446 GNUNET_array_append (ns->helper,
440 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 447 ns->n_helper,
448 GNUNET_HELPER_start (
441 GNUNET_YES, 449 GNUNET_YES,
442 NETJAIL_EXEC_SCRIPT, 450 NETJAIL_EXEC_SCRIPT,
443 script_argv, 451 script_argv,
@@ -508,6 +516,7 @@ netjail_exec_run (void *cls,
508 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. 516 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
509 * 3. Did all peers finished the test case. In this case interpreter_next will be called. 517 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
510 * 518 *
519 * => FIXME: must change _completely_.
511 */ 520 */
512static int 521static int
513netjail_start_finish (void *cls, 522netjail_start_finish (void *cls,
@@ -598,7 +607,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
598 .cls = ns, 607 .cls = ns,
599 .label = label, 608 .label = label,
600 .run = &netjail_exec_run, 609 .run = &netjail_exec_run,
601 .finish = &netjail_start_finish, 610 .ac = &ns->ac,
602 .cleanup = &netjail_exec_cleanup, 611 .cleanup = &netjail_exec_cleanup,
603 .traits = &netjail_exec_traits 612 .traits = &netjail_exec_traits
604 }; 613 };
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
index bb9421aa7..d319b73b4 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -62,6 +62,11 @@ struct HelperMessage
62struct NetJailState 62struct NetJailState
63{ 63{
64 /** 64 /**
65 * Context for our asynchronous completion.
66 */
67 struct GNUNET_TESTING_AsyncContext ac;
68
69 /**
65 * The complete topology information. 70 * The complete topology information.
66 */ 71 */
67 struct GNUNET_TESTING_NetjailTopology *topology; 72 struct GNUNET_TESTING_NetjailTopology *topology;
@@ -637,6 +642,7 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
637 * 3. Did all peers finished the test case. In this case interpreter_next will be called. 642 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
638 * 643 *
639 */ 644 */
645// FIXME: must change completely!
640static int 646static int
641netjail_start_finish (void *cls, 647netjail_start_finish (void *cls,
642 GNUNET_SCHEDULER_TaskCallback cont, 648 GNUNET_SCHEDULER_TaskCallback cont,
@@ -708,7 +714,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
708 .cls = ns, 714 .cls = ns,
709 .label = label, 715 .label = label,
710 .run = &netjail_exec_run, 716 .run = &netjail_exec_run,
711 .finish = &netjail_start_finish, 717 .ac = &ns->ac,
712 .cleanup = &netjail_exec_cleanup, 718 .cleanup = &netjail_exec_cleanup,
713 .traits = &netjail_exec_traits 719 .traits = &netjail_exec_traits
714 }; 720 };
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
index faabed98e..69d5e6a45 100644
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_v2.c
@@ -35,6 +35,11 @@
35 */ 35 */
36struct NetJailState 36struct NetJailState
37{ 37{
38 /**
39 * Context for our asynchronous completion.
40 */
41 struct GNUNET_TESTING_AsyncContext ac;
42
38 // Child Wait handle 43 // Child Wait handle
39 struct GNUNET_ChildWaitHandle *cwh; 44 struct GNUNET_ChildWaitHandle *cwh;
40 45
@@ -86,20 +91,6 @@ netjail_start_cleanup (void *cls)
86 91
87 92
88/** 93/**
89 * Trait function of this cmd does nothing.
90 *
91 */
92static enum GNUNET_GenericReturnValue
93netjail_start_traits (void *cls,
94 const void **ret,
95 const char *trait,
96 unsigned int index)
97{
98 return GNUNET_NO;
99}
100
101
102/**
103 * Callback which will be called if the setup script finished. 94 * Callback which will be called if the setup script finished.
104 * 95 *
105 */ 96 */
@@ -110,19 +101,19 @@ child_completed_callback (void *cls,
110{ 101{
111 struct NetJailState *ns = cls; 102 struct NetJailState *ns = cls;
112 103
104 GNUNET_OS_process_destroy (ns->start_proc);
105 ns->start_proc = NULL;
113 if (0 == exit_code) 106 if (0 == exit_code)
114 { 107 {
115 ns->finished = GNUNET_YES; 108 GNUNET_TESTING_async_finish (&ns->ac);
116 } 109 }
117 else 110 else
118 { 111 {
119 // FIXME: log status code 112 // FIXME: log status code
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
121 "Child completed with an error!\n"); 114 "Child completed with an error!\n");
122 ns->finished = GNUNET_SYSERR; 115 GNUNET_TESTING_async_fail (&ns->ac);
123 } 116 }
124 GNUNET_OS_process_destroy (ns->start_proc);
125 ns->start_proc = NULL;
126} 117}
127 118
128 119
@@ -193,29 +184,6 @@ netjail_start_run (void *cls,
193 184
194 185
195/** 186/**
196 * This function checks the flag NetJailState
197 *
198 * FIXME: fix comment!
199 * #finished, if this cmd finished.
200 *
201 */
202static enum GNUNET_GenericReturnValue
203netjail_start_finish (void *cls,
204 GNUNET_SCHEDULER_TaskCallback cont,
205 void *cont_cls)
206{
207 struct NetJailState *ns = cls;
208
209 if (GNUNET_NO != ns->finished)
210 {
211 cont (cont_cls);
212 }
213 // FIXME: cont should be called later in the else case!
214 return ns->finished;
215}
216
217
218/**
219 * Create command. 187 * Create command.
220 * 188 *
221 * @param label name for command. 189 * @param label name for command.
@@ -235,9 +203,8 @@ GNUNET_TESTING_cmd_netjail_start_v2 (const char *label,
235 .cls = ns, 203 .cls = ns,
236 .label = label, 204 .label = label,
237 .run = &netjail_start_run, 205 .run = &netjail_start_run,
238 .finish = &netjail_start_finish, 206 .ac = &ns->ac,
239 .cleanup = &netjail_start_cleanup, 207 .cleanup = &netjail_start_cleanup
240 .traits = &netjail_start_traits
241 }; 208 };
242 209
243 return cmd; 210 return cmd;
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index c93e5cca3..8c78b5e93 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -39,6 +39,11 @@ struct GNUNET_ChildWaitHandle *cwh;
39 */ 39 */
40struct NetJailState 40struct NetJailState
41{ 41{
42 /**
43 * Context for our asynchronous completion.
44 */
45 struct GNUNET_TESTING_AsyncContext ac;
46
42 // Number of local nodes in each namespace. 47 // Number of local nodes in each namespace.
43 char *local_m; 48 char *local_m;
44 49
@@ -50,8 +55,6 @@ struct NetJailState
50 */ 55 */
51 struct GNUNET_OS_Process *stop_proc; 56 struct GNUNET_OS_Process *stop_proc;
52 57
53 // Flag indication if the script finished.
54 unsigned int finished;
55}; 58};
56 59
57 60
@@ -108,16 +111,17 @@ child_completed_callback (void *cls,
108 struct NetJailState *ns = cls; 111 struct NetJailState *ns = cls;
109 112
110 cwh = NULL; 113 cwh = NULL;
114 GNUNET_OS_process_destroy (ns->stop_proc);
115 ns->stop_proc = NULL;
111 if (0 == exit_code) 116 if (0 == exit_code)
112 { 117 {
113 ns->finished = GNUNET_YES; 118 GNUNET_TESTING_async_finish (&ns->ac);
114 } 119 }
115 else 120 else
116 { 121 {
117 ns->finished = GNUNET_SYSERR; 122 // FIXME: log exit code!
123 GNUNET_TESTING_async_fail (&ns->ac);
118 } 124 }
119 GNUNET_OS_process_destroy (ns->stop_proc);
120 ns->stop_proc = NULL;
121} 125}
122 126
123 127
@@ -174,33 +178,6 @@ netjail_stop_run (void *cls,
174} 178}
175 179
176 180
177/**
178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 *
180 */
181static enum GNUNET_GenericReturnValue
182netjail_stop_finish (void *cls,
183 GNUNET_SCHEDULER_TaskCallback cont,
184 void *cont_cls)
185{
186 struct NetJailState *ns = cls;
187
188 if (ns->finished)
189 {
190 cont (cont_cls);
191 }
192 return ns->finished;
193}
194
195
196/**
197 * Create command.
198 *
199 * @param label name for command.
200 * @param local_m Number of local nodes in each namespace.
201 * @param global_n The number of namespaces.
202 * @return command.
203 */
204struct GNUNET_TESTING_Command 181struct GNUNET_TESTING_Command
205GNUNET_TESTING_cmd_netjail_stop (const char *label, 182GNUNET_TESTING_cmd_netjail_stop (const char *label,
206 char *local_m, 183 char *local_m,
@@ -216,7 +193,7 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
216 .cls = ns, 193 .cls = ns,
217 .label = label, 194 .label = label,
218 .run = &netjail_stop_run, 195 .run = &netjail_stop_run,
219 .finish = &netjail_stop_finish, 196 .ac = &ns->ac,
220 .cleanup = &netjail_stop_cleanup, 197 .cleanup = &netjail_stop_cleanup,
221 .traits = &netjail_stop_traits 198 .traits = &netjail_stop_traits
222 }; 199 };
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
index 348e8c9f7..a0e2657cb 100644
--- a/src/testing/testing_api_cmd_netjail_stop_v2.c
+++ b/src/testing/testing_api_cmd_netjail_stop_v2.c
@@ -40,6 +40,11 @@ static struct GNUNET_ChildWaitHandle *cwh;
40struct NetJailState 40struct NetJailState
41{ 41{
42 /** 42 /**
43 * Context for our asynchronous completion.
44 */
45 struct GNUNET_TESTING_AsyncContext ac;
46
47 /**
43 * Configuration file for the test topology. 48 * Configuration file for the test topology.
44 */ 49 */
45 char *topology_config; 50 char *topology_config;
@@ -49,8 +54,6 @@ struct NetJailState
49 */ 54 */
50 struct GNUNET_OS_Process *stop_proc; 55 struct GNUNET_OS_Process *stop_proc;
51 56
52 // Flag indication if the script finished.
53 enum GNUNET_GenericReturnValue finished;
54}; 57};
55 58
56 59
@@ -82,20 +85,6 @@ netjail_stop_cleanup (void *cls)
82 85
83 86
84/** 87/**
85 * Trait function of this cmd does nothing.
86 *
87 */
88static enum GNUNET_GenericReturnValue
89netjail_stop_traits (void *cls,
90 const void **ret,
91 const char *trait,
92 unsigned int index)
93{
94 return GNUNET_NO;
95}
96
97
98/**
99 * Callback which will be called if the setup script finished. 88 * Callback which will be called if the setup script finished.
100 * 89 *
101 */ 90 */
@@ -106,17 +95,17 @@ child_completed_callback (void *cls,
106{ 95{
107 struct NetJailState *ns = cls; 96 struct NetJailState *ns = cls;
108 97
109 cwh = NULL; 98 cwh = NULL; // WTF? globals!?!?!
99 GNUNET_OS_process_destroy (ns->stop_proc);
100 ns->stop_proc = NULL;
110 if (0 == exit_code) 101 if (0 == exit_code)
111 { 102 {
112 ns->finished = GNUNET_YES; 103 GNUNET_TESTING_async_finish (&ns->ac);
113 } 104 }
114 else 105 else
115 { 106 {
116 ns->finished = GNUNET_SYSERR; 107 GNUNET_TESTING_async_fail (&ns->ac);
117 } 108 }
118 GNUNET_OS_process_destroy (ns->stop_proc);
119 ns->stop_proc = NULL;
120} 109}
121 110
122 111
@@ -132,6 +121,7 @@ netjail_stop_run (void *cls,
132{ 121{
133 struct NetJailState *ns = cls; 122 struct NetJailState *ns = cls;
134 char *pid; 123 char *pid;
124
135 GNUNET_asprintf (&pid, 125 GNUNET_asprintf (&pid,
136 "%u", 126 "%u",
137 getpid ()); 127 getpid ());
@@ -170,36 +160,9 @@ netjail_stop_run (void *cls,
170 &child_completed_callback, 160 &child_completed_callback,
171 ns); 161 ns);
172 GNUNET_break (NULL != cwh); 162 GNUNET_break (NULL != cwh);
173
174} 163}
175 164
176 165
177/**
178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 *
180 */
181static enum GNUNET_GenericReturnValue
182netjail_stop_finish (void *cls,
183 GNUNET_SCHEDULER_TaskCallback cont,
184 void *cont_cls)
185{
186 struct NetJailState *ns = cls;
187
188 if (ns->finished)
189 {
190 cont (cont_cls);
191 }
192 return ns->finished;
193}
194
195
196/**
197 * Create command.
198 *
199 * @param label name for command.
200 * @param topology_config Configuration file for the test topology.
201 * @return command.
202 */
203struct GNUNET_TESTING_Command 166struct GNUNET_TESTING_Command
204GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, 167GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
205 char *topology_config) 168 char *topology_config)
@@ -213,9 +176,8 @@ GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
213 .cls = ns, 176 .cls = ns,
214 .label = label, 177 .label = label,
215 .run = &netjail_stop_run, 178 .run = &netjail_stop_run,
216 .finish = &netjail_stop_finish, 179 .ac = &ns->ac,
217 .cleanup = &netjail_stop_cleanup, 180 .cleanup = &netjail_stop_cleanup
218 .traits = &netjail_stop_traits
219 }; 181 };
220 182
221 return cmd; 183 return cmd;
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index b21e01fcc..e0cb3fcda 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -46,7 +46,7 @@ struct GNUNET_TESTING_Interpreter
46 * Closure for @e rc. 46 * Closure for @e rc.
47 */ 47 */
48 void *rc_cls; 48 void *rc_cls;
49 49
50 /** 50 /**
51 * Commands the interpreter will run. 51 * Commands the interpreter will run.
52 */ 52 */
@@ -294,7 +294,7 @@ interpreter_run (void *cls)
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
295 "Running command END\n"); 295 "Running command END\n");
296 is->result = GNUNET_OK; 296 is->result = GNUNET_OK;
297 GNUNET_SCHEDULER_shutdown (); 297 finish_test (is);
298 return; 298 return;
299 } 299 }
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -304,17 +304,19 @@ interpreter_run (void *cls)
304 = cmd->last_req_time 304 = cmd->last_req_time
305 = GNUNET_TIME_absolute_get (); 305 = GNUNET_TIME_absolute_get ();
306 cmd->num_tries = 1; 306 cmd->num_tries = 1;
307 cmd->run (cmd->cls, 307 if (NULL != cmd->ac)
308 is);
309 if ( (NULL != cmd->finish) &&
310 (! cmd->asynchronous_finish) )
311 { 308 {
312 cmd->finish (cmd->cls, 309 cmd->ac->is = is;
313 &interpreter_next, 310 cmd->ac->cont = &interpreter_next;
314 is); 311 cmd->ac->cont_cls = is;
312 cmd->ac->finished = GNUNET_NO;
315 } 313 }
316 else 314 cmd->run (cmd->cls,
315 is);
316 if ( (cmd->asynchronous_finish) &&
317 (NULL != cmd->ac->cont) )
317 { 318 {
319 cmd->ac->cont = NULL;
318 interpreter_next (is); 320 interpreter_next (is);
319 } 321 }
320} 322}
@@ -380,12 +382,12 @@ struct MainParams
380 382
381 /** 383 /**
382 * Global timeout for the test. 384 * Global timeout for the test.
383 */ 385 */
384 struct GNUNET_TIME_Relative timeout; 386 struct GNUNET_TIME_Relative timeout;
385 387
386 /** 388 /**
387 * Set to #EXIT_FAILURE on error. 389 * Set to #EXIT_FAILURE on error.
388 */ 390 */
389 int rv; 391 int rv;
390}; 392};
391 393
@@ -444,4 +446,31 @@ GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
444} 446}
445 447
446 448
449void
450GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac)
451{
452 GNUNET_assert (GNUNET_NO == ac->finished);
453 ac->finished = GNUNET_SYSERR;
454 GNUNET_TESTING_interpreter_fail (ac->is);
455 if (NULL != ac->cont)
456 {
457 ac->cont (ac->cont_cls);
458 ac->cont = NULL;
459 }
460}
461
462
463void
464GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac)
465{
466 GNUNET_assert (GNUNET_NO == ac->finished);
467 ac->finished = GNUNET_OK;
468 if (NULL != ac->cont)
469 {
470 ac->cont (ac->cont_cls);
471 ac->cont = NULL;
472 }
473}
474
475
447/* end of testing_api_loop.c */ 476/* end of testing_api_loop.c */
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index ddf1c3872..82194ff15 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -42,6 +42,11 @@
42 */ 42 */
43struct ConnectPeersState 43struct ConnectPeersState
44{ 44{
45 /**
46 * Context for our asynchronous completion.
47 */
48 struct GNUNET_TESTING_AsyncContext ac;
49
45 // Label of the cmd which started the test system. 50 // Label of the cmd which started the test system.
46 const char *create_label; 51 const char *create_label;
47 52
@@ -183,6 +188,7 @@ connect_peers_run (void *cls,
183 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. 188 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
184 * 189 *
185 */ 190 */
191// FIXME: this needs a complete rewrite!
186static int 192static int
187connect_peers_finish (void *cls, 193connect_peers_finish (void *cls,
188 GNUNET_SCHEDULER_TaskCallback cont, 194 GNUNET_SCHEDULER_TaskCallback cont,
@@ -222,20 +228,6 @@ connect_peers_finish (void *cls,
222 228
223 229
224/** 230/**
225 * Trait function of this cmd does nothing.
226 *
227 */
228static int
229connect_peers_traits (void *cls,
230 const void **ret,
231 const char *trait,
232 unsigned int index)
233{
234 return GNUNET_OK;
235}
236
237
238/**
239 * The cleanup function of this cmd frees resources the cmd allocated. 231 * The cleanup function of this cmd frees resources the cmd allocated.
240 * 232 *
241 */ 233 */
@@ -249,13 +241,6 @@ connect_peers_cleanup (void *cls)
249} 241}
250 242
251 243
252/**
253 * Create command.
254 *
255 * @param label name for command.
256 * @param start_peer_label Label of the cmd to start a peer.
257 * @return command.
258 */
259struct GNUNET_TESTING_Command 244struct GNUNET_TESTING_Command
260GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 245GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
261 const char *start_peer_label, 246 const char *start_peer_label,
@@ -269,15 +254,15 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
269 cps->num = num; 254 cps->num = num;
270 cps->create_label = create_label; 255 cps->create_label = create_label;
271 256
272 257 {
273 struct GNUNET_TESTING_Command cmd = { 258 struct GNUNET_TESTING_Command cmd = {
274 .cls = cps, 259 .cls = cps,
275 .label = label, 260 .label = label,
276 .run = &connect_peers_run, 261 .run = &connect_peers_run,
277 .finish = &connect_peers_finish, 262 .ac = &cps->ac,
278 .cleanup = &connect_peers_cleanup, 263 .cleanup = &connect_peers_cleanup
279 .traits = &connect_peers_traits 264 };
280 }; 265
281 266 return cmd;
282 return cmd; 267 }
283} 268}
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
index 8ef556946..8d0f74916 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v2.c
@@ -44,6 +44,11 @@
44 */ 44 */
45struct ConnectPeersState 45struct ConnectPeersState
46{ 46{
47 /**
48 * Context for our asynchronous completion.
49 */
50 struct GNUNET_TESTING_AsyncContext ac;
51
47 // Label of the cmd which started the test system. 52 // Label of the cmd which started the test system.
48 const char *create_label; 53 const char *create_label;
49 54
@@ -185,20 +190,6 @@ connect_peers_finish (void *cls,
185 190
186 191
187/** 192/**
188 * Trait function of this cmd does nothing.
189 *
190 */
191static int
192connect_peers_traits (void *cls,
193 const void **ret,
194 const char *trait,
195 unsigned int index)
196{
197 return GNUNET_OK;
198}
199
200
201/**
202 * The cleanup function of this cmd frees resources the cmd allocated. 193 * The cleanup function of this cmd frees resources the cmd allocated.
203 * 194 *
204 */ 195 */
@@ -237,9 +228,8 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
237 .cls = cps, 228 .cls = cps,
238 .label = label, 229 .label = label,
239 .run = &connect_peers_run, 230 .run = &connect_peers_run,
240 .finish = &connect_peers_finish, 231 .ac = &cps->ac,
241 .cleanup = &connect_peers_cleanup, 232 .cleanup = &connect_peers_cleanup
242 .traits = &connect_peers_traits
243 }; 233 };
244 234
245 return cmd; 235 return cmd;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
index a73d81064..ae32a087a 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -59,6 +59,11 @@
59struct ConnectPeersState 59struct ConnectPeersState
60{ 60{
61 /** 61 /**
62 * Context for our asynchronous completion.
63 */
64 struct GNUNET_TESTING_AsyncContext ac;
65
66 /**
62 * The testing system of this node. 67 * The testing system of this node.
63 */ 68 */
64 struct GNUNET_TESTING_System *tl_system; 69 struct GNUNET_TESTING_System *tl_system;
@@ -448,20 +453,6 @@ connect_peers_finish (void *cls,
448 453
449 454
450/** 455/**
451 * Trait function of this cmd does nothing.
452 *
453 */
454static int
455connect_peers_traits (void *cls,
456 const void **ret,
457 const char *trait,
458 unsigned int index)
459{
460 return GNUNET_OK;
461}
462
463
464/**
465 * The cleanup function of this cmd frees resources the cmd allocated. 456 * The cleanup function of this cmd frees resources the cmd allocated.
466 * 457 *
467 */ 458 */
@@ -475,13 +466,6 @@ connect_peers_cleanup (void *cls)
475} 466}
476 467
477 468
478/**
479 * Create command.
480 *
481 * @param label name for command.
482 * @param start_peer_label Label of the cmd to start a peer.
483 * @return command.
484 */
485struct GNUNET_TESTING_Command 469struct GNUNET_TESTING_Command
486GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, 470GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
487 const char *start_peer_label, 471 const char *start_peer_label,
@@ -498,15 +482,15 @@ GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
498 cps->create_label = create_label; 482 cps->create_label = create_label;
499 cps->topology = topology; 483 cps->topology = topology;
500 484
501 485 {
502 struct GNUNET_TESTING_Command cmd = { 486 struct GNUNET_TESTING_Command cmd = {
503 .cls = cps, 487 .cls = cps,
504 .label = label, 488 .label = label,
505 .run = &connect_peers_run, 489 .run = &connect_peers_run,
506 .finish = &connect_peers_finish, 490 .ac = &cps->ac,
507 .cleanup = &connect_peers_cleanup, 491 .cleanup = &connect_peers_cleanup
508 .traits = &connect_peers_traits 492 };
509 }; 493
510 494 return cmd;
511 return cmd; 495 }
512} 496}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 8a53ed22c..44fc68807 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -51,6 +51,7 @@ hello_iter_cb (void *cb_cls,
51 const char *emsg) 51 const char *emsg)
52{ 52{
53 struct StartPeerState *sps = cb_cls; 53 struct StartPeerState *sps = cb_cls;
54
54 if (NULL == record) 55 if (NULL == record)
55 { 56 {
56 sps->pic = NULL; 57 sps->pic = NULL;
@@ -90,26 +91,6 @@ retrieve_hello (void *cls)
90 91
91 92
92/** 93/**
93 * This function checks StartPeerState#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service. 94 * Disconnect callback for the connection to the core service.
114 * 95 *
115 */ 96 */
@@ -597,14 +578,15 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
597 i * sizeof(struct GNUNET_MQ_MessageHandler)); 578 i * sizeof(struct GNUNET_MQ_MessageHandler));
598 } 579 }
599 580
600 struct GNUNET_TESTING_Command cmd = { 581 {
601 .cls = sps, 582 struct GNUNET_TESTING_Command cmd = {
602 .label = label, 583 .cls = sps,
603 .run = &start_peer_run, 584 .label = label,
604 .finish = &start_peer_finish, 585 .run = &start_peer_run,
605 .cleanup = &start_peer_cleanup, 586 .cleanup = &start_peer_cleanup,
606 .traits = &start_peer_traits 587 .traits = &start_peer_traits
607 }; 588 };
608 589
609 return cmd; 590 return cmd;
591 }
610} 592}
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
index 2ab58574a..94799eddd 100644
--- a/src/transport/transport_api_cmd_start_peer_v2.c
+++ b/src/transport/transport_api_cmd_start_peer_v2.c
@@ -597,7 +597,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
597 .cls = sps, 597 .cls = sps,
598 .label = label, 598 .label = label,
599 .run = &start_peer_run, 599 .run = &start_peer_run,
600 .finish = &start_peer_finish,
601 .cleanup = &start_peer_cleanup, 600 .cleanup = &start_peer_cleanup,
602 .traits = &start_peer_traits 601 .traits = &start_peer_traits
603 }; 602 };
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
index fa6300ef5..1a19ce60e 100644
--- a/src/transport/transport_api_cmd_start_peer_v3.c
+++ b/src/transport/transport_api_cmd_start_peer_v3.c
@@ -609,7 +609,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
609 .cls = sps, 609 .cls = sps,
610 .label = label, 610 .label = label,
611 .run = &start_peer_run, 611 .run = &start_peer_run,
612 .finish = &start_peer_finish,
613 .cleanup = &start_peer_cleanup, 612 .cleanup = &start_peer_cleanup,
614 .traits = &start_peer_traits 613 .traits = &start_peer_traits
615 }; 614 };