GNUnet 0.22.0
testing_api_cmd_batch.c File Reference

Implement batch-execution of CMDs. More...

#include "platform.h"
#include "gnunet_testing_lib.h"
#include "testing_api_cmd_batch.h"
#include "testing_api_loop.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...
 

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.

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 61 of file testing_api_cmd_batch.c.

63{
64 struct BatchState *bs = cls;
65 struct GNUNET_TESTING_Command *cmd;
66
67 cmd = &bs->batch[bs->batch_ip];
68 if (NULL != cmd->run)
70 "Running batched command: %s\n",
71 cmd->label.value);
72
73 /* hit end command, leap to next top-level command. */
74 if (NULL == cmd->run)
75 {
77 "Exiting from batch: %s\n",
78 bs->label.value);
80 return;
81 }
83 cmd);
84}
static struct GNUNET_TESTING_Interpreter * is
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO
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.
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
void GNUNET_TESTING_interpreter_run_cmd_(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Command *cmd)
void GNUNET_TESTING_interpreter_next_(void *cls)
Current command is done, run the next one.

References BatchState::batch, BatchState::batch_ip, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_TESTING_interpreter_next_(), GNUNET_TESTING_interpreter_run_cmd_(), is, GNUNET_TESTING_Command::label, BatchState::label, GNUNET_TESTING_Command::run, and GNUNET_TESTING_CommandLabel::value.

Referenced by GNUNET_TESTING_cmd_batch(), GNUNET_TESTING_cmd_batch_set_current_(), 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.
void * cls
Closure for all commands with command-specific context information.

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 struct GNUNET_TESTING_Trait traits[] = {
127 };
128
129 /* Always return current command. */
131 ret,
132 trait,
133 index);
134}
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd(const struct GNUNET_TESTING_Command *value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_batch_cmds(struct GNUNET_TESTING_Command **value)
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.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

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

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 150 of file testing_api_cmd_batch.c.

152{
153 struct BatchState *bs;
154 unsigned int i;
155
156 bs = GNUNET_new (struct BatchState);
158 label);
159 /* Get number of commands. */
160 for (i = 0; NULL != batch[i].run; i++)
161 /* noop */
162 ;
163
164 bs->batch = GNUNET_new_array (i + 1,
166 memcpy (bs->batch,
167 batch,
168 sizeof (struct GNUNET_TESTING_Command) * i);
170 label,
171 &batch_run,
173 &batch_traits);
174}
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
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.
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 178 of file testing_api_cmd_batch.c.

179{
180 struct BatchState *bs = cls;
181 struct GNUNET_TESTING_Command *bcmd = &bs->batch[bs->batch_ip];
182
183 if (NULL == bcmd->run)
184 return true; /* this batch is done */
186 {
188 {
189 /* sub-batch is done */
191 bs->batch_ip++;
192 return false;
193 }
194 }
195 /* Simple command is done */
197 bs->batch_ip++;
198 return false;
199}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
bool GNUNET_TESTING_cmd_batch_next_(void *cls)
Advance internal pointer to next command.
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_TESTING_Command::finish_time, GNUNET_TESTING_cmd_batch_next_(), GNUNET_TESTING_cmd_is_batch_(), GNUNET_TIME_absolute_get(), and GNUNET_TESTING_Command::run.

Referenced by GNUNET_TESTING_cmd_batch_next_(), and GNUNET_TESTING_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 203 of file testing_api_cmd_batch.c.

204{
205 return cmd->run == &batch_run;
206}

References batch_run(), and GNUNET_TESTING_Command::run.

Referenced by do_stat(), GNUNET_TESTING_cmd_batch_get_current_(), GNUNET_TESTING_cmd_batch_next_(), GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_interpreter_next_(), GNUNET_TESTING_interpreter_run_cmd_(), rewind_ip_run(), and seek_batch().

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 210 of file testing_api_cmd_batch.c.

211{
212 struct BatchState *bs = cmd->cls;
213
215 return &bs->batch[bs->batch_ip];
216}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

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

Here is the call 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.

Parameters
cmdcurrent batch command
new_ipwhere to move the IP

Definition at line 220 of file testing_api_cmd_batch.c.

223{
224 struct BatchState *bs = cmd->cls;
225
226 /* sanity checks */
227 GNUNET_assert (cmd->run == &batch_run);
228 for (unsigned int i = 0; i < new_ip; i++)
229 GNUNET_assert (NULL != bs->batch[i].run);
230 /* actual logic */
231 bs->batch_ip = new_ip;
232}

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

Referenced by seek_batch().

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