GNUnet  0.11.x
testbed_api_cmd_netjail_stop_testbed.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"
29 #include "testbed_api.h"
30 #include "testbed_api_hosts.h"
31 
32 
34 {
35 
36  const char *helper_start_label;
37 
42 
43  char *local_m;
44 
45  char *global_n;
46 };
47 
48 
55 static void
57  const struct GNUNET_TESTING_Command *cmd)
58 {
59 
60 }
61 
62 
72 static int
74  const void **ret,
75  const char *trait,
76  unsigned int index)
77 {
78  return GNUNET_OK;
79 }
80 
81 
89 static void
90 stop_testbed_run (void *cls,
91  const struct GNUNET_TESTING_Command *cmd,
93 {
94  struct StopHelperState *shs = cls;
95  struct GNUNET_HELPER_Handle **helper;
96  const struct GNUNET_TESTING_Command *start_helper_cmd;
97 
99  shs->helper_start_label);
100  GNUNET_TESTBED_get_trait_helper_handles (start_helper_cmd,
101  &helper);
102 
103  for (int i = 1; i <= atoi (shs->global_n); i++) {
104  for (int j = 1; j <= atoi (shs->local_m); j++)
105  {
106  GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1],
107  GNUNET_YES);
108  }
109  }
110 }
111 
112 
122  const char *helper_start_label,
123  char *local_m,
124  char *global_n
125  )
126 {
127  struct StopHelperState *shs;
128 
129  shs = GNUNET_new (struct StopHelperState);
131  shs->local_m = local_m;
132  shs->global_n = global_n;
133 
134  struct GNUNET_TESTING_Command cmd = {
135  .cls = shs,
136  .label = label,
137  .run = &stop_testbed_run,
138  .cleanup = &stop_testbed_cleanup,
139  .traits = &stop_testbed_traits
140  };
141 
142  return cmd;
143 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
@ GNUNET_OK
Definition: gnunet_common.h:87
@ GNUNET_YES
Definition: gnunet_common.h:89
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(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:567
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_stop_testbed(const char *label, const char *helper_start_label, char *local_m, char *global_n)
Create command.
int GNUNET_TESTBED_get_trait_helper_handles(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_HELPER_Handle ***helper)
Offer handles to testbed helper from trait.
The handle to a helper process.
Definition: helper.c:79
A command to be run by the interpreter.
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.
Definition: testing.h:35
struct GNUNET_HELPER_Handle ** helper
The process handle.
Interface for functions internally exported from testbed_api.c.
static void stop_testbed_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.
static int stop_testbed_traits(void *cls, const void **ret, const char *trait, unsigned int index)
static void stop_testbed_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
internal API to access the 'hosts' subsystem
struct GNUNET_TESTING_Interpreter * is