aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-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
11 files changed, 176 insertions, 401 deletions
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 */