GNUnet  0.17.6
testing_api_cmd_block_until_external_trigger.c
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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
30 
34 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35 
36 
41 static void
43 {
44  struct BlockState *bs = cls;
45 
46  GNUNET_free (bs);
47 }
48 
49 static int
51  const void **ret,
52  const char *trait,
53  unsigned int index)
54 {
55  struct BlockState *bs = cls;
56  struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
57  struct GNUNET_TESTING_Trait traits[] = {
59  GNUNET_TESTING_make_trait_block_state ((const void *) bs),
61  };
62 
63  return GNUNET_TESTING_get_trait (traits,
64  ret,
65  trait,
66  index);
67 }
68 
69 
74 static void
77 {
78  struct BlockState *bs = cls;
79  struct GNUNET_TESTING_Command *cmd =
81 
83  "block %s running %u!\n",
84  bs->label,
87  {
89  "block %s running asynchronous!\n",
90  bs->label);
92  }
93 }
94 
95 
106  const char *label)
107 {
108  struct BlockState *bs;
109 
110  bs = GNUNET_new (struct BlockState);
111  bs->label = label;
113  {
114  struct GNUNET_TESTING_Command cmd = {
115  .cls = bs,
116  .label = label,
118  .ac = &bs->ac,
121  };
122 
123  return cmd;
124  }
125 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_async_context(const struct GNUNET_TESTING_AsyncContext *value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_block_state(const struct BlockState *value)
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
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.
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Struct with information for callbacks.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
unsigned int asynchronous_finish
If this command will block.
const char * label
The label of this command.
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
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.
unsigned int index
Index number associated with the trait.
static void block_until_all_peers_started_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static int block_until_external_trigger_traits(void *cls, const void **ret, const char *trait, unsigned int index)
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_block_until_external_trigger(const char *label)
Create command.
#define LOG(kind,...)
Generic logging shortcut.
static void block_until_all_peers_started_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function does nothing but to start the cmd.