GNUnet  0.19.4
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 
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib.h"
33 
40 #define GNUNET_S(a) #a
41 
45 #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
46 
47 /* ********************* Helper functions ********************* */
48 
53 #define GNUNET_TESTING_FAIL(is) \
54  do \
55  { \
56  GNUNET_break (0); \
57  GNUNET_TESTING_interpreter_fail (is); \
58  return; \
59  } while (0)
60 
61 
62 /* ******************* Generic interpreter logic ************ */
63 
69 
74 {
75 
80 
85 
89  void *cont_cls;
90 
97 };
98 
99 typedef void
102 
103 typedef void
105 
106 typedef enum GNUNET_GenericReturnValue
107 (*GNUNET_TESTING_CommandGetTraits) (void *cls,
108  const void **ret,
109  const char *trait,
110  unsigned int index);
111 
125  const char *label,
130 
135 {
139  void *cls;
140 
145 
162 
172 
180 
193 
198 
203 
214 
222 
228  unsigned int num_tries;
229 
237 
238 };
239 
240 
249 const struct GNUNET_TESTING_Command *
252  const char *label);
253 
254 
262 const struct GNUNET_TESTING_Command *
265  const char *label);
266 
267 
276 const struct GNUNET_TESTING_Command *
279  const char *label);
280 
281 
288 const char *
291 
292 
298 void
300 
301 
307 void
309 
310 
316 void
318 
319 
327 
328 
340 
341 
353 const struct GNUNET_TESTING_Command
354 GNUNET_TESTING_cmd_finish (const char *finish_label,
355  const char *cmd_ref,
357 
358 
370  const char *target_label,
371  unsigned int counter);
372 
373 
382 typedef void
384  enum GNUNET_GenericReturnValue rv);
385 
386 
403  void *rc_cls);
404 
405 
416 int
419 
420 
421 /* ************** Specific interpreter commands ************ */
422 
423 
432 GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
433 
434 
443 GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command);
444 
445 
456 GNUNET_TESTING_cmd_signal (const char *label,
457  const char *process_label,
458  unsigned int process_index,
459  int signal);
460 
461 
470 GNUNET_TESTING_cmd_sleep (const char *label,
472 
473 
485 GNUNET_TESTING_cmd_batch (const char *label,
486  struct GNUNET_TESTING_Command *batch);
487 
488 
494 {
498  const char *prefix;
499 
504 
510 
514  unsigned int num_commands;
515 
519  unsigned int num_retries;
520 };
521 
522 
530 struct GNUNET_PeerIdentity *
531 GNUNET_TESTING_get_peer (unsigned int num,
532  const struct GNUNET_TESTING_System *tl_system);
533 
534 
543 
544 
545 /* *** Generic trait logic for implementing traits ********* */
546 
557 {
563  unsigned int index;
564 
568  const char *trait_name;
569 
573  const void *ptr;
574 };
575 
576 
584 
585 
597 GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
598  const void **ret,
599  const char *trait,
600  unsigned int index);
601 
602 
603 /* ****** Specific traits supported by this component ******* */
604 
605 
610 #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
611  enum GNUNET_GenericReturnValue \
612  GNUNET_TESTING_get_trait_ ## name ( \
613  const struct GNUNET_TESTING_Command *cmd, \
614  type **ret); \
615  struct GNUNET_TESTING_Trait \
616  GNUNET_TESTING_make_trait_ ## name ( \
617  type * value);
618 
619 
624 #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
625  enum GNUNET_GenericReturnValue \
626  GNUNET_TESTING_get_trait_ ## name ( \
627  const struct GNUNET_TESTING_Command *cmd, \
628  type * *ret) \
629  { \
630  if (NULL == cmd->traits) return GNUNET_SYSERR; \
631  return cmd->traits (cmd->cls, \
632  (const void **) ret, \
633  GNUNET_S (name), \
634  0); \
635  } \
636  struct GNUNET_TESTING_Trait \
637  GNUNET_TESTING_make_trait_ ## name ( \
638  type * value) \
639  { \
640  struct GNUNET_TESTING_Trait ret = { \
641  .trait_name = GNUNET_S (name), \
642  .ptr = (const void *) value \
643  }; \
644  return ret; \
645  }
646 
647 
652 #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
653  enum GNUNET_GenericReturnValue \
654  GNUNET_TESTING_get_trait_ ## name ( \
655  const struct GNUNET_TESTING_Command *cmd, \
656  unsigned int index, \
657  type **ret); \
658  struct GNUNET_TESTING_Trait \
659  GNUNET_TESTING_make_trait_ ## name ( \
660  unsigned int index, \
661  type *value);
662 
663 
668 #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
669  enum GNUNET_GenericReturnValue \
670  GNUNET_TESTING_get_trait_ ## name ( \
671  const struct GNUNET_TESTING_Command *cmd, \
672  unsigned int index, \
673  type * *ret) \
674  { \
675  if (NULL == cmd->traits) return GNUNET_SYSERR; \
676  return cmd->traits (cmd->cls, \
677  (const void **) ret, \
678  GNUNET_S (name), \
679  index); \
680  } \
681  struct GNUNET_TESTING_Trait \
682  GNUNET_TESTING_make_trait_ ## name ( \
683  unsigned int index, \
684  type * value) \
685  { \
686  struct GNUNET_TESTING_Trait ret = { \
687  .index = index, \
688  .trait_name = GNUNET_S (name), \
689  .ptr = (const void *) value \
690  }; \
691  return ret; \
692  }
693 
694 
698 #define GNUNET_TESTING_SIMPLE_TRAITS(op) \
699  op (batch_cmds, struct GNUNET_TESTING_Command *) \
700  op (process, struct GNUNET_OS_Process *)
701 
702 
706 #define GNUNET_TESTING_INDEXED_TRAITS(op) \
707  op (uint32, const uint32_t) \
708  op (uint64, const uint64_t) \
709  op (int64, const int64_t) \
710  op (uint, const unsigned int) \
711  op (string, const char) \
712  op (cmd, const struct GNUNET_TESTING_Command) \
713  op (uuid, const struct GNUNET_Uuid) \
714  op (time, const struct GNUNET_TIME_Absolute) \
715  op (absolute_time, const struct GNUNET_TIME_Absolute) \
716  op (relative_time, const struct GNUNET_TIME_Relative)
717 
719 
721 
722 #endif
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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
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.
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?
Convenience API for writing testcases for GNUnet.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_sleep(const char *label, struct GNUNET_TIME_Relative duration)
Sleep for duration.
void(* GNUNET_TESTING_CommandRunRoutine)(void *cls, struct GNUNET_TESTING_Interpreter *is)
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_peer(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve peer identity from the test system with the unique node id.
Definition: testing.c:2309
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.
#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.
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_CommandCleanupRoutine)(void *cls)
#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_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.
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_CommandGetTraits)(void *cls, const void **ret, const char *trait, unsigned int index)
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.
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.
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_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.
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.
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
Maximum length of label in command.
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.
GNUNET_GenericReturnValue
Named constants for return values.
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.
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_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.
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.
void * rc_cls
Closure for rc.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
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.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
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.