GNUnet  0.19.3
testing_api_loop.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #include "platform.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testing_ng_lib.h"
31 #include "gnunet_testing_plugin.h"
32 #include "gnunet_testing_barrier.h"
34 #include "testing.h"
35 
41 {
45  const struct GNUNET_HELPER_Handle **helper;
46 
51  unsigned int n_helper;
52 
57 
61  void *rc_cls;
62 
67 
72 
76  unsigned int cmds_n;
77 
82 
87 
92 
98  int ip;
99 
104 
108  unsigned int finishing;
109 
110 };
111 
113 {
118 
123 };
124 
125 
126 const struct GNUNET_TESTING_Command *
128  const char *label,
129  unsigned int future)
130 {
131  int start_i = GNUNET_NO == future ? is->ip : is->cmds_n - 1;
132  int end_i = GNUNET_NO == future ? 0 : is->ip + 1;
133 
135  "start_i: %u end_i: %u\n",
136  start_i,
137  end_i);
138  if (NULL == label)
139  {
141  "Attempt to lookup command for empty label\n");
142  return NULL;
143  }
144 
145  for (int i = start_i; i >= end_i; i--)
146  {
147  const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
148 
149  if (NULL != cmd->run)
151  "label to compare %s\n",
152  cmd->label);
153  /* Give precedence to top-level commands. */
154  if ( (NULL != cmd->run) &&
155  (0 == strcmp (cmd->label,
156  label)) )
157  return cmd;
158 
160  {
161  struct GNUNET_TESTING_Command **batch;
162  struct GNUNET_TESTING_Command *current;
163  const struct GNUNET_TESTING_Command *icmd;
164  const struct GNUNET_TESTING_Command *match;
165 
169  &batch));
170  /* We must do the loop forward, but we can find the last match */
171  match = NULL;
172  for (unsigned int j = 0;
173  NULL != (icmd = &(*batch)[j])->run;
174  j++)
175  {
176  if (current == icmd)
177  break; /* do not go past current command */
178  if ( (NULL != icmd->run) &&
179  (0 == strcmp (icmd->label,
180  label)) )
181  match = icmd;
182  }
183  if (NULL != match)
184  return match;
185  }
186  }
188  "Command `%s' not found\n",
189  label);
190  return NULL;
191 }
192 
193 
202 const struct GNUNET_TESTING_Command *
205  const char *label)
206 {
207  return get_command (is, label, GNUNET_YES);
208 }
209 
210 
219 const struct GNUNET_TESTING_Command *
222  const char *label)
223 {
224  return get_command (is, label, GNUNET_NO);
225 }
226 
227 
228 const struct GNUNET_TESTING_Command *
231  const char *label)
232 {
233  const struct GNUNET_TESTING_Command *cmd;
234 
235  cmd = get_command (is, label, GNUNET_NO);
236  if (NULL == cmd)
237  cmd = get_command (is, label, GNUNET_YES);
238  return cmd;
239 }
240 
241 
247 static void
249 {
250  struct GNUNET_TESTING_Interpreter *is = cls;
251  struct GNUNET_TESTING_Command *cmd;
252  const char *label;
253 
255  is->final_task = NULL;
256  label = is->commands[is->ip].label;
257  if (NULL == is->commands[is->ip].run)
258  label = "END";
260  "Interpreter finishes at `%s' with status %d\n",
261  label,
262  is->result);
263  for (unsigned int j = 0;
264  NULL != (cmd = &is->commands[j])->run;
265  j++)
266  {
268  "Cleaning up cmd %s\n",
269  cmd->label);
270  cmd->cleanup (cmd->cls);
272  "Cleaned up cmd %s\n",
273  cmd->label);
274  }
275  if (NULL != is->task)
276  {
278  is->task = NULL;
279  }
280  if (NULL != is->timeout_task)
281  {
283  is->timeout_task = NULL;
284  }
286  is->rc (is->rc_cls,
287  is->result);
288  GNUNET_free (is->helper);
289  GNUNET_free (is);
290 }
291 
292 
298 static void
299 interpreter_run (void *cls);
300 
301 
305 static void
307 {
308  struct GNUNET_TESTING_Interpreter *is = cls;
309  static unsigned long long ipc;
310  static struct GNUNET_TIME_Absolute last_report;
311  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
312 
313  if (GNUNET_SYSERR == is->result)
314  return; /* ignore, we already failed! */
316  if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) ||
318  is->ip++;
319  if (0 == (ipc % 1000))
320  {
321  if (0 != ipc)
323  "Interpreter executed 1000 instructions in %s\n",
325  GNUNET_TIME_absolute_get_duration (last_report),
326  GNUNET_YES));
327  last_report = GNUNET_TIME_absolute_get ();
328  }
329  ipc++;
331  is);
332 }
333 
334 
335 void
337 {
338  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
339 
340  if (GNUNET_SYSERR == is->result)
341  {
342  GNUNET_break (0);
343  return; /* ignore, we already failed! */
344  }
345  if (NULL != cmd)
346  {
348  "Failed at command `%s'\n",
349  cmd->label);
350  while (GNUNET_TESTING_cmd_is_batch_ (cmd))
351  {
354  "Failed in batch at command `%s'\n",
355  cmd->label);
356  }
357  }
358  else
359  {
361  "Failed with CMD being NULL!\n");
362  }
364  GNUNET_assert (NULL == is->final_task);
366  is);
367 }
368 
369 
377 struct GNUNET_TESTING_Command *
380 {
381  return &is->commands[is->ip];
382 }
383 
384 
385 const char *
388 {
389  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
390 
391  return cmd->label;
392 }
393 
394 
400 static void
402 {
403  struct GNUNET_TESTING_Interpreter *is = cls;
404  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
405 
406  is->task = NULL;
407  if (NULL == cmd->run)
408  {
410  "Running command END\n");
411  is->result = GNUNET_OK;
412  finish_test (is);
413  return;
414  }
416  "Running command `%s'\n",
417  cmd->label);
419  "start time of %p expected 0 is `%lu'\n",
420  cmd,
421  cmd->start_time.abs_value_us);
422  cmd->start_time
423  = cmd->last_req_time
426  "start time of %p expected something is `%lu'\n",
427  cmd,
428  cmd->start_time.abs_value_us);
429  cmd->num_tries = 1;
430  if (NULL != cmd->ac)
431  {
432  cmd->ac->is = is;
433  cmd->ac->cont = &interpreter_next;
434  cmd->ac->cont_cls = is;
435  cmd->ac->finished = GNUNET_NO;
436  }
437  cmd->run (cmd->cls,
438  is);
439  if (NULL == cmd->ac)
440  {
442  }
443  else if ( (cmd->asynchronous_finish) &&
444  (NULL != cmd->ac->cont) )
445  {
446  cmd->ac->cont = NULL;
448  }
449 }
450 
451 
457 static void
459 {
460  struct GNUNET_TESTING_Interpreter *is = cls;
461 
462  is->timeout_task = NULL;
464  "Terminating test due to global timeout\n");
466  finish_test (is);
467 }
468 
469 
471 GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command)
472 {
473  return 0 != command->start_time.abs_value_us && 0 ==
474  command->finish_time.abs_value_us;
475 }
476 
477 
479 GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command)
480 {
483  command->finish_time,
484  now);
485  return 0 < diff.rel_value_us;
486 }
487 
488 
493  void *rc_cls)
494 {
496  unsigned int i;
497 
499  is->rc = rc;
500  is->rc_cls = rc_cls;
502  /* get the number of commands */
503  for (i = 0; NULL != commands[i].run; i++)
504  ;
505  is->cmds_n = i + 1;
506  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u commands\n", i);
508  struct GNUNET_TESTING_Command);
509  memcpy (is->commands,
510  commands,
511  sizeof (struct GNUNET_TESTING_Command) * i);
514  &do_timeout,
515  is);
517  is);
518 
519  return is;
520 }
521 
522 
525  const char *label,
530 {
531  struct GNUNET_TESTING_Command cmd = {
532  .cls = cls,
533  .run = run,
534  .ac = ac,
535  .cleanup = cleanup,
536  .traits = traits
537  };
538  memset (&cmd.label, 0, sizeof (cmd.label));
539  if (NULL != label)
541 
542  return cmd;
543 
544 }
545 
546 
551 {
552 
557 
562 
566  int rv;
567 };
568 
569 
576 static void
577 handle_result (void *cls,
579 {
580  struct MainParams *mp = cls;
581 
583  "Test exits with status %d\n",
584  rv);
585  if (GNUNET_OK != rv)
586  mp->rv = EXIT_FAILURE;
588 }
589 
590 
596 static void
597 loop_run (void *cls)
598 {
599  struct MainParams *mp = cls;
600 
602  mp->timeout,
603  &handle_result,
604  mp);
605 }
606 
607 
616 static void
617 clear_msg (void *cls, int result)
618 {
620 }
621 
622 
629 void
631  const struct GNUNET_HELPER_Handle *helper)
632 {
633  GNUNET_array_append (is->helper, is->n_helper, helper);
634 }
635 
636 
644 void
646  unsigned int global_node_number,
647  struct GNUNET_MessageHeader *header)
648 {
649  const struct GNUNET_HELPER_Handle *helper;
650 
652  "send message of type %u to locals\n",
653  ntohs (header->type));
654  helper = is->helper[global_node_number - 1];
656  (struct GNUNET_HELPER_Handle *) helper,
657  header,
658  GNUNET_NO,
659  &clear_msg,
660  NULL);
661 }
662 
663 
664 void
666  const char *barrier_name,
667  unsigned int global_node_number)
668 {
669  struct CommandBarrierCrossable *adm;
670  size_t msg_length;
671  size_t name_len;
672  char *terminator = "\0";
673 
675  "send barrier name %s barrier_name\n",
676  barrier_name);
677  name_len = strlen (barrier_name);
678  msg_length = sizeof(struct CommandBarrierCrossable) + name_len + 1;
679  adm = GNUNET_malloc (msg_length);
681  adm->header.size = htons ((uint16_t) msg_length);
682  memcpy (&adm[1], barrier_name, name_len);
684  global_node_number,
685  &adm->header);
686  GNUNET_free (adm);
687 }
688 
689 
690 int
692  const struct GNUNET_ShortHashCode *key,
693  void *value)
694 {
695  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
696  struct GNUNET_TESTING_NetjailNode *node = value;
697  struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
698  struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
699 
701  "free_barrier_node_cb\n");
702  if (GNUNET_NO == is->finishing)
703  {
705  "TST_interpreter_send_barrier_crossable\n");
707  barrier->name,
708  node->node_number);
709  }
711  barrier->nodes, key, node));
712  return GNUNET_YES;
713 }
714 
715 
723 struct GNUNET_TESTING_Barrier *
725  const char *barrier_name)
726 {
727  struct GNUNET_HashCode hc;
728  struct GNUNET_ShortHashCode create_key;
729  struct GNUNET_TESTING_Barrier *barrier;
730 
731  GNUNET_CRYPTO_hash (barrier_name, strlen (barrier_name), &hc);
732  memcpy (&create_key,
733  &hc,
734  sizeof (create_key));
735  barrier = GNUNET_CONTAINER_multishortmap_get (is->barriers, &create_key);
736  return barrier;
737 }
738 
739 
745 void
747  const char *barrier_name)
748 {
749  struct CommandListEntry *pos;
750  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
752  barrier_name);
753 
754  while (NULL != barrier && NULL != (pos = barrier->cmds_head))
755  {
757  "command label %s\n",
758  pos->command->label);
759  if (GNUNET_NO == pos->command->ac->finished &&
761  {
763  "command label %s finish\n",
764  pos->command->label);
766  }
767  else if (GNUNET_NO == pos->command->ac->finished)
768  {
770  }
772  barrier->cmds_tail,
773  pos);
775  "command entry label %s removed\n",
776  pos->command->label);
777  GNUNET_free (pos);
779  "command entry freed\n");
780  }
781  if (NULL != barrier->nodes)
782  {
783  free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
784  free_barrier_node_cb_cls->barrier = barrier;
785  free_barrier_node_cb_cls->is = is;
787  "freeing nodes\n");
790  free_barrier_node_cb_cls);
792  "nodes freed\n");
793  GNUNET_free (free_barrier_node_cb_cls);
795  barrier->nodes = NULL;
796  }
797 }
798 
799 
800 int
801 free_barriers_cb (void *cls,
802  const struct GNUNET_ShortHashCode *key,
803  void *value)
804 {
805  struct GNUNET_TESTING_Interpreter *is = cls;
806  struct GNUNET_TESTING_Barrier *barrier = value;
807  struct CommandListEntry *pos;
808  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
809 
810  if (NULL != barrier->nodes)
811  {
812  free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
813  free_barrier_node_cb_cls->barrier = barrier;
814  free_barrier_node_cb_cls->is = is;
817  free_barrier_node_cb_cls);
819  barrier->nodes = NULL;
820  }
821 
822  while (NULL != (pos = barrier->cmds_head))
823  {
826  pos);
827  GNUNET_free (pos);
828  }
830  return GNUNET_YES;
831 }
832 
833 
839 void
841 {
844  is);
846 }
847 
848 
855 void
858 {
859  struct GNUNET_HashCode hc;
860  struct GNUNET_ShortHashCode create_key;
861 
862  GNUNET_CRYPTO_hash (barrier->name, strlen (barrier->name), &hc);
863  memcpy (&create_key,
864  &hc,
865  sizeof (create_key));
867  &create_key,
868  barrier,
870 }
871 
872 
873 int
876 {
877  struct MainParams mp = {
878  .commands = commands,
879  .timeout = timeout,
880  .rv = EXIT_SUCCESS
881  };
882 
884  &mp);
885  return mp.rv;
886 }
887 
888 
889 void
891 {
892  GNUNET_assert (GNUNET_NO == ac->finished);
893  ac->finished = GNUNET_SYSERR;
895  if (NULL != ac->cont)
896  {
897  ac->cont (ac->cont_cls);
898  ac->cont = NULL;
899  }
900 }
901 
902 
903 void
905 {
906  GNUNET_assert (GNUNET_NO == ac->finished);
907  ac->finished = GNUNET_OK;
908  if (NULL != ac->cont)
909  {
910  ac->cont (ac->cont_cls);
911  ac->cont = NULL;
912  }
913 }
914 
915 
916 /* end of testing_api_loop.c */
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
Definition: gnunet-abd.c:757
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct SolverHandle * sh
struct GNUNET_TESTING_Interpreter * is
static struct VoipCommand commands[]
List of supported commands.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
static int result
Global testing status.
API to manage barriers.
void(* GNUNET_TESTING_CommandRunRoutine)(void *cls, struct GNUNET_TESTING_Interpreter *is)
void(* GNUNET_TESTING_CommandCleanupRoutine)(void *cls)
void(* GNUNET_TESTING_ResultCallback)(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
enum GNUNET_GenericReturnValue(* GNUNET_TESTING_CommandGetTraits)(void *cls, const void **ret, const char *trait, unsigned int index)
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
Maximum length of label in command.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_batch_cmds(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Command ***ret)
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:614
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:720
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:1299
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1272
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:436
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
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:569
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:421
Message send to a child loop to inform the child loop about a barrier being advanced.
Definition: testing.h:35
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE.
Definition: testing.h:39
struct GNUNET_TESTING_Command * command
Definition: testing.h:148
struct GNUNET_TESTING_Interpreter * is
The interpreter.
struct GNUNET_TESTING_Barrier * barrier
The barrier from which the nodes are freed.
Internal representation of the hash map.
The handle to a helper process.
Definition: helper.c:78
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
A 512-bit hashcode.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Entry in list of pending tasks.
Definition: scheduler.c:136
A 256-bit hashcode.
State each asynchronous command must have in its closure.
GNUNET_SCHEDULER_TaskCallback cont
Function to call when done.
void * cont_cls
Closure for cont.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).
const char * name
Name of the barrier.
Definition: testing.h:182
struct GNUNET_CONTAINER_MultiShortmap * nodes
Hash map containing the global known nodes which are not natted.
Definition: testing.h:177
struct CommandListEntry * cmds_tail
Tail of the DLL with local commands the barrier is attached too.
Definition: testing.h:172
struct CommandListEntry * cmds_head
Head of the DLL with local commands the barrier is attached too.
Definition: testing.h:167
A command to be run by the interpreter.
GNUNET_TESTING_CommandCleanupRoutine cleanup
Clean up after the command.
char label[127+1]
Label for the command.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
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...
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
GNUNET_TESTING_CommandGetTraits traits
Extract information from a command that is useful for other commands.
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
GNUNET_TESTING_ResultCallback rc
Function to call with the test result.
struct GNUNET_CONTAINER_MultiShortmap * barriers
Map with barriers for this loop.
unsigned int cmds_n
Number of GNUNET_TESTING_Command in commands.
unsigned int n_helper
Size of the array helper.
void * rc_cls
Closure for rc.
struct GNUNET_SCHEDULER_Task * final_task
Final task that returns the result.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
unsigned int finishing
Is the interpreter finishing?
int ip
Instruction pointer.
struct GNUNET_SCHEDULER_Task * task
Interpreter task (if one is scheduled).
const struct GNUNET_HELPER_Handle ** helper
Array with handles of helper processes for communication with netjails.
struct GNUNET_TESTING_Command * commands
Commands the interpreter will run.
enum GNUNET_GenericReturnValue result
Result of the testcases, GNUNET_OK on success.
Node in the netjail topology.
unsigned int node_number
The overall number of the node in the whole test system.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Closure for loop_run().
int rv
Set to #EXIT_FAILURE on error.
struct GNUNET_TIME_Relative timeout
Global timeout for the test.
struct GNUNET_TESTING_Command * commands
NULL-label terminated array of commands.
struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current_(const struct GNUNET_TESTING_Command *cmd)
Obtain what command the batch is at.
bool GNUNET_TESTING_cmd_batch_next_(void *cls)
Advance internal pointer to next command.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
int free_barrier_node_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
static void clear_msg(void *cls, int result)
Continuation function from GNUNET_HELPER_send()
void send_message_to_netjail(struct GNUNET_TESTING_Interpreter *is, unsigned int global_node_number, struct GNUNET_MessageHeader *header)
Send Message to netjail nodes.
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.
void TST_interpreter_send_barrier_crossable(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name, unsigned int global_node_number)
Send Message to a netjail node that a barrier can be crossed.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
static void do_timeout(void *cls)
Function run when the test terminates (good or bad) with timeout.
static void interpreter_run(void *cls)
Run the main interpreter loop that performs exchange operations.
const struct GNUNET_TESTING_Command * get_command(struct GNUNET_TESTING_Interpreter *is, const char *label, unsigned int future)
static void interpreter_next(void *cls)
Current command is done, run the next one.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
static void handle_result(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
enum GNUNET_GenericReturnValue GNUNET_TESTING_finished(const struct GNUNET_TESTING_Command *command)
Check if a command is finished.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command_all(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void TST_interpreter_delete_barriers(struct GNUNET_TESTING_Interpreter *is)
Deleting all barriers create in the context of this interpreter.
void TST_interpreter_add_barrier(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_future_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
const char * GNUNET_TESTING_interpreter_get_current_label(struct GNUNET_TESTING_Interpreter *is)
Obtain label of the command being now run.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Barrier * TST_interpreter_get_barrier(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Getting a barrier from the interpreter.
enum GNUNET_GenericReturnValue GNUNET_TESTING_running(const struct GNUNET_TESTING_Command *command)
Check if the command is running.
void TST_interpreter_finish_attached_cmds(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" comands attached to this barrier.
int free_barriers_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
static void finish_test(void *cls)
Finish the test run, return the final result.
void GNUNET_TESTING_add_netjail_helper(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_HELPER_Handle *helper)
Adding a helper handle to the interpreter.
static void loop_run(void *cls)
Main function to run the test cases.
int GNUNET_TESTING_main(struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Start a GNUnet scheduler event loop and run the testsuite.