diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-08 20:51:35 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-08 20:51:35 +0900 |
commit | 7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e (patch) | |
tree | aaabeaa4b8e8a0afe82d8d7538d271525105da48 /src/testing | |
parent | dccf4142eaac44711692c295d81e0103c8042cd2 (diff) | |
download | gnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.tar.gz gnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.zip |
TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API
This commit changes the label member of GNUNET_TRANSPORT_Command to a
static, fixed length buffer allocated with the struct itself.
The check for the end of a command array should be done by checking the
run command instead of the label.
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/testing_api_cmd_barrier.c | 28 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_barrier_reached.c | 31 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_batch.c | 25 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_block_until_external_trigger.c | 17 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_end.c | 8 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_finish.c | 15 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_local_test_finished.c | 14 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_local_test_prepared.c | 15 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start.c | 15 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start_testsystem.c | 22 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_stop.c | 15 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_stop_testsystem.c | 12 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_send_peer_ready.c | 15 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_system_create.c | 12 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_system_destroy.c | 14 | ||||
-rw-r--r-- | src/testing/testing_api_loop.c | 42 |
16 files changed, 115 insertions, 185 deletions
diff --git a/src/testing/testing_api_cmd_barrier.c b/src/testing/testing_api_cmd_barrier.c index ad75f8297..be5dc6d2d 100644 --- a/src/testing/testing_api_cmd_barrier.c +++ b/src/testing/testing_api_cmd_barrier.c | |||
@@ -109,10 +109,10 @@ GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier) | |||
109 | unsigned int reached = barrier->reached; | 109 | unsigned int reached = barrier->reached; |
110 | double percentage_to_be_reached = barrier->percentage_to_be_reached; | 110 | double percentage_to_be_reached = barrier->percentage_to_be_reached; |
111 | unsigned int number_to_be_reached = barrier->number_to_be_reached; | 111 | unsigned int number_to_be_reached = barrier->number_to_be_reached; |
112 | 112 | double percentage_reached = (double)expected_reaches/reached*100; | |
113 | if ((0 < percentage_to_be_reached && | 113 | if (((0 < percentage_to_be_reached) && |
114 | (double)expected_reaches/reached*100) >= percentage_to_be_reached || | 114 | (percentage_reached >= percentage_to_be_reached)) || |
115 | (0 < number_to_be_reached && reached >= number_to_be_reached )) | 115 | ((0 < number_to_be_reached) && (reached >= number_to_be_reached))) |
116 | { | 116 | { |
117 | return GNUNET_YES; | 117 | return GNUNET_YES; |
118 | } | 118 | } |
@@ -237,20 +237,14 @@ GNUNET_TESTING_cmd_barrier_create (const char *label, | |||
237 | bs->label = label; | 237 | bs->label = label; |
238 | barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); | 238 | barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); |
239 | barrier->name = label; | 239 | barrier->name = label; |
240 | GNUNET_assert (0 < percentage_to_be_reached && 0 == number_to_be_reached || | 240 | GNUNET_assert ((0 < percentage_to_be_reached && 0 == number_to_be_reached) || |
241 | 0 == percentage_to_be_reached && 0 < number_to_be_reached); | 241 | (0 == percentage_to_be_reached && 0 < number_to_be_reached)); |
242 | barrier->percentage_to_be_reached; | 242 | barrier->percentage_to_be_reached; |
243 | barrier->number_to_be_reached; | 243 | barrier->number_to_be_reached; |
244 | bs->barrier = barrier; | 244 | bs->barrier = barrier; |
245 | { | 245 | return GNUNET_TESTING_command_new (bs, label, |
246 | struct GNUNET_TESTING_Command cmd = { | 246 | &barrier_run, |
247 | .cls = bs, | 247 | &barrier_cleanup, |
248 | .label = GNUNET_strdup (label), | 248 | &barrier_traits, |
249 | .run = &barrier_run, | 249 | NULL); |
250 | .cleanup = &barrier_cleanup, | ||
251 | .traits = &barrier_traits | ||
252 | }; | ||
253 | |||
254 | return cmd; | ||
255 | } | ||
256 | } | 250 | } |
diff --git a/src/testing/testing_api_cmd_barrier_reached.c b/src/testing/testing_api_cmd_barrier_reached.c index c5b0b692e..1a3b25d32 100644 --- a/src/testing/testing_api_cmd_barrier_reached.c +++ b/src/testing/testing_api_cmd_barrier_reached.c | |||
@@ -79,11 +79,11 @@ struct BarrierReachedState | |||
79 | */ | 79 | */ |
80 | static void | 80 | static void |
81 | barrier_reached_run (void *cls, | 81 | barrier_reached_run (void *cls, |
82 | struct GNUNET_TESTING_Interpreter *is) | 82 | struct GNUNET_TESTING_Interpreter *is) |
83 | { | 83 | { |
84 | struct BarrierReachedState *brs = cls; | 84 | struct BarrierReachedState *brs = cls; |
85 | struct GNUNET_TESTING_Barrier *barrier; | 85 | struct GNUNET_TESTING_Barrier *barrier; |
86 | struct GNUNET_TESTING_Command *cmd; | 86 | struct GNUNET_TESTING_Command *cmd = NULL; |
87 | size_t msg_length; | 87 | size_t msg_length; |
88 | struct GNUNET_TESTING_CommandBarrierReached *msg; | 88 | struct GNUNET_TESTING_CommandBarrierReached *msg; |
89 | 89 | ||
@@ -98,6 +98,8 @@ barrier_reached_run (void *cls, | |||
98 | barrier->reached++; | 98 | barrier->reached++; |
99 | if (GNUNET_TESTING_can_barrier_advance (barrier)) | 99 | if (GNUNET_TESTING_can_barrier_advance (barrier)) |
100 | { | 100 | { |
101 | //FIXME cmd uninitialized | ||
102 | GNUNET_assert (NULL != cmd); | ||
101 | cmd->asynchronous_finish = GNUNET_YES; | 103 | cmd->asynchronous_finish = GNUNET_YES; |
102 | GNUNET_TESTING_finish_attached_cmds (is, barrier); | 104 | GNUNET_TESTING_finish_attached_cmds (is, barrier); |
103 | } | 105 | } |
@@ -121,7 +123,7 @@ barrier_reached_run (void *cls, | |||
121 | msg_length = sizeof(struct GNUNET_TESTING_CommandBarrierReached); | 123 | msg_length = sizeof(struct GNUNET_TESTING_CommandBarrierReached); |
122 | msg = GNUNET_new (struct GNUNET_TESTING_CommandBarrierReached); | 124 | msg = GNUNET_new (struct GNUNET_TESTING_CommandBarrierReached); |
123 | msg->header.size = htons ((uint16_t) msg_length); | 125 | msg->header.size = htons ((uint16_t) msg_length); |
124 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED); | 126 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED); |
125 | msg->barrier_name = barrier->name; | 127 | msg->barrier_name = barrier->name; |
126 | msg->node_number = brs->node_number; | 128 | msg->node_number = brs->node_number; |
127 | brs->write_message ((struct GNUNET_MessageHeader *) msg, msg_length); | 129 | brs->write_message ((struct GNUNET_MessageHeader *) msg, msg_length); |
@@ -155,9 +157,9 @@ barrier_reached_cleanup (void *cls) | |||
155 | */ | 157 | */ |
156 | static enum GNUNET_GenericReturnValue | 158 | static enum GNUNET_GenericReturnValue |
157 | barrier_reached_traits (void *cls, | 159 | barrier_reached_traits (void *cls, |
158 | const void **ret, | 160 | const void **ret, |
159 | const char *trait, | 161 | const char *trait, |
160 | unsigned int index) | 162 | unsigned int index) |
161 | { | 163 | { |
162 | struct BarrierReachedState *brs = cls; | 164 | struct BarrierReachedState *brs = cls; |
163 | struct GNUNET_TESTING_AsyncContext *ac = &brs->ac; | 165 | struct GNUNET_TESTING_AsyncContext *ac = &brs->ac; |
@@ -203,16 +205,9 @@ GNUNET_TESTING_cmd_barrier_reached ( | |||
203 | brs->node_number = node_number; | 205 | brs->node_number = node_number; |
204 | brs->running_on_master = running_on_master; | 206 | brs->running_on_master = running_on_master; |
205 | brs->write_message = write_message; | 207 | brs->write_message = write_message; |
206 | { | 208 | return GNUNET_TESTING_command_new (brs, label, |
207 | struct GNUNET_TESTING_Command cmd = { | 209 | &barrier_reached_run, |
208 | .cls = brs, | 210 | &barrier_reached_cleanup, |
209 | .label = GNUNET_strdup (label), | 211 | &barrier_reached_traits, |
210 | .run = &barrier_reached_run, | 212 | &brs->ac); |
211 | .ac = &brs->ac, | ||
212 | .cleanup = &barrier_reached_cleanup, | ||
213 | .traits = &barrier_reached_traits | ||
214 | }; | ||
215 | |||
216 | return cmd; | ||
217 | } | ||
218 | } | 213 | } |
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c index e7ecbf28d..7dc990855 100644 --- a/src/testing/testing_api_cmd_batch.c +++ b/src/testing/testing_api_cmd_batch.c | |||
@@ -62,13 +62,13 @@ batch_run (void *cls, | |||
62 | { | 62 | { |
63 | struct BatchState *bs = cls; | 63 | struct BatchState *bs = cls; |
64 | 64 | ||
65 | if (NULL != bs->batch[bs->batch_ip].label) | 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); |
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].label) | 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", |
@@ -96,7 +96,7 @@ batch_cleanup (void *cls) | |||
96 | struct BatchState *bs = cls; | 96 | struct BatchState *bs = cls; |
97 | 97 | ||
98 | for (unsigned int i = 0; | 98 | for (unsigned int i = 0; |
99 | NULL != bs->batch[i].label; | 99 | NULL != bs->batch[i].run; |
100 | i++) | 100 | i++) |
101 | bs->batch[i].cleanup (bs->batch[i].cls); | 101 | bs->batch[i].cleanup (bs->batch[i].cls); |
102 | GNUNET_free (bs->batch); | 102 | GNUNET_free (bs->batch); |
@@ -161,7 +161,7 @@ GNUNET_TESTING_cmd_batch (const char *label, | |||
161 | bs = GNUNET_new (struct BatchState); | 161 | bs = GNUNET_new (struct BatchState); |
162 | bs->label = label; | 162 | bs->label = label; |
163 | /* Get number of commands. */ | 163 | /* Get number of commands. */ |
164 | for (i = 0; NULL != batch[i].label; i++) | 164 | for (i = 0; NULL != batch[i].run; i++) |
165 | /* noop */ | 165 | /* noop */ |
166 | ; | 166 | ; |
167 | 167 | ||
@@ -170,17 +170,10 @@ GNUNET_TESTING_cmd_batch (const char *label, | |||
170 | memcpy (bs->batch, | 170 | memcpy (bs->batch, |
171 | batch, | 171 | batch, |
172 | sizeof (struct GNUNET_TESTING_Command) * i); | 172 | sizeof (struct GNUNET_TESTING_Command) * i); |
173 | { | 173 | return GNUNET_TESTING_command_new (bs, label, |
174 | struct GNUNET_TESTING_Command cmd = { | 174 | &batch_run, |
175 | .cls = bs, | 175 | &batch_cleanup, |
176 | .label = GNUNET_strdup (label), | 176 | &batch_traits, NULL); |
177 | .run = &batch_run, | ||
178 | .cleanup = &batch_cleanup, | ||
179 | .traits = &batch_traits | ||
180 | }; | ||
181 | |||
182 | return cmd; | ||
183 | } | ||
184 | } | 177 | } |
185 | 178 | ||
186 | 179 | ||
@@ -189,7 +182,7 @@ GNUNET_TESTING_cmd_batch_next_ (void *cls) | |||
189 | { | 182 | { |
190 | struct BatchState *bs = cls; | 183 | struct BatchState *bs = cls; |
191 | 184 | ||
192 | if (NULL == bs->batch[bs->batch_ip].label) | 185 | if (NULL == bs->batch[bs->batch_ip].run) |
193 | return false; | 186 | return false; |
194 | bs->batch[bs->batch_ip].finish_time | 187 | bs->batch[bs->batch_ip].finish_time |
195 | = GNUNET_TIME_absolute_get (); | 188 | = GNUNET_TIME_absolute_get (); |
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 b4f088077..1e2c3be7c 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c | |||
@@ -108,16 +108,9 @@ GNUNET_TESTING_cmd_block_until_external_trigger ( | |||
108 | bs = GNUNET_new (struct BlockState); | 108 | bs = GNUNET_new (struct BlockState); |
109 | bs->label = label; | 109 | bs->label = label; |
110 | bs->asynchronous_finish = GNUNET_NO; | 110 | bs->asynchronous_finish = GNUNET_NO; |
111 | { | 111 | return GNUNET_TESTING_command_new (bs, label, |
112 | struct GNUNET_TESTING_Command cmd = { | 112 | &block_until_all_peers_started_run, |
113 | .cls = bs, | 113 | &block_until_all_peers_started_cleanup, |
114 | .label = GNUNET_strdup (label), | 114 | &block_until_external_trigger_traits, |
115 | .run = &block_until_all_peers_started_run, | 115 | &bs->ac); |
116 | .ac = &bs->ac, | ||
117 | .cleanup = &block_until_all_peers_started_cleanup, | ||
118 | .traits = block_until_external_trigger_traits | ||
119 | }; | ||
120 | |||
121 | return cmd; | ||
122 | } | ||
123 | } | 116 | } |
diff --git a/src/testing/testing_api_cmd_end.c b/src/testing/testing_api_cmd_end.c index f0f036429..085420f81 100644 --- a/src/testing/testing_api_cmd_end.c +++ b/src/testing/testing_api_cmd_end.c | |||
@@ -29,11 +29,9 @@ | |||
29 | struct GNUNET_TESTING_Command | 29 | struct GNUNET_TESTING_Command |
30 | GNUNET_TESTING_cmd_end (void) | 30 | GNUNET_TESTING_cmd_end (void) |
31 | { | 31 | { |
32 | static struct GNUNET_TESTING_Command cmd = { | 32 | return GNUNET_TESTING_command_new (NULL, NULL, |
33 | .label = NULL | 33 | NULL, NULL, |
34 | }; | 34 | NULL, NULL); |
35 | |||
36 | return cmd; | ||
37 | } | 35 | } |
38 | 36 | ||
39 | 37 | ||
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c index cad5edc67..b352e28dc 100644 --- a/src/testing/testing_api_cmd_finish.c +++ b/src/testing/testing_api_cmd_finish.c | |||
@@ -175,17 +175,10 @@ GNUNET_TESTING_cmd_finish (const char *finish_label, | |||
175 | finish_state = GNUNET_new (struct FinishState); | 175 | finish_state = GNUNET_new (struct FinishState); |
176 | finish_state->async_label = cmd_ref; | 176 | finish_state->async_label = cmd_ref; |
177 | finish_state->timeout = timeout; | 177 | finish_state->timeout = timeout; |
178 | { | 178 | return GNUNET_TESTING_command_new (finish_state, finish_label, |
179 | struct GNUNET_TESTING_Command cmd = { | 179 | &run_finish, |
180 | .cls = finish_state, | 180 | &cleanup_finish, |
181 | .label = GNUNET_strdup (finish_label), | 181 | NULL, &finish_state->ac); |
182 | .run = &run_finish, | ||
183 | .ac = &finish_state->ac, | ||
184 | .cleanup = &cleanup_finish | ||
185 | }; | ||
186 | |||
187 | return cmd; | ||
188 | } | ||
189 | } | 182 | } |
190 | 183 | ||
191 | 184 | ||
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index 7eca7e0d3..fb6fef030 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c | |||
@@ -107,14 +107,8 @@ GNUNET_TESTING_cmd_local_test_finished ( | |||
107 | 107 | ||
108 | lfs = GNUNET_new (struct LocalFinishedState); | 108 | lfs = GNUNET_new (struct LocalFinishedState); |
109 | lfs->write_message = write_message; | 109 | lfs->write_message = write_message; |
110 | { | 110 | return GNUNET_TESTING_command_new (lfs, label, |
111 | struct GNUNET_TESTING_Command cmd = { | 111 | &local_test_finished_run, |
112 | .cls = lfs, | 112 | &local_test_finished_cleanup, |
113 | .label = GNUNET_strdup (label), | 113 | NULL, NULL); |
114 | .run = &local_test_finished_run, | ||
115 | .cleanup = &local_test_finished_cleanup, | ||
116 | }; | ||
117 | |||
118 | return cmd; | ||
119 | } | ||
120 | } | 114 | } |
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c index a4082f0e3..3f976f554 100644 --- a/src/testing/testing_api_cmd_local_test_prepared.c +++ b/src/testing/testing_api_cmd_local_test_prepared.c | |||
@@ -102,14 +102,9 @@ GNUNET_TESTING_cmd_local_test_prepared (const char *label, | |||
102 | lfs = GNUNET_new (struct LocalPreparedState); | 102 | lfs = GNUNET_new (struct LocalPreparedState); |
103 | lfs->write_message = write_message; | 103 | lfs->write_message = write_message; |
104 | 104 | ||
105 | struct GNUNET_TESTING_Command cmd = { | 105 | return GNUNET_TESTING_command_new (lfs, label, |
106 | .cls = lfs, | 106 | &local_test_prepared_run, |
107 | .label = GNUNET_strdup (label), | 107 | &local_test_prepared_cleanup, |
108 | .run = &local_test_prepared_run, | 108 | &local_test_prepared_traits, |
109 | .ac = &lfs->ac, | 109 | &lfs->ac); |
110 | .cleanup = &local_test_prepared_cleanup, | ||
111 | .traits = &local_test_prepared_traits | ||
112 | }; | ||
113 | |||
114 | return cmd; | ||
115 | } | 110 | } |
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 8b239275b..9c1949c88 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c | |||
@@ -222,15 +222,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label, | |||
222 | ns = GNUNET_new (struct NetJailState); | 222 | ns = GNUNET_new (struct NetJailState); |
223 | ns->topology_config = topology_config; | 223 | ns->topology_config = topology_config; |
224 | ns->read_file = read_file; | 224 | ns->read_file = read_file; |
225 | { | 225 | return GNUNET_TESTING_command_new (ns, label, |
226 | struct GNUNET_TESTING_Command cmd = { | 226 | &netjail_start_run, |
227 | .cls = ns, | 227 | &netjail_start_cleanup, |
228 | .label = GNUNET_strdup (label), | 228 | NULL, &ns->ac); |
229 | .run = &netjail_start_run, | ||
230 | .ac = &ns->ac, | ||
231 | .cleanup = &netjail_start_cleanup | ||
232 | }; | ||
233 | |||
234 | return cmd; | ||
235 | } | ||
236 | } | 229 | } |
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index d33284b78..6663e9b82 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c | |||
@@ -284,9 +284,9 @@ send_message_to_locals ( | |||
284 | tbc = GNUNET_new (struct TestingSystemCount); | 284 | tbc = GNUNET_new (struct TestingSystemCount); |
285 | tbc->ns = ns; | 285 | tbc->ns = ns; |
286 | if (0 == i) | 286 | if (0 == i) |
287 | count = j; | 287 | count = j; |
288 | else | 288 | else |
289 | count = (i - 1) * ns->local_m + j + ns->known; | 289 | count = (i - 1) * ns->local_m + j + ns->known; |
290 | 290 | ||
291 | helper = ns->helper[count - 1]; | 291 | helper = ns->helper[count - 1]; |
292 | 292 | ||
@@ -311,7 +311,7 @@ send_barrier_advanced (struct GNUNET_TESTING_CommandBarrierReached *rm, | |||
311 | { | 311 | { |
312 | struct GNUNET_TESTING_CommandBarrierAdvanced *adm = GNUNET_new (struct GNUNET_TESTING_CommandBarrierAdvanced); | 312 | struct GNUNET_TESTING_CommandBarrierAdvanced *adm = GNUNET_new (struct GNUNET_TESTING_CommandBarrierAdvanced); |
313 | size_t msg_length = sizeof(struct GNUNET_TESTING_CommandAllLocalTestsPrepared); | 313 | size_t msg_length = sizeof(struct GNUNET_TESTING_CommandAllLocalTestsPrepared); |
314 | 314 | ||
315 | adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); | 315 | adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); |
316 | adm->header.size = htons ((uint16_t) msg_length); | 316 | adm->header.size = htons ((uint16_t) msg_length); |
317 | adm->barrier_name = rm->barrier_name; | 317 | adm->barrier_name = rm->barrier_name; |
@@ -383,7 +383,6 @@ barrier_reached (struct NetJailState *ns, const struct GNUNET_MessageHeader *mes | |||
383 | { | 383 | { |
384 | struct GNUNET_TESTING_CommandBarrierReached *rm = (struct GNUNET_TESTING_CommandBarrierReached *) message; | 384 | struct GNUNET_TESTING_CommandBarrierReached *rm = (struct GNUNET_TESTING_CommandBarrierReached *) message; |
385 | struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (ns->is, rm->barrier_name); | 385 | struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (ns->is, rm->barrier_name); |
386 | struct GNUNET_TESTING_NetjailNode *node; | ||
387 | 386 | ||
388 | GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); | 387 | GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); |
389 | barrier->reached++; | 388 | barrier->reached++; |
@@ -825,14 +824,9 @@ GNUNET_TESTING_cmd_netjail_start_testing_system ( | |||
825 | ns->topology_data = topology_data; | 824 | ns->topology_data = topology_data; |
826 | ns->timeout = GNUNET_TIME_relative_subtract (timeout, TIMEOUT); | 825 | ns->timeout = GNUNET_TIME_relative_subtract (timeout, TIMEOUT); |
827 | 826 | ||
828 | struct GNUNET_TESTING_Command cmd = { | 827 | return GNUNET_TESTING_command_new (ns, label, |
829 | .cls = ns, | 828 | &netjail_exec_run, |
830 | .label = GNUNET_strdup (label), | 829 | &netjail_exec_cleanup, |
831 | .run = &netjail_exec_run, | 830 | &netjail_exec_traits, |
832 | .ac = &ns->ac, | 831 | &ns->ac); |
833 | .cleanup = &netjail_exec_cleanup, | ||
834 | .traits = &netjail_exec_traits | ||
835 | }; | ||
836 | |||
837 | return cmd; | ||
838 | } | 832 | } |
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 05435f63c..49151a168 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c | |||
@@ -189,15 +189,8 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label, | |||
189 | ns = GNUNET_new (struct NetJailState); | 189 | ns = GNUNET_new (struct NetJailState); |
190 | ns->topology_config = topology_config; | 190 | ns->topology_config = topology_config; |
191 | ns->read_file = read_file; | 191 | ns->read_file = read_file; |
192 | { | 192 | return GNUNET_TESTING_command_new (ns, label, |
193 | struct GNUNET_TESTING_Command cmd = { | 193 | &netjail_stop_run, |
194 | .cls = ns, | 194 | &netjail_stop_cleanup, |
195 | .label = GNUNET_strdup (label), | 195 | NULL, &ns->ac); |
196 | .run = &netjail_stop_run, | ||
197 | .ac = &ns->ac, | ||
198 | .cleanup = &netjail_stop_cleanup | ||
199 | }; | ||
200 | |||
201 | return cmd; | ||
202 | } | ||
203 | } | 196 | } |
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 69455c909..38b14ac5c 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c | |||
@@ -147,12 +147,8 @@ GNUNET_TESTING_cmd_stop_testing_system ( | |||
147 | shs->known = topology->nodes_x; | 147 | shs->known = topology->nodes_x; |
148 | shs->topology = topology; | 148 | shs->topology = topology; |
149 | 149 | ||
150 | struct GNUNET_TESTING_Command cmd = { | 150 | return GNUNET_TESTING_command_new (shs, label, |
151 | .cls = shs, | 151 | &stop_testing_system_run, |
152 | .label = GNUNET_strdup (label), | 152 | &stop_testing_system_cleanup, |
153 | .run = &stop_testing_system_run, | 153 | NULL, NULL); |
154 | .cleanup = &stop_testing_system_cleanup, | ||
155 | }; | ||
156 | |||
157 | return cmd; | ||
158 | } | 154 | } |
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c index f277b8dbd..d76a95ae8 100644 --- a/src/testing/testing_api_cmd_send_peer_ready.c +++ b/src/testing/testing_api_cmd_send_peer_ready.c | |||
@@ -113,15 +113,8 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label, | |||
113 | 113 | ||
114 | sprs = GNUNET_new (struct SendPeerReadyState); | 114 | sprs = GNUNET_new (struct SendPeerReadyState); |
115 | sprs->write_message = write_message; | 115 | sprs->write_message = write_message; |
116 | { | 116 | return GNUNET_TESTING_command_new (sprs, label, |
117 | struct GNUNET_TESTING_Command cmd = { | 117 | &send_peer_ready_run, |
118 | .cls = sprs, | 118 | &send_peer_ready_cleanup, |
119 | .label = GNUNET_strdup (label), | 119 | &send_peer_ready_traits, NULL); |
120 | .run = &send_peer_ready_run, | ||
121 | .cleanup = &send_peer_ready_cleanup, | ||
122 | .traits = &send_peer_ready_traits | ||
123 | }; | ||
124 | |||
125 | return cmd; | ||
126 | } | ||
127 | } | 120 | } |
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c index 4199eccd6..66b0f57b9 100644 --- a/src/testing/testing_api_cmd_system_create.c +++ b/src/testing/testing_api_cmd_system_create.c | |||
@@ -117,13 +117,7 @@ GNUNET_TESTING_cmd_system_create (const char *label, | |||
117 | tss = GNUNET_new (struct TestSystemState); | 117 | tss = GNUNET_new (struct TestSystemState); |
118 | tss->testdir = testdir; | 118 | tss->testdir = testdir; |
119 | 119 | ||
120 | struct GNUNET_TESTING_Command cmd = { | 120 | return GNUNET_TESTING_command_new (tss, label, &system_create_run, |
121 | .cls = tss, | 121 | &system_create_cleanup, |
122 | .label = GNUNET_strdup (label), | 122 | &system_create_traits, NULL); |
123 | .run = &system_create_run, | ||
124 | .cleanup = &system_create_cleanup, | ||
125 | .traits = &system_create_traits | ||
126 | }; | ||
127 | |||
128 | return cmd; | ||
129 | } | 123 | } |
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c index ebb975fc3..23d8b9162 100644 --- a/src/testing/testing_api_cmd_system_destroy.c +++ b/src/testing/testing_api_cmd_system_destroy.c | |||
@@ -104,15 +104,7 @@ GNUNET_TESTING_cmd_system_destroy (const char *label, | |||
104 | 104 | ||
105 | tss = GNUNET_new (struct TestSystemState); | 105 | tss = GNUNET_new (struct TestSystemState); |
106 | tss->create_label = create_label; | 106 | tss->create_label = create_label; |
107 | { | 107 | return GNUNET_TESTING_command_new (tss, label, &system_destroy_run, |
108 | struct GNUNET_TESTING_Command cmd = { | 108 | &system_destroy_cleanup, |
109 | .cls = tss, | 109 | &system_destroy_traits, NULL); |
110 | .label = GNUNET_strdup (label), | ||
111 | .run = &system_destroy_run, | ||
112 | .cleanup = &system_destroy_cleanup, | ||
113 | .traits = &system_destroy_traits | ||
114 | }; | ||
115 | |||
116 | return cmd; | ||
117 | } | ||
118 | } | 110 | } |
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index a3a8219b3..da95500f7 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c | |||
@@ -149,12 +149,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is, | |||
149 | { | 149 | { |
150 | const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; | 150 | const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; |
151 | 151 | ||
152 | if (NULL != cmd->label) | 152 | if (NULL != cmd->run) |
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "label to compare %s\n", | 154 | "label to compare %s\n", |
155 | cmd->label); | 155 | cmd->label); |
156 | /* Give precedence to top-level commands. */ | 156 | /* Give precedence to top-level commands. */ |
157 | if ( (NULL != cmd->label) && | 157 | if ( (NULL != cmd->run) && |
158 | (0 == strcmp (cmd->label, | 158 | (0 == strcmp (cmd->label, |
159 | label)) ) | 159 | label)) ) |
160 | return cmd; | 160 | return cmd; |
@@ -173,12 +173,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is, | |||
173 | /* We must do the loop forward, but we can find the last match */ | 173 | /* We must do the loop forward, but we can find the last match */ |
174 | match = NULL; | 174 | match = NULL; |
175 | for (unsigned int j = 0; | 175 | for (unsigned int j = 0; |
176 | NULL != (icmd = &(*batch)[j])->label; | 176 | NULL != (icmd = &(*batch)[j])->run; |
177 | j++) | 177 | j++) |
178 | { | 178 | { |
179 | if (current == icmd) | 179 | if (current == icmd) |
180 | break; /* do not go past current command */ | 180 | break; /* do not go past current command */ |
181 | if ( (NULL != icmd->label) && | 181 | if ( (NULL != icmd->run) && |
182 | (0 == strcmp (icmd->label, | 182 | (0 == strcmp (icmd->label, |
183 | label)) ) | 183 | label)) ) |
184 | match = icmd; | 184 | match = icmd; |
@@ -264,14 +264,13 @@ finish_test (void *cls) | |||
264 | label, | 264 | label, |
265 | is->result); | 265 | is->result); |
266 | for (unsigned int j = 0; | 266 | for (unsigned int j = 0; |
267 | NULL != (cmd = &is->commands[j])->label; | 267 | NULL != (cmd = &is->commands[j])->run; |
268 | j++) | 268 | j++) |
269 | { | 269 | { |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
271 | "Cleaning up cmd %s\n", | 271 | "Cleaning up cmd %s\n", |
272 | cmd->label); | 272 | cmd->label); |
273 | cmd->cleanup (cmd->cls); | 273 | cmd->cleanup (cmd->cls); |
274 | GNUNET_free (cmd->label); | ||
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
276 | "Cleaned up cmd %s\n", | 275 | "Cleaned up cmd %s\n", |
277 | cmd->label); | 276 | cmd->label); |
@@ -407,7 +406,7 @@ interpreter_run (void *cls) | |||
407 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; | 406 | struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; |
408 | 407 | ||
409 | is->task = NULL; | 408 | is->task = NULL; |
410 | if (NULL == cmd->label) | 409 | if (NULL == cmd->run) |
411 | { | 410 | { |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
413 | "Running command END\n"); | 412 | "Running command END\n"); |
@@ -490,7 +489,7 @@ GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command) | |||
490 | 489 | ||
491 | 490 | ||
492 | struct GNUNET_TESTING_Interpreter * | 491 | struct GNUNET_TESTING_Interpreter * |
493 | GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | 492 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, |
494 | struct GNUNET_TIME_Relative timeout, | 493 | struct GNUNET_TIME_Relative timeout, |
495 | GNUNET_TESTING_ResultCallback rc, | 494 | GNUNET_TESTING_ResultCallback rc, |
496 | void *rc_cls) | 495 | void *rc_cls) |
@@ -503,7 +502,7 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | |||
503 | is->rc_cls = rc_cls; | 502 | is->rc_cls = rc_cls; |
504 | is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | 503 | is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); |
505 | /* get the number of commands */ | 504 | /* get the number of commands */ |
506 | for (i = 0; NULL != commands[i].label; i++) | 505 | for (i = 0; NULL != commands[i].run; i++) |
507 | ; | 506 | ; |
508 | is->cmds_n = i + 1; | 507 | is->cmds_n = i + 1; |
509 | is->commands = GNUNET_new_array (is->cmds_n, | 508 | is->commands = GNUNET_new_array (is->cmds_n, |
@@ -521,6 +520,27 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | |||
521 | return is; | 520 | return is; |
522 | } | 521 | } |
523 | 522 | ||
523 | struct GNUNET_TESTING_Command | ||
524 | GNUNET_TESTING_command_new (void *cls, | ||
525 | const char *label, | ||
526 | GNUNET_TESTING_CommandRunRoutine run, | ||
527 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
528 | GNUNET_TESTING_CommandGetTraits traits, | ||
529 | struct GNUNET_TESTING_AsyncContext *ac) | ||
530 | { | ||
531 | struct GNUNET_TESTING_Command cmd = { | ||
532 | .cls = cls, | ||
533 | .run = run, | ||
534 | .ac = ac, | ||
535 | .cleanup = cleanup, | ||
536 | .traits = traits | ||
537 | }; | ||
538 | memset (&cmd, 0, sizeof (cmd)); | ||
539 | strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH); | ||
540 | |||
541 | return cmd; | ||
542 | |||
543 | } | ||
524 | 544 | ||
525 | /** | 545 | /** |
526 | * Closure for #loop_run(). | 546 | * Closure for #loop_run(). |
@@ -658,6 +678,7 @@ free_barrier_node_cb (void *cls, | |||
658 | node->node_number); | 678 | node->node_number); |
659 | } | 679 | } |
660 | GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); | 680 | GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); |
681 | return GNUNET_YES; | ||
661 | } | 682 | } |
662 | 683 | ||
663 | 684 | ||
@@ -708,7 +729,6 @@ free_barriers_cb (void *cls, | |||
708 | struct GNUNET_TESTING_Interpreter *is = cls; | 729 | struct GNUNET_TESTING_Interpreter *is = cls; |
709 | struct GNUNET_TESTING_Barrier *barrier = value; | 730 | struct GNUNET_TESTING_Barrier *barrier = value; |
710 | struct GNUNET_TESTING_Command *pos; | 731 | struct GNUNET_TESTING_Command *pos; |
711 | struct GNUNET_TESTING_NetjailNode *node; | ||
712 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; | 732 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; |
713 | 733 | ||
714 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); | 734 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); |
@@ -725,6 +745,7 @@ free_barriers_cb (void *cls, | |||
725 | GNUNET_free (pos); | 745 | GNUNET_free (pos); |
726 | } | 746 | } |
727 | GNUNET_free (barrier); | 747 | GNUNET_free (barrier); |
748 | return GNUNET_YES; | ||
728 | } | 749 | } |
729 | 750 | ||
730 | 751 | ||
@@ -756,7 +777,6 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, | |||
756 | struct GNUNET_HashCode hc; | 777 | struct GNUNET_HashCode hc; |
757 | struct GNUNET_ShortHashCode create_key; | 778 | struct GNUNET_ShortHashCode create_key; |
758 | struct GNUNET_TESTING_Barrier *barrier; | 779 | struct GNUNET_TESTING_Barrier *barrier; |
759 | unsigned int kx; | ||
760 | 780 | ||
761 | GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc); | 781 | GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc); |
762 | memcpy (&create_key, | 782 | memcpy (&create_key, |