GNUnet 0.21.1
gnunet_testing_loop_lib.h
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021, 2023 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_LOOP_LIB_H
28#define GNUNET_TESTING_LOOP_LIB_H
29
33#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
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 struct GNUNET_TESTING_Interpreter *is; // FIXME: Why needed? When available?
68
73
77 void *cont_cls;
78
85};
86
87
93void
95
96
102void
104
105
113typedef void
116
117
124typedef void
126
127
138typedef enum GNUNET_GenericReturnValue
140 const void **ret,
141 const char *trait,
142 unsigned int index);
143
157 const char *label,
161 struct GNUNET_TESTING_AsyncContext *ac);
162
163
168{
170};
171
172
180void
182 const char *value);
183
184
189{
193 void *cls;
194
199
216
226
234
247
252
257
268
276
282 unsigned int num_tries;
283
291
292};
293
294
304// FIXME: think harder about whether this is actually needed, likely not.
305const struct GNUNET_TESTING_Command *
308 const char *label);
309
310
318const struct GNUNET_TESTING_Command *
321 const char *label);
322
323
333const struct GNUNET_TESTING_Command *
336 const char *label);
337
338
344void
346
347
362
363
375const struct GNUNET_TESTING_Command
376GNUNET_TESTING_cmd_finish (const char *finish_label,
377 const char *cmd_ref,
379
380
392 const char *target_label,
393 unsigned int counter);
394
395
404typedef void
407
408
425 void *rc_cls);
426
427
438int
441
442
443
444/* ************** Fundamental interpreter commands ************ */
445
446
454
455
468 struct GNUNET_TESTING_Command *batch);
469
470
475{
479 const char *prefix;
480
485
491
495 unsigned int num_commands;
496
500 unsigned int num_retries;
501};
502
511
512
513/* *** Generic trait logic for implementing traits ********* */
514
525{
531 unsigned int index;
532
536 const char *trait_name;
537
541 const void *ptr;
542};
543
544
552
553
565 const void **ret,
566 const char *trait,
567 unsigned int index);
568
569
570
579#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \
580 enum GNUNET_GenericReturnValue \
581 prefix ## _get_trait_ ## name ( \
582 const struct GNUNET_TESTING_Command *cmd, \
583 type **ret); \
584 struct GNUNET_TESTING_Trait \
585 prefix ## _make_trait_ ## name ( \
586 type * value);
587
588
597#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \
598 enum GNUNET_GenericReturnValue \
599 prefix ## _get_trait_ ## name ( \
600 const struct GNUNET_TESTING_Command *cmd, \
601 type * *ret) \
602 { \
603 if (NULL == cmd->traits) return GNUNET_SYSERR; \
604 return cmd->traits (cmd->cls, \
605 (const void **) ret, \
606 GNUNET_S (name), \
607 0); \
608 } \
609 struct GNUNET_TESTING_Trait \
610 prefix ## _make_trait_ ## name ( \
611 type * value) \
612 { \
613 struct GNUNET_TESTING_Trait ret = { \
614 .trait_name = GNUNET_S (name), \
615 .ptr = (const void *) value \
616 }; \
617 return ret; \
618 }
619
620
629#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \
630 enum GNUNET_GenericReturnValue \
631 prefix ## _get_trait_ ## name ( \
632 const struct GNUNET_TESTING_Command *cmd, \
633 unsigned int index, \
634 type **ret); \
635 struct GNUNET_TESTING_Trait \
636 prefix ## _make_trait_ ## name ( \
637 unsigned int index, \
638 type *value);
639
640
645#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \
646 enum GNUNET_GenericReturnValue \
647 prefix ## _get_trait_ ## name ( \
648 const struct GNUNET_TESTING_Command *cmd, \
649 unsigned int index, \
650 type * *ret) \
651 { \
652 if (NULL == cmd->traits) return GNUNET_SYSERR; \
653 return cmd->traits (cmd->cls, \
654 (const void **) ret, \
655 GNUNET_S (name), \
656 index); \
657 } \
658 struct GNUNET_TESTING_Trait \
659 prefix ## _make_trait_ ## name ( \
660 unsigned int index, \
661 type * value) \
662 { \
663 struct GNUNET_TESTING_Trait ret = { \
664 .index = index, \
665 .trait_name = GNUNET_S (name), \
666 .ptr = (const void *) value \
667 }; \
668 return ret; \
669 }
670
671
678#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op,prefix) \
679 op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
680
681
683
684
685
691#define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op,prefix) \
692 op (prefix, cmd, const struct GNUNET_TESTING_Command)
693
695
696
697#endif
static int ret
Final status code.
Definition: gnunet-arm.c:94
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
Definition: gnunet-arm.c:917
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
struct GNUNET_TESTING_Interpreter * is
static struct VoipCommand commands[]
List of supported commands.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
static char * value
Value of the record to add/remove.
#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix, name, type)
Create headers for a trait with name name for statically allocated data of type type.
void(* GNUNET_TESTING_CommandRunRoutine)(void *cls, struct GNUNET_TESTING_Interpreter *is)
Signature of a function used to start executing a command of a test.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op, prefix)
Call op on all indexed traits needed by loop logic.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_batch(const char *label, struct GNUNET_TESTING_Command *batch)
Create a "batch" command.
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)
Signature of a function used to clean up resources allocated by a command.
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.
void(* GNUNET_TESTING_ResultCallback)(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op, prefix)
Call op on all simple traits needed by loop logic.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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)
Signature of a function used to extract traits exposed by a command.
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_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command_all(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.
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
Central interpreter and command loop for writing an interpreter to test asynchronous systems.
#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix, name, type)
Create headers for a trait with name name for statically allocated data of type type.
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.
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).
Structure with storage space for a label.
A command to be run by the interpreter.
GNUNET_TESTING_CommandCleanupRoutine cleanup
Clean up after the command.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
struct GNUNET_TESTING_CommandLabel label
Label for 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.
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.
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.