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  */
26 #ifndef GNUNET_TESTING_NG_LIB_H
27 #define GNUNET_TESTING_NG_LIB_H
28 
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testing_plugin.h"
31 #include "gnunet_testing_lib.h"
32 
33 
34 /* ********************* Helper functions ********************* */
35 
40 #define GNUNET_TESTING_FAIL(is) \
41  do \
42  { \
43  GNUNET_break (0); \
44  GNUNET_TESTING_interpreter_fail (is); \
45  return; \
46  } while (0)
47 
48 
54 {
58  unsigned int tcp_port;
59 
63  unsigned int udp_port;
64 };
65 
66 
72 {
77 
82 };
83 
84 
85 // FIXME: this does not belong here!
87 {
92 
97 
102 };
103 
104 
105 // FIXME: this does not belong here!
107 
113 {
118 
123 
128  unsigned int namespace_n;
129 
133  unsigned int node_n;
134 
139 
144 
149 
154 };
155 
161 {
165  char *plugin;
166 
170  unsigned int is_global;
171 
175  unsigned int namespace_n;
176 
180  unsigned int node_n;
181 
186 
191 };
192 
193 
199 {
203  unsigned int namespace_n;
204 
209 
214 };
215 
221 {
222 
226  char *plugin;
227 
231  unsigned int namespaces_n;
232 
236  unsigned int nodes_m;
237 
241  unsigned int nodes_x;
242 
247 
252 };
253 
254 
255 /* ******************* Generic interpreter logic ************ */
256 
262 
267 {
268 
273 
278 
282  void *cont_cls;
283 
290 };
291 
292 
297 {
298 
302  void *cls;
303 
307  const char *label;
308 
324  void
325  (*run)(void *cls,
327 
337 
344  void
345  (*cleanup)(void *cls);
346 
359  (*traits)(void *cls,
360  const void **ret,
361  const char *trait,
362  unsigned int index);
363 
368 
373 
384 
392 
398  unsigned int num_tries;
399 
407 
408 };
409 
410 
418 const struct GNUNET_TESTING_Command *
421  const char *label);
422 
423 
430 const char *
433 
434 
440 void
442 
443 
449 void
451 
452 
458 void
460 
461 
469 
470 
479 
480 
492 const struct GNUNET_TESTING_Command
493 GNUNET_TESTING_cmd_finish (const char *finish_label,
494  const char *cmd_ref,
496 
497 
509  const char *target_label,
510  unsigned int counter);
511 
512 
519 typedef void
521  enum GNUNET_GenericReturnValue rv);
522 
523 
535 void
539  void *rc_cls);
540 
541 
551 int
554 
555 
564 int
565 GNUNET_TESTING_has_in_name (const char *prog,
566  const char *marker);
567 
568 
569 /* ************** Specific interpreter commands ************ */
570 
581 GNUNET_TESTING_cmd_signal (const char *label,
582  const char *process_label,
583  unsigned int process_index,
584  int signal);
585 
586 
595 GNUNET_TESTING_cmd_sleep (const char *label,
597 
598 
610 GNUNET_TESTING_cmd_batch (const char *label,
611  struct GNUNET_TESTING_Command *batch);
612 
613 
619 {
623  const char *prefix;
624 
629 
635 
639  unsigned int num_commands;
640 
644  unsigned int num_retries;
645 };
646 
647 
656 
657 
666 
667 
668 /* *** Generic trait logic for implementing traits ********* */
669 
674 {
680  unsigned int index;
681 
685  const char *trait_name;
686 
690  const void *ptr;
691 };
692 
693 
701 
702 
713 GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
714  const void **ret,
715  const char *trait,
716  unsigned int index);
717 
718 
719 /* ****** Specific traits supported by this component ******* */
720 
733  unsigned int index,
734  struct GNUNET_OS_Process ***processp);
735 
736 
747  struct GNUNET_OS_Process **processp);
748 
749 
758  const uint32_t *n);
759 
760 
771  unsigned int index,
772  const uint32_t **n);
773 
774 
783  const uint64_t *n);
784 
785 
796  unsigned int index,
797  const uint64_t **n);
798 
799 
808  const int64_t *n);
809 
810 
821  unsigned int index,
822  const int64_t **n);
823 
824 
834  const unsigned int *i);
835 
836 
847  unsigned int index,
848  const unsigned int **n);
849 
862  const struct GNUNET_TESTING_Command *cmd,
863  unsigned int index,
864  const char **s);
865 
866 
877  const char *s);
878 
891  const struct GNUNET_TESTING_Command *cmd);
892 
893 
907  unsigned int index,
908  struct GNUNET_TESTING_Command **_cmd);
909 
910 
922  unsigned int index,
923  struct GNUNET_Uuid **uuid);
924 
925 
936  const struct GNUNET_Uuid *uuid);
937 
938 
950  const struct GNUNET_TESTING_Command *cmd,
951  unsigned int index,
952  const struct GNUNET_TIME_Absolute **time);
953 
954 
964  unsigned int index,
965  const struct GNUNET_TIME_Absolute *time);
966 
967 
977 int
979  const struct GNUNET_TESTING_Command *cmd,
980  unsigned int index,
981  const struct GNUNET_TIME_Relative **time);
982 
983 
993  unsigned int index,
994  const struct GNUNET_TIME_Relative *time);
995 
996 
997 // FIXME: move these commands into a separate libgnunetestingnetjail lib or so!
998 
999 
1009  struct GNUNET_TIME_Absolute *now);
1010 
1020  const char *birthLabel,
1021  char *message);
1022 
1032 int
1034  char **what_am_i);
1035 
1036 
1037 int
1041 
1042 
1045  const char *testdir);
1046 
1047 
1050  const char *create_label);
1051 
1052 
1062  char *topology_config);
1063 
1064 
1075  const char *topology_config);
1076 
1077 
1087  char *topology_config);
1088 
1089 
1099  const char *helper_start_label,
1100  const char *topology_config);
1101 
1102 
1109 struct GNUNET_MessageHeader *
1111 
1112 
1119 int
1121  const struct GNUNET_TESTING_Command *cmd,
1122  struct GNUNET_TESTING_AsyncContext **ac);
1123 
1124 
1134  const struct GNUNET_TESTING_Command *cmd,
1135  struct GNUNET_HELPER_Handle ***helper);
1136 
1137 
1140  const char *label,
1141  unsigned int *all_peers_started);
1142 
1143 
1146  const char *label);
1147 
1151 
1154  const char *label,
1156 
1157 #endif
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static struct VoipCommand commands[]
List of supported commands.
static char * filename
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
static struct GNUNET_TESTING_System * test_system
Handle to the testing system.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
enum GNUNET_GenericReturnValue 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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep(const char *label, struct GNUNET_TIME_Relative duration)
Sleep for duration.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_string(unsigned int index, const char *s)
Offer string subject.
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.
int GNUNET_TESTING_get_trait_async_context(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_AsyncContext **ac)
Function to get the trait with the async context.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_local_test_finished(const char *label, TESTING_CMD_HELPER_write_cb write_message)
Create command.
struct GNUNET_MessageHeader * GNUNET_TESTING_send_local_test_finished_msg(enum GNUNET_GenericReturnValue rv)
Create a GNUNET_CMDS_LOCAL_FINISHED message.
Definition: testing.c:2013
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_helper_handles(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_HELPER_Handle ***helper)
Offer handles to testing cmd helper from trait.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_testing_system(const char *label, const char *topology_config)
Create command.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch(const char *label, struct GNUNET_TESTING_Command *batch)
Create a "batch" command.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uint(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const unsigned int **n)
Obtain a number from cmd.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_uuid(const struct GNUNET_TESTING_Command *cmd, unsigned int index, struct GNUNET_Uuid **uuid)
Obtain a uuid from cmd.
int GNUNET_TESTING_has_in_name(const char *prog, const char *marker)
Look for substring in a programs' name.
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.
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_TESTING_Command GNUNET_TESTING_cmd_netjail_stop(const char *label, char *topology_config)
Create command.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_system_destroy(const char *label, const char *create_label)
Create command.
void GNUNET_TESTING_run(struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
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_uint32(unsigned int index, const uint32_t *n)
Offer number trait, 32-bit version.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_int64(unsigned int index, const int64_t *n)
Offer number trait, 64-bit signed version.
enum GNUNET_GenericReturnValue 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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_block_until_external_trigger(const char *label)
Create command.
enum GNUNET_GenericReturnValue 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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start(const char *label, char *topology_config)
Create command.
void(* GNUNET_TESTING_ResultCallback)(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_cmd(unsigned int index, const struct GNUNET_TESTING_Command *cmd)
Offer a command in a trait.
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.
enum GNUNET_GenericReturnValue 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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_make_unblocking(struct GNUNET_TESTING_Command cmd)
Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_send_peer_ready(const char *label, TESTING_CMD_HELPER_write_cb write_message)
Create command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_block_until_all_peers_started(const char *label, unsigned int *all_peers_started)
Create command.
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_hello_world_birth(const char *label, struct GNUNET_TIME_Absolute *now)
Create command.
int GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_System **test_system)
Function to get the trait with struct GNUNET_TESTING_System.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_string(const struct GNUNET_TESTING_Command *cmd, unsigned int index, const char **s)
Obtain a string from cmd.
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.
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.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
GNUNET_TESTING_NODE_TYPE
Enum for the different types of nodes.
@ GNUNET_TESTING_SUBNET_NODE
Node in a subnet.
@ GNUNET_TESTING_GLOBAL_NODE
Global known node.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world(const char *label, const char *birthLabel, char *message)
Create command.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uint64(unsigned int index, const uint64_t *n)
Offer number trait, 64-bit version.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_testing_system(const char *label, const char *helper_start_label, const char *topology_config)
Create command.
enum GNUNET_GenericReturnValue 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_signal(const char *label, const char *process_label, unsigned int process_index, int signal)
Create a "signal" CMD.
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_file(const char *filename)
Getting the topology from file.
Definition: testing.c:2038
int GNUNET_TESTING_get_trait_what_am_i(const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
Offer data from trait.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_uuid(unsigned int index, const struct GNUNET_Uuid *uuid)
Offer a uuid in a trait.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_system_create(const char *label, const char *testdir)
Create command.
int GNUNET_TESTING_main(struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Start a GNUnet scheduler event loop and run the testsuite.
enum GNUNET_GenericReturnValue 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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat(struct GNUNET_TESTING_Timer *timers)
Obtain performance data from the interpreter.
void(* TESTING_CMD_HELPER_write_cb)(struct GNUNET_MessageHeader *message, size_t msg_length)
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
Internal representation of the hash map.
The handle to a helper process.
Definition: helper.c:79
Header for all communications.
char * address_prefix
The address prefix.
struct GNUNET_TESTING_ADDRESS_PREFIX * prev
Pointer to the previous prefix in the DLL.
struct GNUNET_TESTING_ADDRESS_PREFIX * next
Pointer to the next prefix in the DLL.
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).
A command to be run by the interpreter.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
void(* cleanup)(void *cls)
Clean up after 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...
struct GNUNET_TIME_Relative default_timeout
In case asynchronous_finish is true, how long should we wait for this command to complete?...
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
void(* run)(void *cls, struct GNUNET_TESTING_Interpreter *is)
Runs the command.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
enum GNUNET_GenericReturnValue(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
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?
const char * label
Label for the command.
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.
unsigned int namespace_n
The number of the namespace.
struct GNUNET_CONTAINER_MultiShortmap * nodes
Hash map containing the nodes in this namespace.
struct GNUNET_TESTING_NetjailRouter * router
Router of the namespace.
Node in the netjail topology.
unsigned int namespace_n
The number of the namespace this node is running in.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Head of the DLL with the connections which shall be established to other nodes.
unsigned int is_global
Flag indicating if this node is a global known node.
char * plugin
Plugin for the test case to be run on this node.
unsigned int node_n
The number of this node in the namespace.
struct GNUNET_TESTING_NodeConnection * node_connections_tail
Tail of the DLL with the connections which shall be established to other nodes.
Router of a network namespace.
unsigned int tcp_port
Will tcp be forwarded?
unsigned int udp_port
Will udp be forwarded?
Toplogy of our netjail setup.
struct GNUNET_CONTAINER_MultiShortmap * map_globals
Hash map containing the global known nodes which are not natted.
char * plugin
Default plugin for the test case to be run on nodes.
unsigned int nodes_m
Number of nodes per namespace.
unsigned int nodes_x
Number of global known nodes per namespace.
unsigned int namespaces_n
Number of namespaces.
struct GNUNET_CONTAINER_MultiShortmap * map_namespaces
Hash map containing the namespaces (for natted nodes) of the topology.
Connection to another node.
struct GNUNET_TESTING_NodeConnection * prev
Pointer to the previous connection in the DLL.
enum GNUNET_TESTING_NODE_TYPE node_type
The type of the node this connection points to.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.
struct GNUNET_TESTING_ADDRESS_PREFIX * address_prefixes_head
Head of the DLL with the address prefixes for the protocolls this node is reachable.
struct GNUNET_TESTING_ADDRESS_PREFIX * address_prefixes_tail
Tail of the DLL with the address prefixes for the protocolls this node is reachable.
unsigned int node_n
The number of the node this connection points to.
struct GNUNET_TESTING_NetjailNode * node
The node which establish the connection.
unsigned int namespace_n
The number of the subnet of the node this connection points to.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:94
Performance counter.
unsigned int num_commands
Number of commands summed up.
const char * prefix
For which type of commands.
struct GNUNET_TIME_Relative total_duration
Total time spend in all commands of this type.
unsigned int num_retries
Number of retries summed up.
struct GNUNET_TIME_Relative success_latency
Total time spend waiting for the successful exeuction in all commands of this type.
const void * ptr
Pointer to the piece of data to offer.
unsigned int index
Index number associated with the trait.
const char * trait_name
Trait type, for example "reserve-pub" or "coin-priv".
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
A UUID, a 128 bit "random" value.