GNUnet  0.11.x
Data Structures | Macros | Functions
gnunet_testing_ng_lib.h File Reference
#include "gnunet_util_lib.h"
Include dependency graph for gnunet_testing_ng_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_TESTING_Command
 A command to be run by the interpreter. More...
 
struct  SyncState
 Struct to use for command-specific context information closure of a command waiting for another command. More...
 
struct  GNUNET_TESTING_Timer
 Performance counter. More...
 
struct  GNUNET_TESTING_Trait
 A trait. More...
 

Macros

#define GNUNET_TESTING_FAIL(is)
 API for writing an interpreter to test GNUnet components. More...
 

Functions

const struct GNUNET_TESTING_CommandGNUNET_TESTING_interpreter_lookup_command (const char *label)
 Lookup command by label. More...
 
const char * GNUNET_TESTING_interpreter_get_current_label (struct GNUNET_TESTING_Interpreter *is)
 Obtain label of the command being now run. More...
 
void GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
 Current command failed, clean up and fail the test case. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end (void)
 Create command array terminator. More...
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd)
 Turn asynchronous command into non blocking command by setting asynchronous_finish to true. More...
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish (const char *finish_label, const char *cmd_ref, struct GNUNET_TIME_Relative timeout)
 Create (synchronous) command that waits for another command to finish. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_rewind_ip (const char *label, const char *target_label, unsigned int counter)
 Make the instruction pointer point to target_label only if counter is greater than zero. More...
 
int GNUNET_TESTING_run (const char *cfg_filename, struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
 Wait until we receive SIGCHLD signal. More...
 
int GNUNET_TESTING_has_in_name (const char *prog, const char *marker)
 Look for substring in a programs' name. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal (const char *label, const char *process_label, unsigned int process_index, int signal)
 Create a "signal" CMD. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep (const char *label, struct GNUNET_TIME_Relative duration)
 Sleep for duration. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch (const char *label, struct GNUNET_TESTING_Command *batch)
 Create a "batch" command. More...
 
int GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd)
 Test if this command is a batch command. More...
 
void GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is)
 Advance internal pointer to next 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...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers)
 Obtain performance data from the interpreter. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end (void)
 "end" trait. More...
 
int GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
 Extract a trait. More...
 
int GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_OS_Process ***processp)
 Obtain location where a command stores a pointer to a process. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process (unsigned int index, struct GNUNET_OS_Process **processp)
 Offer location where a command stores a pointer to a process. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint32 (unsigned int index, const uint32_t *n)
 Offer number trait, 32-bit version. More...
 
int GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint32_t **n)
 Obtain a "number" value from cmd, 32-bit version. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint64 (unsigned int index, const uint64_t *n)
 Offer number trait, 64-bit version. More...
 
int GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint64_t **n)
 Obtain a "number" value from cmd, 64-bit version. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_int64 (unsigned int index, const int64_t *n)
 Offer number trait, 64-bit signed version. More...
 
int GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const int64_t **n)
 Obtain a "number" value from cmd, 64-bit signed version. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint (unsigned int index, const unsigned int *i)
 Offer a number. More...
 
int GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const unsigned int **n)
 Obtain a number from cmd. More...
 
int GNUNET_TESTING_get_trait_string (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const char **s)
 Obtain a string from cmd. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_string (unsigned int index, const char *s)
 Offer string subject. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd (unsigned int index, const struct GNUNET_TESTING_Command *cmd)
 Offer a command in a trait. More...
 
int GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_TESTING_Command **_cmd)
 Obtain a command from cmd. More...
 
int GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_Uuid **uuid)
 Obtain a uuid from cmd. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uuid (unsigned int index, const struct GNUNET_Uuid *uuid)
 Offer a uuid in a trait. More...
 
int GNUNET_TESTING_get_trait_absolute_time (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const struct GNUNET_TIME_Absolute **time)
 Obtain a absolute time from cmd. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_absolute_time (unsigned int index, const struct GNUNET_TIME_Absolute *time)
 Offer a absolute time. More...
 
