GNUnet  0.11.x
gnunet_testing_ng_lib.h
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 
27 #ifndef GNUNET_TESTING_NG_LIB_H
28 #define GNUNET_TESTING_NG_LIB_H
29 
30 #include "gnunet_util_lib.h"
31 
32 
33 /* ********************* Helper functions ********************* */
34 
39 #define GNUNET_TESTING_FAIL(is) \
40  do \
41  { \
42  GNUNET_break (0); \
43  GNUNET_TESTING_interpreter_fail (is); \
44  return; \
45  } while (0)
46 
47 
48 /* ******************* Generic interpreter logic ************ */
49 
55 
60 {
61 
65  void *cls;
66 
70  const char *label;
71 
88  void
89  (*run)(void *cls,
90  const struct GNUNET_TESTING_Command *cmd,
91  struct GNUNET_TESTING_Interpreter *i);
92 
104  bool
105  (*finish)(void *cls,
107  void *cont_cls);
108 
113 
121  void
122  (*cleanup)(void *cls,
123  const struct GNUNET_TESTING_Command *cmd);
124 
135  int
136  (*traits)(void *cls,
137  const void **ret,
138  const char *trait,
139  unsigned int index);
140 
145 
150 
161 
167  unsigned int num_tries;
168 
176 
184 
185 };
186 
187 
192 struct SyncState
193 {
197  void *cls;
198 
203 
208 
212  struct GNUNET_TIME_Absolute start_finish_time;
213 };
214 
221 const struct GNUNET_TESTING_Command *
223  const char *label);
224 
225 
232 const char *
235 
236 
242 void
244 
245 
253 
254 
261 const struct GNUNET_TESTING_Command
263 
264 
276 const struct GNUNET_TESTING_Command
277 GNUNET_TESTING_cmd_finish (const char *finish_label,
278  const char *cmd_ref,
280 
281 
293  const char *target_label,
294  unsigned int counter);
295 
296 
303 // void
304 // GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is);
305 // => replace with child_management.c
306 
307 
319 int
320 GNUNET_TESTING_run (const char *cfg_filename,
323 
324 
331 int
332 GNUNET_TESTING_has_in_name (const char *prog,
333  const char *marker);
334 
335 
336 /* ************** Specific interpreter commands ************ */
337 
348 GNUNET_TESTING_cmd_signal (const char *label,
349  const char *process_label,
350  unsigned int process_index,
351  int signal);
352 
353 
362 GNUNET_TESTING_cmd_sleep (const char *label,
364 
365 
377 GNUNET_TESTING_cmd_batch (const char *label,
378  struct GNUNET_TESTING_Command *batch);
379 
380 
386 // TODO: figure out if this needs to be exposed in the public API.
387 int
389 
390 
396 // TODO: figure out if this needs to be exposed in the public API.
397 void
399 
400 
406 // TODO: figure out if this needs to be exposed in the public API.
407 struct GNUNET_TESTING_Command *
409 
410 
417 // TODO: figure out if this needs to be exposed in the public API.
418 void
420  unsigned int new_ip);
421 
422 
427 {
431  const char *prefix;
432 
436  struct GNUNET_TIME_Relative total_duration;
437 
442  struct GNUNET_TIME_Relative success_latency;
443 
447  unsigned int num_commands;
448 
452  unsigned int num_retries;
453 };
454 
455 
464 
465 
466 /* *** Generic trait logic for implementing traits ********* */
467 
472 {
478  unsigned int index;
479 
483  const char *trait_name;
484 
488  const void *ptr;
489 };
490 
491 
499 
500 
510 int
512  const void **ret,
513  const char *trait,
514  unsigned int index);
515 
516 
517 /* ****** Specific traits supported by this component ******* */
518 
529 int
531  unsigned int index,
532  struct GNUNET_OS_Process ***processp);
533 
534 
545  struct GNUNET_OS_Process **processp);
546 
547 
556  const uint32_t *n);
557 
558 
567 int
569  unsigned int index,
570  const uint32_t **n);
571 
572 
581  const uint64_t *n);
582 
583 
592 int
594  unsigned int index,
595  const uint64_t **n);
596 
597 
606  const int64_t *n);
607 
608 
617 int
619  unsigned int index,
620  const int64_t **n);
621 
622 
632  const unsigned int *i);
633 
634 
643 int
645  unsigned int index,
646  const unsigned int **n);
647 
658 int
660  const struct GNUNET_TESTING_Command *cmd,
661  unsigned int index,
662  const char **s);
663 
664 
675  const char *s);
676 
690  const struct GNUNET_TESTING_Command *cmd);
691 
692 
704 int
706  unsigned int index,
707  struct GNUNET_TESTING_Command **_cmd);
708 
709 
719 int
721  unsigned int index,
722  struct GNUNET_Uuid **uuid);
723 
724 
736  const struct GNUNET_Uuid *uuid);
737 
738 
748 int
750  const struct GNUNET_TESTING_Command *cmd,
751  unsigned int index,
752  const struct GNUNET_TIME_Absolute **time);
753 
754 
764  unsigned int index,
765  const struct GNUNET_TIME_Absolute *time);
766 
767 
777 int
779  const struct GNUNET_TESTING_Command *cmd,
780  unsigned int index,
781  const struct GNUNET_TIME_Relative **time);
782 
783 
793  unsigned int index,
794  const struct GNUNET_TIME_Relative *time);
795 
796 
806  struct GNUNET_TIME_Absolute *now);
807 
817  const char *birthLabel,
818  char *message);
819 
829 int
831  char **what_am_i);
832 
833 #endif
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
void(* cleanup)(void *cls, const struct GNUNET_TESTING_Command *cmd)
Clean up after the command.
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".
unsigned int num_retries
Number of retries summed up.
void GNUNET_TESTING_cmd_batch_next(struct GNUNET_TESTING_Interpreter *is)
Advance internal pointer to next command.
static char * cfg_filename
Name of the configuration file.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_int64(unsigned int index, const int64_t *n)
Offer number trait, 64-bit signed version.
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish method of the asynchronous task the command is waiting for...
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd(unsigned int index, const struct GNUNET_TESTING_Command *cmd)
Offer a command in a trait.
int GNUNET_TESTING_get_trait_uint(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const unsigned int **n)
Obtain a number from cmd.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process(unsigned int index, struct GNUNET_OS_Process **processp)
Offer location where a command stores a pointer to a process.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch(const char *label, struct GNUNET_TESTING_Command *batch)
Create a "batch" command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uuid(unsigned int index, const struct GNUNET_Uuid *uuid)
Offer a uuid in a trait.
const char * label
Label for the command.
A command to be run by the interpreter.
int GNUNET_TESTING_get_trait_string(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const char **s)
Obtain a string from cmd.
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 int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_TESTING_has_in_name(const char *prog, const char *marker)
Look for substring in a programs&#39; name.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint64(unsigned int index, const uint64_t *n)
Offer number trait, 64-bit version.
unsigned int num_commands
Number of commands summed up.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_signal(const char *label, const char *process_label, unsigned int process_index, int signal)
Create a "signal" CMD.
Struct to use for command-specific context information closure of a command waiting for another comma...
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat(struct GNUNET_TESTING_Timer *timers)
Obtain performance data from the interpreter.
const void * ptr
Pointer to the piece of data to offer.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world(const char *label, const char *birthLabel, char *message)
Create command.
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.
int GNUNET_TESTING_get_trait_uint64(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint64_t **n)
Obtain a "number" value from cmd, 64-bit version.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
int GNUNET_TESTING_get_trait_absolute_time(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const struct GNUNET_TIME_Absolute **time)
Obtain a absolute time from cmd.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world_birth(const char *label, struct GNUNET_TIME_Absolute *now)
Create command.
Global state of the interpreter, used by a command to access information about other commands...
Definition: testing.h:34
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
unsigned int index
Index number associated with the trait.
static struct VoipCommand commands[]
List of supported commands.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
Performance counter.
A UUID, a 128 bit "random" value.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint32(unsigned int index, const uint32_t *n)
Offer number trait, 32-bit version.
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 GNUNET_TESTING_cmd_batch_set_current(const struct GNUNET_TESTING_Command *cmd, unsigned int new_ip)
Set what command the batch should be at.
int GNUNET_TESTING_get_trait_int64(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const int64_t **n)
Obtain a "number" value from cmd, 64-bit signed version.
const struct GNUNET_TESTING_Command * async_cmd
The asynchronous command the synchronous command of this closure waits for.
int GNUNET_TESTING_get_trait_relative_time(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const struct GNUNET_TIME_Relative **time)
Obtain a relative time from cmd.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep(const char *label, struct GNUNET_TIME_Relative duration)
Sleep for duration.
const char * prefix
For which type of commands.
int GNUNET_TESTING_cmd_is_batch(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
int GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
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...
int GNUNET_TESTING_get_trait_what_am_i(const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
Offer data from trait.
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.
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...
int GNUNET_TESTING_run(const char *cfg_filename, struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Wait until we receive SIGCHLD signal.
struct GNUNET_TESTING_Command * GNUNET_TESTING_cmd_batch_get_current(const struct GNUNET_TESTING_Command *cmd)
Obtain what command the batch is at.
void * cls
Closure for all commands with command-specific context information.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_absolute_time(unsigned int index, const struct GNUNET_TIME_Absolute *time)
Offer a absolute time.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_rewind_ip(const char *label, const char *target_label, unsigned int counter)
Make the instruction pointer point to target_label only if counter is greater than zero...
Entry in list of pending tasks.
Definition: scheduler.c:134
void * cls
Closure for all commands with command-specific context information.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
int GNUNET_TESTING_get_trait_uint32(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const uint32_t **n)
Obtain a "number" value from cmd, 32-bit version.
Time for absolute times used by GNUnet, in microseconds.
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_TESTING_Trait GNUNET_TESTING_make_trait_relative_time(unsigned int index, const struct GNUNET_TIME_Relative *time)
Offer a relative time.
struct GNUNET_SCHEDULER_Task * finish_task
Task for running the finish function.
const char * GNUNET_TESTING_interpreter_get_current_label(struct GNUNET_TESTING_Interpreter *is)
Obtain label of the command being now run.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint(unsigned int index, const unsigned int *i)
Offer a number.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_string(unsigned int index, const char *s)
Offer string subject.
int GNUNET_TESTING_get_trait_uuid(const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_Uuid **uuid)
Obtain a uuid from cmd.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
Time for relative time used by GNUnet, in microseconds.
int GNUNET_TESTING_get_trait_process(const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_OS_Process ***processp)
Obtain location where a command stores a pointer to a process.