GNUnet 0.22.2
testing_api_cmd_exec.c File Reference

cmd to block the interpreter loop until all peers started. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
Include dependency graph for testing_api_cmd_exec.c:

Go to the source code of this file.

Data Structures

struct  BashScriptState
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 

Functions

static void exec_bash_script_cleanup (void *cls)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static void child_completed_callback (void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)
 Callback which will be called if the setup script finished. More...
 
static void exec_bash_script_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run method of the command created by the interpreter to wait for another command to finish. More...
 
static enum GNUNET_GenericReturnValue traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits. More...
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec (const char *label, enum GNUNET_OS_ProcessStatusType expected_type, unsigned long int expected_exit_code, char *const script_argv[])
 Command to execute a command. More...
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec_va (const char *label, enum GNUNET_OS_ProcessStatusType expected_type, unsigned long int expected_exit_code,...)
 Command to execute a command. More...
 

Detailed Description

cmd to block the interpreter loop until all peers started.

Author
t3sserakt

Definition in file testing_api_cmd_exec.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Definition at line 30 of file testing_api_cmd_exec.c.

Function Documentation

◆ exec_bash_script_cleanup()

static void exec_bash_script_cleanup ( void *  cls)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 77 of file testing_api_cmd_exec.c.

78{
79 struct BashScriptState *bss = cls;
80
81 if (NULL != bss->cwh)
82 {
84 "Cancel child\n");
86 bss->cwh = NULL;
87 }
88 if (NULL != bss->start_proc)
89 {
91 "Kill process\n");
92 GNUNET_assert (0 ==
94 SIGKILL));
98 bss->start_proc = NULL;
99 }
100 for (unsigned int i = 0; NULL != bss->args[i]; i++)
101 GNUNET_free (bss->args[i]);
102 GNUNET_free (bss->args);
103 GNUNET_free (bss);
104}
#define GNUNET_log(kind,...)
void GNUNET_wait_child_cancel(struct GNUNET_ChildWaitHandle *cwh)
Stop waiting on this child.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:871
char ** args
NULL-terminated array of command-line arguments.
struct GNUNET_ChildWaitHandle * cwh
Wait for death of start_proc.
struct GNUNET_OS_Process * start_proc
The process id of the script.

References BashScriptState::args, BashScriptState::cwh, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_wait_child_cancel(), and BashScriptState::start_proc.

Referenced by GNUNET_TESTING_cmd_exec(), and GNUNET_TESTING_cmd_exec_va().

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

◆ child_completed_callback()

static void child_completed_callback ( void *  cls,
enum GNUNET_OS_ProcessStatusType  type,
long unsigned int  exit_code 
)
static

Callback which will be called if the setup script finished.

Definition at line 112 of file testing_api_cmd_exec.c.

115{
116 struct BashScriptState *bss = cls;
117
118 bss->cwh = NULL;
120 bss->start_proc = NULL;
121 if ( (bss->expected_type != type) ||
122 (bss->expected_exit_code != exit_code) )
123 {
125 "Child failed with error %lu (wanted %lu) %d/%d!\n",
126 exit_code,
128 type,
129 bss->expected_type);
131 return;
132 }
134}
static uint32_t type
Type string converted to DNS type value.
static int exit_code
Global exit code.
Definition: gnunet-qr.c:43
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
enum GNUNET_OS_ProcessStatusType expected_type
unsigned long int expected_exit_code

References BashScriptState::ac, BashScriptState::cwh, exit_code, BashScriptState::expected_exit_code, BashScriptState::expected_type, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OS_process_destroy(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), BashScriptState::start_proc, and type.

Referenced by exec_bash_script_run().

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

◆ exec_bash_script_run()

static void exec_bash_script_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Run method of the command created by the interpreter to wait for another command to finish.

Definition at line 143 of file testing_api_cmd_exec.c.

