GNUnet 0.24.1-14-gdb0ea5ed9
plugin_testing_transport_simple_send_broadcast.c File Reference
Include dependency graph for plugin_testing_transport_simple_send_broadcast.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 
#define BASE_DIR   "testdir"
 
#define TOPOLOGY_CONFIG   "test_transport_simple_send_topo.conf"
 
#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
 

Functions

static int check_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received. More...
 
static void handle_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received. More...
 
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers ()
 
static void all_peers_started ()
 Callback to set the flag indicating all peers started. More...
 
static void handle_result (void *cls, enum GNUNET_GenericReturnValue rv)
 Function called with the final result of the test. More...
 
static void * notify_connect (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
 Callback from start peer cmd for signaling a peer got connected. More...
 
static void all_local_tests_prepared ()
 Callback to set the flag indicating all peers are prepared to finish. More...
 
static struct GNUNET_TESTING_Interpreterstart_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message, const char *router_ip, const char *node_ip, const char *m, const char *n, const char *local_m, const char *topology_data, unsigned int *read_file, GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
 Function to start a local test case. More...
 
void * libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done (void *cls)
 Exit point from the plugin. More...
 

Variables

static struct GNUNET_TESTING_Command block_send
 
static struct GNUNET_TESTING_Command block_receive
 
static struct GNUNET_TESTING_Command connect_peers
 
static struct GNUNET_TESTING_Command local_prepared
 
static struct GNUNET_TESTING_Interpreteris
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 36 of file plugin_testing_transport_simple_send_broadcast.c.

◆ BASE_DIR

#define BASE_DIR   "testdir"

◆ TOPOLOGY_CONFIG

#define TOPOLOGY_CONFIG   "test_transport_simple_send_topo.conf"

◆ TIMEOUT

Function Documentation

◆ check_test()

static int check_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.

Definition at line 60 of file plugin_testing_transport_simple_send_broadcast.c.

62{
63 return GNUNET_OK;
64}
@ GNUNET_OK

References GNUNET_OK.

◆ handle_test()

static void handle_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.

Definition at line 73 of file plugin_testing_transport_simple_send_broadcast.c.

75{
77
78 GNUNET_TESTING_get_trait_async_context (&block_receive,
79 &ac);
80 GNUNET_assert (NULL != ac);
81 if ((GNUNET_NO == ac->finished) && (NULL == ac->cont))
83 else if (GNUNET_NO == ac->finished)
85}
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_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_TESTING_Command block_receive
State each asynchronous command must have in its closure.
enum GNUNET_GenericReturnValue finished
Indication if the command finished (GNUNET_OK).

References block_receive, GNUNET_TESTING_AsyncContext::finished, GNUNET_assert, GNUNET_NO, GNUNET_TESTING_async_fail(), and GNUNET_TESTING_async_finish().

Here is the call graph for this function:

◆ get_waiting_for_barriers()

struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers ( )

Definition at line 89 of file plugin_testing_transport_simple_send_broadcast.c.

90{
91 // No Barrier
92 return GNUNET_new (struct GNUNET_TESTING_BarrierList);
93}
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References GNUNET_new.

Referenced by libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init().

Here is the caller graph for this function:

◆ all_peers_started()

static void all_peers_started ( )
static

Callback to set the flag indicating all peers started.

Will be called via the plugin api.

Definition at line 101 of file plugin_testing_transport_simple_send_broadcast.c.

102{
104
106 "Received message\n");
107 GNUNET_TESTING_get_trait_async_context (&block_send,
108 &ac);
109 GNUNET_assert (NULL != ac);
110 if (NULL == ac->cont)
112 else
114}
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
static struct GNUNET_TESTING_Command block_send

References block_send, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TESTING_async_fail(), and GNUNET_TESTING_async_finish().

Referenced by libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init().

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

◆ handle_result()

static void handle_result ( void *  cls,
enum GNUNET_GenericReturnValue  rv 
)
static

Function called with the final result of the test.

Parameters
clsthe struct MainParams
rvGNUNET_OK if the test passed

Definition at line 124 of file plugin_testing_transport_simple_send_broadcast.c.

126{
127 struct TestState *ts = cls;
128
130 "Local test exits with status %d\n",
131 rv);
132 ts->finished_cb (rv);
133 GNUNET_free (ts->testdir);
134 GNUNET_free (ts->cfgname);
136 GNUNET_free (ts);
137}
#define GNUNET_free(ptr)
Wrapper around free.
char * cfgname
The name for the configuration file of the specific node.
char * testdir
The name for a specific test environment directory.
struct GNUNET_TESTING_NetjailTopology * topology
The complete topology information.
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