int GNUNET_TESTING_get_trait_relative_time (const struct GNUNET_TESTING_Command *cmd, unsigned int index, const struct GNUNET_TIME_Relative **time)
 Obtain a relative time from cmd. More...
 
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_relative_time (unsigned int index, const struct GNUNET_TIME_Relative *time)
 Offer a relative time. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world_birth (const char *label, struct GNUNET_TIME_Absolute *now)
 Create command. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world (const char *label, const char *birthLabel, char *message)
 Create command. More...
 
int GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
 Offer data from trait. More...
 

Macro Definition Documentation

◆ GNUNET_TESTING_FAIL

#define GNUNET_TESTING_FAIL (   is)
Value:
do \
{ \
GNUNET_break (0); \
GNUNET_TESTING_interpreter_fail (is); \
return; \
} while (0)
struct GNUNET_TESTING_Interpreter * is

API for writing an interpreter to test GNUnet components.

Author
Christian Grothoff chris.nosp@m.tian.nosp@m.@grot.nosp@m.hoff.nosp@m..org
Marcello Stanisci
t3sserakt Print failing line number and trigger shutdown. Useful quite any time after the command "run" method has been called.

Definition at line 39 of file gnunet_testing_ng_lib.h.

Function Documentation

◆ GNUNET_TESTING_interpreter_lookup_command()

const struct GNUNET_TESTING_Command* GNUNET_TESTING_interpreter_lookup_command ( const char *  label)

Lookup command by label.

Parameters
labellabel of the command to lookup.
Returns
the command, if it is found, or NULL.
Parameters
labellabel to look for
Returns
NULL if command was not found

Definition at line 81 of file testing_api_loop.c.

References BATCH_INDEX, GNUNET_TESTING_Command::cls, GNUNET_TESTING_Interpreter::commands, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_TESTING_cmd_batch_get_current(), GNUNET_TESTING_cmd_is_batch(), GNUNET_TESTING_get_trait_cmd(), interpreter_run(), GNUNET_TESTING_Interpreter::ip, and GNUNET_TESTING_Command::label.

Referenced by GNUNET_TESTING_cmd_finish(), hello_world_run(), peer_run(), and tng_service_run().

