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 
34 
35 /* ********************* Helper functions ********************* */
36 
41 #define GNUNET_TESTING_FAIL(is) \
42  do \
43  { \
44  GNUNET_break (0); \
45  GNUNET_TESTING_interpreter_fail (is); \
46  return; \
47  } while (0)
48 
49 
50 /* ******************* Generic interpreter logic ************ */
51 
57 
62 {
63 
67  void *cls;
68 
72  const char *label;
73 
90  void
91  (*run)(void *cls,
92  const struct GNUNET_TESTING_Command *cmd,
93  struct GNUNET_TESTING_Interpreter *i);
94 
106  int
107  (*finish)(void *cls,
109  void *cont_cls);
110 
115 
123  void
124  (*cleanup)(void *cls,
125  const struct GNUNET_TESTING_Command *cmd);
126 
137  int
138  (*traits)(void *cls,
139  const void **ret,
140  const char *trait,
141  unsigned int index);
142 
147 
152 
163 
169  unsigned int num_tries;
170 
178 
186 
187 };
188 
189 
194 struct SyncState
195 {
199  void *cls;
200 
205 
210 
214  struct GNUNET_TIME_Absolute start_finish_time;
215 };
216 
223 const struct GNUNET_TESTING_Command *
225  const char *label);
226 
227 
234 const char *
237 
238 
244 void
246 
247 
255 
256 
263 const struct GNUNET_TESTING_Command
265 
266 
278 const struct GNUNET_TESTING_Command
279 GNUNET_TESTING_cmd_finish (const char *finish_label,
280  const char *cmd_ref,
282 
283 
295  const char *target_label,
296  unsigned int counter);
297 
298 
305 // void
306 // GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is);
307 // => replace with child_management.c
308 
309 
321 int
322 GNUNET_TESTING_run (const char *cfg_filename,
325 
326 
333 int
334 GNUNET_TESTING_has_in_name (const char *prog,
335  const char *marker);
336 
337 
338 /* ************** Specific interpreter commands ************ */
339 
350 GNUNET_TESTING_cmd_signal (const char *label,
351  const char *process_label,
352  unsigned int process_index,
353  int signal);
354 
355 
364 GNUNET_TESTING_cmd_sleep (const char *label,
366 
367 
379 GNUNET_TESTING_cmd_batch (const char *label,
380  struct GNUNET_TESTING_Command *batch);
381 
382 
388 // TODO: figure out if this needs to be exposed in the public API.
389 int
391 
392 
398 // TODO: figure out if this needs to be exposed in the public API.
399 void
401 
402 
408 // TODO: figure out if this needs to be exposed in the public API.
409 struct GNUNET_TESTING_Command *
411 
412 
419 // TODO: figure out if this needs to be exposed in the public API.
420 void
422  unsigned int new_ip);
423 
424 
429 {
433  const char *prefix;
434 
438  struct GNUNET_TIME_Relative total_duration;
439 
444  struct GNUNET_TIME_Relative success_latency;
445 
449  unsigned int num_commands;
450 
454  unsigned int num_retries;
455 };
456 
457 
466 
467 
468 /* *** Generic trait logic for implementing traits ********* */
469 
474 {
480  unsigned int index;
481 
485  const char *trait_name;
486 
490  const void *ptr;
491 };
492 
493 
501 
502 
512 int
514  const void **ret,
515  const char *trait,
516  unsigned int index);
517 
518 
519 /* ****** Specific traits supported by this component ******* */
520 
531 int
533  unsigned int index,
534  struct GNUNET_OS_Process ***processp);
535 
536 
547  struct GNUNET_OS_Process **processp);
548 
549 
558  const uint32_t *n);
559 
560 
569 int
571  unsigned int index,
572  const uint32_t **n);
573 
574 
583  const uint64_t *n);
584 
585 
594 int
596  unsigned int index,
597  const uint64_t **n);
598 
599 
608  const int64_t *n);
609 
610 
619 int
621  unsigned int index,
622  const int64_t **n);
623 
624 
634  const unsigned int *i);
635 
636 
645 int
647  unsigned int index,
648  const unsigned int **n);
649 
660 int
662  const struct GNUNET_TESTING_Command *cmd,
663  unsigned int index,
664  const char **s);
665 
666 
677  const char *s);
678 
692  const struct GNUNET_TESTING_Command *cmd);
693 
694 
706 int
708  unsigned int index,
709  struct GNUNET_TESTING_Command **_cmd);
710 
711 
721 int
723  unsigned int index,
724  struct GNUNET_Uuid **uuid);
725 
726 
738  const struct GNUNET_Uuid *uuid);
739 
740 
750 int
752  const struct GNUNET_TESTING_Command *cmd,
753  unsigned int index,
754  const struct GNUNET_TIME_Absolute **time);
755 
756 
766  unsigned int index,
767  const struct GNUNET_TIME_Absolute *time);
768 
769 
779 int
781  const struct GNUNET_TESTING_Command *cmd,
782  unsigned int index,
783  const struct GNUNET_TIME_Relative **time);
784 
785 
795  unsigned int index,
796  const struct GNUNET_TIME_Relative *time);
797 
798 
808  struct GNUNET_TIME_Absolute *now);
809 
819  const char *birthLabel,
820  char *message);
821 
831 int
833  char **what_am_i);
834 
835 
836 int
840 
843  const char *testdir);
844 
845 #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.
void GNUNET_TESTING_interpreter_fail()
Current command failed, clean up and fail the test case.
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.
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.
static struct GNUNET_TESTING_System * test_system
The process handle to the testbed service.
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.
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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_system_create(const char *label, const char *testdir)
Create command.
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.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:91
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.
int GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_System **test_system)
int(* 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_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.