diff options
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r-- | src/testing/testing_api_loop.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index f4fa4e17e..0c24c0e26 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c | |||
@@ -35,6 +35,7 @@ | |||
35 | 35 | ||
36 | struct GNUNET_TESTING_Interpreter *is; | 36 | struct GNUNET_TESTING_Interpreter *is; |
37 | 37 | ||
38 | |||
38 | /** | 39 | /** |
39 | * Closure used to sync an asynchronous with an synchronous command. | 40 | * Closure used to sync an asynchronous with an synchronous command. |
40 | */ | 41 | */ |
@@ -57,6 +58,7 @@ struct SyncTaskClosure | |||
57 | struct GNUNET_TESTING_Interpreter *is; | 58 | struct GNUNET_TESTING_Interpreter *is; |
58 | }; | 59 | }; |
59 | 60 | ||
61 | |||
60 | /** | 62 | /** |
61 | * Closure used to run the finish task. | 63 | * Closure used to run the finish task. |
62 | */ | 64 | */ |
@@ -74,6 +76,7 @@ struct FinishTaskClosure | |||
74 | struct GNUNET_TESTING_Interpreter *is; | 76 | struct GNUNET_TESTING_Interpreter *is; |
75 | }; | 77 | }; |
76 | 78 | ||
79 | |||
77 | /** | 80 | /** |
78 | * Lookup command by label. | 81 | * Lookup command by label. |
79 | * | 82 | * |
@@ -185,6 +188,10 @@ interpreter_next (void *cls) | |||
185 | } | 188 | } |
186 | 189 | ||
187 | 190 | ||
191 | /** | ||
192 | * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. | ||
193 | * | ||
194 | */ | ||
188 | static void | 195 | static void |
189 | run_finish_task_next (void *cls) | 196 | run_finish_task_next (void *cls) |
190 | { | 197 | { |
@@ -212,6 +219,12 @@ run_finish_task_next (void *cls) | |||
212 | } | 219 | } |
213 | 220 | ||
214 | 221 | ||
222 | /** | ||
223 | * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called. | ||
224 | * | ||
225 | * //TODO run_finish_task_next and this function can be merged. | ||
226 | * | ||
227 | */ | ||
215 | static void | 228 | static void |
216 | run_finish_task_sync (void *cls) | 229 | run_finish_task_sync (void *cls) |
217 | { | 230 | { |
@@ -248,13 +261,17 @@ run_finish_task_sync (void *cls) | |||
248 | } | 261 | } |
249 | else | 262 | else |
250 | { | 263 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
252 | "Sync task finished with an error.\n"); | 265 | "Sync task finished with an error.\n"); |
253 | GNUNET_TESTING_interpreter_fail (); | 266 | GNUNET_TESTING_interpreter_fail (); |
254 | } | 267 | } |
255 | } | 268 | } |
256 | 269 | ||
257 | 270 | ||
271 | /** | ||
272 | * run method of the command created by the interpreter to wait for another command to finish. | ||
273 | * | ||
274 | */ | ||
258 | static void | 275 | static void |
259 | start_finish_on_ref (void *cls, | 276 | start_finish_on_ref (void *cls, |
260 | const struct GNUNET_TESTING_Command *cmd, | 277 | const struct GNUNET_TESTING_Command *cmd, |
@@ -277,6 +294,17 @@ start_finish_on_ref (void *cls, | |||
277 | } | 294 | } |
278 | 295 | ||
279 | 296 | ||
297 | /** | ||
298 | * Create (synchronous) command that waits for another command to finish. | ||
299 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
300 | * the test case. | ||
301 | * | ||
302 | * @param finish_label label for this command | ||
303 | * @param cmd_ref reference to a previous command which we should | ||
304 | * wait for (call `finish()` on) | ||
305 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
306 | * @return a finish-command. | ||
307 | */ | ||
280 | const struct GNUNET_TESTING_Command | 308 | const struct GNUNET_TESTING_Command |
281 | GNUNET_TESTING_cmd_finish (const char *finish_label, | 309 | GNUNET_TESTING_cmd_finish (const char *finish_label, |
282 | const char *cmd_ref, | 310 | const char *cmd_ref, |
@@ -340,7 +368,7 @@ GNUNET_TESTING_interpreter_fail () | |||
340 | while (GNUNET_TESTING_cmd_is_batch (cmd)) | 368 | while (GNUNET_TESTING_cmd_is_batch (cmd)) |
341 | { | 369 | { |
342 | cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); | 370 | cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | "Batch is at command `%s'\n", | 372 | "Batch is at command `%s'\n", |
345 | cmd->label); | 373 | cmd->label); |
346 | } | 374 | } |
@@ -354,7 +382,7 @@ GNUNET_TESTING_interpreter_fail () | |||
354 | 382 | ||
355 | if (NULL == cmd->label) | 383 | if (NULL == cmd->label) |
356 | { | 384 | { |
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
358 | "Failed at command `%s'\n", | 386 | "Failed at command `%s'\n", |
359 | cmd->label); | 387 | cmd->label); |
360 | 388 | ||
@@ -415,7 +443,7 @@ interpreter_run (void *cls) | |||
415 | if (NULL == cmd->label) | 443 | if (NULL == cmd->label) |
416 | { | 444 | { |
417 | 445 | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
419 | "Running command END %p\n", | 447 | "Running command END %p\n", |
420 | is); | 448 | is); |
421 | is->result = GNUNET_OK; | 449 | is->result = GNUNET_OK; |
@@ -424,7 +452,7 @@ interpreter_run (void *cls) | |||
424 | } | 452 | } |
425 | else if (NULL != cmd) | 453 | else if (NULL != cmd) |
426 | { | 454 | { |
427 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
428 | "Running command `%s' %p\n", | 456 | "Running command `%s' %p\n", |
429 | cmd->label, | 457 | cmd->label, |
430 | is); | 458 | is); |
@@ -478,8 +506,14 @@ do_shutdown (void *cls) | |||
478 | for (unsigned int j = 0; | 506 | for (unsigned int j = 0; |
479 | NULL != (cmd = &is->commands[j])->label; | 507 | NULL != (cmd = &is->commands[j])->label; |
480 | j++) { | 508 | j++) { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
510 | "Cleaning up cmd %s\n", | ||
511 | cmd->label); | ||
481 | cmd->cleanup (cmd->cls, | 512 | cmd->cleanup (cmd->cls, |
482 | cmd); | 513 | cmd); |
514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
515 | "Cleaned up cmd %s\n", | ||
516 | cmd->label); | ||
483 | } | 517 | } |
484 | 518 | ||
485 | if (NULL != is->finish_task) | 519 | if (NULL != is->finish_task) |