aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-11-19 15:18:24 +0100
committert3sserakt <t3ss@posteo.de>2021-11-19 15:18:24 +0100
commit6a043a9228022fcce97fd50739db74abdabde055 (patch)
tree8cba6d9a87731cce5d20a3f8f2cf0cb2cb8ef37d /src/testing/testing.c
parent154d13fcb10205edf5fb56c12ac47e65abfec5a6 (diff)
downloadgnunet-6a043a9228022fcce97fd50739db74abdabde055.tar.gz
gnunet-6a043a9228022fcce97fd50739db74abdabde055.zip
- Fixed header, fixed log level, changed block until connect logic, fixed memory issues.
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index ced04e65d..9e664292b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -1838,7 +1838,7 @@ get_first_string_value (char *line)
1838 memcpy (copy, line, slen); 1838 memcpy (copy, line, slen);
1839 token = strtok_r (copy, ":", &rest); 1839 token = strtok_r (copy, ":", &rest);
1840 token = strtok_r (NULL, ":", &rest); 1840 token = strtok_r (NULL, ":", &rest);
1841 LOG (GNUNET_ERROR_TYPE_ERROR, 1841 LOG (GNUNET_ERROR_TYPE_DEBUG,
1842 "first token %s\n", 1842 "first token %s\n",
1843 token); 1843 token);
1844 slen_token = strlen (token); 1844 slen_token = strlen (token);
@@ -1924,7 +1924,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
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 GNUNET_assert (1 == 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_DEBUG,
1928 "node_n %u\n", 1928 "node_n %u\n",
1929 node_n); 1929 node_n);
1930 node_connection->node_n = node_n; 1930 node_connection->node_n = node_n;
@@ -1939,7 +1939,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1939 token = strtok_r (NULL, ":", &rest); 1939 token = strtok_r (NULL, ":", &rest);
1940 sscanf (token, "%u", &node_n); 1940 sscanf (token, "%u", &node_n);
1941 node_connection->node_n = node_n; 1941 node_connection->node_n = node_n;
1942 LOG (GNUNET_ERROR_TYPE_ERROR, 1942 LOG (GNUNET_ERROR_TYPE_DEBUG,
1943 "node_n %u namespace_n %u node->node_n %u node->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,
@@ -1963,14 +1963,14 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1963 memcpy (prefix->address_prefix, token, slen); 1963 memcpy (prefix->address_prefix, token, slen);
1964 } 1964 }
1965 1965
1966 LOG (GNUNET_ERROR_TYPE_ERROR, 1966 LOG (GNUNET_ERROR_TYPE_DEBUG,
1967 "address_prefix %s\n", 1967 "address_prefix %s\n",
1968 prefix->address_prefix); 1968 prefix->address_prefix);
1969 1969
1970 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, 1970 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head,
1971 node_connection->address_prefixes_tail, 1971 node_connection->address_prefixes_tail,
1972 prefix); 1972 prefix);
1973 LOG (GNUNET_ERROR_TYPE_ERROR, 1973 LOG (GNUNET_ERROR_TYPE_DEBUG,
1974 "address_prefix %s\n", 1974 "address_prefix %s\n",
1975 prefix->address_prefix); 1975 prefix->address_prefix);
1976 } 1976 }
@@ -2028,7 +2028,7 @@ log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2028 struct GNUNET_TESTING_NodeConnection *pos_connection; 2028 struct GNUNET_TESTING_NodeConnection *pos_connection;
2029 struct GNUNET_TESTING_AddressPrefix *pos_prefix; 2029 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2030 2030
2031 LOG (GNUNET_ERROR_TYPE_ERROR, 2031 LOG (GNUNET_ERROR_TYPE_DEBUG,
2032 "plugin: %s space: %u node: %u global: %u\n", 2032 "plugin: %s space: %u node: %u global: %u\n",
2033 node->plugin, 2033 node->plugin,
2034 node->namespace_n, 2034 node->namespace_n,
@@ -2039,7 +2039,7 @@ log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2039 pos_connection = pos_connection->next) 2039 pos_connection = pos_connection->next)
2040 { 2040 {
2041 2041
2042 LOG (GNUNET_ERROR_TYPE_ERROR, 2042 LOG (GNUNET_ERROR_TYPE_DEBUG,
2043 "namespace_n: %u node_n: %u node_type: %u\n", 2043 "namespace_n: %u node_n: %u node_type: %u\n",
2044 pos_connection->namespace_n, 2044 pos_connection->namespace_n,
2045 pos_connection->node_n, 2045 pos_connection->node_n,
@@ -2049,7 +2049,7 @@ log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2049 pos_prefix = 2049 pos_prefix =
2050 pos_prefix->next) 2050 pos_prefix->next)
2051 { 2051 {
2052 LOG (GNUNET_ERROR_TYPE_ERROR, 2052 LOG (GNUNET_ERROR_TYPE_DEBUG,
2053 "prefix: %s\n", 2053 "prefix: %s\n",
2054 pos_prefix->address_prefix); 2054 pos_prefix->address_prefix);
2055 } 2055 }
@@ -2071,7 +2071,7 @@ log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2071static int 2071static int
2072log_topo (struct GNUNET_TESTING_NetjailTopology *topology) 2072log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
2073{ 2073{
2074 LOG (GNUNET_ERROR_TYPE_ERROR, 2074 LOG (GNUNET_ERROR_TYPE_DEBUG,
2075 "plugin: %s spaces: %u nodes: %u known: %u\n", 2075 "plugin: %s spaces: %u nodes: %u known: %u\n",
2076 topology->plugin, 2076 topology->plugin,
2077 topology->namespaces_n, 2077 topology->namespaces_n,
@@ -2218,6 +2218,8 @@ free_nodes_cb (void *cls,
2218 GNUNET_free (pos_connection); 2218 GNUNET_free (pos_connection);
2219 pos_connection = tmp_connection; 2219 pos_connection = tmp_connection;
2220 } 2220 }
2221 GNUNET_free (node->plugin);
2222 GNUNET_free (node);
2221 return GNUNET_OK; 2223 return GNUNET_OK;
2222} 2224}
2223 2225
@@ -2248,8 +2250,11 @@ GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology)
2248{ 2250{
2249 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, 2251 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
2250 free_namespaces_cb, NULL); 2252 free_namespaces_cb, NULL);
2253 GNUNET_CONTAINER_multishortmap_destroy (topology->map_namespaces);
2251 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, free_nodes_cb, 2254 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, free_nodes_cb,
2252 NULL); 2255 NULL);
2256 GNUNET_CONTAINER_multishortmap_destroy (topology->map_globals);
2257 GNUNET_free (topology->plugin);
2253 GNUNET_free (topology); 2258 GNUNET_free (topology);
2254} 2259}
2255 2260
@@ -2294,7 +2299,7 @@ GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
2294 char *addr; 2299 char *addr;
2295 char *template; 2300 char *template;
2296 2301
2297 LOG (GNUNET_ERROR_TYPE_ERROR, 2302 LOG (GNUNET_ERROR_TYPE_DEBUG,
2298 "node_n: %u\n", 2303 "node_n: %u\n",
2299 connection->node_n); 2304 connection->node_n);
2300 2305
@@ -2374,7 +2379,7 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2374 char *key = NULL; 2379 char *key = NULL;
2375 unsigned int out; 2380 unsigned int out;
2376 char *rest = NULL; 2381 char *rest = NULL;
2377 char *value; 2382 char *value = NULL;
2378 char *value2; 2383 char *value2;
2379 int ret; 2384 int ret;
2380 struct GNUNET_TESTING_NetjailTopology *topo; 2385 struct GNUNET_TESTING_NetjailTopology *topo;
@@ -2384,9 +2389,6 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2384 struct GNUNET_ShortHashCode *hkey; 2389 struct GNUNET_ShortHashCode *hkey;
2385 struct GNUNET_HashCode hc; 2390 struct GNUNET_HashCode hc;
2386 2391
2387 LOG (GNUNET_ERROR_TYPE_DEBUG,
2388 "data %s\n",
2389 data);
2390 token = strtok_r (data, "\n", &rest); 2392 token = strtok_r (data, "\n", &rest);
2391 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); 2393 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology);
2392 topo->map_namespaces = 2394 topo->map_namespaces =
@@ -2399,46 +2401,46 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2399 if (NULL != key) 2401 if (NULL != key)
2400 free (key); 2402 free (key);
2401 key = get_key (token); 2403 key = get_key (token);
2402 LOG (GNUNET_ERROR_TYPE_ERROR, 2404 LOG (GNUNET_ERROR_TYPE_DEBUG,
2403 "In the loop with token: %s beginning with %s\n", 2405 "In the loop with token: %s beginning with %s\n",
2404 token, 2406 token,
2405 key); 2407 key);
2406 if (0 == strcmp (key, "M")) 2408 if (0 == strcmp (key, "M"))
2407 { 2409 {
2408 LOG (GNUNET_ERROR_TYPE_ERROR, 2410 LOG (GNUNET_ERROR_TYPE_DEBUG,
2409 "Get first Value for M.\n"); 2411 "Get first Value for M.\n");
2410 out = get_first_value (token); 2412 out = get_first_value (token);
2411 LOG (GNUNET_ERROR_TYPE_ERROR, 2413 LOG (GNUNET_ERROR_TYPE_DEBUG,
2412 "M: %u\n", 2414 "M: %u\n",
2413 out); 2415 out);
2414 topo->nodes_m = out; 2416 topo->nodes_m = out;
2415 } 2417 }
2416 else if (0 == strcmp (key, "N")) 2418 else if (0 == strcmp (key, "N"))
2417 { 2419 {
2418 LOG (GNUNET_ERROR_TYPE_ERROR, 2420 LOG (GNUNET_ERROR_TYPE_DEBUG,
2419 "Get first Value for N.\n"); 2421 "Get first Value for N.\n");
2420 out = get_first_value (token); 2422 out = get_first_value (token);
2421 LOG (GNUNET_ERROR_TYPE_ERROR, 2423 LOG (GNUNET_ERROR_TYPE_DEBUG,
2422 "N: %u\n", 2424 "N: %u\n",
2423 out); 2425 out);
2424 topo->namespaces_n = out; 2426 topo->namespaces_n = out;
2425 } 2427 }
2426 else if (0 == strcmp (key, "X")) 2428 else if (0 == strcmp (key, "X"))
2427 { 2429 {
2428 LOG (GNUNET_ERROR_TYPE_ERROR, 2430 LOG (GNUNET_ERROR_TYPE_DEBUG,
2429 "Get first Value for X.\n"); 2431 "Get first Value for X.\n");
2430 out = get_first_value (token); 2432 out = get_first_value (token);
2431 LOG (GNUNET_ERROR_TYPE_ERROR, 2433 LOG (GNUNET_ERROR_TYPE_DEBUG,
2432 "X: %u\n", 2434 "X: %u\n",
2433 out); 2435 out);
2434 topo->nodes_x = out; 2436 topo->nodes_x = out;
2435 } 2437 }
2436 else if (0 == strcmp (key, "T")) 2438 else if (0 == strcmp (key, "T"))
2437 { 2439 {
2438 LOG (GNUNET_ERROR_TYPE_ERROR, 2440 LOG (GNUNET_ERROR_TYPE_DEBUG,
2439 "Get first string value for T.\n"); 2441 "Get first string value for T.\n");
2440 value = get_first_string_value (token); 2442 value = get_first_string_value (token);
2441 LOG (GNUNET_ERROR_TYPE_ERROR, 2443 LOG (GNUNET_ERROR_TYPE_DEBUG,
2442 "value: %s\n", 2444 "value: %s\n",
2443 value); 2445 value);
2444 topo->plugin = value; 2446 topo->plugin = value;
@@ -2448,10 +2450,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2448 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 2450 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2449 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2451 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2450 2452
2451 LOG (GNUNET_ERROR_TYPE_ERROR, 2453 LOG (GNUNET_ERROR_TYPE_DEBUG,
2452 "Get first Value for K.\n"); 2454 "Get first Value for K.\n");
2453 out = get_first_value (token); 2455 out = get_first_value (token);
2454 LOG (GNUNET_ERROR_TYPE_ERROR, 2456 LOG (GNUNET_ERROR_TYPE_DEBUG,
2455 "K: %u\n", 2457 "K: %u\n",
2456 out); 2458 out);
2457 node->node_n = out; 2459 node->node_n = out;
@@ -2470,10 +2472,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2470 hkey, 2472 hkey,
2471 node, 2473 node,
2472 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2473 LOG (GNUNET_ERROR_TYPE_ERROR, 2475 LOG (GNUNET_ERROR_TYPE_DEBUG,
2474 "Get value for key value on K.\n"); 2476 "Get value for key value on K.\n");
2475 value = get_value ("plugin", token); 2477 value = get_value ("plugin", token);
2476 LOG (GNUNET_ERROR_TYPE_ERROR, 2478 LOG (GNUNET_ERROR_TYPE_DEBUG,
2477 "value: %s\n", 2479 "value: %s\n",
2478 value); 2480 value);
2479 node->plugin = value; 2481 node->plugin = value;
@@ -2485,10 +2487,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2485 router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter); 2487 router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2486 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2488 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2487 2489
2488 LOG (GNUNET_ERROR_TYPE_ERROR, 2490 LOG (GNUNET_ERROR_TYPE_DEBUG,
2489 "Get first Value for R.\n"); 2491 "Get first Value for R.\n");
2490 out = get_first_value (token); 2492 out = get_first_value (token);
2491 LOG (GNUNET_ERROR_TYPE_ERROR, 2493 LOG (GNUNET_ERROR_TYPE_DEBUG,
2492 "R: %u\n", 2494 "R: %u\n",
2493 out); 2495 out);
2494 node->node_n = out; 2496 node->node_n = out;
@@ -2496,22 +2498,22 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2496 memcpy (hkey, 2498 memcpy (hkey,
2497 &hc, 2499 &hc,
2498 sizeof (*hkey)); 2500 sizeof (*hkey));
2499 LOG (GNUNET_ERROR_TYPE_ERROR, 2501 LOG (GNUNET_ERROR_TYPE_DEBUG,
2500 "Get value for key tcp_port on R.\n"); 2502 "Get value for key tcp_port on R.\n");
2501 value = get_value ("tcp_port", token); 2503 value = get_value ("tcp_port", token);
2502 LOG (GNUNET_ERROR_TYPE_ERROR, 2504 LOG (GNUNET_ERROR_TYPE_DEBUG,
2503 "tcp_port: %s\n", 2505 "tcp_port: %s\n",
2504 value); 2506 value);
2505 ret = sscanf (value, "%u", &(router->tcp_port)); 2507 ret = sscanf (value, "%u", &(router->tcp_port));
2506 2508
2507 GNUNET_break (0 != ret && 1 >= router->tcp_port); 2509 GNUNET_break (0 != ret && 1 >= router->tcp_port);
2508 2510
2509 LOG (GNUNET_ERROR_TYPE_ERROR, 2511 LOG (GNUNET_ERROR_TYPE_DEBUG,
2510 "Get value for key udp_port on R.\n"); 2512 "Get value for key udp_port on R.\n");
2511 value2 = get_value ("udp_port", token); 2513 value2 = get_value ("udp_port", token);
2512 ret = sscanf (value2, "%u", &(router->udp_port)); 2514 ret = sscanf (value2, "%u", &(router->udp_port));
2513 GNUNET_break (0 != ret && 1 >= router->udp_port); 2515 GNUNET_break (0 != ret && 1 >= router->udp_port);
2514 LOG (GNUNET_ERROR_TYPE_ERROR, 2516 LOG (GNUNET_ERROR_TYPE_DEBUG,
2515 "udp_port: %s\n", 2517 "udp_port: %s\n",
2516 value2); 2518 value2);
2517 2519
@@ -2540,10 +2542,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2540 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 2542 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2541 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 2543 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2542 2544
2543 LOG (GNUNET_ERROR_TYPE_ERROR, 2545 LOG (GNUNET_ERROR_TYPE_DEBUG,
2544 "Get first Value for P.\n"); 2546 "Get first Value for P.\n");
2545 out = get_first_value (token); 2547 out = get_first_value (token);
2546 LOG (GNUNET_ERROR_TYPE_ERROR, 2548 LOG (GNUNET_ERROR_TYPE_DEBUG,
2547 "P: %u\n", 2549 "P: %u\n",
2548 out); 2550 out);
2549 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); 2551 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
@@ -2568,10 +2570,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2568 namespace, 2570 namespace,
2569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2571 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2570 } 2572 }
2571 LOG (GNUNET_ERROR_TYPE_ERROR, 2573 LOG (GNUNET_ERROR_TYPE_DEBUG,
2572 "Get second Value for P.\n"); 2574 "Get second Value for P.\n");
2573 out = get_second_value (token); 2575 out = get_second_value (token);
2574 LOG (GNUNET_ERROR_TYPE_ERROR, 2576 LOG (GNUNET_ERROR_TYPE_DEBUG,
2575 "P: %u\n", 2577 "P: %u\n",
2576 out); 2578 out);
2577 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); 2579 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
@@ -2591,10 +2593,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2591 hkey, 2593 hkey,
2592 node, 2594 node,
2593 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2595 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2594 LOG (GNUNET_ERROR_TYPE_ERROR, 2596 LOG (GNUNET_ERROR_TYPE_DEBUG,
2595 "Get value for key plugin on P.\n"); 2597 "Get value for key plugin on P.\n");
2596 value = get_value ("plugin", token); 2598 value = get_value ("plugin", token);
2597 LOG (GNUNET_ERROR_TYPE_ERROR, 2599 LOG (GNUNET_ERROR_TYPE_DEBUG,
2598 "plugin: %s\n", 2600 "plugin: %s\n",
2599 value); 2601 value);
2600 node->plugin = value; 2602 node->plugin = value;
@@ -2605,10 +2607,14 @@ GNUNET_TESTING_get_topo_from_string (char *data)
2605 } 2607 }
2606 token = strtok_r (NULL, "\n", &rest); 2608 token = strtok_r (NULL, "\n", &rest);
2607 if (NULL != token) 2609 if (NULL != token)
2608 LOG (GNUNET_ERROR_TYPE_ERROR, 2610 LOG (GNUNET_ERROR_TYPE_DEBUG,
2609 "Next token %s\n", 2611 "Next token %s\n",
2610 token); 2612 token);
2611 } 2613 }
2614 if (NULL != key)
2615 GNUNET_free (key);
2616 /*if (NULL != value)
2617 GNUNET_free (value);*/
2612 2618
2613 return topo; 2619 return topo;
2614} 2620}
@@ -2642,7 +2648,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2642 filename); 2648 filename);
2643 return NULL; 2649 return NULL;
2644 } 2650 }
2645 data = GNUNET_malloc (fs); 2651 data = GNUNET_malloc (fs + 1);
2646 if (fs != GNUNET_DISK_fn_read (filename, data, fs)) 2652 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2647 { 2653 {
2648 LOG (GNUNET_ERROR_TYPE_ERROR, 2654 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -2653,9 +2659,8 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2653 } 2659 }
2654 2660
2655 LOG (GNUNET_ERROR_TYPE_DEBUG, 2661 LOG (GNUNET_ERROR_TYPE_DEBUG,
2656 "data: %s\n", 2662 "file lenght %lu\n",
2657 data); 2663 fs);
2658
2659 data[fs] = '\0'; 2664 data[fs] = '\0';
2660 2665
2661 topo = GNUNET_TESTING_get_topo_from_string (data); 2666 topo = GNUNET_TESTING_get_topo_from_string (data);