[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: TESTING: Sanitize API. Add new GNUNET_TE
From: |
gnunet |
Subject: |
[gnunet] branch master updated: TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API |
Date: |
Thu, 08 Dec 2022 12:53:11 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 7768a7a75 TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API
7768a7a75 is described below
commit 7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Thu Dec 8 20:51:35 2022 +0900
TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API
This commit changes the label member of GNUNET_TRANSPORT_Command to a
static, fixed length buffer allocated with the struct itself.
The check for the end of a command array should be done by checking the
run command instead of the label.
---
src/dhtu/testing_dhtu_cmd_send.c | 2 +-
src/include/gnunet_testing_ng_lib.h | 74 +++++++++++++++-------
src/testing/testing_api_cmd_barrier.c | 28 ++++----
src/testing/testing_api_cmd_barrier_reached.c | 31 ++++-----
src/testing/testing_api_cmd_batch.c | 25 +++-----
.../testing_api_cmd_block_until_external_trigger.c | 17 ++---
src/testing/testing_api_cmd_end.c | 8 +--
src/testing/testing_api_cmd_finish.c | 15 ++---
src/testing/testing_api_cmd_local_test_finished.c | 14 ++--
src/testing/testing_api_cmd_local_test_prepared.c | 15 ++---
src/testing/testing_api_cmd_netjail_start.c | 15 ++---
.../testing_api_cmd_netjail_start_testsystem.c | 22 +++----
src/testing/testing_api_cmd_netjail_stop.c | 15 ++---
.../testing_api_cmd_netjail_stop_testsystem.c | 12 ++--
src/testing/testing_api_cmd_send_peer_ready.c | 15 ++---
src/testing/testing_api_cmd_system_create.c | 12 +---
src/testing/testing_api_cmd_system_destroy.c | 14 +---
src/testing/testing_api_loop.c | 42 ++++++++----
.../transport_api_cmd_backchannel_check.c | 16 ++---
src/transport/transport_api_cmd_connecting_peers.c | 18 ++----
src/transport/transport_api_cmd_send_simple.c | 14 ++--
src/transport/transport_api_cmd_start_peer.c | 17 ++---
src/transport/transport_api_cmd_stop_peer.c | 16 ++---
23 files changed, 197 insertions(+), 260 deletions(-)
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index fe8e1c18a..45d166b14 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -107,12 +107,12 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label)
{
struct GNUNET_TESTING_Command cmd = {
.cls = ss,
- .label = label,
.run = &send_run,
.ac = &ss->ac,
.cleanup = &send_cleanup,
.traits = &send_traits
};
+ strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
return cmd;
}
diff --git a/src/include/gnunet_testing_ng_lib.h
b/src/include/gnunet_testing_ng_lib.h
index 768298b48..0b4c05a59 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -40,6 +40,10 @@
*/
#define GNUNET_S(a) #a
+/**
+ * Maximum length of label in command
+ */
+#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
/* ********************* Helper functions ********************* */
@@ -93,6 +97,37 @@ struct GNUNET_TESTING_AsyncContext
enum GNUNET_GenericReturnValue finished;
};
+typedef void
+(*GNUNET_TESTING_CommandRunRoutine)(void *cls,
+ struct GNUNET_TESTING_Interpreter *is);
+
+typedef void
+(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
+
+typedef enum GNUNET_GenericReturnValue
+(*GNUNET_TESTING_CommandGetTraits) (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index);
+
+/**
+ * Create a new command
+ *
+ * @param cls the closure
+ * @param label the Label. Maximum length is
GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
+ * @param run the run routing
+ * @param cleanup the cleanup function
+ * @param traits the traits function (optional)
+ * @param the async context
+ * @return the command the function cannot fail
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_command_new (void *cls,
+ const char *label,
+ GNUNET_TESTING_CommandRunRoutine run,
+ GNUNET_TESTING_CommandCleanupRoutine cleanup,
+ GNUNET_TESTING_CommandGetTraits traits,
+ struct GNUNET_TESTING_AsyncContext *ac);
/**
* A command to be run by the interpreter.
@@ -119,7 +154,7 @@ struct GNUNET_TESTING_Command
/**
* Label for the command.
*/
- char *label;
+ char label[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
/**
* Runs the command. Note that upon return, the interpreter
@@ -136,9 +171,7 @@ struct GNUNET_TESTING_Command
* @param cls closure
* @param is interpreter state
*/
- void
- (*run)(void *cls,
- struct GNUNET_TESTING_Interpreter *is);
+ GNUNET_TESTING_CommandRunRoutine run;
/**
* Pointer to the asynchronous context in the command's
@@ -156,8 +189,7 @@ struct GNUNET_TESTING_Command
*
* @param cls closure
*/
- void
- (*cleanup)(void *cls);
+ GNUNET_TESTING_CommandCleanupRoutine cleanup;
/**
* Extract information from a command that is useful for other
@@ -170,11 +202,7 @@ struct GNUNET_TESTING_Command
* @return #GNUNET_OK on success,
* #GNUNET_NO if no trait was found
*/
- enum GNUNET_GenericReturnValue
- (*traits)(void *cls,
- const void **ret,
- const char *trait,
- unsigned int index);
+ GNUNET_TESTING_CommandGetTraits traits;
/**
* When did the execution of this command start?
@@ -377,7 +405,7 @@ typedef void
* @return The interpreter.
*/
struct GNUNET_TESTING_Interpreter *
-GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
+GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_ResultCallback rc,
void *rc_cls);
@@ -660,11 +688,11 @@ GNUNET_TESTING_get_trait (const struct
GNUNET_TESTING_Trait *traits,
*/
#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
enum GNUNET_GenericReturnValue \
- GNUNET_TESTING_get_trait_ ## name ( \
+ GNUNET_TESTING_get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
type **ret); \
struct GNUNET_TESTING_Trait \
- GNUNET_TESTING_make_trait_ ## name ( \
+ GNUNET_TESTING_make_trait_ ## name ( \
type * value);
@@ -674,9 +702,9 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait
*traits,
*/
#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
enum GNUNET_GenericReturnValue \
- GNUNET_TESTING_get_trait_ ## name ( \
+ GNUNET_TESTING_get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
- type **ret) \
+ type * *ret) \
{ \
if (NULL == cmd->traits) return GNUNET_SYSERR; \
return cmd->traits (cmd->cls, \
@@ -685,7 +713,7 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait
*traits,
0); \
} \
struct GNUNET_TESTING_Trait \
- GNUNET_TESTING_make_trait_ ## name ( \
+ GNUNET_TESTING_make_trait_ ## name ( \
type * value) \
{ \
struct GNUNET_TESTING_Trait ret = { \
@@ -702,14 +730,14 @@ GNUNET_TESTING_get_trait (const struct
GNUNET_TESTING_Trait *traits,
*/
#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
enum GNUNET_GenericReturnValue \
- GNUNET_TESTING_get_trait_ ## name ( \
+ GNUNET_TESTING_get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
unsigned int index, \
type **ret); \
struct GNUNET_TESTING_Trait \
- GNUNET_TESTING_make_trait_ ## name ( \
+ GNUNET_TESTING_make_trait_ ## name ( \
unsigned int index, \
- type * value);
+ type *value);
/**
@@ -718,10 +746,10 @@ GNUNET_TESTING_get_trait (const struct
GNUNET_TESTING_Trait *traits,
*/
#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
enum GNUNET_GenericReturnValue \
- GNUNET_TESTING_get_trait_ ## name ( \
+ GNUNET_TESTING_get_trait_ ## name ( \
const struct GNUNET_TESTING_Command *cmd, \
unsigned int index, \
- type **ret) \
+ type * *ret) \
{ \
if (NULL == cmd->traits) return GNUNET_SYSERR; \
return cmd->traits (cmd->cls, \
@@ -730,7 +758,7 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait
*traits,
index); \
} \
struct GNUNET_TESTING_Trait \
- GNUNET_TESTING_make_trait_ ## name ( \
+ GNUNET_TESTING_make_trait_ ## name ( \
unsigned int index, \
type * value) \
{ \
diff --git a/src/testing/testing_api_cmd_barrier.c
b/src/testing/testing_api_cmd_barrier.c
index ad75f8297..be5dc6d2d 100644
--- a/src/testing/testing_api_cmd_barrier.c
+++ b/src/testing/testing_api_cmd_barrier.c
@@ -109,10 +109,10 @@ GNUNET_TESTING_can_barrier_advance (struct
GNUNET_TESTING_Barrier *barrier)
unsigned int reached = barrier->reached;
double percentage_to_be_reached = barrier->percentage_to_be_reached;
unsigned int number_to_be_reached = barrier->number_to_be_reached;
-
- if ((0 < percentage_to_be_reached &&
- (double)expected_reaches/reached*100) >= percentage_to_be_reached ||
- (0 < number_to_be_reached && reached >= number_to_be_reached ))
+ double percentage_reached = (double)expected_reaches/reached*100;
+ if (((0 < percentage_to_be_reached) &&
+ (percentage_reached >= percentage_to_be_reached)) ||
+ ((0 < number_to_be_reached) && (reached >= number_to_be_reached)))
{
return GNUNET_YES;
}
@@ -237,20 +237,14 @@ GNUNET_TESTING_cmd_barrier_create (const char *label,
bs->label = label;
barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
barrier->name = label;
- GNUNET_assert (0 < percentage_to_be_reached && 0 == number_to_be_reached ||
- 0 == percentage_to_be_reached && 0 < number_to_be_reached);
+ GNUNET_assert ((0 < percentage_to_be_reached && 0 == number_to_be_reached) ||
+ (0 == percentage_to_be_reached && 0 < number_to_be_reached));
barrier->percentage_to_be_reached;
barrier->number_to_be_reached;
bs->barrier = barrier;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = GNUNET_strdup (label),
- .run = &barrier_run,
- .cleanup = &barrier_cleanup,
- .traits = &barrier_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (bs, label,
+ &barrier_run,
+ &barrier_cleanup,
+ &barrier_traits,
+ NULL);
}
diff --git a/src/testing/testing_api_cmd_barrier_reached.c
b/src/testing/testing_api_cmd_barrier_reached.c
index c5b0b692e..1a3b25d32 100644
--- a/src/testing/testing_api_cmd_barrier_reached.c
+++ b/src/testing/testing_api_cmd_barrier_reached.c
@@ -79,11 +79,11 @@ struct BarrierReachedState
*/
static void
barrier_reached_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
+ struct GNUNET_TESTING_Interpreter *is)
{
struct BarrierReachedState *brs = cls;
struct GNUNET_TESTING_Barrier *barrier;
- struct GNUNET_TESTING_Command *cmd;
+ struct GNUNET_TESTING_Command *cmd = NULL;
size_t msg_length;
struct GNUNET_TESTING_CommandBarrierReached *msg;
@@ -98,6 +98,8 @@ barrier_reached_run (void *cls,
barrier->reached++;
if (GNUNET_TESTING_can_barrier_advance (barrier))
{
+ //FIXME cmd uninitialized
+ GNUNET_assert (NULL != cmd);
cmd->asynchronous_finish = GNUNET_YES;
GNUNET_TESTING_finish_attached_cmds (is, barrier);
}
@@ -121,7 +123,7 @@ barrier_reached_run (void *cls,
msg_length = sizeof(struct GNUNET_TESTING_CommandBarrierReached);
msg = GNUNET_new (struct GNUNET_TESTING_CommandBarrierReached);
msg->header.size = htons ((uint16_t) msg_length);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED);
msg->barrier_name = barrier->name;
msg->node_number = brs->node_number;
brs->write_message ((struct GNUNET_MessageHeader *) msg, msg_length);
@@ -155,9 +157,9 @@ barrier_reached_cleanup (void *cls)
*/
static enum GNUNET_GenericReturnValue
barrier_reached_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
+ const void **ret,
+ const char *trait,
+ unsigned int index)
{
struct BarrierReachedState *brs = cls;
struct GNUNET_TESTING_AsyncContext *ac = &brs->ac;
@@ -203,16 +205,9 @@ GNUNET_TESTING_cmd_barrier_reached (
brs->node_number = node_number;
brs->running_on_master = running_on_master;
brs->write_message = write_message;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = brs,
- .label = GNUNET_strdup (label),
- .run = &barrier_reached_run,
- .ac = &brs->ac,
- .cleanup = &barrier_reached_cleanup,
- .traits = &barrier_reached_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (brs, label,
+ &barrier_reached_run,
+ &barrier_reached_cleanup,
+ &barrier_reached_traits,
+ &brs->ac);
}
diff --git a/src/testing/testing_api_cmd_batch.c
b/src/testing/testing_api_cmd_batch.c
index e7ecbf28d..7dc990855 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -62,13 +62,13 @@ batch_run (void *cls,
{
struct BatchState *bs = cls;
- if (NULL != bs->batch[bs->batch_ip].label)
+ if (NULL != bs->batch[bs->batch_ip].run)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Running batched command: %s\n",
bs->batch[bs->batch_ip].label);
/* hit end command, leap to next top-level command. */
- if (NULL == bs->batch[bs->batch_ip].label)
+ if (NULL == bs->batch[bs->batch_ip].run)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Exiting from batch: %s\n",
@@ -96,7 +96,7 @@ batch_cleanup (void *cls)
struct BatchState *bs = cls;
for (unsigned int i = 0;
- NULL != bs->batch[i].label;
+ NULL != bs->batch[i].run;
i++)
bs->batch[i].cleanup (bs->batch[i].cls);
GNUNET_free (bs->batch);
@@ -161,7 +161,7 @@ GNUNET_TESTING_cmd_batch (const char *label,
bs = GNUNET_new (struct BatchState);
bs->label = label;
/* Get number of commands. */
- for (i = 0; NULL != batch[i].label; i++)
+ for (i = 0; NULL != batch[i].run; i++)
/* noop */
;
@@ -170,17 +170,10 @@ GNUNET_TESTING_cmd_batch (const char *label,
memcpy (bs->batch,
batch,
sizeof (struct GNUNET_TESTING_Command) * i);
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = GNUNET_strdup (label),
- .run = &batch_run,
- .cleanup = &batch_cleanup,
- .traits = &batch_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (bs, label,
+ &batch_run,
+ &batch_cleanup,
+ &batch_traits, NULL);
}
@@ -189,7 +182,7 @@ GNUNET_TESTING_cmd_batch_next_ (void *cls)
{
struct BatchState *bs = cls;
- if (NULL == bs->batch[bs->batch_ip].label)
+ if (NULL == bs->batch[bs->batch_ip].run)
return false;
bs->batch[bs->batch_ip].finish_time
= GNUNET_TIME_absolute_get ();
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c
b/src/testing/testing_api_cmd_block_until_external_trigger.c
index b4f088077..1e2c3be7c 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -108,16 +108,9 @@ GNUNET_TESTING_cmd_block_until_external_trigger (
bs = GNUNET_new (struct BlockState);
bs->label = label;
bs->asynchronous_finish = GNUNET_NO;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = GNUNET_strdup (label),
- .run = &block_until_all_peers_started_run,
- .ac = &bs->ac,
- .cleanup = &block_until_all_peers_started_cleanup,
- .traits = block_until_external_trigger_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (bs, label,
+ &block_until_all_peers_started_run,
+ &block_until_all_peers_started_cleanup,
+ &block_until_external_trigger_traits,
+ &bs->ac);
}
diff --git a/src/testing/testing_api_cmd_end.c
b/src/testing/testing_api_cmd_end.c
index f0f036429..085420f81 100644
--- a/src/testing/testing_api_cmd_end.c
+++ b/src/testing/testing_api_cmd_end.c
@@ -29,11 +29,9 @@
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_end (void)
{
- static struct GNUNET_TESTING_Command cmd = {
- .label = NULL
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (NULL, NULL,
+ NULL, NULL,
+ NULL, NULL);
}
diff --git a/src/testing/testing_api_cmd_finish.c
b/src/testing/testing_api_cmd_finish.c
index cad5edc67..b352e28dc 100644
--- a/src/testing/testing_api_cmd_finish.c
+++ b/src/testing/testing_api_cmd_finish.c
@@ -175,17 +175,10 @@ GNUNET_TESTING_cmd_finish (const char *finish_label,
finish_state = GNUNET_new (struct FinishState);
finish_state->async_label = cmd_ref;
finish_state->timeout = timeout;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = finish_state,
- .label = GNUNET_strdup (finish_label),
- .run = &run_finish,
- .ac = &finish_state->ac,
- .cleanup = &cleanup_finish
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (finish_state, finish_label,
+ &run_finish,
+ &cleanup_finish,
+ NULL, &finish_state->ac);
}
diff --git a/src/testing/testing_api_cmd_local_test_finished.c
b/src/testing/testing_api_cmd_local_test_finished.c
index 7eca7e0d3..fb6fef030 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -107,14 +107,8 @@ GNUNET_TESTING_cmd_local_test_finished (
lfs = GNUNET_new (struct LocalFinishedState);
lfs->write_message = write_message;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = lfs,
- .label = GNUNET_strdup (label),
- .run = &local_test_finished_run,
- .cleanup = &local_test_finished_cleanup,
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (lfs, label,
+ &local_test_finished_run,
+ &local_test_finished_cleanup,
+ NULL, NULL);
}
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c
b/src/testing/testing_api_cmd_local_test_prepared.c
index a4082f0e3..3f976f554 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -102,14 +102,9 @@ GNUNET_TESTING_cmd_local_test_prepared (const char *label,
lfs = GNUNET_new (struct LocalPreparedState);
lfs->write_message = write_message;
- struct GNUNET_TESTING_Command cmd = {
- .cls = lfs,
- .label = GNUNET_strdup (label),
- .run = &local_test_prepared_run,
- .ac = &lfs->ac,
- .cleanup = &local_test_prepared_cleanup,
- .traits = &local_test_prepared_traits
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (lfs, label,
+ &local_test_prepared_run,
+ &local_test_prepared_cleanup,
+ &local_test_prepared_traits,
+ &lfs->ac);
}
diff --git a/src/testing/testing_api_cmd_netjail_start.c
b/src/testing/testing_api_cmd_netjail_start.c
index 8b239275b..9c1949c88 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -222,15 +222,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
ns->read_file = read_file;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = GNUNET_strdup (label),
- .run = &netjail_start_run,
- .ac = &ns->ac,
- .cleanup = &netjail_start_cleanup
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (ns, label,
+ &netjail_start_run,
+ &netjail_start_cleanup,
+ NULL, &ns->ac);
}
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c
b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index d33284b78..6663e9b82 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -284,9 +284,9 @@ send_message_to_locals (
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
if (0 == i)
- count = j;
+ count = j;
else
- count = (i - 1) * ns->local_m + j + ns->known;
+ count = (i - 1) * ns->local_m + j + ns->known;
helper = ns->helper[count - 1];
@@ -311,7 +311,7 @@ send_barrier_advanced (struct
GNUNET_TESTING_CommandBarrierReached *rm,
{
struct GNUNET_TESTING_CommandBarrierAdvanced *adm = GNUNET_new (struct
GNUNET_TESTING_CommandBarrierAdvanced);
size_t msg_length = sizeof(struct
GNUNET_TESTING_CommandAllLocalTestsPrepared);
-
+
adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
adm->header.size = htons ((uint16_t) msg_length);
adm->barrier_name = rm->barrier_name;
@@ -383,7 +383,6 @@ barrier_reached (struct NetJailState *ns, const struct
GNUNET_MessageHeader *mes
{
struct GNUNET_TESTING_CommandBarrierReached *rm = (struct
GNUNET_TESTING_CommandBarrierReached *) message;
struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (ns->is,
rm->barrier_name);
- struct GNUNET_TESTING_NetjailNode *node;
GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow);
barrier->reached++;
@@ -825,14 +824,9 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (
ns->topology_data = topology_data;
ns->timeout = GNUNET_TIME_relative_subtract (timeout, TIMEOUT);
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = GNUNET_strdup (label),
- .run = &netjail_exec_run,
- .ac = &ns->ac,
- .cleanup = &netjail_exec_cleanup,
- .traits = &netjail_exec_traits
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (ns, label,
+ &netjail_exec_run,
+ &netjail_exec_cleanup,
+ &netjail_exec_traits,
+ &ns->ac);
}
diff --git a/src/testing/testing_api_cmd_netjail_stop.c
b/src/testing/testing_api_cmd_netjail_stop.c
index 05435f63c..49151a168 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -189,15 +189,8 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
ns->read_file = read_file;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = GNUNET_strdup (label),
- .run = &netjail_stop_run,
- .ac = &ns->ac,
- .cleanup = &netjail_stop_cleanup
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (ns, label,
+ &netjail_stop_run,
+ &netjail_stop_cleanup,
+ NULL, &ns->ac);
}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 69455c909..38b14ac5c 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -147,12 +147,8 @@ GNUNET_TESTING_cmd_stop_testing_system (
shs->known = topology->nodes_x;
shs->topology = topology;
- struct GNUNET_TESTING_Command cmd = {
- .cls = shs,
- .label = GNUNET_strdup (label),
- .run = &stop_testing_system_run,
- .cleanup = &stop_testing_system_cleanup,
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (shs, label,
+ &stop_testing_system_run,
+ &stop_testing_system_cleanup,
+ NULL, NULL);
}
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c
b/src/testing/testing_api_cmd_send_peer_ready.c
index f277b8dbd..d76a95ae8 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -113,15 +113,8 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label,
sprs = GNUNET_new (struct SendPeerReadyState);
sprs->write_message = write_message;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = sprs,
- .label = GNUNET_strdup (label),
- .run = &send_peer_ready_run,
- .cleanup = &send_peer_ready_cleanup,
- .traits = &send_peer_ready_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (sprs, label,
+ &send_peer_ready_run,
+ &send_peer_ready_cleanup,
+ &send_peer_ready_traits, NULL);
}
diff --git a/src/testing/testing_api_cmd_system_create.c
b/src/testing/testing_api_cmd_system_create.c
index 4199eccd6..66b0f57b9 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -117,13 +117,7 @@ GNUNET_TESTING_cmd_system_create (const char *label,
tss = GNUNET_new (struct TestSystemState);
tss->testdir = testdir;
- struct GNUNET_TESTING_Command cmd = {
- .cls = tss,
- .label = GNUNET_strdup (label),
- .run = &system_create_run,
- .cleanup = &system_create_cleanup,
- .traits = &system_create_traits
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (tss, label, &system_create_run,
+ &system_create_cleanup,
+ &system_create_traits, NULL);
}
diff --git a/src/testing/testing_api_cmd_system_destroy.c
b/src/testing/testing_api_cmd_system_destroy.c
index ebb975fc3..23d8b9162 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -104,15 +104,7 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
tss = GNUNET_new (struct TestSystemState);
tss->create_label = create_label;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = tss,
- .label = GNUNET_strdup (label),
- .run = &system_destroy_run,
- .cleanup = &system_destroy_cleanup,
- .traits = &system_destroy_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (tss, label, &system_destroy_run,
+ &system_destroy_cleanup,
+ &system_destroy_traits, NULL);
}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index a3a8219b3..da95500f7 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -149,12 +149,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
{
const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
- if (NULL != cmd->label)
+ if (NULL != cmd->run)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"label to compare %s\n",
cmd->label);
/* Give precedence to top-level commands. */
- if ( (NULL != cmd->label) &&
+ if ( (NULL != cmd->run) &&
(0 == strcmp (cmd->label,
label)) )
return cmd;
@@ -173,12 +173,12 @@ get_command (struct GNUNET_TESTING_Interpreter *is,
/* We must do the loop forward, but we can find the last match */
match = NULL;
for (unsigned int j = 0;
- NULL != (icmd = &(*batch)[j])->label;
+ NULL != (icmd = &(*batch)[j])->run;
j++)
{
if (current == icmd)
break; /* do not go past current command */
- if ( (NULL != icmd->label) &&
+ if ( (NULL != icmd->run) &&
(0 == strcmp (icmd->label,
label)) )
match = icmd;
@@ -264,14 +264,13 @@ finish_test (void *cls)
label,
is->result);
for (unsigned int j = 0;
- NULL != (cmd = &is->commands[j])->label;
+ NULL != (cmd = &is->commands[j])->run;
j++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Cleaning up cmd %s\n",
cmd->label);
cmd->cleanup (cmd->cls);
- GNUNET_free (cmd->label);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Cleaned up cmd %s\n",
cmd->label);
@@ -407,7 +406,7 @@ interpreter_run (void *cls)
struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
is->task = NULL;
- if (NULL == cmd->label)
+ if (NULL == cmd->run)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Running command END\n");
@@ -490,7 +489,7 @@ GNUNET_TESTING_finished (const struct
GNUNET_TESTING_Command *command)
struct GNUNET_TESTING_Interpreter *
-GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
+GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_ResultCallback rc,
void *rc_cls)
@@ -503,7 +502,7 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
is->rc_cls = rc_cls;
is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
/* get the number of commands */
- for (i = 0; NULL != commands[i].label; i++)
+ for (i = 0; NULL != commands[i].run; i++)
;
is->cmds_n = i + 1;
is->commands = GNUNET_new_array (is->cmds_n,
@@ -521,6 +520,27 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command
*commands,
return is;
}
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_command_new (void *cls,
+ const char *label,
+ GNUNET_TESTING_CommandRunRoutine run,
+ GNUNET_TESTING_CommandCleanupRoutine cleanup,
+ GNUNET_TESTING_CommandGetTraits traits,
+ struct GNUNET_TESTING_AsyncContext *ac)
+{
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = cls,
+ .run = run,
+ .ac = ac,
+ .cleanup = cleanup,
+ .traits = traits
+ };
+ memset (&cmd, 0, sizeof (cmd));
+ strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
+
+ return cmd;
+
+}
/**
* Closure for #loop_run().
@@ -658,6 +678,7 @@ free_barrier_node_cb (void *cls,
node->node_number);
}
GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node);
+ return GNUNET_YES;
}
@@ -708,7 +729,6 @@ free_barriers_cb (void *cls,
struct GNUNET_TESTING_Interpreter *is = cls;
struct GNUNET_TESTING_Barrier *barrier = value;
struct GNUNET_TESTING_Command *pos;
- struct GNUNET_TESTING_NetjailNode *node;
struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
@@ -725,6 +745,7 @@ free_barriers_cb (void *cls,
GNUNET_free (pos);
}
GNUNET_free (barrier);
+ return GNUNET_YES;
}
@@ -756,7 +777,6 @@ GNUNET_TESTING_get_barrier (struct
GNUNET_TESTING_Interpreter *is,
struct GNUNET_HashCode hc;
struct GNUNET_ShortHashCode create_key;
struct GNUNET_TESTING_Barrier *barrier;
- unsigned int kx;
GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc);
memcpy (&create_key,
diff --git a/src/transport/transport_api_cmd_backchannel_check.c
b/src/transport/transport_api_cmd_backchannel_check.c
index e67d9a79c..9f62281a4 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -545,14 +545,10 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
cs->node_n = node_n;
cs->namespace_n = namespace_n;
- struct GNUNET_TESTING_Command cmd = {
- .cls = cs,
- .label = GNUNET_strdup (label),
- .run = &backchannel_check_run,
- .ac = &cs->ac,
- .cleanup = &backchannel_check_cleanup,
- .traits = &backchannel_check_traits
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (cs,
+ label,
+ &backchannel_check_run,
+ &backchannel_check_cleanup,
+ &backchannel_check_traits,
+ &cs->ac);
}
diff --git a/src/transport/transport_api_cmd_connecting_peers.c
b/src/transport/transport_api_cmd_connecting_peers.c
index d610bbcb7..528e05b5f 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -251,16 +251,10 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
cps->notify_connect = notify_connect;
cps->additional_connects = additional_connects;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = cps,
- .label = GNUNET_strdup (label),
- .run = &connect_peers_run,
- .ac = &cps->ac,
- .cleanup = &connect_peers_cleanup,
- .traits = &connect_peers_traits
- };
-
- return cmd;
- }
+ return GNUNET_TESTING_command_new (cps,
+ label,
+ &connect_peers_run,
+ &connect_peers_cleanup,
+ &connect_peers_traits,
+ &cps->ac);
}
diff --git a/src/transport/transport_api_cmd_send_simple.c
b/src/transport/transport_api_cmd_send_simple.c
index 73edcf549..2671727c0 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -153,12 +153,10 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
sss->create_label = create_label;
sss->topology = topology;
- struct GNUNET_TESTING_Command cmd = {
- .cls = sss,
- .label = GNUNET_strdup (label),
- .run = &send_simple_run,
- .cleanup = &send_simple_cleanup
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (sss,
+ label,
+ &send_simple_run,
+ &send_simple_cleanup,
+ NULL,
+ NULL);
}
diff --git a/src/transport/transport_api_cmd_start_peer.c
b/src/transport/transport_api_cmd_start_peer.c
index 7de1d842e..0677b6227 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -469,15 +469,10 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
handlers,
i * sizeof(struct GNUNET_MQ_MessageHandler));
}
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = sps,
- .label = GNUNET_strdup (label),
- .run = &start_peer_run,
- .ac = &sps->ac,
- .cleanup = &start_peer_cleanup,
- .traits = &start_peer_traits
- };
-
- return cmd;
+ return GNUNET_TESTING_command_new (sps,
+ label,
+ &start_peer_run,
+ &start_peer_cleanup,
+ &start_peer_traits,
+ &sps->ac);
}
diff --git a/src/transport/transport_api_cmd_stop_peer.c
b/src/transport/transport_api_cmd_stop_peer.c
index 04c822155..1fdd48fa6 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -143,14 +143,10 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
sps = GNUNET_new (struct StopPeerState);
sps->start_label = start_label;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = sps,
- .label = GNUNET_strdup (label),
- .run = &stop_peer_run,
- .cleanup = &stop_peer_cleanup,
- .traits = &stop_peer_traits
- };
- return cmd;
- }
+ return GNUNET_TESTING_command_new (sps,
+ label,
+ &stop_peer_run,
+ &stop_peer_cleanup,
+ &stop_peer_traits,
+ NULL);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API,
gnunet <=