145{
146 struct BashScriptState *bss = cls;
147
148 GNUNET_assert (NULL == bss->cwh);
149 bss->start_proc
152 NULL,
153 NULL,
154 NULL,
155 bss->args[0],
156 bss->args);
157 bss->cwh = GNUNET_wait_child (bss->start_proc,
159 bss);
160 GNUNET_break (NULL != bss->cwh);
161}
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
Starts the handling of the child processes.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:567
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:95
static void child_completed_callback(void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)
Callback which will be called if the setup script finished.

References BashScriptState::args, child_completed_callback(), BashScriptState::cwh, GNUNET_assert, GNUNET_break, GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_start_process_vap(), GNUNET_wait_child(), and BashScriptState::start_proc.

Referenced by GNUNET_TESTING_cmd_exec(), and GNUNET_TESTING_cmd_exec_va().

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

◆ traits()

static enum GNUNET_GenericReturnValue traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

This function prepares an array with traits.

Definition at line 168 of file testing_api_cmd_exec.c.

172{
173 struct BashScriptState *bss = cls;
174 struct GNUNET_TESTING_Trait traits[] = {
177 };
178
180 ret,
181 trait,
182 index);
183}
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process(struct GNUNET_OS_Process **value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_make_trait_process(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, BashScriptState::start_proc, and traits().

Referenced by barrier_reached_traits(), barrier_traits(), batch_traits(), connect_peers_traits(), GNUNET_TESTING_cmd_exec(), GNUNET_TESTING_cmd_exec_va(), GNUNET_TESTING_command_new_ac(), GNUNET_TESTING_get_trait(), netjail_exec_traits(), start_peer_traits(), start_service_traits(), stop_peer_traits(), system_create_traits(), and traits().

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

◆ GNUNET_TESTING_cmd_exec()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec ( const char *  label,
enum GNUNET_OS_ProcessStatusType  expected_type,
unsigned long int  expected_exit_code,
char *const  script_argv[] 
)

Command to execute a command.

Parameters
labelLabel of the command.

Definition at line 187 of file testing_api_cmd_exec.c.

192{
193 struct BashScriptState *bss;
194 unsigned int cnt;
195
196 cnt = 0;
197 while (NULL != script_argv[cnt])
198 cnt++;
199 bss = GNUNET_new (struct BashScriptState);
200 bss->args = GNUNET_new_array (cnt + 1,
201 char *);
202 for (unsigned int i = 0; i<cnt; i++)
203 bss->args[i] = GNUNET_strdup (script_argv[i]);
207 bss,
208 label,
211 &traits,
212 &bss->ac);
213}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
static void exec_bash_script_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void exec_bash_script_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run method of the command created by the interpreter to wait for another command to finish.

References BashScriptState::ac, BashScriptState::args, exec_bash_script_cleanup(), exec_bash_script_run(), BashScriptState::expected_exit_code, BashScriptState::expected_type, GNUNET_new, GNUNET_new_array, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), and traits().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_exec_va()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec_va ( const char *  label,
enum GNUNET_OS_ProcessStatusType  expected_type,
unsigned long int  expected_exit_code,
  ... 
)

Command to execute a command.

Parameters
labelLabel of the command.

Definition at line 217 of file testing_api_cmd_exec.c.

222{
223 struct BashScriptState *bss;
224 va_list ap;
225 const char *arg;
226 unsigned int cnt;
227
228 bss = GNUNET_new (struct BashScriptState);
229 va_start (ap,
231 cnt = 1;
232 while (NULL != (arg = va_arg (ap,
233 const char *)))
234 cnt++;
235 va_end (ap);
236 bss->args = GNUNET_new_array (cnt,
237 char *);
238 cnt = 0;
239 va_start (ap,
241 while (NULL != (arg = va_arg (ap,
242 const char *)))
243 bss->args[cnt++] = GNUNET_strdup (arg);
244 va_end (ap);
248 bss,
249 label,
252 &traits,
253 &bss->ac);
254}

References BashScriptState::ac, find_typedefs::arg, BashScriptState::args, exec_bash_script_cleanup(), exec_bash_script_run(), BashScriptState::expected_exit_code, BashScriptState::expected_type, GNUNET_new, GNUNET_new_array, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), and traits().

Here is the call graph for this function: