GNUnet 0.26.2-98-gb402d9955
 
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
static enum GNUNET_GenericReturnValue traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits.
 
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.
 
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.
 

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");
94 SIGKILL));
97 true,
98 NULL,
99 NULL));
101 bss->start_proc = NULL;
102 }
103 for (unsigned int i = 0; NULL != bss->args[i]; i++)
104 GNUNET_free (bss->args[i]);
105 GNUNET_free (bss->args);
106 GNUNET_free (bss);
107}
#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.
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
char ** args
NULL-terminated array of command-line arguments.
struct GNUNET_ChildWaitHandle * cwh
Wait for death of start_proc.
struct GNUNET_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_process_destroy(), GNUNET_process_kill(), GNUNET_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 115 of file testing_api_cmd_exec.c.

118{
119 struct BashScriptState *bss = cls;
120
121 bss->cwh = NULL;
123 bss->start_proc = NULL;
124 if ( (bss->expected_type != type) ||
125 (bss->expected_exit_code != exit_code) )
126 {
128 "Child failed with error %lu (wanted %lu) %d/%d!\n",
129 exit_code,
131 type,
132 bss->expected_type);
134 return;
135 }
137}
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_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 146 of file testing_api_cmd_exec.c.

148{
149 struct BashScriptState *bss = cls;
150
151 GNUNET_assert (NULL == bss->cwh);
153 if (GNUNET_OK !=
155 bss->args[0],
156 (const char **) bss->args))
157 {
158 GNUNET_break (0);
160 return;
161 }
162 bss->cwh = GNUNET_wait_child (bss->start_proc,
164 bss);
165 GNUNET_break (NULL != bss->cwh);
166}
static struct GNUNET_TESTING_Interpreter * is
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_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.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_argv(struct GNUNET_Process *p, const char *filename, const char **argv)
Set the command and start a process.
Definition os_process.c:840
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
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_OK, GNUNET_OS_INHERIT_STD_ERR, GNUNET_process_create(), GNUNET_process_run_command_argv(), GNUNET_TESTING_FAIL, GNUNET_wait_child(), is, 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 173 of file testing_api_cmd_exec.c.

177{
178 struct BashScriptState *bss = cls;
179 struct GNUNET_TESTING_Trait traits[] = {
182 };
183
185 ret,
186 trait,
187 index);
188}
static int ret
Final status code.
Definition gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_process(struct GNUNET_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(), connect_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_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()

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 192 of file testing_api_cmd_exec.c.

197{
198 struct BashScriptState *bss;
199 unsigned int cnt;
200
201 cnt = 0;
202 while (NULL != script_argv[cnt])
203 cnt++;
204 bss = GNUNET_new (struct BashScriptState);
205 bss->args = GNUNET_new_array (cnt + 1,
206 char *);
207 for (unsigned int i = 0; i<cnt; i++)
208 bss->args[i] = GNUNET_strdup (script_argv[i]);
212 bss,
213 label,
216 &traits,
217 &bss->ac);
218}
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()

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 222 of file testing_api_cmd_exec.c.

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

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: