GNUnet 0.22.2
gnunet-testbed.c File Reference

tool to use testing functionality from cmd line More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_lib.h"
Include dependency graph for gnunet-testbed.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "gnunet-testbed", __VA_ARGS__)
 

Functions

static int create_unique_cfgs (const char *template, const unsigned int no)
 
static void run_no_scheduler (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be running without scheduler. More...
 
int main (int argc, char *const *argv)
 The main function. More...
 

Variables

static int ret
 Final status code. More...
 
static unsigned int create_no
 Number of config files to create. More...
 
static char * create_cfg_template
 Filename of the config template to be written. More...
 

Detailed Description

tool to use testing functionality from cmd line

Author
Christian Grothoff

Definition in file gnunet-testbed.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "gnunet-testbed", __VA_ARGS__)

Definition at line 31 of file gnunet-testbed.c.

Function Documentation

◆ create_unique_cfgs()

static int create_unique_cfgs ( const char *  template,
const unsigned int  no 
)
static

Definition at line 51 of file gnunet-testbed.c.

53{
54 struct GNUNET_TESTBED_System *system;
55 int fail;
56 char *cur_file;
57 struct GNUNET_CONFIGURATION_Handle *cfg_new;
58 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
59
60 if (GNUNET_NO == GNUNET_DISK_file_test (template))
61 {
63 "Configuration template `%s': file not found\n",
65 return 1;
66 }
68
69 /* load template */
70 if ((create_cfg_template != NULL) &&
71 (GNUNET_OK !=
74 {
76 "Could not load template `%s'\n",
79
80 return 1;
81 }
82 /* load defaults */
83 if (GNUNET_OK !=
85 NULL))
86 {
88 "Could not load template `%s'\n",
91 return 1;
92 }
93
94 fail = GNUNET_NO;
95 system =
97 NULL /* controller */,
98 NULL);
99 for (unsigned int cur = 0; cur < no; cur++)
100 {
102 "Creating configuration no. %u \n",
103 cur);
104 if (create_cfg_template != NULL)
105 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
106 else
107 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
108
109 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
110 if (GNUNET_OK !=
112 cfg_new,
113 NULL,
114 NULL))
115 {
117 "Could not create another configuration\n");
119 fail = GNUNET_YES;
120 break;
121 }
123 "Writing configuration no. %u to file `%s' \n",
124 cur,
125 cur_file);
126 if (GNUNET_OK !=
128 cur_file))
129 {
131 "Failed to write configuration no. %u \n",
132 cur);
133 fail = GNUNET_YES;
134 }
136 GNUNET_free (cur_file);
137 if (GNUNET_YES == fail)
138 break;
139 }
142 false);
143 if (GNUNET_YES == fail)
144 return 1;
145 return 0;
146}
static char * create_cfg_template
Filename of the config template to be written.
struct GNUNET_TESTBED_System * GNUNET_TESTBED_system_create(const char *testdir, const char *trusted_ip, const char *hostname)
Create a system handle.
Definition: testbed.c:136
void GNUNET_TESTBED_system_destroy(struct GNUNET_TESTBED_System *system, bool remove_paths)
Free system resources.
Definition: testbed.c:150
enum GNUNET_GenericReturnValue GNUNET_TESTBED_configuration_create(struct GNUNET_TESTBED_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testbed.c:532
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:506
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testbed.c:54

References create_cfg_template, GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_TESTBED_configuration_create(), GNUNET_TESTBED_system_create(), GNUNET_TESTBED_system_destroy(), and GNUNET_YES.

Referenced by run_no_scheduler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_no_scheduler()

static void run_no_scheduler ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be running without scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 158 of file gnunet-testbed.c.

162{
163 if (create_no > 0)
164 {
166 "Creating %u configuration files based on template `%s'\n",
167 create_no,
170 create_no);
171 }
172 else
173 {
175 "Missing arguments!\n");
176 ret = 1;
177 }
178}
static int ret
Final status code.
static unsigned int create_no
Number of config files to create.
static int create_unique_cfgs(const char *template, const unsigned int no)

References create_cfg_template, create_no, create_unique_cfgs(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, and ret.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 189 of file gnunet-testbed.c.

190{
193 'n',
194 "number",
195 "NUMBER",
196 gettext_noop ("number of unique configuration files to create"),
197 &create_no),
199 't',
200 "template",
201 "FILENAME",
202 gettext_noop ("configuration template"),
205 };
206
207 ret =
208 (GNUNET_OK ==
210 argc,
211 argv,
212 "gnunet-testing",
214 "Command line tool to access the testing library"),
215 options,
217 NULL,
218 GNUNET_YES))
219 ? ret
220 : 1;
221 return ret;
222}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static void run_no_scheduler(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be running without scheduler.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:132
Definition of a command line option.

References create_cfg_template, create_no, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run2(), GNUNET_YES, options, ret, and run_no_scheduler().

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Final status code.

Definition at line 37 of file gnunet-testbed.c.

Referenced by main(), and run_no_scheduler().

◆ create_no

unsigned int create_no
static

Number of config files to create.

Definition at line 42 of file gnunet-testbed.c.

Referenced by main(), and run_no_scheduler().

◆ create_cfg_template

char* create_cfg_template
static

Filename of the config template to be written.

Definition at line 47 of file gnunet-testbed.c.

Referenced by create_unique_cfgs(), main(), and run_no_scheduler().