82 {
83  if (NULL == label)
84  {
86  "Attempt to lookup command for empty label\n");
87  return NULL;
88  }
89  /* Search backwards as we most likely reference recent commands */
90  for (int i = is->ip; i >= 0; i--)
91  {
92  const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
93 
94  /* Give precedence to top-level commands. */
95  if ( (NULL != cmd->label) &&
96  (0 == strcmp (cmd->label,
97  label)) )
98  return cmd;
99 
100  if (GNUNET_TESTING_cmd_is_batch (cmd))
101  {
102 #define BATCH_INDEX 1
103  struct GNUNET_TESTING_Command *batch;
104  struct GNUNET_TESTING_Command *current;
105  struct GNUNET_TESTING_Command *icmd;
106  const struct GNUNET_TESTING_Command *match;
107 
108  current = GNUNET_TESTING_cmd_batch_get_current (cmd);
111  BATCH_INDEX,
112  &batch));
113  /* We must do the loop forward, but we can find the last match */
114  match = NULL;
115  for (unsigned int j = 0;
116  NULL != (icmd = &batch[j])->label;
117  j++)
118  {
119  if (current == icmd)
120  break; /* do not go past current command */
121  if ( (NULL != icmd->label) &&
122  (0 == strcmp (icmd->label,
123  label)) )
124  match = icmd;
125  }
126  if (NULL != match)
127  return match;
128  }
129  }
131  "Command not found: %s\n",
132  label);
133  return NULL;
134 
135 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * label
Label for the command.
A command to be run by the interpreter.
struct GNUNET_TESTING_Interpreter * is
#define BATCH_INDEX
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
int GNUNET_TESTING_cmd_is_batch(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
int ip
Instruction pointer.
Definition: testing.h:67
int GNUNET_TESTING_get_trait_cmd(const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_TESTING_Command **_cmd)
Obtain a command from cmd.
struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current(const struct GNUNET_TESTING_Command *cmd)
Obtain what command the batch is at.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_interpreter_get_current_label()

const char* GNUNET_TESTING_interpreter_get_current_label ( struct GNUNET_TESTING_Interpreter is)

Obtain label of the command being now run.

Parameters
isinterpreter state.
Returns
the label.

Obtain label of the command being now run.

Definition at line 346 of file testing_api_loop.c.

References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::ip, and GNUNET_TESTING_Command::label.

348 {
349  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
350 
351  return cmd->label;
352 }
const char * label
Label for the command.
A command to be run by the interpreter.
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
int ip
Instruction pointer.
Definition: testing.h:67

◆ GNUNET_TESTING_interpreter_fail()

void GNUNET_TESTING_interpreter_fail ( struct GNUNET_TESTING_Interpreter is)

Current command failed, clean up and fail the test case.

Parameters
isinterpreter state.
isinterpreter of the test

Definition at line 308 of file testing_api_loop.c.

References GNUNET_TESTING_Interpreter::commands, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_get_current(), GNUNET_TESTING_cmd_is_batch(), GNUNET_TESTING_Interpreter::ip, GNUNET_TESTING_Command::label, and GNUNET_TESTING_Interpreter::result.

309 {
310  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
311 
313  "Failed at command `%s'\n",
314  cmd->label);
315  while (GNUNET_TESTING_cmd_is_batch (cmd))
316  {
319  "Batch is at command `%s'\n",
320  cmd->label);
321  }
322  is->result = GNUNET_SYSERR;
324 }
const char * label
Label for the command.
A command to be run by the interpreter.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
int GNUNET_TESTING_cmd_is_batch(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
int ip
Instruction pointer.
Definition: testing.h:67
struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current(const struct GNUNET_TESTING_Command *cmd)
Obtain what command the batch is at.
#define GNUNET_log(kind,...)
int result
Result of the testcases, GNUNET_OK on success.
Definition: testing.h:72
Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_end()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end ( void  )

Create command array terminator.

Returns
a end-command.

Definition at line 333 of file testing_api_loop.c.

References GNUNET_TESTING_Command::label.

334 {
335  static struct GNUNET_TESTING_Command cmd;
336  cmd.label = NULL;
337 
338  return cmd;
339 }
const char * label
Label for the command.
A command to be run by the interpreter.

◆ GNUNET_TESTING_cmd_make_unblocking()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_make_unblocking ( const struct GNUNET_TESTING_Command  cmd)

Turn asynchronous command into non blocking command by setting asynchronous_finish to true.

Parameters
cmdcommand to make synchronous.
Returns
a finish-command.

◆ GNUNET_TESTING_cmd_finish()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish ( const char *  finish_label,
const char *  cmd_ref,
struct GNUNET_TIME_Relative  timeout 
)

Create (synchronous) command that waits for another command to finish.

If cmd_ref did not finish after timeout, this command will fail the test case.

Parameters
finish_labellabel for this command
cmd_refreference to a previous command which we should wait for (call finish() on)
timeouthow long to wait at most for cmd_ref to finish
Returns
a finish-command.

Definition at line 261 of file testing_api_loop.c.

References SyncTaskClosure::async_cmd, SyncState::async_cmd, GNUNET_TESTING_Command::cls, GNUNET_new, GNUNET_NO, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_Command::run, and start_finish_on_ref().

264 {
265  const struct GNUNET_TESTING_Command *async_cmd;
266  struct SyncState *sync_state;
267 
268  async_cmd = GNUNET_TESTING_interpreter_lookup_command (cmd_ref);
269  sync_state = GNUNET_new (struct SyncState);
270  sync_state->async_cmd = async_cmd;
271 
272  struct GNUNET_TESTING_Command cmd = {
273  .cls = sync_state,
274  .label = finish_label,
275  .run = &start_finish_on_ref,
276  .asynchronous_finish = GNUNET_NO
277  };
278 
279  return cmd;
280 }
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
A command to be run by the interpreter.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Struct to use for command-specific context information closure of a command waiting for another comma...
const struct GNUNET_TESTING_Command * async_cmd
The asynchronous command the synchronous command of this closure waits for.
static void start_finish_on_ref(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
void * cls
Closure for all commands with command-specific context information.
Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_rewind_ip()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_rewind_ip ( const char *  label,
const char *  target_label,
unsigned int  counter 
)

Make the instruction pointer point to target_label only if counter is greater than zero.

Parameters
labelcommand label
target_labellabel of the new instruction pointer's destination after the jump; must be before the current instruction
countercounts how many times the rewinding is to happen.

◆ GNUNET_TESTING_run()

int GNUNET_TESTING_run ( const char *  cfg_filename,
struct GNUNET_TESTING_Command commands,
struct GNUNET_TIME_Relative  timeout 
)

Wait until we receive SIGCHLD signal.

Then obtain the process trait of the current command, wait on the the zombie and continue with the next command.

Parameters
isinterpreter state. Start scheduling loop with signal handlers and run the test suite with the commands.
cfg_namename of configuration file to use
commandsthe list of command to execute
timeouthow long to wait for each command to execute
Returns
GNUNET_OK if all is okay, != GNUNET_OK otherwise. non-GNUNET_OK codes are GNUNET_SYSERR most of the times.

Wait until we receive SIGCHLD signal.

Note, CMDs are copied into the interpreter state because they are usually defined into the "run" method that returns after having scheduled the test interpreter.

Parameters
isthe interpreter state
commandsthe list of command to execute
timeouthow long to wait

Definition at line 478 of file testing_api_loop.c.

References GNUNET_TESTING_Interpreter::commands, do_shutdown(), do_timeout(), GNUNET_new, GNUNET_new_array, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_cancel(), interpreter_run(), GNUNET_TESTING_Command::label, GNUNET_TESTING_Interpreter::task, and GNUNET_TESTING_Interpreter::timeout_task.

481 {
482  unsigned int i;
483 
485 
486  if (NULL != is->timeout_task)
487  {
489  is->timeout_task = NULL;
490  }
491  /* get the number of commands */
492  for (i = 0; NULL != commands[i].label; i++)
493  ;
494  is->commands = GNUNET_new_array (i + 1,
495  struct GNUNET_TESTING_Command);
496  memcpy (is->commands,
497  commands,
498  sizeof (struct GNUNET_TESTING_Command) * i);
499 
501  (timeout,
502  &do_timeout,
503  is);
506  return GNUNET_OK;
507 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
const char * label
Label for the command.
A command to be run by the interpreter.
static void do_shutdown(void *cls)
Function run when the test terminates (good or bad).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void interpreter_run(void *cls)
Run the main interpreter loop that performs exchange operations.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
Global state of the interpreter, used by a command to access information about other commands...
Definition: testing.h:34
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
static void do_timeout(void *cls)
Function run when the test terminates (good or bad) with timeout.
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
Definition: testing.h:45
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
Definition: testing.h:60
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:

◆ GNUNET_TESTING_has_in_name()

int GNUNET_TESTING_has_in_name ( const char *  prog,
const char *  marker 
)

Look for substring in a programs' name.

Parameters
progprogram's name to look into
markerchunk to find in prog

◆ GNUNET_TESTING_cmd_signal()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal ( const char *  label,
const char *  process_label,
unsigned int  process_index,
int  signal 
)

Create a "signal" CMD.

Parameters
labelcommand label.
process_labellabel of a command that has a process trait
process_indexindex of the process trait at process_label
signalsignal to send to process.
Returns
the command.

◆ GNUNET_TESTING_cmd_sleep()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep ( const char *  label,
struct GNUNET_TIME_Relative  duration 
)

Sleep for duration.

Parameters
labelcommand label.
durationtime to sleep
Returns
the command.

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

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

160 {
161  struct BatchState *bs;
162  unsigned int i;
163 
164  bs = GNUNET_new (struct BatchState);
165 
166  /* Get number of commands. */
167  for (i = 0; NULL != batch[i].label; i++)
168  /* noop */
169  ;
170 
171  bs->batch = GNUNET_new_array (i + 1,
172  struct GNUNET_TESTING_Command);
173  memcpy (bs->batch,
174  batch,
175  sizeof (struct GNUNET_TESTING_Command) * i);
176  {
177  struct GNUNET_TESTING_Command cmd = {
178  .cls = bs,
179  .label = label,
180  .run = &batch_run,
181  .cleanup = &batch_cleanup,
182  .traits = &batch_traits
183  };
184 
185  return cmd;
186  }
187 }
static void batch_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static int batch_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.
const char * label
Label for the command.
A command to be run by the interpreter.
struct GNUNET_TESTING_Command * batch
CMDs batch.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
State for a "batch" CMD.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
void * cls
Closure for all commands with command-specific context information.
static void batch_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
Cleanup the state from a "reserve status" CMD, and possibly cancel a pending operation thereof...
Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_is_batch()

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

References batch_run(), and GNUNET_TESTING_Command::run.

Referenced by GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), and interpreter_next().

218 {
219  return cmd->run == &batch_run;
220 }
static void batch_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the command.
void(* run)(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *i)
Runs the command.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_batch_next()

void GNUNET_TESTING_cmd_batch_next ( struct GNUNET_TESTING_Interpreter is)

Advance internal pointer to next command.

Parameters
isinterpreter state.

Definition at line 196 of file testing_api_cmd_batch.c.

References BatchState::batch, BatchState::batch_ip, GNUNET_TESTING_Command::cls, GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Command::finish_time, GNUNET_TIME_absolute_get(), GNUNET_TESTING_Interpreter::ip, and GNUNET_TESTING_Command::label.

Referenced by interpreter_next().

197 {
198  struct BatchState *bs = is->commands[is->ip].cls;
199 
200  if (NULL == bs->batch[bs->batch_ip].label)
201  {
203  is->ip++;
204  return;
205  }
207  bs->batch_ip++;
208 }
const char * label
Label for the command.
unsigned int batch_ip
Internal command pointer.
struct GNUNET_TESTING_Command * batch
CMDs batch.
State for a "batch" CMD.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
int ip
Instruction pointer.
Definition: testing.h:67
void * cls
Closure for all commands with command-specific context information.
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 229 of file testing_api_cmd_batch.c.

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

Referenced by GNUNET_TESTING_interpreter_fail(), and GNUNET_TESTING_interpreter_lookup_command().

230 {
231  struct BatchState *bs = cmd->cls;
232 
233  GNUNET_assert (cmd->run == &batch_run);
234  return &bs->batch[bs->batch_ip];
235 }
static void batch_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the command.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int batch_ip
Internal command pointer.
struct GNUNET_TESTING_Command * batch
CMDs batch.
State for a "batch" CMD.
void(* run)(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *i)
Runs the command.
void * cls
Closure for all commands with command-specific context information.
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.

Parameters
cmdcurrent batch command
new_ipwhere to move the IP

Definition at line 245 of file testing_api_cmd_batch.c.

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

247 {
248  struct BatchState *bs = cmd->cls;
249 
250  /* sanity checks */
251  GNUNET_assert (cmd->run == &batch_run);
252  for (unsigned int i = 0; i < new_ip; i++)
253  GNUNET_assert (NULL != bs->batch[i].label);
254  /* actual logic */
255  bs->batch_ip = new_ip;
256 }
static void batch_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the command.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * label
Label for the command.
unsigned int batch_ip
Internal command pointer.
struct GNUNET_TESTING_Command * batch
CMDs batch.
State for a "batch" CMD.
void(* run)(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *i)
Runs the command.
void * cls
Closure for all commands with command-specific context information.
Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_stat()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat ( struct GNUNET_TESTING_Timer timers)

Obtain performance data from the interpreter.

Parameters
timerswhat commands (by label) to obtain runtimes for
Returns
the command

◆ GNUNET_TESTING_trait_end()

struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end ( void  )

"end" trait.

Because traits are offered into arrays, this type of trait is used to mark the end of such arrays; useful when iterating over those.

"end" trait.

Usually, commands offer several traits, and put them in arrays.

Definition at line 37 of file testing_api_traits.c.

References end, and GNUNET_TESTING_Trait::index.

Referenced by batch_traits(), controller_traits(), hello_world_birth_traits(), and peer_traits().

38 {
39  struct GNUNET_TESTING_Trait end = {
40  .index = 0,
41  .trait_name = NULL,
42  .ptr = NULL
43  };
44 
45  return end;
46 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait()

int GNUNET_TESTING_get_trait ( const struct GNUNET_TESTING_Trait traits,
const void **  ret,
const char *  trait,
unsigned int  index 
)

Extract a trait.

Parameters
traitsthe array of all the traits.
[out]retwhere to store the result.
traittype of the trait to extract.
indexindex number of the trait to extract.
Returns
GNUNET_OK when the trait is found.

Extract a trait.

Parameters
traitsthe traits array.
retwhere to store the result.
traittype of the trait to extract.
indexindex number of the object to extract.
Returns
GNUNET_OK if no error occurred, GNUNET_SYSERR otherwise.

Definition at line 59 of file testing_api_traits.c.

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_Trait::ptr, and GNUNET_TESTING_Trait::trait_name.

Referenced by batch_traits(), controller_traits(), hello_world_birth_traits(), and peer_traits().

63 {
64  for (unsigned int i = 0; NULL != traits[i].trait_name; i++)
65  {
66  if ( (0 == strcmp (trait, traits[i].trait_name)) &&
67  (index == traits[i].index) )
68  {
69  *ret = (void *) traits[i].ptr;
70  return GNUNET_OK;
71  }
72  }
74  "Trait %s/%u not found.\n",
75  trait, index);
76 
77  return GNUNET_SYSERR;
78 }
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
const void * ptr
Pointer to the piece of data to offer.
unsigned int index
Index number associated with the trait.
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_process()

int GNUNET_TESTING_get_trait_process ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
struct GNUNET_OS_Process ***  processp 
)

Obtain location where a command stores a pointer to a process.

Parameters
cmdcommand to extract trait from.
indexwhich process to pick if cmd has multiple on offer.
[out]processpset to the address of the pointer to the process.
Returns
GNUNET_OK on success.

Definition at line 46 of file testing_api_trait_process.c.

References GNUNET_TESTING_Command::cls, GNUNET_TESTING_TRAIT_PROCESS, and GNUNET_TESTING_Command::traits.

49 {
50  return cmd->traits (cmd->cls,
51  (const void **) processp,
53  index);
54 }
unsigned int index
Index number associated with the trait.
int(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
void * cls
Closure for all commands with command-specific context information.
#define GNUNET_TESTING_TRAIT_PROCESS

◆ GNUNET_TESTING_make_trait_process()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process ( unsigned int  index,
struct GNUNET_OS_Process **  processp 
)

Offer location where a command stores a pointer to a process.

Parameters
indexoffered location index number, in case there are multiple on offer.
processpprocess location to offer.
Returns
the trait.

Definition at line 68 of file testing_api_trait_process.c.

References GNUNET_TESTING_TRAIT_PROCESS, GNUNET_TESTING_Trait::index, and ret.

70 {
71  struct GNUNET_TESTING_Trait ret = {
72  .index = index,
73  .trait_name = GNUNET_TESTING_TRAIT_PROCESS,
74  .ptr = (const void *) processp
75  };
76 
77  return ret;
78 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
unsigned int index
Index number associated with the trait.
#define GNUNET_TESTING_TRAIT_PROCESS

◆ GNUNET_TESTING_make_trait_uint32()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint32 ( unsigned int  index,
const uint32_t *  n 
)

Offer number trait, 32-bit version.

Parameters
indexthe number's index number.
nnumber to offer.

◆ GNUNET_TESTING_get_trait_uint32()

int GNUNET_TESTING_get_trait_uint32 ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const uint32_t **  n 
)

Obtain a "number" value from cmd, 32-bit version.

Parameters
cmdcommand to extract the number from.
indexthe number's index number.
[out]nset to the number coming from cmd.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_make_trait_uint64()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint64 ( unsigned int  index,
const uint64_t *  n 
)

Offer number trait, 64-bit version.

Parameters
indexthe number's index number.
nnumber to offer.

◆ GNUNET_TESTING_get_trait_uint64()

int GNUNET_TESTING_get_trait_uint64 ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const uint64_t **  n 
)

Obtain a "number" value from cmd, 64-bit version.

Parameters
cmdcommand to extract the number from.
indexthe number's index number.
[out]nset to the number coming from cmd.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_make_trait_int64()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_int64 ( unsigned int  index,
const int64_t *  n 
)

Offer number trait, 64-bit signed version.

Parameters
indexthe number's index number.
nnumber to offer.

◆ GNUNET_TESTING_get_trait_int64()

int GNUNET_TESTING_get_trait_int64 ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const int64_t **  n 
)

Obtain a "number" value from cmd, 64-bit signed version.

Parameters
cmdcommand to extract the number from.
indexthe number's index number.
[out]nset to the number coming from cmd.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_make_trait_uint()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint ( unsigned int  index,
const unsigned int *  i 
)

Offer a number.

Parameters
indexthe number's index number.
nthe number to offer.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_get_trait_uint()

int GNUNET_TESTING_get_trait_uint ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const unsigned int **  n 
)

Obtain a number from cmd.

Parameters
cmdcommand to extract the number from.
indexthe number's index number.
[out]nset to the number coming from cmd.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_get_trait_string()

int GNUNET_TESTING_get_trait_string ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const char **  s 
)

Obtain a string from cmd.

Parameters
cmdcommand to extract the subject from.
indexindex number associated with the transfer subject to offer.
[out]swhere to write the offered string.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_make_trait_string()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_string ( unsigned int  index,
const char *  s 
)

Offer string subject.

Parameters
indexindex number associated with the transfer subject being offered.
sstring to offer.
Returns
the trait.

◆ GNUNET_TESTING_make_trait_cmd()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd ( unsigned int  index,
const struct GNUNET_TESTING_Command cmd 
)

Offer a command in a trait.

Parameters
indexalways zero. Commands offering this kind of traits do not need this index. For example, a "meta" CMD returns always the CMD currently being executed.
cmdwire details to offer.
Returns
the trait.

Definition at line 67 of file testing_api_trait_cmd.c.

References GNUNET_TESTING_TRAIT_CMD, GNUNET_TESTING_Trait::index, and ret.

Referenced by batch_traits().

69 {
70  struct GNUNET_TESTING_Trait ret = {
71  .index = index,
72  .trait_name = GNUNET_TESTING_TRAIT_CMD,
73  .ptr = (const struct GNUNET_TESTING_Command *) cmd
74  };
75  return ret;
76 }
A command to be run by the interpreter.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_TESTING_TRAIT_CMD
unsigned int index
Index number associated with the trait.
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_cmd()

int GNUNET_TESTING_get_trait_cmd ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
struct GNUNET_TESTING_Command **  _cmd 
)

Obtain a command from cmd.

Parameters
cmdcommand to extract the command from.
indexalways zero. Commands offering this kind of traits do not need this index. For example, a "meta" CMD returns always the CMD currently being executed.
[out]_cmdwhere to write the wire details.
Returns
GNUNET_OK on success.
Parameters
cmdcommand to extract the command from.
indexalways zero. Commands offering this kind of traits do not need this index. For example, a "batch" CMD returns always the CMD currently being executed.
[out]_cmdwhere to write the wire details.
Returns
GNUNET_OK on success.

Definition at line 45 of file testing_api_trait_cmd.c.

References GNUNET_TESTING_Command::cls, GNUNET_TESTING_TRAIT_CMD, and GNUNET_TESTING_Command::traits.

Referenced by GNUNET_TESTING_interpreter_lookup_command().

48 {
49  return cmd->traits (cmd->cls,
50  (const void **) _cmd,
52  index);
53 }
#define GNUNET_TESTING_TRAIT_CMD
int(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
void * cls
Closure for all commands with command-specific context information.
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_trait_uuid()

int GNUNET_TESTING_get_trait_uuid ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
struct GNUNET_Uuid **  uuid 
)

Obtain a uuid from cmd.

Parameters
cmdcommand to extract the uuid from.
indexwhich amount to pick if cmd has multiple on offer
[out]uuidwhere to write the uuid.
Returns
GNUNET_OK on success.

◆ GNUNET_TESTING_make_trait_uuid()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uuid ( unsigned int  index,
const struct GNUNET_Uuid uuid 
)

Offer a uuid in a trait.

Parameters
indexwhich uuid to offer, in case there are multiple available.
uuidthe uuid to offer.
Returns
the trait.

◆ GNUNET_TESTING_get_trait_absolute_time()

int GNUNET_TESTING_get_trait_absolute_time ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const struct GNUNET_TIME_Absolute **  time 
)

Obtain a absolute time from cmd.

Parameters
cmdcommand to extract trait from
indexwhich time stamp to pick if cmd has multiple on offer.
[out]timeset to the wanted WTID.
Returns
GNUNET_OK on success

◆ GNUNET_TESTING_make_trait_absolute_time()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_absolute_time ( unsigned int  index,
const struct GNUNET_TIME_Absolute time 
)

Offer a absolute time.

Parameters
indexassociate the object with this index
timewhich object should be returned
Returns
the trait.

◆ GNUNET_TESTING_get_trait_relative_time()

int GNUNET_TESTING_get_trait_relative_time ( const struct GNUNET_TESTING_Command cmd,
unsigned int  index,
const struct GNUNET_TIME_Relative **  time 
)

Obtain a relative time from cmd.

Parameters
cmdcommand to extract trait from
indexwhich time to pick if cmd has multiple on offer.
[out]timeset to the wanted WTID.
Returns
GNUNET_OK on success

◆ GNUNET_TESTING_make_trait_relative_time()

struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_relative_time ( unsigned int  index,
const struct GNUNET_TIME_Relative time 
)

Offer a relative time.

Parameters
indexassociate the object with this index
timewhich object should be returned
Returns
the trait.

◆ GNUNET_TESTING_cmd_hello_world_birth()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world_birth ( const char *  label,
struct GNUNET_TIME_Absolute now 
)

Create command.

Parameters
labelname for command.
nowwhen the command was started.
Returns
command.

Definition at line 142 of file testing_api_cmd_hello_world_birth.c.

References GNUNET_TESTING_Command::cls, HelloWorldBirthState::date, GNUNET_new, hello_world_birth_cleanup(), hello_world_birth_run(), hello_world_birth_traits(), and GNUNET_TESTING_Command::label.

144 {
145  struct HelloWorldBirthState *hbs;
146 
147  hbs = GNUNET_new (struct HelloWorldBirthState);
148  hbs->date = now;
149 
150  struct GNUNET_TESTING_Command cmd = {
151  .cls = hbs,
152  .label = label,
153  .run = &hello_world_birth_run,
154  .cleanup = &hello_world_birth_cleanup,
155  .traits = &hello_world_birth_traits
156  };
157 
158  return cmd;
159 }
const char * label
Label for the command.
A command to be run by the interpreter.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void hello_world_birth_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.
static void hello_world_birth_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
static int hello_world_birth_traits(void *cls, const void **ret, const char *trait, unsigned int index)
void * cls
Closure for all commands with command-specific context information.
struct GNUNET_TIME_Absolute * date
Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_hello_world()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world ( const char *  label,
const char *  birthLabel,
char *  message 
)

Create command.

Parameters
labelname for command.
messageinitial message.
Returns
command.

Definition at line 102 of file testing_api_cmd_hello_world.c.

References HelloWorldState::birthLabel, GNUNET_TESTING_Command::cls, GNUNET_new, hello_world_cleanup(), hello_world_run(), hello_world_traits(), GNUNET_TESTING_Command::label, and HelloWorldState::message.

105 {
106  struct HelloWorldState *hs;
107 
108  hs = GNUNET_new (struct HelloWorldState);
109  hs->message = "Hello World, I was nobody!";
110  hs->birthLabel = birthLabel;
111 
112  struct GNUNET_TESTING_Command cmd = {
113  .cls = hs,
114  .label = label,
115  .run = &hello_world_run,
116  .cleanup = &hello_world_cleanup,
117  .traits = &hello_world_traits
118  };
119 
120  return cmd;
121 }
static void hello_world_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
const char * label
Label for the command.
A command to be run by the interpreter.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void hello_world_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.
static int hello_world_traits(void *cls, const void **ret, const char *trait, unsigned int index)
void * cls
Closure for all commands with command-specific context information.
Here is the call graph for this function:

◆ GNUNET_TESTING_get_trait_what_am_i()

int GNUNET_TESTING_get_trait_what_am_i ( const struct GNUNET_TESTING_Command cmd,
char **  what_am_i 
)

Offer data from trait.

Parameters
cmdcommand to extract the url from.
ptwhich url is to be picked, in case multiple are offered.
[out]urlwhere to write the url.
Returns
GNUNET_OK on success.
Parameters
cmdcommand to extract the message from.
ptpointer to message.
Returns
GNUNET_OK on success.

Definition at line 125 of file testing_api_cmd_hello_world_birth.c.

References GNUNET_TESTING_Command::cls, and GNUNET_TESTING_Command::traits.

Referenced by hello_world_run().

127 {
128  return cmd->traits (cmd->cls,
129  (const void **) what_am_i,
130  "what_am_i",
131  (unsigned int) 0);
132 }
int(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
void * cls
Closure for all commands with command-specific context information.
Here is the caller graph for this function: