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 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_asynchronous (const struct GNUNET_TESTING_Command cmd)
 
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 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

◆ 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 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:

◆ 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 361 of file testing_api_loop.c.

References GNUNET_TESTING_Command::asynchronous_finish, GNUNET_TESTING_Command::cls, FinishTaskClosure::cmd, GNUNET_TESTING_Interpreter::commands, GNUNET_TESTING_Command::finish, GNUNET_TESTING_Command::finish_task, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), 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().

362 {
363  struct FinishTaskClosure *ftc;
364  struct GNUNET_TESTING_Interpreter *is = cls;
365  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
366 
367  is->task = NULL;
368 
369  if (NULL == cmd->label)
370  {
371 
373  "Running command END\n");
374  is->result = GNUNET_OK;
376  return;
377  }
378 
380  "Running command `%s'\n",
381  cmd->label);
382  cmd->start_time
383  = cmd->last_req_time
385  cmd->num_tries = 1;
386  cmd->run (cmd->cls,
387  cmd,
388  is);
389  if ((NULL != cmd->finish) && (GNUNET_NO == cmd->asynchronous_finish))
390  {
391  ftc = GNUNET_new (struct FinishTaskClosure);
392  ftc->cmd = cmd;
393  ftc->is = is;
395  }
396  else
397  {
398  interpreter_next (is);
399  }
400 }
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.
bool(* 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_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
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
struct GNUNET_TIME_Absolute start_time
When did the execution of this command 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
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.
#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.
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish function.
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 151 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(), and run_finish_task_next().

152 {
153  struct GNUNET_TESTING_Interpreter *is = cls;
154  static unsigned long long ipc;
155  static struct GNUNET_TIME_Absolute last_report;
156  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
157 
158  if (GNUNET_SYSERR == is->result)
159  return; /* ignore, we already failed! */
160  if (GNUNET_TESTING_cmd_is_batch (cmd))
161  {
163  }
164  else
165  {
167  is->ip++;
168  }
169  if (0 == (ipc % 1000))
170  {
171  if (0 != ipc)
173  "Interpreter executed 1000 instructions in %s\n",
175  GNUNET_TIME_absolute_get_duration (last_report),
176  GNUNET_YES));
177  last_report = GNUNET_TIME_absolute_get ();
178  }
179  ipc++;
181  is);
182 }
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:702
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 186 of file testing_api_loop.c.

References GNUNET_TESTING_Command::cls, FinishTaskClosure::cmd, GNUNET_TESTING_Command::finish, GNUNET_TESTING_Interpreter::finish_task, GNUNET_SCHEDULER_add_now(), interpreter_next(), and FinishTaskClosure::is.

Referenced by interpreter_run(), and run_finish_task_sync().

187 {
188  struct FinishTaskClosure *ftc = cls;
189  const struct GNUNET_TESTING_Command *cmd = ftc->cmd;
190  struct GNUNET_TESTING_Interpreter *is = ftc->is;
191 
192  if (cmd->finish (cmd->cls, &interpreter_next, is))
193  {
195  }
196  else
197  {
198  is->finish_task = NULL;
199  }
200 
201 }
static void interpreter_next(void *cls)
Current command is done, run the next one.
A command to be run by the interpreter.
bool(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
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
struct GNUNET_SCHEDULER_Task * finish_task
Finish task of a blocking call to a commands finish method.
Definition: testing.h:50
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.
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 205 of file testing_api_loop.c.

References GNUNET_TIME_Absolute::abs_value_us, SyncTaskClosure::async_cmd, 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_ERROR, GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), SyncTaskClosure::is, FinishTaskClosure::is, GNUNET_TESTING_Command::label, GNUNET_TIME_Relative::rel_value_us, GNUNET_TESTING_Interpreter::result, run_finish_task_next(), SyncState::start_finish_time, and SyncTaskClosure::sync_cmd.

Referenced by start_finish_on_ref().

206 {
207  struct SyncTaskClosure *stc = cls;
208  const struct GNUNET_TESTING_Command *cmd = stc->async_cmd;
209  const struct GNUNET_TESTING_Command *sync_cmd = stc->sync_cmd;
210  struct FinishTaskClosure *ftc;
211  struct SyncState *sync_state = sync_cmd->cls;
212  struct GNUNET_SCHEDULER_Task *finish_task = sync_state->finish_task;
213 
214  GNUNET_assert (NULL != finish_task);
215  ftc = GNUNET_new (struct FinishTaskClosure);
216  ftc->cmd = stc->sync_cmd;
217  ftc->is = stc->is;
220  - sync_state->start_finish_time.abs_value_us)
221  {
223  "The command with label %s did not finish its asynchronous task in time.\n",
224  cmd->label);
227  }
228 
229  if (cmd->finish (cmd->cls, run_finish_task_next, ftc))
230  {
231  finish_task = GNUNET_SCHEDULER_add_now (&run_finish_task_sync, stc);
232  }
233  else
234  {
235  finish_task = NULL;
236  }
237 }
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish method of the asynchronous task the command is waiting for...
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.
bool(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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_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
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)
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.
#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.
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:

◆ 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 241 of file testing_api_loop.c.

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

Referenced by GNUNET_TESTING_cmd_finish().

244 {
245  struct SyncState *sync_state = cls;
246  struct SyncTaskClosure *stc;
247  const struct GNUNET_TESTING_Command *async_cmd;
248 
249  async_cmd = sync_state->async_cmd;
250  stc = GNUNET_new (struct SyncTaskClosure);
251  stc->async_cmd = async_cmd;
252  stc->sync_cmd = cmd;
253  stc->is = is;
256  stc);
257 }
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_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
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 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_make_asynchronous()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_make_asynchronous ( const struct GNUNET_TESTING_Command  cmd)

Definition at line 284 of file testing_api_loop.c.

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

285 {
286 
287  GNUNET_assert (NULL != cmd.finish);
288  const struct GNUNET_TESTING_Command async_cmd = {
289  .cls = cmd.cls,
290  .label = cmd.label,
291  .run = cmd.run,
292  .cleanup = cmd.cleanup,
293  .traits = cmd.traits,
294  .finish = cmd.finish,
295  .asynchronous_finish = GNUNET_YES
296  };
297 
298  return async_cmd;
299 }
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.
bool(* finish)(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Wait for any asynchronous execution of run to conclude, then call finish_cont.
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.
void * cls
Closure for all commands with command-specific context information.

◆ 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 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_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 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

◆ 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 410 of file testing_api_loop.c.

References GNUNET_TESTING_Command::cleanup, GNUNET_TESTING_Command::cls, GNUNET_TESTING_Interpreter::commands, 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().

411 {
412  (void) cls;
413  struct GNUNET_TESTING_Command *cmd;
414  const char *label;
415 
416  label = is->commands[is->ip].label;
417  if (NULL == label)
418  label = "END";
419 
421  "Executing shutdown at `%s'\n",
422  label);
423 
424  for (unsigned int j = 0;
425  NULL != (cmd = &is->commands[j])->label;
426  j++) {
427  cmd->cleanup (cmd->cls,
428  cmd);
429  if (NULL != cmd->finish_task)
430  {
432  cmd->finish_task = NULL;
433  }
434  }
435 
436  if (NULL != is->task)
437  {
439  is->task = NULL;
440  }
441  if (NULL != is->timeout_task)
442  {
444  is->timeout_task = NULL;
445  }
447 }
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_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 456 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().

457 {
458  (void) cls;
459 
460  is->timeout_task = NULL;
462  "Terminating test due to timeout\n");
464 }
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 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:

Variable Documentation

◆ is