commit 57bc2fed38fe8f6bc6dbd66234c1657645625554
parent 8bfe56861b37dd57819f032bc967956eb4e3bb5c
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 19 May 2024 19:26:55 +0200
-fix bugs in batch implementation
Diffstat:
4 files changed, 114 insertions(+), 61 deletions(-)
diff --git a/src/lib/testing/test_testing_api.c b/src/lib/testing/test_testing_api.c
@@ -30,10 +30,24 @@ int
main (int argc,
char *const *argv)
{
+ struct GNUNET_TESTING_Timer timers[] = {
+ { .prefix = "batch" },
+ { .prefix = NULL }
+ };
+ struct GNUNET_TESTING_Command batch[] = {
+ GNUNET_TESTING_cmd_end ()
+ };
struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_batch ("batch",
+ batch),
+ GNUNET_TESTING_cmd_stat ("stat",
+ timers),
GNUNET_TESTING_cmd_end ()
};
+ GNUNET_log_setup ("test-testing-api",
+ "DEBUG",
+ NULL);
return GNUNET_TESTING_main (commands,
GNUNET_TIME_UNIT_MINUTES);
}
diff --git a/src/lib/testing/testing_api_cmd_batch.c b/src/lib/testing/testing_api_cmd_batch.c
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_testing_lib.h"
#include "testing_api_cmd_batch.h"
+#include "testing_api_loop.h"
/**
* State for a "batch" CMD.
@@ -61,26 +62,25 @@ batch_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct BatchState *bs = cls;
+ struct GNUNET_TESTING_Command *cmd;
- if (NULL != bs->batch[bs->batch_ip].run)
+ cmd = &bs->batch[bs->batch_ip];
+ if (NULL != cmd->run)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Running batched command: %s\n",
- bs->batch[bs->batch_ip].label.value);
+ cmd->label.value);
/* hit end command, leap to next top-level command. */
- if (NULL == bs->batch[bs->batch_ip].run)
+ if (NULL == cmd->run)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Exiting from batch: %s\n",
bs->label.value);
+ GNUNET_TESTING_interpreter_next_ (is);
return;
}
- bs->batch[bs->batch_ip].start_time
- = bs->batch[bs->batch_ip].last_req_time
- = GNUNET_TIME_absolute_get ();
- bs->batch[bs->batch_ip].num_tries = 1;
- bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
- is);
+ GNUNET_TESTING_interpreter_run_cmd_ (is,
+ cmd);
}
@@ -178,13 +178,24 @@ bool
GNUNET_TESTING_cmd_batch_next_ (void *cls)
{
struct BatchState *bs = cls;
+ struct GNUNET_TESTING_Command *bcmd = &bs->batch[bs->batch_ip];
- if (NULL == bs->batch[bs->batch_ip].run)
- return false;
- bs->batch[bs->batch_ip].finish_time
- = GNUNET_TIME_absolute_get ();
+ if (NULL == bcmd->run)
+ return true; /* this batch is done */
+ if (GNUNET_TESTING_cmd_is_batch_ (bcmd))
+ {
+ if (GNUNET_TESTING_cmd_batch_next_ (bcmd->cls))
+ {
+ /* sub-batch is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
+ bs->batch_ip++;
+ return false;
+ }
+ }
+ /* Simple command is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
bs->batch_ip++;
- return true;
+ return false;
}
diff --git a/src/lib/testing/testing_api_loop.c b/src/lib/testing/testing_api_loop.c
@@ -342,11 +342,8 @@ static void
interpreter_run (void *cls);
-/**
- * Current command is done, run the next one.
- */
-static void
-interpreter_next (void *cls)
+void
+GNUNET_TESTING_interpreter_next_ (void *cls)
{
static unsigned long long ipc;
static struct GNUNET_TIME_Absolute last_report;
@@ -387,29 +384,11 @@ interpreter_next (void *cls)
}
-/**
- * Run the main interpreter loop.
- *
- * @param cls contains the `struct GNUNET_TESTING_Interpreter`
- */
-static void
-interpreter_run (void *cls)
+void
+GNUNET_TESTING_interpreter_run_cmd_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ struct GNUNET_TESTING_Command *cmd)
{
- struct GNUNET_TESTING_Interpreter *is = cls;
- struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
-
- is->task = NULL;
- if (NULL == cmd->run)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Running command END\n");
- is->result = GNUNET_OK;
- finish_test (is);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Running command `%s'\n",
- cmd->label.value);
cmd->last_req_time
= GNUNET_TIME_absolute_get ();
if (0 == cmd->num_tries)
@@ -435,16 +414,45 @@ interpreter_run (void *cls)
}
cmd->run (cmd->cls,
is);
- if ( (NULL == cmd->ac) ||
- (cmd->asynchronous_finish) )
+ if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) &&
+ ( (NULL == cmd->ac) ||
+ (cmd->asynchronous_finish) ) )
{
if (NULL != cmd->ac)
cmd->ac->next_called = true;
- interpreter_next (is);
+ GNUNET_TESTING_interpreter_next_ (is);
}
}
+/**
+ * Run the main interpreter loop.
+ *
+ * @param cls contains the `struct GNUNET_TESTING_Interpreter`
+ */
+static void
+interpreter_run (void *cls)
+{
+ struct GNUNET_TESTING_Interpreter *is = cls;
+ struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
+
+ is->task = NULL;
+ if (NULL == cmd->run)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running command END\n");
+ is->result = GNUNET_OK;
+ finish_test (is);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running command `%s'\n",
+ cmd->label.value);
+ GNUNET_TESTING_interpreter_run_cmd_ (is,
+ cmd);
+}
+
+
void
GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
{
@@ -507,7 +515,7 @@ GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac)
if (! ac->next_called)
{
ac->next_called = true;
- interpreter_next (ac->is);
+ GNUNET_TESTING_interpreter_next_ (ac->is);
}
}
diff --git a/src/lib/testing/testing_api_loop.h b/src/lib/testing/testing_api_loop.h
@@ -83,8 +83,9 @@ struct GNUNET_TESTING_PluginFunctions
* @param is The interpreter loop.
*/
void
-GNUNET_TESTING_loop_notify_parent_ (struct GNUNET_TESTING_Interpreter *is,
- const struct GNUNET_MessageHeader *hdr);
+GNUNET_TESTING_loop_notify_parent_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_MessageHeader *hdr);
/**
@@ -94,19 +95,33 @@ GNUNET_TESTING_loop_notify_parent_ (struct GNUNET_TESTING_Interpreter *is,
* @param is The interpreter loop.
*/
void
-GNUNET_TESTING_loop_notify_children_ (struct GNUNET_TESTING_Interpreter *is,
- const struct GNUNET_MessageHeader *hdr);
+GNUNET_TESTING_loop_notify_children_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_MessageHeader *hdr);
/**
+ * Current command is done, run the next one.
+ */
+void
+GNUNET_TESTING_interpreter_next_ (void *cls);
+
+
+void
+GNUNET_TESTING_interpreter_run_cmd_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ struct GNUNET_TESTING_Command *cmd);
+
+/**
* Adding a helper handle to the interpreter.
*
* @param is The interpreter.
* @param helper The helper handle.
*/
void
-GNUNET_TESTING_add_netjail_helper_ (struct GNUNET_TESTING_Interpreter *is,
- struct GNUNET_HELPER_Handle *helper);
+GNUNET_TESTING_add_netjail_helper_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ struct GNUNET_HELPER_Handle *helper);
/**
@@ -117,27 +132,32 @@ GNUNET_TESTING_add_netjail_helper_ (struct GNUNET_TESTING_Interpreter *is,
* @param barrier The barrier to add.
*/
void
-GNUNET_TESTING_add_barrier_ (struct GNUNET_TESTING_Interpreter *is,
- struct GNUNET_TESTING_Barrier *barrier);
+GNUNET_TESTING_add_barrier_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ struct GNUNET_TESTING_Barrier *barrier);
struct GNUNET_TESTING_Barrier *
-GNUNET_TESTING_get_barrier2_ (struct GNUNET_TESTING_Interpreter *is,
- const struct GNUNET_ShortHashCode *create_key);
+GNUNET_TESTING_get_barrier2_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_ShortHashCode *create_key);
struct GNUNET_TESTING_Barrier *
-GNUNET_TESTING_get_barrier_ (struct GNUNET_TESTING_Interpreter *is,
- const char *barrier_name);
+GNUNET_TESTING_get_barrier_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ const char *barrier_name);
unsigned int
-GNUNET_TESTING_barrier_count_ (struct GNUNET_TESTING_Interpreter *is);
+GNUNET_TESTING_barrier_count_ (
+ struct GNUNET_TESTING_Interpreter *is);
void
-GNUNET_TESTING_barrier_iterate_ (struct GNUNET_TESTING_Interpreter *is,
- GNUNET_CONTAINER_ShortmapIterator cb,
- void *cb_cls);
+GNUNET_TESTING_barrier_iterate_ (
+ struct GNUNET_TESTING_Interpreter *is,
+ GNUNET_CONTAINER_ShortmapIterator cb,
+ void *cb_cls);
#endif