GNUnet  0.11.x
testbed_api_test.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008--2013 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_testbed_service.h"
30 #include "testbed.h"
31 
32 
37 {
42 
47 
52 
56  void *cc_cls;
57 
61  uint64_t event_mask;
62 
66  unsigned int num_peers;
67 };
68 
69 
78 static void
79 run (void *cls, char *const *args, const char *cfgfile,
80  const struct GNUNET_CONFIGURATION_Handle *config)
81 {
82  struct TestRunContext *rc = cls;
83 
84  GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc,
85  rc->cc_cls, rc->test_master, rc->test_master_cls);
86 }
87 
88 
122 int
123 GNUNET_TESTBED_test_run (const char *testname,
124  const char *cfg_filename,
125  unsigned int num_peers,
126  uint64_t event_mask,
128  void *cc_cls,
130  void *test_master_cls)
131 {
132  char *argv2[] = {
133  NULL,
134  "-c",
135  NULL,
136  NULL
137  };
138  struct GNUNET_GETOPT_CommandLineOption options[] = {
140  };
141  struct TestRunContext *rc;
142  int ret;
143 
144  argv2[0] = GNUNET_strdup (testname);
145  argv2[2] = GNUNET_strdup (cfg_filename);
146  GNUNET_assert (NULL != test_master);
147  GNUNET_assert (num_peers > 0);
148 
149  char* envcfg = getenv(ENV_TESTBED_CONFIG);
150  setenv(ENV_TESTBED_CONFIG, cfg_filename, 1);
151 
152  rc = GNUNET_malloc (sizeof(struct TestRunContext)
153  + (num_peers * sizeof(struct GNUNET_TESTBED_Peer *)));
154  rc->test_master = test_master;
156  rc->num_peers = num_peers;
157  rc->event_mask = event_mask;
158  rc->cc = cc;
159  rc->cc_cls = cc_cls;
160  ret = GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
161  testname, "nohelp", options, &run, rc);
162 
163  if (envcfg)
164  setenv(ENV_TESTBED_CONFIG, envcfg, 1);
165  else
166  unsetenv(ENV_TESTBED_CONFIG);
167 
168  GNUNET_free (rc);
169  GNUNET_free (argv2[0]);
170  GNUNET_free (argv2[2]);
171  return ret;
172 }
173 
174 
175 /* end of testbed_api_test.c */
static char * cfg_filename
Name of the configuration file.
GNUNET_TESTBED_TestMaster test_master
Test master callback.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:360
Context information for test run.
int GNUNET_TESTBED_test_run(const char *testname, const char *cfg_filename, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a "simple" test on the local system with a single call from &#39;main&#39;...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t event_mask
event mask for the controller callback
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
IPC messages between testing API and service ("controller")
void(* GNUNET_TESTBED_ControllerCallback)(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Signature of the event handler function called by the respective event controller.
Definition of a command line option.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main run function.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void(* GNUNET_TESTBED_TestMaster)(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
Signature of a main function for a testcase.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static const struct GNUNET_CONFIGURATION_Handle * config
static char ** argv2
The arguments including the binary to spawn.
void GNUNET_TESTBED_run(const char *host_filename, const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a testbed with a single call.
GNUNET_TESTBED_ControllerCallback cc
The controller event callback.
char * getenv()
unsigned int num_peers
Number of peers to start.
configuration data
void * test_master_cls
Closure for test master.
A peer controlled by the testing framework.
void * cc_cls
Closure for the above callback.
#define ENV_TESTBED_CONFIG
The environmental variable which when available refers to the configuration file the local testbed co...
Definition: testbed.h:776
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.