aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/gnunet-cmds-helper.c10
-rw-r--r--src/testing/test_testing_topology.c44
-rw-r--r--src/testing/testing.c264
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c2
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c168
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c181
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c2
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c22
-rw-r--r--src/testing/testing_api_loop.c19
-rw-r--r--src/testing/testing_cmds.h17
11 files changed, 674 insertions, 56 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index efb22b279..07caeb44e 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -44,6 +44,7 @@ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
44 44
45libgnunettesting_la_SOURCES = \ 45libgnunettesting_la_SOURCES = \
46 testing_api_cmd_local_test_finished.c \ 46 testing_api_cmd_local_test_finished.c \
47 testing_api_cmd_local_test_prepared.c \
47 testing_api_cmd_send_peer_ready.c \ 48 testing_api_cmd_send_peer_ready.c \
48 testing_api_cmd_block_until_all_peers_started.c \ 49 testing_api_cmd_block_until_all_peers_started.c \
49 testing_api_cmd_block_until_external_trigger.c \ 50 testing_api_cmd_block_until_external_trigger.c \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index e50db0cf6..4aeccb115 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -418,9 +418,19 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
418 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 418 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
419 message->type)) 419 message->type))
420 { 420 {
421 LOG (GNUNET_ERROR_TYPE_DEBUG,
422 "all peers started\n");
421 plugin->api->all_peers_started (); 423 plugin->api->all_peers_started ();
422 return GNUNET_OK; 424 return GNUNET_OK;
423 } 425 }
426 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED == ntohs (
427 message->type))
428 {
429 LOG (GNUNET_ERROR_TYPE_DEBUG,
430 "all local tests prepared\n");
431 plugin->api->all_local_tests_prepared ();
432 return GNUNET_OK;
433 }
424 else 434 else
425 { 435 {
426 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 436 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
new file mode 100644
index 000000000..cfc91e609
--- /dev/null
+++ b/src/testing/test_testing_topology.c
@@ -0,0 +1,44 @@
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 testbed/plugin_testcmd.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
31
32int
33main (int argc,
34 char *const *argv)
35{
36 GNUNET_log_setup ("test-topology",
37 "DEBUG",
38 NULL);
39 LOG (GNUNET_ERROR_TYPE_DEBUG,
40 "Test\n");
41 GNUNET_TESTING_get_topo_from_file ("topo.conf");
42 LOG (GNUNET_ERROR_TYPE_DEBUG,
43 "Test2\n");
44}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a11d404a5..d3acd4689 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -37,6 +37,15 @@
37 37
38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 39
40#define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u:60002"
41
42#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u:60002"
43
44#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u:60002"
45
46#define PREFIX_TCP "tcp"
47
48#define PREFIX_UDP "udp"
40 49
41/** 50/**
42 * Lowest port used for GNUnet testing. Should be high enough to not 51 * Lowest port used for GNUnet testing. Should be high enough to not
@@ -1900,7 +1909,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1900 unsigned int namespace_n; 1909 unsigned int namespace_n;
1901 char *rest = NULL; 1910 char *rest = NULL;
1902 char *rest2 = NULL; 1911 char *rest2 = NULL;
1903 struct GNUNET_TESTING_ADDRESS_PREFIX *prefix; 1912 struct GNUNET_TESTING_AddressPrefix *prefix;
1904 1913
1905 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection); 1914 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1906 node_connection->node = node; 1915 node_connection->node = node;
@@ -1936,7 +1945,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1936 } 1945 }
1937 while (NULL != (token = strtok_r (NULL, ":", &rest))) 1946 while (NULL != (token = strtok_r (NULL, ":", &rest)))
1938 { 1947 {
1939 prefix = GNUNET_new (struct GNUNET_TESTING_ADDRESS_PREFIX); 1948 prefix = GNUNET_new (struct GNUNET_TESTING_AddressPrefix);
1940 token2 = strtok_r (token, "}", &rest2); 1949 token2 = strtok_r (token, "}", &rest2);
1941 if (NULL != token2) 1950 if (NULL != token2)
1942 { 1951 {
@@ -1958,13 +1967,12 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1958 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, 1967 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head,
1959 node_connection->address_prefixes_tail, 1968 node_connection->address_prefixes_tail,
1960 prefix); 1969 prefix);
1970 LOG (GNUNET_ERROR_TYPE_ERROR,
1971 "address_prefix %s\n",
1972 prefix->address_prefix);
1961 } 1973 }
1962 1974
1963 GNUNET_free (copy); 1975 GNUNET_free (copy);
1964 LOG (GNUNET_ERROR_TYPE_ERROR,
1965 "address_prefix %s\n",
1966 prefix->address_prefix);
1967
1968 return node_connection; 1976 return node_connection;
1969} 1977}
1970 1978
@@ -2006,6 +2014,250 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
2006} 2014}
2007 2015
2008 2016
2017static int
2018log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2019{
2020 struct GNUNET_TESTING_NetjailNode *node = value;
2021 struct GNUNET_TESTING_NodeConnection *pos_connection;
2022 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2023
2024 LOG (GNUNET_ERROR_TYPE_ERROR,
2025 "plugin: %s space: %u node: %u global: %u\n",
2026 node->plugin,
2027 node->namespace_n,
2028 node->node_n,
2029 node->is_global);
2030
2031 for (pos_connection = node->node_connections_head; NULL != pos_connection;
2032 pos_connection = pos_connection->next)
2033 {
2034
2035 LOG (GNUNET_ERROR_TYPE_ERROR,
2036 "namespace_n: %u node_n: %u node_type: %u\n",
2037 pos_connection->namespace_n,
2038 pos_connection->node_n,
2039 pos_connection->node_type);
2040
2041 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2042 pos_prefix =
2043 pos_prefix->next)
2044 {
2045 LOG (GNUNET_ERROR_TYPE_ERROR,
2046 "prefix: %s\n",
2047 pos_prefix->address_prefix);
2048 }
2049 }
2050 return GNUNET_YES;
2051}
2052
2053
2054static int
2055log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2056{
2057 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2058 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
2059
2060 LOG (GNUNET_ERROR_TYPE_ERROR,
2061 "router_tcp: %u router_udp: %u spaces: %u\n",
2062 router->tcp_port,
2063 router->udp_port,
2064 namespace->namespace_n);
2065 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2066 return GNUNET_YES;
2067}
2068
2069
2070static int
2071log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
2072{
2073 LOG (GNUNET_ERROR_TYPE_ERROR,
2074 "plugin: %s spaces: %u nodes: %u known: %u\n",
2075 topology->plugin,
2076 topology->namespaces_n,
2077 topology->nodes_m,
2078 topology->nodes_x);
2079
2080 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
2081 log_namespaces, NULL);
2082 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
2083 NULL);
2084 return GNUNET_YES;
2085}
2086
2087
2088/**
2089 * Get the connections to other nodes for a specific node.
2090 *
2091 * @param num The specific node we want the connections for.
2092 * @param topology The topology we get the connections from.
2093 * @return The connections of the node.
2094 */
2095struct GNUNET_TESTING_NodeConnection *
2096GNUNET_TESTING_get_connections (unsigned int num, struct
2097 GNUNET_TESTING_NetjailTopology *topology)
2098{
2099 struct GNUNET_TESTING_NetjailNode *node;
2100 struct GNUNET_ShortHashCode *hkey;
2101 struct GNUNET_HashCode hc;
2102 struct GNUNET_TESTING_NetjailNamespace *namespace;
2103 unsigned int namespace_n, node_m;
2104
2105 log_topo (topology);
2106
2107 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2108 if (topology->nodes_x >= num)
2109 {
2110
2111 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2112 memcpy (hkey,
2113 &hc,
2114 sizeof (*hkey));
2115 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
2116 hkey);
2117 }
2118 else
2119 {
2120 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
2121 / topology->nodes_m);
2122 LOG (GNUNET_ERROR_TYPE_ERROR,
2123 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2124 num,
2125 topology->nodes_x,
2126 topology->nodes_m,
2127 namespace_n);
2128 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2129 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2130 memcpy (hkey,
2131 &hc,
2132 sizeof (*hkey));
2133 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2134 hkey);
2135 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2136 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2137 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2138 memcpy (hkey,
2139 &hc,
2140 sizeof (*hkey));
2141 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2142 hkey);
2143 }
2144
2145
2146 return node->node_connections_head;
2147}
2148
2149
2150/**
2151 * Retrieve the public key from the test system with the unique node id.
2152 *
2153 * @param num The unique node id.
2154 * @param tl_system The test system.
2155 * @return The peer identity wrapping the public key.
2156 */
2157struct GNUNET_PeerIdentity *
2158GNUNET_TESTING_get_pub_key (unsigned int num, struct
2159 GNUNET_TESTING_System *tl_system)
2160{
2161 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
2162 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2163 GNUNET_CRYPTO_EddsaPublicKey);
2164 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
2165 GNUNET_CRYPTO_EddsaPrivateKey);
2166
2167 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2168 num,
2169 peer);
2170
2171 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
2172 pub_key);
2173 peer->public_key = *pub_key;
2174 return peer;
2175}
2176
2177
2178/**
2179 * Calculate the unique id identifying a node from a given connction.
2180 *
2181 * @param node_connection The connection we calculate the id from.
2182 * @param topology The topology we get all needed information from.
2183 * @return The unique id of the node from the connection.
2184 */
2185unsigned int
2186GNUNET_TESTING_calculate_num (struct
2187 GNUNET_TESTING_NodeConnection *node_connection,
2188 struct GNUNET_TESTING_NetjailTopology *topology)
2189{
2190 unsigned int n, m, num;
2191
2192 n = node_connection->namespace_n;
2193 m = node_connection->node_n;
2194
2195 if (0 == n)
2196 num = m;
2197 else
2198 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2199
2200 return num;
2201}
2202
2203
2204/**
2205 * Get the address for a specific communicator from a connection.
2206 *
2207 * @param connection The connection we like to have the address from.
2208 * @param prefix The communicator protocol prefix.
2209 * @return The address of the communicator.
2210 */
2211char *
2212GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
2213 char *prefix)
2214{
2215 struct GNUNET_TESTING_NetjailNode *node;
2216 char *addr;
2217 char *template;
2218
2219 LOG (GNUNET_ERROR_TYPE_ERROR,
2220 "node_n: %u\n",
2221 connection->node_n);
2222
2223 node = connection->node;
2224 if (connection->namespace_n == node->namespace_n)
2225 {
2226 template = CONNECT_ADDRESS_TEMPLATE;
2227 }
2228 else if (0 == connection->namespace_n)
2229 {
2230 template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2231 }
2232 else
2233 {
2234 template = ROUTER_CONNECT_ADDRESS_TEMPLATE;
2235 }
2236
2237 if (0 == strcmp (PREFIX_TCP, prefix))
2238 {
2239
2240 GNUNET_asprintf (&addr,
2241 template,
2242 prefix,
2243 connection->node_n);
2244 }
2245 else if (0 == strcmp (PREFIX_UDP, prefix))
2246 {
2247 GNUNET_asprintf (&addr,
2248 template,
2249 prefix,
2250 connection->node_n);
2251 }
2252 else
2253 {
2254 GNUNET_break (0);
2255 }
2256
2257 return addr;
2258}
2259
2260
2009/** 2261/**
2010 * Getting the topology from file. 2262 * Getting the topology from file.
2011 * 2263 *
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 383de4c10..b50e471e9 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -115,7 +115,7 @@ local_test_finished_finish (void *cls,
115 GNUNET_SCHEDULER_TaskCallback cont, 115 GNUNET_SCHEDULER_TaskCallback cont,
116 void *cont_cls) 116 void *cont_cls)
117{ 117{
118 LOG (GNUNET_ERROR_TYPE_DEBUG, 118 LOG (GNUNET_ERROR_TYPE_ERROR,
119 "Stopping local loop\n"); 119 "Stopping local loop\n");
120 return GNUNET_YES; 120 return GNUNET_YES;
121} 121}
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
new file mode 100644
index 000000000..4e915c7c0
--- /dev/null
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -0,0 +1,168 @@
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_api_cmd_local_test_prepared.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testing_cmds.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36
37/**
38 * Struct to hold information for callbacks.
39 *
40 */
41struct LocalPreparedState
42{
43 /**
44 * Callback to write messages to the master loop.
45 *
46 */
47 TESTING_CMD_HELPER_write_cb write_message;
48
49 /**
50 * The message send back to the master loop.
51 *
52 */
53 struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply;
54
55 /**
56 * Flag indicating if all local tests finished.
57 */
58 unsigned int *all_local_tests_prepared;
59};
60
61
62/**
63 * Trait function of this cmd does nothing.
64 *
65 */
66static int
67local_test_prepared_traits (void *cls,
68 const void **ret,
69 const char *trait,
70 unsigned int index)
71{
72 return GNUNET_OK;
73}
74
75
76/**
77 * The cleanup function of this cmd frees resources the cmd allocated.
78 *
79 */
80static void
81local_test_prepared_cleanup (void *cls,
82 const struct GNUNET_TESTING_Command *cmd)
83{
84 struct LocalPreparedState *lfs = cls;
85
86 GNUNET_free (lfs->reply);
87 GNUNET_free (lfs);
88}
89
90
91/**
92 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop.
93 *
94 */
95static void
96local_test_prepared_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is)
99{
100 struct LocalPreparedState *lfs = cls;
101
102 struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply;
103 size_t msg_length;
104
105 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_TEST_PREPARED);
106 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_TEST_PREPARED);
107 reply->header.type = htons (
108 GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED);
109 reply->header.size = htons ((uint16_t) msg_length);
110 lfs->reply = reply;
111 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
112}
113
114
115/**
116 * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
117 *
118 */
119static int
120local_test_prepared_finish (void *cls,
121 GNUNET_SCHEDULER_TaskCallback cont,
122 void *cont_cls)
123{
124 struct LocalPreparedState *lfs = cls;
125 unsigned int *ret = lfs->all_local_tests_prepared;
126
127 if (GNUNET_YES == *ret)
128 {
129 cont (cont_cls);
130 }
131
132 return *ret;
133
134}
135
136
137/**
138 * Create command.
139 *
140 * @param label name for command.
141 * @param write_message Callback to write messages to the master loop.
142 * @param all_local_tests_prepared Flag which will be set from outside.
143 * @return command.
144 */
145struct GNUNET_TESTING_Command
146GNUNET_TESTING_cmd_local_test_prepared (const char *label,
147 TESTING_CMD_HELPER_write_cb
148 write_message,
149 unsigned int *
150 all_local_tests_prepared)
151{
152 struct LocalPreparedState *lfs;
153
154 lfs = GNUNET_new (struct LocalPreparedState);
155 lfs->write_message = write_message;
156 lfs->all_local_tests_prepared = all_local_tests_prepared;
157
158 struct GNUNET_TESTING_Command cmd = {
159 .cls = lfs,
160 .label = label,
161 .run = &local_test_prepared_run,
162 .finish = &local_test_prepared_finish,
163 .cleanup = &local_test_prepared_cleanup,
164 .traits = &local_test_prepared_traits
165 };
166
167 return cmd;
168}
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
index ccb3f5ae8..5e27a7a82 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -30,6 +30,11 @@
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh"
31 31
32/** 32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37/**
33 * Struct to store messages send/received by the helper into a DLL 38 * Struct to store messages send/received by the helper into a DLL
34 * 39 *
35 */ 40 */
@@ -116,13 +121,13 @@ struct NetJailState
116 /** 121 /**
117 * The send handle for the helper 122 * The send handle for the helper
118 */ 123 */
119 struct GNUNET_HELPER_SendHandle **shandle; 124 // struct GNUNET_HELPER_SendHandle **shandle;
120 125
121 /** 126 /**
122 * Size of the array NetJailState#shandle. 127 * Size of the array NetJailState#shandle.
123 * 128 *
124 */ 129 */
125 unsigned int n_shandle; 130 // unsigned int n_shandle;
126 131
127 /** 132 /**
128 * The messages send to the helper. 133 * The messages send to the helper.
@@ -151,7 +156,13 @@ struct NetJailState
151 * Number of local tests finished. 156 * Number of local tests finished.
152 * 157 *
153 */ 158 */
154 unsigned int number_of_local_test_finished; 159 unsigned int number_of_local_tests_finished;
160
161 /**
162 * Number of local tests prepared to finish.
163 *
164 */
165 unsigned int number_of_local_tests_prepared;
155 166
156 /** 167 /**
157 * Name of the test case plugin the helper will load. 168 * Name of the test case plugin the helper will load.
@@ -189,6 +200,17 @@ struct TestingSystemCount
189 struct TestingSystemCount *prev; 200 struct TestingSystemCount *prev;
190 201
191 /** 202 /**
203 * The send handle for the helper
204 */
205 struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
206
207 /**
208 * Size of the array NetJailState#shandle.
209 *
210 */
211 // unsigned int n_shandle;
212
213 /**
192 * The number of the test environment. 214 * The number of the test environment.
193 * 215 *
194 */ 216 */
@@ -277,10 +299,9 @@ netjail_exec_traits (void *cls,
277 * @return #GNUNET_OK on success. 299 * @return #GNUNET_OK on success.
278 */ 300 */
279int 301int
280GNUNET_TESTING_get_trait_helper_handles_v2 (const struct 302GNUNET_TESTING_get_trait_helper_handles_v2 (
281 GNUNET_TESTING_Command *cmd, 303 const struct GNUNET_TESTING_Command *cmd,
282 struct GNUNET_HELPER_Handle *** 304 struct GNUNET_HELPER_Handle ***helper)
283 helper)
284{ 305{
285 return cmd->traits (cmd->cls, 306 return cmd->traits (cmd->cls,
286 (const void **) helper, 307 (const void **) helper,
@@ -293,18 +314,19 @@ GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
293 * Continuation function from GNUNET_HELPER_send() 314 * Continuation function from GNUNET_HELPER_send()
294 * 315 *
295 * @param cls closure 316 * @param cls closure
296 * @param result GNUNET_OK on success, 317 * @param result #GNUNET_OK on success,
297 * GNUNET_NO if helper process died 318 * #GNUNET_NO if helper process died
298 * GNUNET_SYSERR during GNUNET_HELPER_stop 319 * #GNUNET_SYSERR during GNUNET_HELPER_stop
299 */ 320 */
300static void 321static void
301clear_msg (void *cls, int result) 322clear_msg (void *cls,
323 int result)
302{ 324{
303 struct TestingSystemCount *tbc = cls; 325 struct TestingSystemCount *tbc = cls;
304 struct NetJailState *ns = tbc->ns; 326 struct NetJailState *ns = tbc->ns;
305 327
306 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 328 GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
307 ns->shandle[tbc->count - 1] = NULL; 329 tbc->shandle = NULL;// [tbc->count - 1] = NULL;
308 GNUNET_free (ns->msg[tbc->count - 1]); 330 GNUNET_free (ns->msg[tbc->count - 1]);
309 ns->msg[tbc->count - 1] = NULL; 331 ns->msg[tbc->count - 1] = NULL;
310} 332}
@@ -323,10 +345,11 @@ clear_msg (void *cls, int result)
323 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 345 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
324 */ 346 */
325static int 347static int
326helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 348helper_mst (void *cls,
349 const struct GNUNET_MessageHeader *message)
327{ 350{
328 struct TestingSystemCount *tbc = cls; 351 // struct TestingSystemCount *tbc = cls;
329 struct NetJailState *ns = tbc->ns; 352 struct NetJailState *ns = cls;// tbc->ns;
330 struct HelperMessage *hp_msg; 353 struct HelperMessage *hp_msg;
331 354
332 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 355 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
@@ -338,10 +361,18 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
338 { 361 {
339 ns->number_of_peers_started++; 362 ns->number_of_peers_started++;
340 } 363 }
364 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
365 message->type))
366 {
367 LOG (GNUNET_ERROR_TYPE_DEBUG,
368 "received prepare msg %u\n",
369 ns->number_of_local_tests_prepared);
370 ns->number_of_local_tests_prepared++;
371 }
341 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 372 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
342 message->type)) 373 message->type))
343 { 374 {
344 ns->number_of_local_test_finished++; 375 ns->number_of_local_tests_finished++;
345 } 376 }
346 else 377 else
347 { 378 {
@@ -364,8 +395,10 @@ static void
364exp_cb (void *cls) 395exp_cb (void *cls)
365{ 396{
366 struct NetJailState *ns = cls; 397 struct NetJailState *ns = cls;
398 unsigned int *rv = ns->rv;
399
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
368 *ns->rv = 1; 401 *rv = 1;
369} 402}
370 403
371 404
@@ -420,6 +453,7 @@ start_helper (struct NetJailState *ns, struct
420 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 453 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
421 struct GNUNET_TESTING_NetjailNode *node; 454 struct GNUNET_TESTING_NetjailNode *node;
422 struct GNUNET_TESTING_NetjailNamespace *namespace; 455 struct GNUNET_TESTING_NetjailNamespace *namespace;
456 unsigned int *rv = ns->rv;
423 457
424 458
425 if (0 == n) 459 if (0 == n)
@@ -460,7 +494,8 @@ start_helper (struct NetJailState *ns, struct
460 else 494 else
461 tbc->count = (n - 1) * ns->local_m + m + ns->known; 495 tbc->count = (n - 1) * ns->local_m + m + ns->known;
462 496
463 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, 497 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
498 ns->tbcs_tail,
464 tbc); 499 tbc);
465 500
466 501
@@ -469,14 +504,14 @@ start_helper (struct NetJailState *ns, struct
469 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
470 "No SUID for %s!\n", 505 "No SUID for %s!\n",
471 NETJAIL_EXEC_SCRIPT); 506 NETJAIL_EXEC_SCRIPT);
472 *ns->rv = 1; 507 *rv = 1;
473 } 508 }
474 else if (GNUNET_NO == helper_check) 509 else if (GNUNET_NO == helper_check)
475 { 510 {
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "%s not found!\n", 512 "%s not found!\n",
478 NETJAIL_EXEC_SCRIPT); 513 NETJAIL_EXEC_SCRIPT);
479 *ns->rv = 1; 514 *rv = 1;
480 } 515 }
481 516
482 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 517 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
@@ -485,7 +520,7 @@ start_helper (struct NetJailState *ns, struct
485 script_argv, 520 script_argv,
486 &helper_mst, 521 &helper_mst,
487 &exp_cb, 522 &exp_cb,
488 tbc)); 523 ns));
489 524
490 helper = ns->helper[tbc->count - 1]; 525 helper = ns->helper[tbc->count - 1];
491 526
@@ -542,19 +577,20 @@ start_helper (struct NetJailState *ns, struct
542 577
543 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 578 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
544 579
545 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 580 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
546 helper, 581 tbc->shandle = GNUNET_HELPER_send (
547 &msg->header, 582 helper,
548 GNUNET_NO, 583 &msg->header,
549 &clear_msg, 584 GNUNET_NO,
550 tbc)); 585 &clear_msg,
586 tbc); // );
551 587
552 if (NULL == ns->shandle[tbc->count - 1]) 588 if (NULL == tbc->shandle)// [tbc->count - 1])
553 { 589 {
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Send handle is NULL!\n"); 591 "Send handle is NULL!\n");
556 GNUNET_free (msg); 592 GNUNET_free (msg);
557 *ns->rv = 1; 593 *rv = 1;
558 } 594 }
559} 595}
560 596
@@ -595,39 +631,76 @@ netjail_exec_run (void *cls,
595 631
596 632
597static void 633static void
598send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) 634send_message_to_locals (
635 unsigned int i,
636 unsigned int j,
637 struct NetJailState *ns,
638 struct GNUNET_MessageHeader *header
639 )
599{ 640{
600 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 641 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
601 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
602 size_t msg_length;
603 struct GNUNET_HELPER_Handle *helper; 642 struct GNUNET_HELPER_Handle *helper;
604 struct TestingSystemCount *tbc; 643 struct TestingSystemCount *tbc;
605 644
645 LOG (GNUNET_ERROR_TYPE_DEBUG,
646 "send message to locals\n");
606 tbc = GNUNET_new (struct TestingSystemCount); 647 tbc = GNUNET_new (struct TestingSystemCount);
607 tbc->ns = ns; 648 tbc->ns = ns;
608 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. 649 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
609 if (0 == i) 650 if (0 == i)
610 tbc->count = j + total_number; 651 tbc->count = j; // + total_number;
611 else 652 else
612 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; 653 tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
613 654
614 helper = ns->helper[tbc->count - 1 - total_number]; 655 helper = ns->helper[tbc->count - 1];// - total_number];
615 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
616 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
617 reply->header.type = htons (
618 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
619 reply->header.size = htons ((uint16_t) msg_length);
620 656
621 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); 657 GNUNET_array_append (ns->msg, ns->n_msg, header);
622 658
623 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( 659 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
624 helper, 660 helper,
625 &reply->header, 661 header,
626 GNUNET_NO, 662 GNUNET_NO,
627 &clear_msg, 663 &clear_msg,
628 tbc); 664 tbc);
629 665
630 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 666 tbc->shandle = sh;
667 // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
668}
669
670
671static void
672send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
673 NetJailState *ns)
674{
675 struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
676 size_t msg_length;
677
678
679 msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
680 reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
681 reply->header.type = htons (
682 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
683 reply->header.size = htons ((uint16_t) msg_length);
684
685 send_message_to_locals (i, j, ns, &reply->header);
686}
687
688
689static void
690send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
691{
692
693 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
694 size_t msg_length;
695
696
697 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
698 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
699 reply->header.type = htons (
700 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
701 reply->header.size = htons ((uint16_t) msg_length);
702
703 send_message_to_locals (i, j, ns, &reply->header);
631} 704}
632 705
633 706
@@ -650,12 +723,28 @@ netjail_start_finish (void *cls,
650 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 723 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
651 724
652 725
653 if (ns->number_of_local_test_finished == total_number) 726 if (ns->number_of_local_tests_finished == total_number)
654 { 727 {
655 ret = GNUNET_YES; 728 ret = GNUNET_YES;
656 cont (cont_cls); 729 cont (cont_cls);
657 } 730 }
658 731
732 if (ns->number_of_local_tests_prepared == total_number)
733 {
734 for (int i = 1; i <= ns->known; i++)
735 {
736 send_all_local_tests_prepared (0,i, ns);
737 }
738
739 for (int i = 1; i <= ns->global_n; i++)
740 {
741 for (int j = 1; j <= ns->local_m; j++)
742 {
743 send_all_local_tests_prepared (i,j, ns);
744 }
745 }
746 }
747
659 if (ns->number_of_testsystems_started == total_number) 748 if (ns->number_of_testsystems_started == total_number)
660 { 749 {
661 ns->number_of_testsystems_started = 0; 750 ns->number_of_testsystems_started = 0;
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
index 36fbb0e10..7d802db6a 100644
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_v2.c
@@ -75,7 +75,7 @@ netjail_start_cleanup (void *cls,
75 { 75 {
76 GNUNET_assert (0 == 76 GNUNET_assert (0 ==
77 GNUNET_OS_process_kill (ns->start_proc, 77 GNUNET_OS_process_kill (ns->start_proc,
78 SIGKILL)); 78 SIGTERM));
79 GNUNET_assert (GNUNET_OK == 79 GNUNET_assert (GNUNET_OK ==
80 GNUNET_OS_process_wait (ns->start_proc)); 80 GNUNET_OS_process_wait (ns->start_proc));
81 GNUNET_OS_process_destroy (ns->start_proc); 81 GNUNET_OS_process_destroy (ns->start_proc);
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
index 8eccc5764..6ce106eaa 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
@@ -45,6 +45,12 @@ struct StopHelperState
45 unsigned int local_m; 45 unsigned int local_m;
46 46
47 unsigned int global_n; 47 unsigned int global_n;
48
49 /**
50 * Number of global known nodes.
51 *
52 */
53 unsigned int known;
48}; 54};
49 55
50 56
@@ -97,11 +103,24 @@ stop_testing_system_run (void *cls,
97 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, 103 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
98 &helper); 104 &helper);
99 105
106 for (int i = 1; i <= shs->known; i++)
107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "i: %u\n",
110 i);
111 GNUNET_HELPER_stop (helper[i - 1],
112 GNUNET_YES);
113 }
114
100 for (int i = 1; i <= shs->global_n; i++) 115 for (int i = 1; i <= shs->global_n; i++)
101 { 116 {
102 for (int j = 1; j <= shs->local_m; j++) 117 for (int j = 1; j <= shs->local_m; j++)
103 { 118 {
104 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j - 1], 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "i: %u j: %u\n",
121 i,
122 j);
123 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
105 GNUNET_YES); 124 GNUNET_YES);
106 } 125 }
107 } 126 }
@@ -130,6 +149,7 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
130 shs->helper_start_label = helper_start_label; 149 shs->helper_start_label = helper_start_label;
131 shs->local_m = topology->nodes_m; 150 shs->local_m = topology->nodes_m;
132 shs->global_n = topology->namespaces_n; 151 shs->global_n = topology->namespaces_n;
152 shs->known = topology->nodes_x;
133 153
134 struct GNUNET_TESTING_Command cmd = { 154 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs, 155 .cls = shs,
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 0c24c0e26..ab095aafa 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -408,6 +408,22 @@ GNUNET_TESTING_cmd_end (void)
408{ 408{
409 static struct GNUNET_TESTING_Command cmd; 409 static struct GNUNET_TESTING_Command cmd;
410 cmd.label = NULL; 410 cmd.label = NULL;
411 cmd.shutdown_on_end = GNUNET_YES;
412
413 return cmd;
414}
415
416/**
417 * Create command array terminator without shutdown.
418 *
419 * @return a end-command.
420 */
421struct GNUNET_TESTING_Command
422GNUNET_TESTING_cmd_end_without_shutdown (void)
423{
424 static struct GNUNET_TESTING_Command cmd;
425 cmd.label = NULL;
426 cmd.shutdown_on_end = GNUNET_NO;
411 427
412 return cmd; 428 return cmd;
413} 429}
@@ -447,7 +463,8 @@ interpreter_run (void *cls)
447 "Running command END %p\n", 463 "Running command END %p\n",
448 is); 464 is);
449 is->result = GNUNET_OK; 465 is->result = GNUNET_OK;
450 GNUNET_SCHEDULER_shutdown (); 466 if (GNUNET_YES == cmd->shutdown_on_end)
467 GNUNET_SCHEDULER_shutdown ();
451 return; 468 return;
452 } 469 }
453 else if (NULL != cmd) 470 else if (NULL != cmd)
diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h
index 7a5860aea..005402a73 100644
--- a/src/testing/testing_cmds.h
+++ b/src/testing/testing_cmds.h
@@ -85,6 +85,23 @@ struct GNUNET_CMDS_LOCAL_FINISHED
85 struct GNUNET_MessageHeader header; 85 struct GNUNET_MessageHeader header;
86}; 86};
87 87
88struct GNUNET_CMDS_LOCAL_TEST_PREPARED
89{
90 /**
91 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED
92 */
93 struct GNUNET_MessageHeader header;
94};
95
96struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED
97{
98 /**
99 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED
100 */
101 struct GNUNET_MessageHeader header;
102};
103
88GNUNET_NETWORK_STRUCT_END 104GNUNET_NETWORK_STRUCT_END
105
89#endif 106#endif
90/* end of testing_cmds.h */ 107/* end of testing_cmds.h */