GNUnet  0.19.4
testing_api_cmd_netjail_stop_cmds_helper.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_testing_ng_lib.h"
28 #include "gnunet_testing_plugin.h"
29 #include "gnunet_testing_barrier.h"
31 #include "testing_cmds.h"
32 
33 
39 {
40 
45 
46  const char *helper_start_label;
47 
52 
53  unsigned int local_m;
54 
55  unsigned int global_n;
56 
61  unsigned int known;
62 };
63 
64 
71 static void
73 {
74  struct StopHelperState *shs = cls;
75 
76  GNUNET_free (shs);
77 }
78 
79 
86 static void
89 {
90  struct StopHelperState *shs = cls;
91  const struct GNUNET_HELPER_Handle **helper;
92  const struct GNUNET_TESTING_Command *start_helper_cmd;
93 
95  shs->
96  helper_start_label);
98  &helper);
99 
100  for (int i = 1; i <= shs->known; i++)
101  {
103  "i: %u\n",
104  i);
106  (struct GNUNET_HELPER_Handle *) helper[i - 1],
107  GNUNET_YES);
108  }
109 
110  for (int i = 1; i <= shs->global_n; i++)
111  {
112  for (int j = 1; j <= shs->local_m; j++)
113  {
115  "i: %u j: %u\n",
116  i,
117  j);
118  GNUNET_HELPER_stop ((struct GNUNET_HELPER_Handle *) helper[(i - 1)
119  * shs->local_m
120  + j
121  + shs->known
122  - 1],
123  GNUNET_YES);
124  }
125  }
126  GNUNET_free (helper);
127 }
128 
129 
140  const char *label,
141  const char *helper_start_label,
143 {
144  struct StopHelperState *shs;
145 
146  shs = GNUNET_new (struct StopHelperState);
148  shs->local_m = topology->nodes_m;
149  shs->global_n = topology->namespaces_n;
150  shs->known = topology->nodes_x;
151  shs->topology = topology;
152 
153  return GNUNET_TESTING_command_new (shs, label,
156  NULL, NULL);
157 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
struct GNUNET_TESTING_Interpreter * is
API to manage barriers.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_helper_handles(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_HELPER_Handle ***ret)
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_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process.
Definition: helper.c:537
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
The handle to a helper process.
Definition: helper.c:78
A command to be run by the interpreter.
char label[127+1]
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
Struct to store information handed over to callbacks.
unsigned int known
Number of global known nodes.
struct GNUNET_TESTING_NetjailTopology * topology
The complete topology information.
struct GNUNET_HELPER_Handle ** helper
The process handle.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_cmds_helper(const char *label, const char *helper_start_label, struct GNUNET_TESTING_NetjailTopology *topology)
Create command.
static void stop_testing_system_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function stops the helper process for each node.
static void stop_testing_system_cleanup(void *cls)
Code to clean up resource this cmd used.
Message formats for communication between testing cmds helper and testcase plugins.