diff options
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 140 |
1 files changed, 107 insertions, 33 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 4d9b7c0cb..02cedc744 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -1798,7 +1798,7 @@ get_first_value (char *line) | |||
1798 | memcpy (copy, line, slen); | 1798 | memcpy (copy, line, slen); |
1799 | token = strtok_r (copy, ":", &rest); | 1799 | token = strtok_r (copy, ":", &rest); |
1800 | token = strtok_r (NULL, ":", &rest); | 1800 | token = strtok_r (NULL, ":", &rest); |
1801 | sscanf (token, "%u", &ret); | 1801 | GNUNET_assert (1 == sscanf (token, "%u", &ret)); |
1802 | GNUNET_free (copy); | 1802 | GNUNET_free (copy); |
1803 | return ret; | 1803 | return ret; |
1804 | } | 1804 | } |
@@ -1864,7 +1864,7 @@ get_second_value (char *line) | |||
1864 | token = strtok_r (copy, ":", &rest); | 1864 | token = strtok_r (copy, ":", &rest); |
1865 | token = strtok_r (NULL, ":", &rest); | 1865 | token = strtok_r (NULL, ":", &rest); |
1866 | token = strtok_r (NULL, ":", &rest); | 1866 | token = strtok_r (NULL, ":", &rest); |
1867 | sscanf (token, "%u", &ret); | 1867 | GNUNET_assert (1 == sscanf (token, "%u", &ret)); |
1868 | GNUNET_free (copy); | 1868 | GNUNET_free (copy); |
1869 | return ret; | 1869 | return ret; |
1870 | } | 1870 | } |
@@ -1923,7 +1923,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1923 | { | 1923 | { |
1924 | node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE; | 1924 | node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE; |
1925 | token = strtok_r (NULL, ":", &rest); | 1925 | token = strtok_r (NULL, ":", &rest); |
1926 | sscanf (token, "%u", &node_n); | 1926 | GNUNET_assert (1 == sscanf (token, "%u", &node_n)); |
1927 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1927 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1928 | "node_n %u\n", | 1928 | "node_n %u\n", |
1929 | node_n); | 1929 | node_n); |
@@ -1934,15 +1934,17 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1934 | { | 1934 | { |
1935 | node_connection->node_type = GNUNET_TESTING_SUBNET_NODE; | 1935 | node_connection->node_type = GNUNET_TESTING_SUBNET_NODE; |
1936 | token = strtok_r (NULL, ":", &rest); | 1936 | token = strtok_r (NULL, ":", &rest); |
1937 | sscanf (token, "%u", &node_n); | ||
1938 | node_connection->node_n = node_n; | ||
1939 | token = strtok_r (NULL, ":", &rest); | ||
1940 | sscanf (token, "%u", &namespace_n); | 1937 | sscanf (token, "%u", &namespace_n); |
1941 | node_connection->namespace_n = namespace_n; | 1938 | node_connection->namespace_n = namespace_n; |
1939 | token = strtok_r (NULL, ":", &rest); | ||
1940 | sscanf (token, "%u", &node_n); | ||
1941 | node_connection->node_n = node_n; | ||
1942 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1942 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1943 | "node_n %u namespace_n %u\n", | 1943 | "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n", |
1944 | node_n, | 1944 | node_n, |
1945 | namespace_n); | 1945 | namespace_n, |
1946 | node->node_n, | ||
1947 | node->namespace_n); | ||
1946 | } | 1948 | } |
1947 | while (NULL != (token = strtok_r (NULL, ":", &rest))) | 1949 | while (NULL != (token = strtok_r (NULL, ":", &rest))) |
1948 | { | 1950 | { |
@@ -1994,13 +1996,16 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1994 | if (NULL != temp) | 1996 | if (NULL != temp) |
1995 | { | 1997 | { |
1996 | slen = strlen (temp) + 1; | 1998 | slen = strlen (temp) + 1; |
1997 | copy = malloc (slen); | 1999 | copy = GNUNET_malloc (slen); |
1998 | memcpy (copy, temp, slen); | 2000 | memcpy (copy, temp, slen); |
1999 | strtok_r (copy, ":", &rest); | 2001 | strtok_r (copy, ":", &rest); |
2000 | value = strtok_r (rest, "|", &rest2); | 2002 | value = strtok_r (rest, "|", &rest2); |
2001 | 2003 | ||
2002 | while (NULL != value) | 2004 | while (NULL != value) |
2003 | { | 2005 | { |
2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2007 | "node_connections value %s\n", | ||
2008 | value); | ||
2004 | node_connection = get_connect_value (value, node); | 2009 | node_connection = get_connect_value (value, node); |
2005 | GNUNET_CONTAINER_DLL_insert (node->node_connections_head, | 2010 | GNUNET_CONTAINER_DLL_insert (node->node_connections_head, |
2006 | node->node_connections_tail, | 2011 | node->node_connections_tail, |
@@ -2011,6 +2016,7 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
2011 | value = strtok_r (NULL, "|", &rest2); | 2016 | value = strtok_r (NULL, "|", &rest2); |
2012 | 2017 | ||
2013 | } | 2018 | } |
2019 | GNUNET_free (copy); | ||
2014 | } | 2020 | } |
2015 | } | 2021 | } |
2016 | 2022 | ||
@@ -2056,13 +2062,7 @@ static int | |||
2056 | log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | 2062 | log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value) |
2057 | { | 2063 | { |
2058 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; | 2064 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; |
2059 | struct GNUNET_TESTING_NetjailRouter *router = namespace->router; | ||
2060 | 2065 | ||
2061 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2062 | "router_tcp: %u router_udp: %u spaces: %u\n", | ||
2063 | router->tcp_port, | ||
2064 | router->udp_port, | ||
2065 | namespace->namespace_n); | ||
2066 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL); | 2066 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL); |
2067 | return GNUNET_YES; | 2067 | return GNUNET_YES; |
2068 | } | 2068 | } |
@@ -2103,9 +2103,15 @@ GNUNET_TESTING_get_connections (unsigned int num, struct | |||
2103 | struct GNUNET_TESTING_NetjailNamespace *namespace; | 2103 | struct GNUNET_TESTING_NetjailNamespace *namespace; |
2104 | unsigned int namespace_n, node_m; | 2104 | unsigned int namespace_n, node_m; |
2105 | 2105 | ||
2106 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2107 | "gaga 1\n"); | ||
2106 | log_topo (topology); | 2108 | log_topo (topology); |
2107 | 2109 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
2110 | "gaga 2\n"); | ||
2108 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | 2111 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); |
2112 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2113 | "num: %u \n", | ||
2114 | num); | ||
2109 | if (topology->nodes_x >= num) | 2115 | if (topology->nodes_x >= num) |
2110 | { | 2116 | { |
2111 | 2117 | ||
@@ -2118,10 +2124,10 @@ GNUNET_TESTING_get_connections (unsigned int num, struct | |||
2118 | } | 2124 | } |
2119 | else | 2125 | else |
2120 | { | 2126 | { |
2121 | namespace_n = (unsigned int) floor ((num - topology->nodes_x) | 2127 | namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x) |
2122 | / topology->nodes_m); | 2128 | / topology->nodes_m); |
2123 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2129 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2124 | "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", | 2130 | "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", |
2125 | num, | 2131 | num, |
2126 | topology->nodes_x, | 2132 | topology->nodes_x, |
2127 | topology->nodes_m, | 2133 | topology->nodes_m, |
@@ -2143,7 +2149,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct | |||
2143 | hkey); | 2149 | hkey); |
2144 | } | 2150 | } |
2145 | 2151 | ||
2146 | 2152 | GNUNET_free (hkey); | |
2147 | return node->node_connections_head; | 2153 | return node->node_connections_head; |
2148 | } | 2154 | } |
2149 | 2155 | ||
@@ -2172,10 +2178,74 @@ GNUNET_TESTING_get_pub_key (unsigned int num, struct | |||
2172 | GNUNET_CRYPTO_eddsa_key_get_public (priv_key, | 2178 | GNUNET_CRYPTO_eddsa_key_get_public (priv_key, |
2173 | pub_key); | 2179 | pub_key); |
2174 | peer->public_key = *pub_key; | 2180 | peer->public_key = *pub_key; |
2181 | GNUNET_free (priv_key); | ||
2182 | GNUNET_free (pub_key); | ||
2175 | return peer; | 2183 | return peer; |
2176 | } | 2184 | } |
2177 | 2185 | ||
2178 | 2186 | ||
2187 | int | ||
2188 | free_nodes_cb (void *cls, | ||
2189 | const struct GNUNET_ShortHashCode *key, | ||
2190 | void *value) | ||
2191 | { | ||
2192 | (void) cls; | ||
2193 | struct GNUNET_TESTING_NetjailNode *node = value; | ||
2194 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
2195 | struct GNUNET_TESTING_NodeConnection *tmp_connection; | ||
2196 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; | ||
2197 | struct GNUNET_TESTING_AddressPrefix *tmp_prefix; | ||
2198 | |||
2199 | pos_connection = node->node_connections_head; | ||
2200 | |||
2201 | while (NULL != pos_connection->next) | ||
2202 | { | ||
2203 | pos_prefix = pos_connection->address_prefixes_head; | ||
2204 | while (NULL != pos_prefix->next) | ||
2205 | { | ||
2206 | tmp_prefix = pos_prefix->next; | ||
2207 | GNUNET_free (pos_prefix); | ||
2208 | pos_prefix = tmp_prefix; | ||
2209 | } | ||
2210 | tmp_connection = pos_connection->next; | ||
2211 | GNUNET_free (pos_connection); | ||
2212 | pos_connection = tmp_connection; | ||
2213 | } | ||
2214 | return GNUNET_OK; | ||
2215 | } | ||
2216 | |||
2217 | |||
2218 | int | ||
2219 | free_namespaces_cb (void *cls, | ||
2220 | const struct GNUNET_ShortHashCode *key, | ||
2221 | void *value) | ||
2222 | { | ||
2223 | (void) cls; | ||
2224 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; | ||
2225 | |||
2226 | GNUNET_free (namespace->router); | ||
2227 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, free_nodes_cb, | ||
2228 | NULL); | ||
2229 | return GNUNET_OK; | ||
2230 | |||
2231 | } | ||
2232 | |||
2233 | |||
2234 | /** | ||
2235 | * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. | ||
2236 | * | ||
2237 | * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. | ||
2238 | */ | ||
2239 | void | ||
2240 | GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology) | ||
2241 | { | ||
2242 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, | ||
2243 | free_namespaces_cb, NULL); | ||
2244 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, free_nodes_cb, | ||
2245 | NULL); | ||
2246 | GNUNET_free (topology); | ||
2247 | } | ||
2248 | |||
2179 | /** | 2249 | /** |
2180 | * Calculate the unique id identifying a node from a given connction. | 2250 | * Calculate the unique id identifying a node from a given connction. |
2181 | * | 2251 | * |
@@ -2252,7 +2322,7 @@ GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, | |||
2252 | } | 2322 | } |
2253 | else | 2323 | else |
2254 | { | 2324 | { |
2255 | GNUNET_break (0); | 2325 | GNUNET_assert (0); |
2256 | } | 2326 | } |
2257 | 2327 | ||
2258 | return addr; | 2328 | return addr; |
@@ -2296,24 +2366,19 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2296 | uint64_t fs; | 2366 | uint64_t fs; |
2297 | char *data; | 2367 | char *data; |
2298 | char *token; | 2368 | char *token; |
2299 | char *key; | 2369 | char *key = NULL; |
2300 | unsigned int out; | 2370 | unsigned int out; |
2301 | char *rest = NULL; | 2371 | char *rest = NULL; |
2302 | char *value; | 2372 | char *value; |
2373 | char *value2; | ||
2303 | int ret; | 2374 | int ret; |
2304 | struct GNUNET_TESTING_NetjailTopology *topo = GNUNET_new (struct | 2375 | struct GNUNET_TESTING_NetjailTopology *topo; |
2305 | GNUNET_TESTING_NetjailTopology); | ||
2306 | struct GNUNET_TESTING_NetjailNode *node; | 2376 | struct GNUNET_TESTING_NetjailNode *node; |
2307 | struct GNUNET_TESTING_NetjailRouter *router; | 2377 | struct GNUNET_TESTING_NetjailRouter *router; |
2308 | struct GNUNET_TESTING_NetjailNamespace *namespace; | 2378 | struct GNUNET_TESTING_NetjailNamespace *namespace; |
2309 | struct GNUNET_ShortHashCode *hkey; | 2379 | struct GNUNET_ShortHashCode *hkey; |
2310 | struct GNUNET_HashCode hc; | 2380 | struct GNUNET_HashCode hc; |
2311 | 2381 | ||
2312 | topo->map_namespaces = | ||
2313 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
2314 | topo->map_globals = | ||
2315 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
2316 | |||
2317 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 2382 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
2318 | { | 2383 | { |
2319 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2384 | LOG (GNUNET_ERROR_TYPE_ERROR, |
@@ -2339,14 +2404,22 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2339 | return NULL; | 2404 | return NULL; |
2340 | } | 2405 | } |
2341 | 2406 | ||
2342 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2407 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2343 | "data: %s\n", | 2408 | "data: %s\n", |
2344 | data); | 2409 | data); |
2345 | 2410 | ||
2411 | data[fs] = '\0'; | ||
2346 | token = strtok_r (data, "\n", &rest); | 2412 | token = strtok_r (data, "\n", &rest); |
2413 | topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); | ||
2414 | topo->map_namespaces = | ||
2415 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
2416 | topo->map_globals = | ||
2417 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
2347 | 2418 | ||
2348 | while (NULL != token) | 2419 | while (NULL != token) |
2349 | { | 2420 | { |
2421 | if (NULL != key) | ||
2422 | free (key); | ||
2350 | key = get_key (token); | 2423 | key = get_key (token); |
2351 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2424 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2352 | "In the loop with token: %s beginning with %s\n", | 2425 | "In the loop with token: %s beginning with %s\n", |
@@ -2457,12 +2530,12 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2457 | 2530 | ||
2458 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2531 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2459 | "Get value for key udp_port on R.\n"); | 2532 | "Get value for key udp_port on R.\n"); |
2460 | value = get_value ("udp_port", token); | 2533 | value2 = get_value ("udp_port", token); |
2461 | ret = sscanf (value, "%u", &(router->udp_port)); | 2534 | ret = sscanf (value2, "%u", &(router->udp_port)); |
2462 | GNUNET_break (0 != ret && 1 >= router->udp_port); | 2535 | GNUNET_break (0 != ret && 1 >= router->udp_port); |
2463 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2536 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2464 | "udp_port: %s\n", | 2537 | "udp_port: %s\n", |
2465 | value); | 2538 | value2); |
2466 | 2539 | ||
2467 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( | 2540 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( |
2468 | topo->map_namespaces, | 2541 | topo->map_namespaces, |
@@ -2554,6 +2627,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2554 | } | 2627 | } |
2555 | token = strtok_r (NULL, "\n", &rest); | 2628 | token = strtok_r (NULL, "\n", &rest); |
2556 | } | 2629 | } |
2630 | GNUNET_free (data); | ||
2557 | 2631 | ||
2558 | return topo; | 2632 | return topo; |
2559 | } | 2633 | } |