References TestState::cfgname, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_TESTING_free_topology(), TestState::testdir, and TestState::topology.

Referenced by start_testcase().

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

◆ notify_connect()

static void * notify_connect ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_PeerIdentity peer 
)
static

Callback from start peer cmd for signaling a peer got connected.

Definition at line 145 of file plugin_testing_transport_simple_send_broadcast.c.

147{
149 void *ret = NULL;
150 const struct GNUNET_TESTING_Command *cmd;
151 struct GNUNET_TESTING_BlockState *bs;
152
154 "notify_connect\n");
155 GNUNET_TESTING_get_trait_async_context (&connect_peers,
156 &ac);
157 if (NULL != ac->is)
158 {
160 "notify_connect running\n");
161 GNUNET_assert (NULL != ac);
162 if (NULL == ac->cont)
164 else
166 }
167 else
168 {
169 cmd = GNUNET_TESTING_interpreter_lookup_future_command (is,
170 "connect-peers");
172 "block state %s\n",
173 cmd->label.value);
174 GNUNET_TESTING_get_trait_block_state (
175 cmd,
176 &bs);
177
179 "block state %u\n",
180 bs->asynchronous_finish);
181 bs->asynchronous_finish = GNUNET_YES;
183 "block state %u\n",
184 bs->asynchronous_finish);
185 }
186
187 return ret;
188}
static int ret
Final status code.
Definition: gnunet-arm.c:93
@ GNUNET_YES
static struct GNUNET_TESTING_Command connect_peers
static struct GNUNET_TESTING_Interpreter * is
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.

References connect_peers, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), GNUNET_YES, GNUNET_TESTING_AsyncContext::is, is, GNUNET_TESTING_Command::label, LOG, ret, and GNUNET_TESTING_CommandLabel::value.

Referenced by start_testcase().

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

◆ all_local_tests_prepared()

static void all_local_tests_prepared ( )
static

Callback to set the flag indicating all peers are prepared to finish.

Will be called via the plugin api.

Definition at line 195 of file plugin_testing_transport_simple_send_broadcast.c.

196{
197 const struct GNUNET_TESTING_LocalPreparedState *lfs;
198
199 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
200 &lfs);
201 GNUNET_assert (NULL != &lfs->ac);
202 if (NULL == lfs->ac.cont)
204 else
206 GNUNET_TESTING_AsyncContext *) &lfs->ac);
207}
static struct GNUNET_TESTING_Command local_prepared

References GNUNET_assert, GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), and local_prepared.

Referenced by libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init().

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

◆ start_testcase()

static struct GNUNET_TESTING_Interpreter * start_testcase ( GNUNET_TESTING_cmd_helper_write_cb  write_message,
const char *  router_ip,
const char *  node_ip,
const char *  m,
const char *  n,
const char *  local_m,
const char *  topology_data,
unsigned int *  read_file,
GNUNET_TESTING_cmd_helper_finish_cb  finished_cb 
)
static

Function to start a local test case.

Parameters
write_messageCallback to send a message to the master loop.
router_ipGlobal address of the network namespace.
node_ipThe IP address of the node.
mThe number of the node in a network namespace.
nThe number of the network namespace.
local_mThe number of nodes in a network namespace.

Definition at line 221 of file plugin_testing_transport_simple_send_broadcast.c.

