GNUnet 0.21.2
testing_api_cmds.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021-2024 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
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h"
31
32
35 void *cls,
36 const char *label,
41{
42 struct GNUNET_TESTING_Command cmd = {
43 .cls = cls,
44 .run = run,
45 .ac = ac,
46 .cleanup = cleanup,
47 .traits = traits
48 };
49
50 GNUNET_assert (NULL != run);
51 if (NULL != label)
53 label);
54 return cmd;
55}
56
57
58void
61 const char *value)
62{
63 size_t len;
64
65 len = strlen (value);
66 GNUNET_assert (len <=
68 memcpy (label->value,
69 value,
70 len + 1);
71}
72
73
76 const char *name,
77 struct GNUNET_TESTING_Command cmd)
78{
79 cmd.name = name;
80 return cmd;
81}
82
83
86{
87 struct GNUNET_TESTING_Command cmd = {
88 .run = NULL
89 };
90
91 return cmd;
92}
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 void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
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_CommandCleanupRoutine)(void *cls)
Signature of a function used to clean up resources allocated by a command.
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.
#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
Central interpreter and command loop for writing an interpreter to test asynchronous systems.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
State each asynchronous command must have in its closure.
Structure with storage space for a label.
A command to be run by the interpreter.
const char * name
Variable name for the command, NULL for none.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
void * cls
Closure for all commands with command-specific context information.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_set_var(const char *name, struct GNUNET_TESTING_Command cmd)
Set variable to command as side-effect of running a command.
void GNUNET_TESTING_set_label(struct GNUNET_TESTING_CommandLabel *label, const char *value)
Set label to value.