summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-12-01 14:06:12 +0100
committert3sserakt <t3ss@posteo.de>2021-12-01 14:06:12 +0100
commit1408842544b1cbea01efc636bdcb6be73a4e20a9 (patch)
tree238ee0392d0597d297f6dcfa613ea0000a01d6d3 /src/testing
parent5b4c1620bb7ed90d7bb26484c0a39807bb7f1dd5 (diff)
- using the big macrofication of the traits from GNU Taler now
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am2
-rw-r--r--src/testing/testing.c4
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c48
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c25
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c34
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c2
-rw-r--r--src/testing/testing_api_cmd_system_create.c24
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c4
-rw-r--r--src/testing/testing_api_trait_cmd.c79
-rw-r--r--src/testing/testing_api_trait_process.c81
-rw-r--r--src/testing/testing_api_traits.c7
11 files changed, 21 insertions, 289 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index a9a1b5a02..bcb45da70 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -44,8 +44,6 @@ libgnunettesting_la_SOURCES = \
testing_api_cmd_system_destroy.c \
testing_api_cmd_batch.c \
testing_api_loop.c \
- testing_api_trait_cmd.c \
- testing_api_trait_process.c \
testing_api_traits.c
libgnunettesting_la_LIBADD = \
$(top_builddir)/src/arm/libgnunetarm.la \
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 7474d9b5f..fd0701d7d 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -2169,8 +2169,8 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
* @return The peer identity wrapping the public key.
*/
struct GNUNET_PeerIdentity *
-GNUNET_TESTING_get_pub_key (unsigned int num, struct
- GNUNET_TESTING_System *tl_system)
+GNUNET_TESTING_get_pub_key (unsigned int num,
+ const struct GNUNET_TESTING_System *tl_system)
{
struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
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 9360dd02e..f51b2109b 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -55,16 +55,8 @@ block_until_external_trigger_traits (void *cls,
struct BlockState *bs = cls;
struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "async_context",
- .ptr = (const void *) ac,
- },
- {
- .index = 1,
- .trait_name = "block_state",
- .ptr = (const void *) bs,
- },
+ GNUNET_TESTING_make_trait_async_context ((const void *) ac),
+ GNUNET_TESTING_make_trait_block_state ((const void *) bs),
GNUNET_TESTING_trait_end ()
};
@@ -76,42 +68,6 @@ block_until_external_trigger_traits (void *cls,
/**
- * Function to get the trait with the internal command state BlockState.
- *
- * * @param[out] ac struct BlockState.
-* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- */
-int
-GNUNET_TESTING_get_trait_block_state (
- const struct GNUNET_TESTING_Command *cmd,
- struct BlockState **bs)
-{
- return cmd->traits (cmd->cls,
- (const void **) bs,
- "block_state",
- (unsigned int) 1);
-}
-
-
-/**
- * Function to get the trait with the async context.
- *
- * @param[out] ac struct GNUNET_TESTING_AsyncContext.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- */
-int
-GNUNET_TESTING_get_trait_async_context (
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_AsyncContext **ac)
-{
- return cmd->traits (cmd->cls,
- (const void **) ac,
- "async_context",
- (unsigned int) 0);
-}
-
-
-/**
* This function does nothing but to start the cmd.
*
*/
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 9dc7dfa9a..1f470a6c1 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -47,11 +47,7 @@ local_test_prepared_traits (void *cls,
{
struct LocalPreparedState *lfs = cls;
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "state",
- .ptr = (const void *) lfs,
- },
+ GNUNET_TESTING_make_trait_local_prepared_state ((const void *) lfs),
GNUNET_TESTING_trait_end ()
};
return GNUNET_TESTING_get_trait (traits,
@@ -62,25 +58,6 @@ local_test_prepared_traits (void *cls,
/**
- * Function to get the trait with the struct LocalPreparedState.
- *
- * @param[out] lfs struct LocalPreparedState.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- *
- */
-enum GNUNET_GenericReturnValue
-GNUNET_TESTING_get_trait_local_prepared_state (
- const struct GNUNET_TESTING_Command *cmd,
- struct LocalPreparedState **lfs)
-{
- return cmd->traits (cmd->cls,
- (const void **) lfs,
- "state",
- (unsigned int) 0);
-}
-
-
-/**
* The cleanup function of this cmd frees resources the cmd allocated.
*
*/
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 1709a58d2..d24ad3d28 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -86,7 +86,7 @@ struct NetJailState
/**
* Array with handles of helper processes.
*/
- struct GNUNET_HELPER_Handle **helper;
+ const struct GNUNET_HELPER_Handle **helper;
/**
* Size of the array NetJailState#helper.
@@ -211,22 +211,18 @@ netjail_exec_cleanup (void *cls)
* This function prepares an array with traits.
*
*/
-static int
+static enum GNUNET_GenericReturnValue
netjail_exec_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
struct NetJailState *ns = cls;
- struct GNUNET_HELPER_Handle **helper = ns->helper;
+ const struct GNUNET_HELPER_Handle **helper = ns->helper;
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "helper_handles",
- .ptr = (const void *) helper,
- },
+ GNUNET_TESTING_make_trait_helper_handles ((const void **) helper),
GNUNET_TESTING_trait_end ()
};
@@ -238,26 +234,6 @@ netjail_exec_traits (void *cls,
/**
- * Offer handles to testing cmd helper from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_helper_handles (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***
- helper)
-{
- return cmd->traits (cmd->cls,
- (const void **) helper,
- "helper_handles",
- (unsigned int) 0);
-}
-
-
-/**
* Continuation function from GNUNET_HELPER_send()
*
* @param cls closure
@@ -287,7 +263,7 @@ send_message_to_locals (
)
{
// unsigned int total_number = ns->local_m * ns->global_n + ns->known;
- struct GNUNET_HELPER_Handle *helper;
+ const struct GNUNET_HELPER_Handle *helper;
struct TestingSystemCount *tbc;
LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 4b52878c4..caf83ab0e 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -86,7 +86,7 @@ stop_testing_system_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct StopHelperState *shs = cls;
- struct GNUNET_HELPER_Handle **helper;
+ const struct GNUNET_HELPER_Handle **helper;
const struct GNUNET_TESTING_Command *start_helper_cmd;
start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 275132684..221bbb8f6 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -77,11 +77,7 @@ system_create_traits (void *cls,
struct GNUNET_TESTING_System *test_system = tss->test_system;
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "test_system",
- .ptr = (const void *) test_system,
- },
+ GNUNET_TESTING_make_trait_test_system ((const void *) test_system),
GNUNET_TESTING_trait_end ()
};
@@ -93,24 +89,6 @@ system_create_traits (void *cls,
/**
- * Function to get the trait with struct GNUNET_TESTING_System
- *
- * @param[out] test_system The struct GNUNET_TESTING_System.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- */
-int
-GNUNET_TESTING_get_trait_test_system (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_System **test_system)
-{
- return cmd->traits (cmd->cls,
- (const void **) test_system,
- "test_system",
- (unsigned int) 0);
-}
-
-
-/**
* The cleanup function of this cmd frees resources the cmd allocated.
*
*/
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index cdfc65d53..5a2440766 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -51,13 +51,13 @@ system_destroy_run (void *cls,
{
struct TestSystemState *tss = cls;
const struct GNUNET_TESTING_Command *system_cmd;
- struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_System *tl_system;
system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
tss->create_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
- GNUNET_TESTING_system_destroy (tl_system,
+ GNUNET_TESTING_system_destroy ((struct GNUNET_TESTING_System *) tl_system,
GNUNET_YES);
}
diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c
deleted file mode 100644
index 7afa8b264..000000000
--- a/src/testing/testing_api_trait_cmd.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_trait_cmd.c
- * @brief offers CMDs as traits.
- * @author Marcello Stanisci (GNU Taler testing)
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define GNUNET_TESTING_TRAIT_CMD "cmd"
-
-
-/**
- * Obtain a command from @a cmd.
- *
- * @param cmd command to extract the command from.
- * @param index always zero. Commands offering this
- * kind of traits do not need this index. For
- * example, a "batch" CMD returns always the
- * CMD currently being executed.
- * @param[out] _cmd where to write the wire details.
- * @return #GNUNET_OK on success.
- */
-enum GNUNET_GenericReturnValue
-GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
- unsigned int index,
- struct GNUNET_TESTING_Command **_cmd)
-{
- return cmd->traits (cmd->cls,
- (const void **) _cmd,
- GNUNET_TESTING_TRAIT_CMD,
- index);
-}
-
-
-/**
- * Offer a command in a trait.
- *
- * @param index always zero. Commands offering this
- * kind of traits do not need this index. For
- * example, a "meta" CMD returns always the
- * CMD currently being executed.
- * @param cmd wire details to offer.
- * @return the trait.
- */
-struct GNUNET_TESTING_Trait
-GNUNET_TESTING_make_trait_cmd (unsigned int index,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct GNUNET_TESTING_Trait ret = {
- .index = index,
- .trait_name = GNUNET_TESTING_TRAIT_CMD,
- .ptr = (const struct GNUNET_TESTING_Command *) cmd
- };
- return ret;
-}
-
-
-/* end of testing_api_trait_cmd.c */
diff --git a/src/testing/testing_api_trait_process.c b/src/testing/testing_api_trait_process.c
deleted file mode 100644
index 31cdb01df..000000000
--- a/src/testing/testing_api_trait_process.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_trait_process.c
- * @brief trait offering process handles.
- * @author Christian Grothoff (GNU Taler testing)
- * @author Marcello Stanisci (GNU Taler testing)
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define GNUNET_TESTING_TRAIT_PROCESS "process"
-
-
-/**
- * Obtain location where a command stores a pointer to a process.
- *
- * @param cmd command to extract trait from.
- * @param index which process to pick if @a cmd
- * has multiple on offer.
- * @param[out] processp set to the address of the pointer to the
- * process.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_process
- (const struct GNUNET_TESTING_Command *cmd,
- unsigned int index,
- struct GNUNET_OS_Process ***processp)
-{
- return cmd->traits (cmd->cls,
- (const void **) processp,
- GNUNET_TESTING_TRAIT_PROCESS,
- index);
-}
-
-
-/**
- * Offer location where a command stores a pointer to a process.
- *
- * @param index offered location index number, in case there are
- * multiple on offer.
- * @param processp process location to offer.
- *
- * @return the trait.
- */
-struct GNUNET_TESTING_Trait
-GNUNET_TESTING_make_trait_process
- (unsigned int index,
- struct GNUNET_OS_Process **processp)
-{
- struct GNUNET_TESTING_Trait ret = {
- .index = index,
- .trait_name = GNUNET_TESTING_TRAIT_PROCESS,
- .ptr = (const void *) processp
- };
-
- return ret;
-}
-
-
-/* end of testing_api_trait_process.c */
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index 2f836ddfa..9b54443a1 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -27,8 +27,15 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
+
+GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT)
+
+GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
+
/**
* End a trait array. Usually, commands offer several traits,
* and put them in arrays.