aboutsummaryrefslogtreecommitdiff
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)
downloadgnunet-1408842544b1cbea01efc636bdcb6be73a4e20a9.tar.gz
gnunet-1408842544b1cbea01efc636bdcb6be73a4e20a9.zip
- 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 = \
44 testing_api_cmd_system_destroy.c \ 44 testing_api_cmd_system_destroy.c \
45 testing_api_cmd_batch.c \ 45 testing_api_cmd_batch.c \
46 testing_api_loop.c \ 46 testing_api_loop.c \
47 testing_api_trait_cmd.c \
48 testing_api_trait_process.c \
49 testing_api_traits.c 47 testing_api_traits.c
50libgnunettesting_la_LIBADD = \ 48libgnunettesting_la_LIBADD = \
51 $(top_builddir)/src/arm/libgnunetarm.la \ 49 $(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
2169 * @return The peer identity wrapping the public key. 2169 * @return The peer identity wrapping the public key.
2170 */ 2170 */
2171struct GNUNET_PeerIdentity * 2171struct GNUNET_PeerIdentity *
2172GNUNET_TESTING_get_pub_key (unsigned int num, struct 2172GNUNET_TESTING_get_pub_key (unsigned int num,
2173 GNUNET_TESTING_System *tl_system) 2173 const struct GNUNET_TESTING_System *tl_system)
2174{ 2174{
2175 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); 2175 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
2176 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct 2176 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,
55 struct BlockState *bs = cls; 55 struct BlockState *bs = cls;
56 struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; 56 struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
57 struct GNUNET_TESTING_Trait traits[] = { 57 struct GNUNET_TESTING_Trait traits[] = {
58 { 58 GNUNET_TESTING_make_trait_async_context ((const void *) ac),
59 .index = 0, 59 GNUNET_TESTING_make_trait_block_state ((const void *) bs),
60 .trait_name = "async_context",
61 .ptr = (const void *) ac,
62 },
63 {
64 .index = 1,
65 .trait_name = "block_state",
66 .ptr = (const void *) bs,
67 },
68 GNUNET_TESTING_trait_end () 60 GNUNET_TESTING_trait_end ()
69 }; 61 };
70 62
@@ -76,42 +68,6 @@ block_until_external_trigger_traits (void *cls,
76 68
77 69
78/** 70/**
79 * Function to get the trait with the internal command state BlockState.
80 *
81 * * @param[out] ac struct BlockState.
82* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
83 */
84int
85GNUNET_TESTING_get_trait_block_state (
86 const struct GNUNET_TESTING_Command *cmd,
87 struct BlockState **bs)
88{
89 return cmd->traits (cmd->cls,
90 (const void **) bs,
91 "block_state",
92 (unsigned int) 1);
93}
94
95
96/**
97 * Function to get the trait with the async context.
98 *
99 * @param[out] ac struct GNUNET_TESTING_AsyncContext.
100 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
101 */
102int
103GNUNET_TESTING_get_trait_async_context (
104 const struct GNUNET_TESTING_Command *cmd,
105 struct GNUNET_TESTING_AsyncContext **ac)
106{
107 return cmd->traits (cmd->cls,
108 (const void **) ac,
109 "async_context",
110 (unsigned int) 0);
111}
112
113
114/**
115 * This function does nothing but to start the cmd. 71 * This function does nothing but to start the cmd.
116 * 72 *
117 */ 73 */
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,
47{ 47{
48 struct LocalPreparedState *lfs = cls; 48 struct LocalPreparedState *lfs = cls;
49 struct GNUNET_TESTING_Trait traits[] = { 49 struct GNUNET_TESTING_Trait traits[] = {
50 { 50 GNUNET_TESTING_make_trait_local_prepared_state ((const void *) lfs),
51 .index = 0,
52 .trait_name = "state",
53 .ptr = (const void *) lfs,
54 },
55 GNUNET_TESTING_trait_end () 51 GNUNET_TESTING_trait_end ()
56 }; 52 };
57 return GNUNET_TESTING_get_trait (traits, 53 return GNUNET_TESTING_get_trait (traits,
@@ -62,25 +58,6 @@ local_test_prepared_traits (void *cls,
62 58
63 59
64/** 60/**
65 * Function to get the trait with the struct LocalPreparedState.
66 *
67 * @param[out] lfs struct LocalPreparedState.
68 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
69 *
70 */
71enum GNUNET_GenericReturnValue
72GNUNET_TESTING_get_trait_local_prepared_state (
73 const struct GNUNET_TESTING_Command *cmd,
74 struct LocalPreparedState **lfs)
75{
76 return cmd->traits (cmd->cls,
77 (const void **) lfs,
78 "state",
79 (unsigned int) 0);
80}
81
82
83/**
84 * The cleanup function of this cmd frees resources the cmd allocated. 61 * The cleanup function of this cmd frees resources the cmd allocated.
85 * 62 *
86 */ 63 */
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
86 /** 86 /**
87 * Array with handles of helper processes. 87 * Array with handles of helper processes.
88 */ 88 */
89 struct GNUNET_HELPER_Handle **helper; 89 const struct GNUNET_HELPER_Handle **helper;
90 90
91 /** 91 /**
92 * Size of the array NetJailState#helper. 92 * Size of the array NetJailState#helper.
@@ -211,22 +211,18 @@ netjail_exec_cleanup (void *cls)
211 * This function prepares an array with traits. 211 * This function prepares an array with traits.
212 * 212 *
213 */ 213 */
214static int 214static enum GNUNET_GenericReturnValue
215netjail_exec_traits (void *cls, 215netjail_exec_traits (void *cls,
216 const void **ret, 216 const void **ret,
217 const char *trait, 217 const char *trait,
218 unsigned int index) 218 unsigned int index)
219{ 219{
220 struct NetJailState *ns = cls; 220 struct NetJailState *ns = cls;
221 struct GNUNET_HELPER_Handle **helper = ns->helper; 221 const struct GNUNET_HELPER_Handle **helper = ns->helper;
222 222
223 223
224 struct GNUNET_TESTING_Trait traits[] = { 224 struct GNUNET_TESTING_Trait traits[] = {
225 { 225 GNUNET_TESTING_make_trait_helper_handles ((const void **) helper),
226 .index = 0,
227 .trait_name = "helper_handles",
228 .ptr = (const void *) helper,
229 },
230 GNUNET_TESTING_trait_end () 226 GNUNET_TESTING_trait_end ()
231 }; 227 };
232 228
@@ -238,26 +234,6 @@ netjail_exec_traits (void *cls,
238 234
239 235
240/** 236/**
241 * Offer handles to testing cmd helper from trait
242 *
243 * @param cmd command to extract the message from.
244 * @param pt pointer to message.
245 * @return #GNUNET_OK on success.
246 */
247int
248GNUNET_TESTING_get_trait_helper_handles (const struct
249 GNUNET_TESTING_Command *cmd,
250 struct GNUNET_HELPER_Handle ***
251 helper)
252{
253 return cmd->traits (cmd->cls,
254 (const void **) helper,
255 "helper_handles",
256 (unsigned int) 0);
257}
258
259
260/**
261 * Continuation function from GNUNET_HELPER_send() 237 * Continuation function from GNUNET_HELPER_send()
262 * 238 *
263 * @param cls closure 239 * @param cls closure
@@ -287,7 +263,7 @@ send_message_to_locals (
287 ) 263 )
288{ 264{
289 // unsigned int total_number = ns->local_m * ns->global_n + ns->known; 265 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
290 struct GNUNET_HELPER_Handle *helper; 266 const struct GNUNET_HELPER_Handle *helper;
291 struct TestingSystemCount *tbc; 267 struct TestingSystemCount *tbc;
292 268
293 LOG (GNUNET_ERROR_TYPE_DEBUG, 269 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,
86 struct GNUNET_TESTING_Interpreter *is) 86 struct GNUNET_TESTING_Interpreter *is)
87{ 87{
88 struct StopHelperState *shs = cls; 88 struct StopHelperState *shs = cls;
89 struct GNUNET_HELPER_Handle **helper; 89 const struct GNUNET_HELPER_Handle **helper;
90 const struct GNUNET_TESTING_Command *start_helper_cmd; 90 const struct GNUNET_TESTING_Command *start_helper_cmd;
91 91
92 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 92 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,
77 struct GNUNET_TESTING_System *test_system = tss->test_system; 77 struct GNUNET_TESTING_System *test_system = tss->test_system;
78 78
79 struct GNUNET_TESTING_Trait traits[] = { 79 struct GNUNET_TESTING_Trait traits[] = {
80 { 80 GNUNET_TESTING_make_trait_test_system ((const void *) test_system),
81 .index = 0,
82 .trait_name = "test_system",
83 .ptr = (const void *) test_system,
84 },
85 GNUNET_TESTING_trait_end () 81 GNUNET_TESTING_trait_end ()
86 }; 82 };
87 83
@@ -93,24 +89,6 @@ system_create_traits (void *cls,
93 89
94 90
95/** 91/**
96 * Function to get the trait with struct GNUNET_TESTING_System
97 *
98 * @param[out] test_system The struct GNUNET_TESTING_System.
99 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
100 */
101int
102GNUNET_TESTING_get_trait_test_system (const struct
103 GNUNET_TESTING_Command *cmd,
104 struct GNUNET_TESTING_System **test_system)
105{
106 return cmd->traits (cmd->cls,
107 (const void **) test_system,
108 "test_system",
109 (unsigned int) 0);
110}
111
112
113/**
114 * The cleanup function of this cmd frees resources the cmd allocated. 92 * The cleanup function of this cmd frees resources the cmd allocated.
115 * 93 *
116 */ 94 */
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,
51{ 51{
52 struct TestSystemState *tss = cls; 52 struct TestSystemState *tss = cls;
53 const struct GNUNET_TESTING_Command *system_cmd; 53 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system; 54 const struct GNUNET_TESTING_System *tl_system;
55 55
56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
57 tss->create_label); 57 tss->create_label);
58 GNUNET_TESTING_get_trait_test_system (system_cmd, 58 GNUNET_TESTING_get_trait_test_system (system_cmd,
59 &tl_system); 59 &tl_system);
60 GNUNET_TESTING_system_destroy (tl_system, 60 GNUNET_TESTING_system_destroy ((struct GNUNET_TESTING_System *) tl_system,
61 GNUNET_YES); 61 GNUNET_YES);
62} 62}
63 63
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 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_trait_cmd.c
23 * @brief offers CMDs as traits.
24 * @author Marcello Stanisci (GNU Taler testing)
25 * @author t3sserakt
26 */
27#include "platform.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define GNUNET_TESTING_TRAIT_CMD "cmd"
31
32
33/**
34 * Obtain a command from @a cmd.
35 *
36 * @param cmd command to extract the command from.
37 * @param index always zero. Commands offering this
38 * kind of traits do not need this index. For
39 * example, a "batch" CMD returns always the
40 * CMD currently being executed.
41 * @param[out] _cmd where to write the wire details.
42 * @return #GNUNET_OK on success.
43 */
44enum GNUNET_GenericReturnValue
45GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
46 unsigned int index,
47 struct GNUNET_TESTING_Command **_cmd)
48{
49 return cmd->traits (cmd->cls,
50 (const void **) _cmd,
51 GNUNET_TESTING_TRAIT_CMD,
52 index);
53}
54
55
56/**
57 * Offer a command in a trait.
58 *
59 * @param index always zero. Commands offering this
60 * kind of traits do not need this index. For
61 * example, a "meta" CMD returns always the
62 * CMD currently being executed.
63 * @param cmd wire details to offer.
64 * @return the trait.
65 */
66struct GNUNET_TESTING_Trait
67GNUNET_TESTING_make_trait_cmd (unsigned int index,
68 const struct GNUNET_TESTING_Command *cmd)
69{
70 struct GNUNET_TESTING_Trait ret = {
71 .index = index,
72 .trait_name = GNUNET_TESTING_TRAIT_CMD,
73 .ptr = (const struct GNUNET_TESTING_Command *) cmd
74 };
75 return ret;
76}
77
78
79/* 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 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_trait_process.c
23 * @brief trait offering process handles.
24 * @author Christian Grothoff (GNU Taler testing)
25 * @author Marcello Stanisci (GNU Taler testing)
26 * @author t3sserakt
27 */
28#include "platform.h"
29#include "gnunet_testing_ng_lib.h"
30
31#define GNUNET_TESTING_TRAIT_PROCESS "process"
32
33
34/**
35 * Obtain location where a command stores a pointer to a process.
36 *
37 * @param cmd command to extract trait from.
38 * @param index which process to pick if @a cmd
39 * has multiple on offer.
40 * @param[out] processp set to the address of the pointer to the
41 * process.
42 * @return #GNUNET_OK on success.
43 */
44int
45GNUNET_TESTING_get_trait_process
46 (const struct GNUNET_TESTING_Command *cmd,
47 unsigned int index,
48 struct GNUNET_OS_Process ***processp)
49{
50 return cmd->traits (cmd->cls,
51 (const void **) processp,
52 GNUNET_TESTING_TRAIT_PROCESS,
53 index);
54}
55
56
57/**
58 * Offer location where a command stores a pointer to a process.
59 *
60 * @param index offered location index number, in case there are
61 * multiple on offer.
62 * @param processp process location to offer.
63 *
64 * @return the trait.
65 */
66struct GNUNET_TESTING_Trait
67GNUNET_TESTING_make_trait_process
68 (unsigned int index,
69 struct GNUNET_OS_Process **processp)
70{
71 struct GNUNET_TESTING_Trait ret = {
72 .index = index,
73 .trait_name = GNUNET_TESTING_TRAIT_PROCESS,
74 .ptr = (const void *) processp
75 };
76
77 return ret;
78}
79
80
81/* 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 @@
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_testing_ng_lib.h" 29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_netjail_lib.h"
30 31
31 32
33GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
34
35GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT)
36
37GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
38
32/** 39/**
33 * End a trait array. Usually, commands offer several traits, 40 * End a trait array. Usually, commands offer several traits,
34 * and put them in arrays. 41 * and put them in arrays.