GNUnet  0.10.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 
27 #include "platform.h"
28 #include "gnunet_testbed_service.h"
29 
30 
35 {
40 
45 
50 
54  void *cc_cls;
55 
59  uint64_t event_mask;
60 
64  unsigned int num_peers;
65 };
66 
67 
76 static void
77 run (void *cls, char *const *args, const char *cfgfile,
78  const struct GNUNET_CONFIGURATION_Handle *config)
79 {
80  struct TestRunContext *rc = cls;
81 
82  GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc,
83  rc->cc_cls, rc->test_master, rc->test_master_cls);
84 }
85 
86 
120 int
121 GNUNET_TESTBED_test_run (const char *testname,
122  const char *cfg_filename,
123  unsigned int num_peers,
124  uint64_t event_mask,
126  void *cc_cls,
128  void *test_master_cls)
129 {
130  char *argv2[] = {
131  NULL,
132  "-c",
133  NULL,
134  NULL
135  };
136  struct GNUNET_GETOPT_CommandLineOption options[] = {
138  };
139  struct TestRunContext *rc;
140  int ret;
141 
142  argv2[0] = GNUNET_strdup (testname);
143  argv2[2] = GNUNET_strdup (cfg_filename);
144  GNUNET_assert (NULL != test_master);
145  GNUNET_assert (num_peers > 0);
146  rc = GNUNET_malloc (sizeof (struct TestRunContext) +
147  (num_peers * sizeof (struct GNUNET_TESTBED_Peer *)));
148  rc->test_master = test_master;
150  rc->num_peers = num_peers;
151  rc->event_mask = event_mask;
152  rc->cc = cc;
153  rc->cc_cls = cc_cls;
154  ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
155  testname, "nohelp", options, &run, rc);
156  GNUNET_free (rc);
157  GNUNET_free (argv2[0]);
158  GNUNET_free (argv2[2]);
159  return ret;
160 }
161 
162 /* end of testbed_api_test.c */
static char * cfg_filename
Name of the configuration file.
GNUNET_TESTBED_TestMaster test_master
Test master callback.
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
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.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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.
unsigned int num_peers
Number of peers to start.
configuration data
Definition: configuration.c:85
int 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:361
void * test_master_cls
Closure for test master.
A peer controlled by the testing framework.
void * cc_cls
Closure for the above callback.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.