230{
231 unsigned int n_int;
232 unsigned int m_int;
233 unsigned int local_m_int;
234 unsigned int num;
235 struct TestState *ts = GNUNET_new (struct TestState);
236 struct GNUNET_TESTING_NetjailTopology *topology;
237 unsigned int sscanf_ret = 0;
238
239 ts->finished_cb = finished_cb;
241 "n %s m %s\n",
242 n,
243 m);
244
245 if (GNUNET_YES == *read_file)
246 {
248 "read from file\n");
249 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
250 }
251 else
252 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
253
254 ts->topology = topology;
255
256 errno = 0;
257 sscanf_ret = sscanf (m, "%u", &m_int);
258 if (errno != 0)
259 {
261 }
262 GNUNET_assert (0 < sscanf_ret);
263 errno = 0;
264 sscanf_ret = sscanf (n, "%u", &n_int);
265 if (errno != 0)
266 {
268 }
269 GNUNET_assert (0 < sscanf_ret);
270 errno = 0;
271 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
272 if (errno != 0)
273 {
275 }
276 GNUNET_assert (0 < sscanf_ret);
277
278 if (0 == n_int)
279 num = m_int;
280 else
281 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
282
283 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
284 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
285 "block-receive");
286 connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger (
287 "connect-peers");
288 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
289 "local-test-prepared",
291
292
294 "test_transport_api_tcp_node1.conf");
295
297 "plugin cfgname: %s\n",
298 ts->cfgname);
299
301 "node ip: %s\n",
302 node_ip);
303
305 "%s%s%s",
306 BASE_DIR,
307 m,
308 n);
309
314 ts),
316 };
317
319 GNUNET_TESTING_cmd_system_create ("system-create",
320 ts->testdir),
322 "system-create",
323 num,
324 node_ip,
325 handlers,
326 ts->cfgname,
328 GNUNET_YES),
329 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
334 "start-peer",
335 "system-create",
336 num,
337 topology),
341 "start-peer"),
342 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
343 "system-create"),
345 };
346
347 ts->write_message = write_message;
348
350 TIMEOUT,
352 ts);
353 return is;
354}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static void write_message(const struct GNUNET_MessageHeader *message)
Callback to write a message to the parent process.
static void finished_cb(void *cls, enum GNUNET_GenericReturnValue rv)
static struct VoipCommand commands[]
List of supported commands.
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
static void handle_result(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
static void * notify_connect(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
Callback from start peer cmd for signaling a peer got connected.
Message handler for a specific message type.
Topology of our netjail setup.
unsigned int nodes_x
Number of global known nodes.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple(const char *label, const char *start_peer_label, const char *create_label, uint32_t num)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_stop_peer(const char *label, const char *start_label)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer(const char *label, const char *system_label, uint32_t no, const char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, GNUNET_TRANSPORT_notify_connect_cb notify_connect, unsigned int broadcast)
Create command.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().

References BASE_DIR, block_receive, block_send, TestState::cfgname, commands, connect_peers, finished_cb(), GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_new, GNUNET_TESTING_cmd_end(), GNUNET_TESTING_run(), GNUNET_TRANSPORT_cmd_send_simple(), GNUNET_TRANSPORT_cmd_start_peer(), GNUNET_TRANSPORT_cmd_stop_peer(), GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, GNUNET_YES, handle_result(), handlers, is, local_prepared, LOG, m, GNUNET_TESTING_NetjailTopology::nodes_x, notify_connect(), read_file(), TestState::testdir, TIMEOUT, TestState::topology, and write_message().

Referenced by libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init().

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

◆ libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init()

void * libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 364 of file plugin_testing_transport_simple_send_broadcast.c.

365{
367
368 GNUNET_log_setup ("simple-send",
369 "DEBUG",
370 NULL);
371
374 api->all_peers_started = &all_peers_started;
375 api->all_local_tests_prepared = all_local_tests_prepared;
376 api->get_waiting_for_barriers = get_waiting_for_barriers;
377 return api;
378}
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static void all_local_tests_prepared()
Callback to set the flag indicating all peers are prepared to finish.
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers()
static void all_peers_started()
Callback to set the flag indicating all peers started.
static struct GNUNET_TESTING_Interpreter * start_testcase(GNUNET_TESTING_cmd_helper_write_cb write_message, const char *router_ip, const char *node_ip, const char *m, const char *n, const char *local_m, const char *topology_data, unsigned int *read_file, GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
Function to start a local test case.
The plugin API every test case plugin has to implement.
struct GNUNET_TESTING_Interpreter *(* start_testcase)(void *cls, const char *topology_data, uint32_t barrier_count, const struct GNUNET_ShortHashCode *barriers, GNUNET_TESTING_cmd_helper_write_cb write_message, GNUNET_TESTING_ResultCallback finish_cb, void *finish_cb_cls)
Function to be implemented for each test case plugin which starts the test case on a netjail node.

References all_local_tests_prepared(), all_peers_started(), get_waiting_for_barriers(), GNUNET_log_setup(), GNUNET_new, start_testcase(), and GNUNET_TESTING_PluginFunctions::start_testcase.

Here is the call graph for this function:

◆ libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done()

void * libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from #libgnunet_test_transport_plugin_block_test_init
Returns
NULL

Definition at line 388 of file plugin_testing_transport_simple_send_broadcast.c.

389{
391
392 GNUNET_free (api);
393 return NULL;
394}
void * cls
Closure to pass to start_testcase.

References GNUNET_TESTING_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ block_send

struct GNUNET_TESTING_Command block_send
static

◆ block_receive

struct GNUNET_TESTING_Command block_receive
static

Definition at line 46 of file plugin_testing_transport_simple_send_broadcast.c.

Referenced by handle_test(), and start_testcase().

◆ connect_peers

struct GNUNET_TESTING_Command connect_peers
static

◆ local_prepared

struct GNUNET_TESTING_Command local_prepared
static

◆ is

struct GNUNET_TESTING_Interpreter* is
static