GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
testing_api_loop.c File Reference

main interpreter loop for testcases More...

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

Go to the source code of this file.

Data Structures

struct  SyncTaskClosure
 Closure used to sync an asynchronous with an synchronous command. More...
 
struct  FinishTaskClosure
 Closure used to run the finish task. More...
 

Macros

#define CHECK_FINISHED_PERIOD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
#define BATCH_INDEX   1
 

Functions

const struct GNUNET_TESTING_CommandGNUNET_TESTING_interpreter_lookup_command (const char *label)
 Lookup command by label. More...
 
static void interpreter_run (void *cls)
 Run the main interpreter loop that performs exchange operations. More...
 
static void interpreter_next (void *cls)
 Current command is done, run the next one. More...
 
static void run_finish_task_next (void *cls)
 
static void run_finish_task_sync (void *cls)
 
static void start_finish_on_ref (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 
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...
 
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...
 
void GNUNET_TESTING_interpreter_fail ()
 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 char * GNUNET_TESTING_interpreter_get_current_label (struct GNUNET_TESTING_Interpreter *is)
 Obtain current label. More...
 
static void do_shutdown (void *cls)
 Function run when the test terminates (good or bad). More...
 
static void do_timeout (void *cls)
 Function run when the test terminates (good or bad) with timeout. More...
 
int GNUNET_TESTING_run (const char *cfg_filename, struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
 Run the testsuite. More...
 

Variables

struct GNUNET_TESTING_Interpreteris
 

Detailed Description

main interpreter loop for testcases

Author
Christian Grothoff (GNU Taler testing)
Marcello Stanisci (GNU Taler testing)
t3sserakt

Definition in file testing_api_loop.c.

Macro Definition Documentation

◆ CHECK_FINISHED_PERIOD

#define CHECK_FINISHED_PERIOD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)

◆ BATCH_INDEX

#define BATCH_INDEX   1

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 to look for
Returns
NULL if command was not found

Definition at line 84 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 connect_peers_run(), GNUNET_TESTING_cmd_finish(), hello_world_run(), peer_run(), send_simple_run(), start_peer_run(), stop_testbed_run(), and tng_service_run().

85 {
86  if (NULL == label)
87  {
89  "Attempt to lookup command for empty label\n");
90  return NULL;
91  }
92  /* Search backwards as we most likely reference recent commands */
93  for (int i = is->ip; i >= 0; i--)
94  {
95  const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
96 
97  /* Give precedence to top-level commands. */
98  if ( (NULL != cmd->label) &&
99  (0 == strcmp (cmd->label,
100  label)) )
101  return cmd;
102 
103  if (GNUNET_TESTING_cmd_is_batch (cmd))
104  {
105 #define BATCH_INDEX 1
106  struct GNUNET_TESTING_Command *batch;
107  struct GNUNET_TESTING_Command *current;
108  struct GNUNET_TESTING_Command *icmd;
109  const struct GNUNET_TESTING_Command *match;
110 
111  current = GNUNET_TESTING_cmd_batch_get_current (cmd);
114  BATCH_INDEX,
115  &batch));
116  /* We must do the loop forward, but we can find the last match */
117  match = NULL;
118  for (unsigned int j = 0;
119  NULL != (icmd = &batch[j])->label;
120  j++)
121  {
122  if (current == icmd)
123  break; /* do not go past current command */
124  if ( (NULL != icmd->label) &&
125  (0 == strcmp (icmd->label,
126  label)) )
127  match = icmd;
128  }
129  if (NULL != match)
130  return match;
131  }
132  }
134  "Command not found: %s\n",
135  label);
136  return NULL;
137 
138 }
#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:

◆ interpreter_run()

static void interpreter_run ( void *  cls)
static

Run the main interpreter loop that performs exchange operations.

Run the main interpreter loop.

Parameters
clscontains the struct InterpreterState
clscontains the struct GNUNET_TESTING_Interpreter

Definition at line 407 of file testing_api_loop.c.

References GNUNET_TESTING_Command::asynchronous_finish, CHECK_FINISHED_PERIOD, GNUNET_TESTING_Command::cls, FinishTaskClosure::cmd, GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Command::finish, GNUNET_TESTING_Interpreter::finish_task, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_absolute_get(), interpreter_next(), GNUNET_TESTING_Interpreter::ip, SyncTaskClosure::is, FinishTaskClosure::is, GNUNET_TESTING_Command::label, GNUNET_TESTING_Command::last_req_time, GNUNET_TESTING_Command::num_tries, GNUNET_TESTING_Interpreter::result, GNUNET_TESTING_Command::run, run_finish_task_next(), GNUNET_TESTING_Command::start_time, and GNUNET_TESTING_Interpreter::task.

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

408 {
409  struct FinishTaskClosure *ftc;
410  struct GNUNET_TESTING_Interpreter *is = cls;
411  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
412 
413  is->task = NULL;
414 
415  if (NULL == cmd->label)
416  {
417 
419  "Running command END %p\n",
420  is);
421  is->result = GNUNET_OK;
423  return;
424  }
425  else if (NULL != cmd)
426  {
428  "Running command `%s' %p\n",
429  cmd->label,
430  is);
431  }
432  cmd->start_time
433  = cmd->last_req_time
435  cmd->num_tries = 1;
436  cmd->run (cmd->cls,
437  cmd,
438  is);
439  if ((NULL != cmd->finish) && (GNUNET_NO == cmd->asynchronous_finish))
440  {
442  "Next task will not be called directly!\n");
443  ftc = GNUNET_new (struct FinishTaskClosure);
444  ftc->cmd = cmd;
445  ftc->is = is;
448  ftc);
449  }
450  else
451  {
452  interpreter_next (is);
453  }
454 }
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
static void interpreter_next(void *cls)
Current command is done, run the next one.
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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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_TESTING_Interpreter * is
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
struct GNUNET_SCHEDULER_Task * finish_task
Finish task of a blocking call to a commands finish method.
Definition: testing.h:50
#define CHECK_FINISHED_PERIOD
const struct GNUNET_TESTING_Command * cmd
The asynchronous command the synchronous command waits for.
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(* run)(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *i)
Runs 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...
static void run_finish_task_next(void *cls)
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
Definition: testing.h:45
Closure used to run the finish task.
struct GNUNET_TESTING_Interpreter * is
The interpreter of the test.
int(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
#define GNUNET_log(kind,...)
void * cls
Closure for all commands with command-specific context information.
int result
Result of the testcases, GNUNET_OK on success.
Definition: testing.h:72
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated.) Note that a command must have some built-in retry mechanism for this value to be useful.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpreter_next()

static void interpreter_next ( void *  cls)
static

Current command is done, run the next one.

Definition at line 154 of file testing_api_loop.c.

References GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Command::finish_time, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TESTING_cmd_batch_next(), GNUNET_TESTING_cmd_is_batch(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, interpreter_run(), GNUNET_TESTING_Interpreter::ip, GNUNET_TESTING_Interpreter::result, and GNUNET_TESTING_Interpreter::task.

Referenced by interpreter_run(), run_finish_task_next(), and run_finish_task_sync().

155 {
156  struct GNUNET_TESTING_Interpreter *is = cls;
157  static unsigned long long ipc;
158  static struct GNUNET_TIME_Absolute last_report;
159  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
160 
161  if (GNUNET_SYSERR == is->result)
162  return; /* ignore, we already failed! */
163  if (GNUNET_TESTING_cmd_is_batch (cmd))
164  {
166  }
167  else
168  {
170  is->ip++;
171  }
172  if (0 == (ipc % 1000))
173  {
174  if (0 != ipc)
176  "Interpreter executed 1000 instructions in %s\n",
178  GNUNET_TIME_absolute_get_duration (last_report),
179  GNUNET_YES));
180  last_report = GNUNET_TIME_absolute_get ();
181  }
182  ipc++;
184  is);
185 }
void GNUNET_TESTING_cmd_batch_next(struct GNUNET_TESTING_Interpreter *is)
Advance internal pointer to next command.
A command to be run by the interpreter.
static void interpreter_run(void *cls)
Run the main interpreter loop that performs exchange operations.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
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
struct GNUNET_TESTING_Interpreter * is
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:557
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 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_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
Definition: testing.h:45
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:263
#define GNUNET_log(kind,...)
int result
Result of the testcases, GNUNET_OK on success.
Definition: testing.h:72
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_finish_task_next()

static void run_finish_task_next ( void *  cls)
static

Definition at line 189 of file testing_api_loop.c.

References CHECK_FINISHED_PERIOD, GNUNET_TESTING_Command::cls, FinishTaskClosure::cmd, GNUNET_TESTING_Command::finish, GNUNET_TESTING_Interpreter::finish_task, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTING_interpreter_fail(), GNUNET_YES, interpreter_next(), and FinishTaskClosure::is.

Referenced by interpreter_run().

190 {
191  struct FinishTaskClosure *ftc = cls;
192  const struct GNUNET_TESTING_Command *cmd = ftc->cmd;
193  struct GNUNET_TESTING_Interpreter *is = ftc->is;
194  unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
195 
196  if (GNUNET_YES == finished)
197  {
198  is->finish_task = NULL;
199  }
200  else if (GNUNET_NO == finished)
201  {
203  &run_finish_task_next, ftc);
204  }
205  else
206  {
208  "Next task finished with an error.\n");
210  }
211 
212 }
static void interpreter_next(void *cls)
Current command is done, run the next one.
A command to be run by the interpreter.
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_TESTING_Interpreter * is
struct GNUNET_SCHEDULER_Task * finish_task
Finish task of a blocking call to a commands finish method.
Definition: testing.h:50
#define CHECK_FINISHED_PERIOD
const struct GNUNET_TESTING_Command * cmd
The asynchronous command the synchronous command waits for.
static void run_finish_task_next(void *cls)
Closure used to run the finish task.
struct GNUNET_TESTING_Interpreter * is
The interpreter of the test.
int(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
void GNUNET_TESTING_interpreter_fail()
Current command failed, clean up and fail the test case.
#define GNUNET_log(kind,...)
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:

◆ run_finish_task_sync()

static void run_finish_task_sync ( void *  cls)
static

Definition at line 216 of file testing_api_loop.c.

References GNUNET_TIME_Absolute::abs_value_us, SyncTaskClosure::async_cmd, CHECK_FINISHED_PERIOD, GNUNET_TESTING_Command::cls, FinishTaskClosure::cmd, GNUNET_TESTING_Command::default_timeout, GNUNET_TESTING_Command::finish, SyncState::finish_task, finish_task(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTING_interpreter_fail(), GNUNET_TIME_absolute_get(), GNUNET_YES, interpreter_next(), SyncTaskClosure::is, FinishTaskClosure::is, GNUNET_TESTING_Command::label, GNUNET_TIME_Relative::rel_value_us, SyncState::start_finish_time, and SyncTaskClosure::sync_cmd.

Referenced by start_finish_on_ref().

217 {
218  struct SyncTaskClosure *stc = cls;
219  const struct GNUNET_TESTING_Command *cmd = stc->async_cmd;
220  const struct GNUNET_TESTING_Command *sync_cmd = stc->sync_cmd;
221  struct FinishTaskClosure *ftc;
222  struct SyncState *sync_state = sync_cmd->cls;
223  struct GNUNET_SCHEDULER_Task *finish_task = sync_state->finish_task;
224  unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
225 
226  GNUNET_assert (NULL != finish_task);
227  ftc = GNUNET_new (struct FinishTaskClosure);
228  ftc->cmd = stc->sync_cmd;
229  ftc->is = stc->is;
232  - sync_state->start_finish_time.abs_value_us)
233  {
235  "The command with label %s did not finish its asynchronous task in time.\n",
236  cmd->label);
238  }
239 
240  if (GNUNET_YES == finished)
241  {
242  finish_task = NULL;
243  }
244  else if (GNUNET_NO == finished)
245  {
247  &run_finish_task_sync, stc);
248  }
249  else
250  {
252  "Sync task finished with an error.\n");
254  }
255 }
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish method of the asynchronous task the command is waiting for...
static void interpreter_next(void *cls)
Current command is done, run the next one.
uint64_t rel_value_us
The actual value.
#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_TIME_Relative default_timeout
In case asynchronous_finish is true, how long should we wait for this command to complete? If finish did not complete after this amount of time, the interpreter will fail.
static void finish_task(struct TaskEntry *task)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint64_t abs_value_us
The actual value.
Struct to use for command-specific context information closure of a command waiting for another comma...
Closure used to sync an asynchronous with an synchronous command.
struct GNUNET_TESTING_Interpreter * is
The interpreter of the test.
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
struct GNUNET_TESTING_Interpreter * is
#define CHECK_FINISHED_PERIOD
struct GNUNET_TIME_Absolute start_finish_time
When did the execution of this commands finish function start?
const struct GNUNET_TESTING_Command * cmd
The asynchronous command the synchronous command waits for.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
const struct GNUNET_TESTING_Command * async_cmd
The asynchronous command the synchronous command waits for.
static void run_finish_task_sync(void *cls)
Closure used to run the finish task.
struct GNUNET_TESTING_Interpreter * is
The interpreter of the test.
int(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
void GNUNET_TESTING_interpreter_fail()
Current command failed, clean up and fail the test case.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
void * cls
Closure for all commands with command-specific context information.
const struct GNUNET_TESTING_Command * sync_cmd
The synchronous command that waits for the asynchronous command.
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_finish_on_ref()

static void start_finish_on_ref ( void *  cls,
const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Interpreter is 
)
static

Definition at line 259 of file testing_api_loop.c.

References SyncTaskClosure::async_cmd, SyncState::async_cmd, CHECK_FINISHED_PERIOD, SyncState::cls, SyncState::finish_task, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_get(), SyncTaskClosure::is, run_finish_task_sync(), SyncState::start_finish_time, and SyncTaskClosure::sync_cmd.

Referenced by GNUNET_TESTING_cmd_finish().

262 {
263  struct SyncState *sync_state = cls;
264  struct SyncTaskClosure *stc;
265  const struct GNUNET_TESTING_Command *async_cmd;
266 
267  async_cmd = sync_state->async_cmd;
268  stc = GNUNET_new (struct SyncTaskClosure);
269  stc->async_cmd = async_cmd;
270  stc->sync_cmd = cmd;
271  stc->is = is;
276  stc);
277 }
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish method of the asynchronous task the command is waiting for...
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...
Closure used to sync an asynchronous with an synchronous command.
struct GNUNET_TESTING_Interpreter * is
The interpreter of the test.
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
struct GNUNET_TESTING_Interpreter * is
#define CHECK_FINISHED_PERIOD
struct GNUNET_TIME_Absolute start_finish_time
When did the execution of this commands finish function start?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
const struct GNUNET_TESTING_Command * async_cmd
The asynchronous command the synchronous command of this closure waits for.
const struct GNUNET_TESTING_Command * async_cmd
The asynchronous command the synchronous command waits for.
static void run_finish_task_sync(void *cls)
void * cls
Closure for all commands with command-specific context information.
const struct GNUNET_TESTING_Command * sync_cmd
The synchronous command that waits for the asynchronous command.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 281 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().

284 {
285  const struct GNUNET_TESTING_Command *async_cmd;
286  struct SyncState *sync_state;
287 
288  async_cmd = GNUNET_TESTING_interpreter_lookup_command (cmd_ref);
289  sync_state = GNUNET_new (struct SyncState);
290  sync_state->async_cmd = async_cmd;
291 
292  struct GNUNET_TESTING_Command cmd = {
293  .cls = sync_state,
294  .label = finish_label,
295  .run = &start_finish_on_ref,
296  .asynchronous_finish = GNUNET_NO
297  };
298 
299  return cmd;
300 }
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_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.

Definition at line 304 of file testing_api_loop.c.

References SyncTaskClosure::async_cmd, GNUNET_TESTING_Command::cls, GNUNET_assert, and GNUNET_YES.

305 {
306 
307  GNUNET_assert (NULL != cmd.finish);
308  const struct GNUNET_TESTING_Command async_cmd = {
309  .cls = cmd.cls,
310  .label = cmd.label,
311  .run = cmd.run,
312  .cleanup = cmd.cleanup,
313  .traits = cmd.traits,
314  .finish = cmd.finish,
315  .asynchronous_finish = GNUNET_YES
316  };
317 
318  return async_cmd;
319 }
void(* cleanup)(void *cls, const struct GNUNET_TESTING_Command *cmd)
Clean up after the command.
#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.
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(* run)(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *i)
Runs the command.
int(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
void * cls
Closure for all commands with command-specific context information.

◆ GNUNET_TESTING_interpreter_fail()

void GNUNET_TESTING_interpreter_fail ( )

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

Parameters
isinterpreter of the test

Definition at line 328 of file testing_api_loop.c.

References GNUNET_TESTING_Interpreter::commands, GNUNET_ERROR_TYPE_DEBUG, 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.

Referenced by exp_cb(), run_finish_task_next(), run_finish_task_sync(), start_peer_run(), and start_testbed().

329 {
330  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
331 
332  if (GNUNET_SYSERR == is->result)
333  return; /* ignore, we already failed! */
334 
336  "interpreter_fail!\n");
337 
338  if (NULL != cmd)
339  {
340  while (GNUNET_TESTING_cmd_is_batch (cmd))
341  {
344  "Batch is at command `%s'\n",
345  cmd->label);
346  }
347 
348  }
349  else
350  {
352  "cmd is NULL.\n");
353  }
354 
355  if (NULL == cmd->label)
356  {
358  "Failed at command `%s'\n",
359  cmd->label);
360 
361  }
362  else
363  {
365  "cmd->label is NULL.\n");
366  }
367 
370 }
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_Interpreter * is
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:
Here is the caller 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 379 of file testing_api_loop.c.

References GNUNET_TESTING_Command::label.

380 {
381  static struct GNUNET_TESTING_Command cmd;
382  cmd.label = NULL;
383 
384  return cmd;
385 }
const char * label
Label for the command.
A command to be run by the interpreter.

◆ GNUNET_TESTING_interpreter_get_current_label()

const char* GNUNET_TESTING_interpreter_get_current_label ( struct GNUNET_TESTING_Interpreter is)

Obtain current label.

Obtain label of the command being now run.

Definition at line 392 of file testing_api_loop.c.

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

394 {
395  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
396 
397  return cmd->label;
398 }
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

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Function run when the test terminates (good or bad).

Cleans up our state.

Parameters
clsthe interpreter state.

Definition at line 464 of file testing_api_loop.c.

References GNUNET_TESTING_Command::cleanup, GNUNET_TESTING_Command::cls, GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Interpreter::finish_task, GNUNET_TESTING_Command::finish_task, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_Interpreter::ip, GNUNET_TESTING_Command::label, GNUNET_TESTING_Interpreter::task, and GNUNET_TESTING_Interpreter::timeout_task.

Referenced by GNUNET_TESTING_run().

465 {
466  (void) cls;
467  struct GNUNET_TESTING_Command *cmd;
468  const char *label;
469 
470  label = is->commands[is->ip].label;
471  if (NULL == label)
472  label = "END";
473 
475  "Executing shutdown at `%s'\n",
476  label);
477 
478  for (unsigned int j = 0;
479  NULL != (cmd = &is->commands[j])->label;
480  j++) {
481  cmd->cleanup (cmd->cls,
482  cmd);
483  }
484 
485  if (NULL != is->finish_task)
486  {
488  cmd->finish_task = NULL;
489  }
490 
491  if (NULL != is->task)
492  {
494  is->task = NULL;
495  }
496  if (NULL != is->timeout_task)
497  {
499  is->timeout_task = NULL;
500  }
502 }
void(* cleanup)(void *cls, const struct GNUNET_TESTING_Command *cmd)
Clean up after the command.
const char * label
Label for the command.
A command to be run by the interpreter.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_SCHEDULER_Task * finish_task
Finish task of a blocking call to a commands finish method.
Definition: testing.h:50
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
Definition: testing.h:40
int ip
Instruction pointer.
Definition: testing.h:67
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
Definition: testing.h:45
#define GNUNET_log(kind,...)
void * cls
Closure for all commands with command-specific context information.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
Definition: testing.h:60
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish function.
#define GNUNET_free(ptr)
Wrapper around free.
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:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Function run when the test terminates (good or bad) with timeout.

Parameters
clsNULL

Definition at line 511 of file testing_api_loop.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_shutdown(), and GNUNET_TESTING_Interpreter::timeout_task.

Referenced by GNUNET_TESTING_run().

512 {
513  (void) cls;
514 
515  is->timeout_task = NULL;
517  "Terminating test due to timeout\n");
519 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_log(kind,...)
void * cls
Closure for all commands with command-specific context information.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
Definition: testing.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_run()

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

Run the testsuite.

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 533 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.

Referenced by start_testcase().

536 {
537  unsigned int i;
538 
540 
541  if (NULL != is->timeout_task)
542  {
544  is->timeout_task = NULL;
545  }
546  /* get the number of commands */
547  for (i = 0; NULL != commands[i].label; i++)
548  ;
549  is->commands = GNUNET_new_array (i + 1,
550  struct GNUNET_TESTING_Command);
551  memcpy (is->commands,
552  commands,
553  sizeof (struct GNUNET_TESTING_Command) * i);
554 
556  (timeout,
557  &do_timeout,
558  is);
561  return GNUNET_OK;
562 }
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:
Here is the caller graph for this function:

Variable Documentation

◆ is