summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_batch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_batch.c')
-rw-r--r--src/testing/testing_api_cmd_batch.c95
1 files changed, 38 insertions, 57 deletions
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index ca23d7fd9..5bb7b974e 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -38,6 +38,11 @@ struct BatchState
struct TALER_TESTING_Command *batch;
/**
+ * My command (the batch command).
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Internal command pointer.
*/
unsigned int batch_ip;
@@ -58,6 +63,7 @@ batch_run (void *cls,
{
struct BatchState *bs = cls;
+ bs->cmd = cmd;
if (NULL != bs->batch[bs->batch_ip].label)
TALER_LOG_INFO ("Running batched command: %s\n",
bs->batch[bs->batch_ip].label);
@@ -97,8 +103,9 @@ batch_cleanup (void *cls,
for (unsigned int i = 0;
NULL != bs->batch[i].label;
i++)
- bs->batch[i].cleanup (bs->batch[i].cls,
- &bs->batch[i]);
+ if (NULL != bs->batch[i].cleanup)
+ bs->batch[i].cleanup (bs->batch[i].cls,
+ &bs->batch[i]);
GNUNET_free (bs->batch);
GNUNET_free (bs);
}
@@ -113,22 +120,15 @@ batch_cleanup (void *cls,
* @param index index number of the object to offer.
* @return #GNUNET_OK on success.
*/
-static int
+static enum GNUNET_GenericReturnValue
batch_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
-#define CURRENT_CMD_INDEX 0
-#define BATCH_INDEX 1
-
struct BatchState *bs = cls;
-
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_cmd
- (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]),
- TALER_TESTING_make_trait_cmd
- (BATCH_INDEX, bs->batch),
+ TALER_TESTING_make_trait_batch_cmds (bs->batch),
TALER_TESTING_trait_end ()
};
@@ -140,18 +140,6 @@ batch_traits (void *cls,
}
-/**
- * Create a "batch" command. Such command takes a
- * end_CMD-terminated array of CMDs and executed them.
- * Once it hits the end CMD, it passes the control
- * to the next top-level CMD, regardless of it being
- * another batch or ordinary CMD.
- *
- * @param label the command label.
- * @param batch array of CMDs to execute.
- *
- * @return the command.
- */
struct TALER_TESTING_Command
TALER_TESTING_cmd_batch (const char *label,
struct TALER_TESTING_Command *batch)
@@ -168,9 +156,9 @@ TALER_TESTING_cmd_batch (const char *label,
bs->batch = GNUNET_new_array (i + 1,
struct TALER_TESTING_Command);
- memcpy (bs->batch,
- batch,
- sizeof (struct TALER_TESTING_Command) * i);
+ GNUNET_memcpy (bs->batch,
+ batch,
+ sizeof (struct TALER_TESTING_Command) * i);
{
struct TALER_TESTING_Command cmd = {
.cls = bs,
@@ -185,44 +173,43 @@ TALER_TESTING_cmd_batch (const char *label,
}
-/**
- * Advance internal pointer to next command.
- *
- * @param is interpreter state.
- */
-void
-TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is)
+bool
+TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is,
+ void *cls)
{
- struct BatchState *bs = is->commands[is->ip].cls;
+ struct BatchState *bs = cls;
+ struct TALER_TESTING_Command *bcmd = &bs->batch[bs->batch_ip];
- if (NULL == bs->batch[bs->batch_ip].label)
+ if (NULL == bcmd->label)
{
- is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get ();
- is->ip++;
- return;
+ /* This batch is done */
+ return true;
+ }
+ if (TALER_TESTING_cmd_is_batch (bcmd))
+ {
+ if (TALER_TESTING_cmd_batch_next (is,
+ bcmd->cls))
+ {
+ /* sub-batch is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
+ bs->batch_ip++;
+ return false;
+ }
}
- bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get ();
+ /* Simple command is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
bs->batch_ip++;
+ return false;
}
-/**
- * Test if this command is a batch command.
- *
- * @return false if not, true if it is a batch command
- */
-int
+bool
TALER_TESTING_cmd_is_batch (const struct TALER_TESTING_Command *cmd)
{
return cmd->run == &batch_run;
}
-/**
- * Obtain what command the batch is at.
- *
- * @return cmd current batch command
- */
struct TALER_TESTING_Command *
TALER_TESTING_cmd_batch_get_current (const struct TALER_TESTING_Command *cmd)
{
@@ -233,12 +220,6 @@ TALER_TESTING_cmd_batch_get_current (const struct TALER_TESTING_Command *cmd)
}
-/**
- * Set what command the batch should be at.
- *
- * @param cmd current batch command
- * @param new_ip where to move the IP
- */
void
TALER_TESTING_cmd_batch_set_current (const struct TALER_TESTING_Command *cmd,
unsigned int new_ip)