GNUnet  0.19.5
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 
242 int
244  const struct GNUNET_ShortHashCode *key,
245  void *value)
246 {
247  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
248  struct GNUNET_TESTING_NetjailNode *node = value;
249  struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
250  struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
251 
253  "free_barrier_node_cb\n");
254  if (GNUNET_NO == is->finishing)
255  {
257  "TST_interpreter_send_barrier_crossable\n");
259  barrier->name,
260  node->node_number);
261  }
263  barrier->nodes, key, node));
264  return GNUNET_YES;
265 }
266 
267 
268 int
269 free_barriers_cb (void *cls,
270  const struct GNUNET_ShortHashCode *key,
271  void *value)
272 {
273  struct GNUNET_TESTING_Interpreter *is = cls;
274  struct GNUNET_TESTING_Barrier *barrier = value;
275  struct CommandListEntry *pos;
276  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
277 
278  if (NULL != barrier->nodes)
279  {
280  free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
281  free_barrier_node_cb_cls->barrier = barrier;
282  free_barrier_node_cb_cls->is = is;
285  free_barrier_node_cb_cls);
287  barrier->nodes = NULL;
288  }
289 
290  while (NULL != (pos = barrier->cmds_head))
291  {
294  pos);
295  GNUNET_free (pos);
296  }
298  return GNUNET_YES;
299 }
300 
301 
307 static void
309 {
312  is);
314 }
315 
316 
322 static void
323 finish_test (void *cls)
324 {
325  struct GNUNET_TESTING_Interpreter *is = cls;
326  struct GNUNET_TESTING_Command *cmd;
327  const char *label;
328 
330  is->final_task = NULL;
331  label = is->commands[is->ip].label;
332  if (NULL == is->commands[is->ip].run)
333  label = "END";
335  "Interpreter finishes at `%s' with status %d\n",
336  label,
337  is->result);
338  for (unsigned int j = 0;
339  NULL != (cmd = &is->commands[j])->run;
340  j++)
341  {
343  "Cleaning up cmd %s\n",
344  cmd->label);
345  cmd->cleanup (cmd->cls);
347  "Cleaned up cmd %s\n",
348  cmd->label);
349  }
350  if (NULL != is->task)
351  {
353  is->task = NULL;
354  }
355  if (NULL != is->timeout_task)
356  {
358  is->timeout_task = NULL;
359  }
361  is->rc (is->rc_cls,
362  is->result);
364  GNUNET_free (is->helper);
365  GNUNET_free (is);
366 }
367 
368 
374 static void
375 interpreter_run (void *cls);
376 
377 
381 static void
383 {
384  struct GNUNET_TESTING_Interpreter *is = cls;
385  static unsigned long long ipc;
386  static struct GNUNET_TIME_Absolute last_report;
387  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
388 
389  if (GNUNET_SYSERR == is->result)
390  return; /* ignore, we already failed! */
392  if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) ||
394  is->ip++;
395  if (0 == (ipc % 1000))
396  {
397  if (0 != ipc)
399  "Interpreter executed 1000 instructions in %s\n",
401  GNUNET_TIME_absolute_get_duration (last_report),
402  GNUNET_YES));
403  last_report = GNUNET_TIME_absolute_get ();
404  }
405  ipc++;
407  is);
408 }
409 
410 
411 void
413 {
414  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
415 
416  if (GNUNET_SYSERR == is->result)
417  {
418  GNUNET_break (0);
419  return; /* ignore, we already failed! */
420  }
421  if (NULL != cmd)
422  {
424  "Failed at command `%s'\n",
425  cmd->label);
426  while (GNUNET_TESTING_cmd_is_batch_ (cmd))
427  {
430  "Failed in batch at command `%s'\n",
431  cmd->label);
432  }
433  }
434  else
435  {
437  "Failed with CMD being NULL!\n");
438  }
440  GNUNET_assert (NULL == is->final_task);
442  is);
443 }
444 
445 
453 struct GNUNET_TESTING_Command *
456 {
457  return &is->commands[is->ip];
458 }
459 
460 
461 const char *
464 {
465  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
466 
467  return cmd->label;
468 }
469 
470 
476 static void
478 {
479  struct GNUNET_TESTING_Interpreter *is = cls;
480  struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
481 
482  is->task = NULL;
483  if (NULL == cmd->run)
484  {
486  "Running command END\n");
487  is->result = GNUNET_OK;
488  finish_test (is);
489  return;
490  }
492  "Running command `%s'\n",
493  cmd->label);
495  "start time of %p expected 0 is `%" PRIu64 "'\n",
496  cmd,
497  cmd->start_time.abs_value_us);
498  cmd->start_time
499  = cmd->last_req_time
502  "start time of %p expected something is `%" PRIu64 "'\n",
503  cmd,
504  cmd->start_time.abs_value_us);
505  cmd->num_tries = 1;
506  if (NULL != cmd->ac)
507  {
508  cmd->ac->is = is;
509  cmd->ac->cont = &interpreter_next;
510  cmd->ac->cont_cls = is;
511  cmd->ac->finished = GNUNET_NO;
512  }
513  cmd->run (cmd->cls,
514  is);
515  if (NULL == cmd->ac)
516  {
518  }
519  else if ( (cmd->asynchronous_finish) &&
520  (NULL != cmd->ac->cont) )
521  {
522  cmd->ac->cont = NULL;
524  }
525 }
526 
527 
533 static void
535 {
536  struct GNUNET_TESTING_Interpreter *is = cls;
537 
538  is->timeout_task = NULL;
540  "Terminating test due to global timeout\n");
542  finish_test (is);
543 }
544 
545 
547 GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command)
548 {
549  return 0 != command->start_time.abs_value_us && 0 ==
550  command->finish_time.abs_value_us;
551 }
552 
553 
555 GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command)
556 {
559  command->finish_time,
560  now);
561  return 0 < diff.rel_value_us;
562 }
563 
564 
569  void *rc_cls)
570 {
572  unsigned int i;
573 
575  is->rc = rc;
576  is->rc_cls = rc_cls;
578  /* get the number of commands */
579  for (i = 0; NULL != commands[i].run; i++)
580  ;
581  is->cmds_n = i + 1;
582  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u commands\n", i);
584  struct GNUNET_TESTING_Command);
585  memcpy (is->commands,
586  commands,
587  sizeof (struct GNUNET_TESTING_Command) * i);
590  &do_timeout,
591  is);
593  is);
594 
595  return is;
596 }
597 
598 
601  const char *label,
606 {
607  struct GNUNET_TESTING_Command cmd = {
608  .cls = cls,
609  .run = run,
610  .ac = ac,
611  .cleanup = cleanup,
612  .traits = traits
613  };
614  memset (&cmd.label, 0, sizeof (cmd.label));
615  if (NULL != label)
617 
618  return cmd;
619 
620 }
621 
622 
627 {
628 
633 
638 
642  int rv;
643 };
644 
645 
652 static void
653 handle_result (void *cls,
655 {
656  struct MainParams *mp = cls;
657 
659  "Test exits with status %d\n",
660  rv);
661  if (GNUNET_OK != rv)
662  mp->rv = EXIT_FAILURE;
664 }
665 
666 
672 static void
673 loop_run (void *cls)
674 {
675  struct MainParams *mp = cls;
676 
678  mp->timeout,
679  &handle_result,
680  mp);
681 }
682 
683 
692 static void
693 clear_msg (void *cls, int result)
694 {
696 }
697 
698 
705 void
707  const struct GNUNET_HELPER_Handle *helper)
708 {
709  GNUNET_array_append (is->helper, is->n_helper, helper);
710 }
711 
712 
720 void
722  unsigned int global_node_number,
723  struct GNUNET_MessageHeader *header)
724 {
725  const struct GNUNET_HELPER_Handle *helper;
726 
728  "send message of type %u to locals\n",
729  ntohs (header->type));
730  helper = is->helper[global_node_number - 1];
732  (struct GNUNET_HELPER_Handle *) helper,
733  header,
734  GNUNET_NO,
735  &clear_msg,
736  NULL);
737 }
738 
739 
740 void
742  const char *barrier_name,
743  unsigned int global_node_number)
744 {
745  struct CommandBarrierCrossable *adm;
746  size_t msg_length;
747  size_t name_len;
748  char *terminator = "\0";
749 
751  "send barrier name %s barrier_name\n",
752  barrier_name);
753  name_len = strlen (barrier_name);
754  msg_length = sizeof(struct CommandBarrierCrossable) + name_len + 1;
755  adm = GNUNET_malloc (msg_length);
757  adm->header.size = htons ((uint16_t) msg_length);
758  memcpy (&adm[1], barrier_name, name_len);
760  global_node_number,
761  &adm->header);
762  GNUNET_free (adm);
763 }
764 
765 
773 struct GNUNET_TESTING_Barrier *
775  const char *barrier_name)
776 {
777  struct GNUNET_HashCode hc;
778  struct GNUNET_ShortHashCode create_key;
779  struct GNUNET_TESTING_Barrier *barrier;
780 
781  GNUNET_CRYPTO_hash (barrier_name, strlen (barrier_name), &hc);
782  memcpy (&create_key,
783  &hc,
784  sizeof (create_key));
785  barrier = GNUNET_CONTAINER_multishortmap_get (is->barriers, &create_key);
786  return barrier;
787 }
788 
789 
795 void
797  const char *barrier_name)
798 {
799  struct CommandListEntry *pos;
800  struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
802  barrier_name);
803 
804  while (NULL != barrier && NULL != (pos = barrier->cmds_head))
805  {
807  "command label %s\n",
808  pos->command->label);
809  if (GNUNET_NO == pos->command->ac->finished &&
811  {
813  "command label %s finish\n",
814  pos->command->label);
816  }
817  else if (GNUNET_NO == pos->command->ac->finished)
818  {
820  }
822  barrier->cmds_tail,
823  pos);
825  "command entry label %s removed\n",
826  pos->command->label);
827  GNUNET_free (pos);
829  "command entry freed\n");
830  }
831  if (NULL != barrier->nodes)
832  {
833  free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
834  free_barrier_node_cb_cls->barrier = barrier;
835  free_barrier_node_cb_cls->is = is;
837  "freeing nodes\n");
840  free_barrier_node_cb_cls);
842  "nodes freed\n");
843  GNUNET_free (free_barrier_node_cb_cls);
845  barrier->nodes = NULL;
846  }
847 }
848 
849 
856 void
858  struct GNUNET_TESTING_Barrier *barrier)
859 {
860  struct GNUNET_HashCode hc;
861  struct GNUNET_ShortHashCode create_key;
862 
863  GNUNET_CRYPTO_hash (barrier->name, strlen (barrier->name), &hc);
864  memcpy (&create_key,
865  &hc,
866  sizeof (create_key));
868  &create_key,
869  barrier,
871 }
872 
873 
874 int
877 {
878  struct MainParams mp = {
879  .commands = commands,
880  .timeout = timeout,
881  .rv = EXIT_SUCCESS
882  };
883 
885  &mp);
886  return mp.rv;
887 }
888 
889 
890 void
892 {
893  GNUNET_assert (GNUNET_NO == ac->finished);
894  ac->finished = GNUNET_SYSERR;
896  if (NULL != ac->cont)
897  {
898  ac->cont (ac->cont_cls);
899  ac->cont = NULL;
900  }
901 }
902 
903 
904 void
906 {
907  GNUNET_assert (GNUNET_NO == ac->finished);
908  ac->finished = GNUNET_OK;
909  if (NULL != ac->cont)
910  {
911  ac->cont (ac->cont_cls);
912  ac->cont = NULL;
913  }
914 }
915 
916 
917 /* 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_add_barrier(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
static void interpreter_delete_barriers(struct GNUNET_TESTING_Interpreter *is)
Deleting all barriers create in the context of this interpreter.
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.