GNUnet 0.21.1
testing_api_cmd_batch.c File Reference

Implement batch-execution of CMDs. More...

#include "platform.h"
#include "gnunet_testing_ng_lib.h"
#include "testing.h"
Include dependency graph for testing_api_cmd_batch.c:

Go to the source code of this file.

Data Structures

struct  BatchState
 State for a "batch" CMD. More...
 

Macros

#define CURRENT_CMD_INDEX   0
 
#define BATCH_INDEX   1
 

Functions

static void batch_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the command. More...
 
static void batch_cleanup (void *cls)
 Cleanup the state from a "reserve status" CMD, and possibly cancel a pending operation thereof. More...
 
static enum GNUNET_GenericReturnValue batch_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Offer internal data from a "batch" CMD, to other commands. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch (const char *label, struct GNUNET_TESTING_Command *batch)
 Create a "batch" command. More...
 
bool GNUNET_TESTING_cmd_batch_next_ (void *cls)
 Advance internal pointer to next command. More...
 
bool GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd)
 Test if this command is a batch command. More...
 
struct GNUNET_TESTING_CommandGNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd)
 Obtain what command the batch is at. More...
 
void GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd, unsigned int new_ip)
 Set what command the batch should be at. More...
 

Detailed Description

Implement batch-execution of CMDs.

Author
Marcello Stanisci (GNU Taler testing)
t3sserakt

Definition in file testing_api_cmd_batch.c.

Macro Definition Documentation

◆ CURRENT_CMD_INDEX

#define CURRENT_CMD_INDEX   0

◆ BATCH_INDEX

#define BATCH_INDEX   1

Function Documentation

◆ batch_run()

static void batch_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Run the command.

Parameters
clsclosure.
isthe interpreter state.

Definition at line 60 of file testing_api_cmd_batch.c.

62{
63 struct BatchState *bs = cls;
64
65 if (NULL != bs->batch[bs->batch_ip].run)
67 "Running batched command: %s\n",
68 bs->batch[bs->batch_ip].label.value);
69
70 /* hit end command, leap to next top-level command. */
71 if (NULL == bs->batch[bs->batch_ip].run)
72 {
74 "Exiting from batch: %s\n",
75 bs->label.value);
76 return;
77 }
81 bs->batch[bs->batch_ip].num_tries = 1;
82 bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
83 is);
84}
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
State for a "batch" CMD.
unsigned int batch_ip
Internal command pointer.
struct GNUNET_TESTING_CommandLabel label
Our label.
struct GNUNET_TESTING_Command * batch
CMDs batch.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
struct GNUNET_TIME_Absolute last_req_time
When did we start the last run of this command? Delta to finish_time gives the latency for the last s...
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
void * cls
Closure for all commands with command-specific context information.

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_TIME_absolute_get(), is, GNUNET_TESTING_Command::label, BatchState::label, GNUNET_TESTING_Command::last_req_time, GNUNET_TESTING_Command::num_tries, GNUNET_TESTING_Command::run, GNUNET_TESTING_Command::start_time, and GNUNET_TESTING_CommandLabel::value.

Referenced by GNUNET_TESTING_cmd_batch(), and GNUNET_TESTING_cmd_is_batch_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ batch_cleanup()

static void batch_cleanup ( void *  cls)
static

Cleanup the state from a "reserve status" CMD, and possibly cancel a pending operation thereof.

Parameters
clsclosure.

Definition at line 94 of file testing_api_cmd_batch.c.

95{
96 struct BatchState *bs = cls;
97
98 for (unsigned int i = 0;
99 NULL != bs->batch[i].run;
100 i++)
101 bs->batch[i].cleanup (bs->batch[i].cls);
102 GNUNET_free (bs->batch);
103 GNUNET_free (bs);
104}
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_TESTING_CommandCleanupRoutine cleanup
Clean up after the command.

References BatchState::batch, GNUNET_TESTING_Command::cleanup, GNUNET_TESTING_Command::cls, GNUNET_free, and GNUNET_TESTING_Command::run.

Referenced by GNUNET_TESTING_cmd_batch().

Here is the caller graph for this function:

◆ batch_traits()

static enum GNUNET_GenericReturnValue batch_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

Offer internal data from a "batch" CMD, to other commands.

Parameters
clsclosure.
[out]retresult.
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 117 of file testing_api_cmd_batch.c.

121{
122 struct BatchState *bs = cls;
123 // FIXME: these constants should be more global!
124#define CURRENT_CMD_INDEX 0
125#define BATCH_INDEX 1
126 struct GNUNET_TESTING_Trait traits[] = {
128 &bs->batch[bs->batch_ip]),
130 bs->batch),
132 };
133
134 /* Always return current command. */
135 return GNUNET_TESTING_get_trait (traits,
136 ret,
137 trait,
138 index);
139}
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd(unsigned int index, const struct GNUNET_TESTING_Command *value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
#define CURRENT_CMD_INDEX
#define BATCH_INDEX

References BatchState::batch, BATCH_INDEX, BatchState::batch_ip, CURRENT_CMD_INDEX, GNUNET_TESTING_get_trait(), GNUNET_TESTING_make_trait_cmd(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, and ret.

Referenced by GNUNET_TESTING_cmd_batch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_batch()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch ( const char *  label,
struct GNUNET_TESTING_Command batch 
)

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.

Parameters
labelthe command label.
batcharray of CMDs to execute.
Returns
the command.

Definition at line 155 of file testing_api_cmd_batch.c.

157{
158 struct BatchState *bs;
159 unsigned int i;
160
161 bs = GNUNET_new (struct BatchState);
163 label);
164 /* Get number of commands. */
165 for (i = 0; NULL != batch[i].run; i++)
166 /* noop */
167 ;
168
169 bs->batch = GNUNET_new_array (i + 1,
171 memcpy (bs->batch,
172 batch,
173 sizeof (struct GNUNET_TESTING_Command) * i);
175 label,
176 &batch_run,
178 &batch_traits, NULL);
179}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
A command to be run by the interpreter.
static void batch_cleanup(void *cls)
Cleanup the state from a "reserve status" CMD, and possibly cancel a pending operation thereof.
static void batch_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue batch_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.

References BatchState::batch, batch_cleanup(), batch_run(), batch_traits(), GNUNET_new, GNUNET_new_array, GNUNET_TESTING_command_new(), GNUNET_TESTING_set_label(), BatchState::label, and GNUNET_TESTING_Command::run.

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_batch_next_()

bool GNUNET_TESTING_cmd_batch_next_ ( void *  cls)

Advance internal pointer to next command.

Parameters
clsbatch internal state
Returns
true if we could advance, false if the batch has completed and cannot advance anymore

Definition at line 183 of file testing_api_cmd_batch.c.

184{
185 struct BatchState *bs = cls;
186
187 if (NULL == bs->batch[bs->batch_ip].run)
188 return false;
189 bs->batch[bs->batch_ip].finish_time
191 bs->batch_ip++;
192 return true;
193}
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::finish_time, GNUNET_TIME_absolute_get(), and GNUNET_TESTING_Command::run.

Referenced by interpreter_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_is_batch_()

bool GNUNET_TESTING_cmd_is_batch_ ( const struct GNUNET_TESTING_Command cmd)

Test if this command is a batch command.

Returns
false if not, true if it is a batch command

Definition at line 197 of file testing_api_cmd_batch.c.

198{
199 return cmd->run == &batch_run;
200}

References batch_run(), and GNUNET_TESTING_Command::run.

Referenced by get_command(), GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_batch_set_current_(), GNUNET_TESTING_interpreter_fail(), and interpreter_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_batch_get_current_()

struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current_ ( const struct GNUNET_TESTING_Command cmd)

Obtain what command the batch is at.

Returns
cmd current batch command

Definition at line 204 of file testing_api_cmd_batch.c.

205{
206 struct BatchState *bs = cmd->cls;
207
209 return &bs->batch[bs->batch_ip];
210}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_assert, and GNUNET_TESTING_cmd_is_batch_().

Referenced by get_command(), and GNUNET_TESTING_interpreter_fail().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_batch_set_current_()

void GNUNET_TESTING_cmd_batch_set_current_ ( const struct GNUNET_TESTING_Command cmd,
unsigned int  new_ip 
)

Set what command the batch should be at.

Needed for loops. We may want to change this to take a label and/or expose it in the public API in the future. Not used for now.

Parameters
cmdcurrent batch command
new_ipwhere to move the IP

Definition at line 214 of file testing_api_cmd_batch.c.

216{
217 struct BatchState *bs = cmd->cls;
218
219 /* sanity checks */
221 /* actual logic */
222 bs->batch_ip = new_ip;
223}

References BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_assert, and GNUNET_TESTING_cmd_is_batch_().

Here is the call graph for this function: