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 #include "gnunet_testing_plugin.h"
32 #include "gnunet_testing_lib.h"
33 
40 #define GNUNET_S(a) #a
41 
42 
43 /* ********************* Helper functions ********************* */
44 
49 #define GNUNET_TESTING_FAIL(is) \
50  do \
51  { \
52  GNUNET_break (0); \
53  GNUNET_TESTING_interpreter_fail (is); \
54  return; \
55  } while (0)
56 
57 
58 /* ******************* Generic interpreter logic ************ */
59 
65 
70 {
71 
76 
81 
85  void *cont_cls;
86 
93 };
94 
95 
100 {
101 
105  void *cls;
106 
110  const char *label;
111 
127  void
128  (*run)(void *cls,
130 
140 
147  void
148  (*cleanup)(void *cls);
149 
162  (*traits)(void *cls,
163  const void **ret,
164  const char *trait,
165  unsigned int index);
166 
171 
176 
187 
195 
201  unsigned int num_tries;
202 
210 
211 };
212 
213 
222 const struct GNUNET_TESTING_Command *
225  const char *label);
226 
227 
235 const struct GNUNET_TESTING_Command *
238  const char *label);
239 
240 
249 const struct GNUNET_TESTING_Command *
252  const char *label);
253 
254 
261 const char *
264 
265 
271 void
273 
274 
280 void
282 
283 
289 void
291 
292 
300 
301 
310 
311 
323 const struct GNUNET_TESTING_Command
324 GNUNET_TESTING_cmd_finish (const char *finish_label,
325  const char *cmd_ref,
327 
328 
340  const char *target_label,
341  unsigned int counter);
342 
343 
350 typedef void
352  enum GNUNET_GenericReturnValue rv);
353 
354 
366 void
370  void *rc_cls);
371 
372 
382 int
385 
386 
395 int
396 GNUNET_TESTING_has_in_name (const char *prog,
397  const char *marker);
398 
399 
400 /* ************** Specific interpreter commands ************ */
401 
402 
410 struct GNUNET_TESTING_Command *
413 
414 
422 GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
423 
424 
433 
434 
445 GNUNET_TESTING_cmd_signal (const char *label,
446  const char *process_label,
447  unsigned int process_index,
448  int signal);
449 
450 
459 GNUNET_TESTING_cmd_sleep (const char *label,
461 
462 
474 GNUNET_TESTING_cmd_batch (const char *label,
475  struct GNUNET_TESTING_Command *batch);
476 
477 
483 {
487  const char *prefix;
488 
493 
499 
503  unsigned int num_commands;
504 
508  unsigned int num_retries;
509 };
510 
511 
519 struct GNUNET_PeerIdentity *
520 GNUNET_TESTING_get_pub_key (unsigned int num,
521  const struct GNUNET_TESTING_System *tl_system);
522 
523 
532 
533 
534 /* *** Generic trait logic for implementing traits ********* */
535 
540 {
546  unsigned int index;
547 
551  const char *trait_name;
552 
556  const void *ptr;
557 };
558 
559 
567 
568 
579 GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
580  const void **ret,
581  const char *trait,
582  unsigned int index);
583 
584 
585 /* ****** Specific traits supported by this component ******* */
586 
587 
592 #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
593  enum GNUNET_GenericReturnValue \
594  GNUNET_TESTING_get_trait_ ## name ( \
595  const struct GNUNET_TESTING_Command *cmd, \
596  type **ret); \
597  struct GNUNET_TESTING_Trait \
598  GNUNET_TESTING_make_trait_ ## name ( \
599  type * value);
600 
601 
606 #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
607  enum GNUNET_GenericReturnValue \
608  GNUNET_TESTING_get_trait_ ## name ( \
609  const struct GNUNET_TESTING_Command *cmd, \
610  type **ret) \
611  { \
612  if (NULL == cmd->traits) return GNUNET_SYSERR; \
613  return cmd->traits (cmd->cls, \
614  (const void **) ret, \
615  GNUNET_S (name), \
616  0); \
617  } \
618  struct GNUNET_TESTING_Trait \
619  GNUNET_TESTING_make_trait_ ## name ( \
620  type * value) \
621  { \
622  struct GNUNET_TESTING_Trait ret = { \
623  .trait_name = GNUNET_S (name), \
624  .ptr = (const void *) value \
625  }; \
626  return ret; \
627  }
628 
629 
634 #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
635  enum GNUNET_GenericReturnValue \
636  GNUNET_TESTING_get_trait_ ## name ( \
637  const struct GNUNET_TESTING_Command *cmd, \
638  unsigned int index, \
639  type **ret); \
640  struct GNUNET_TESTING_Trait \
641  GNUNET_TESTING_make_trait_ ## name ( \
642  unsigned int index, \
643  type * value);
644 
645 
650 #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
651  enum GNUNET_GenericReturnValue \
652  GNUNET_TESTING_get_trait_ ## name ( \
653  const struct GNUNET_TESTING_Command *cmd, \
654  unsigned int index, \
655  type **ret) \
656  { \
657  if (NULL == cmd->traits) return GNUNET_SYSERR; \
658  return cmd->traits (cmd->cls, \
659  (const void **) ret, \
660  GNUNET_S (name), \
661  index); \
662  } \
663  struct GNUNET_TESTING_Trait \
664  GNUNET_TESTING_make_trait_ ## name ( \
665  unsigned int index, \
666  type * value) \
667  { \
668  struct GNUNET_TESTING_Trait ret = { \
669  .index = index, \
670  .trait_name = GNUNET_S (name), \
671  .ptr = (const void *) value \
672  }; \
673  return ret; \
674  }
675 
676 
680 #define GNUNET_TESTING_SIMPLE_TRAITS(op) \
681  op (batch_cmds, struct GNUNET_TESTING_Command *) \
682  op (process, struct GNUNET_OS_Process *)
683 
684 
688 #define GNUNET_TESTING_INDEXED_TRAITS(op) \
689  op (uint32, const uint32_t) \
690  op (uint64, const uint64_t) \
691  op (int64, const int64_t) \
692  op (uint, const unsigned int) \
693  op (string, const char) \
694  op (cmd, const struct GNUNET_TESTING_Command) \
695  op (uuid, const struct GNUNET_Uuid) \
696  op (time, const struct GNUNET_TIME_Absolute) \
697  op (absolute_time, const struct GNUNET_TIME_Absolute) \
698  op (relative_time, const struct GNUNET_TIME_Relative)
699 
701 
703 
704 #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 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
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep(const char *label, struct GNUNET_TIME_Relative duration)
Sleep for duration.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name, type)
Create headers for a trait with name name for statically allocated data of type type.
#define GNUNET_TESTING_INDEXED_TRAITS(op)
Call op on all indexed traits.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch(const char *label, struct GNUNET_TESTING_Command *batch)
Create a "batch" command.
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.
#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name, type)
Create headers for a trait with name name for statically allocated data of type type.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
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.
void GNUNET_TESTING_run(struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
enum GNUNET_GenericReturnValue GNUNET_TESTING_finished(struct GNUNET_TESTING_Command *command)
Check if a command is finished.
#define GNUNET_TESTING_SIMPLE_TRAITS(op)
Call op on all simple traits.
void(* GNUNET_TESTING_ResultCallback)(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_pub_key(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve the public key from the test system with the unique node id.
Definition: testing.c:2172
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.
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.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command_all(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
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_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
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.
enum GNUNET_GenericReturnValue GNUNET_TESTING_running(const struct GNUNET_TESTING_Command *command)
Check if the command is running.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
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.
int GNUNET_TESTING_main(struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Start a GNUnet scheduler event loop and run the testsuite.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat(struct GNUNET_TESTING_Timer *timers)
Obtain performance data from the interpreter.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
The identity of the host (wraps the signing key of the peer).
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.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:103
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.