aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-cmds-helper.c6
-rw-r--r--src/testing/testing.c93
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c61
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c4
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c1
-rw-r--r--src/testing/testing_api_loop.c116
6 files changed, 208 insertions, 73 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index f90cc3cc4..5ff7c04ea 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -415,8 +415,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
415 plugin->n, plugin->local_m, ni->topology_data, 415 plugin->n, plugin->local_m, ni->topology_data,
416 ni->read_file); 416 ni->read_file);
417 417
418 GNUNET_free (binary);
419
420 msg_length = sizeof(struct GNUNET_CMDS_HelperReply); 418 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
421 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); 419 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
422 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); 420 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
@@ -424,6 +422,10 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
424 422
425 write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 423 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
426 424
425 GNUNET_free (binary);
426 GNUNET_free (router_ip);
427 GNUNET_free (plugin_name);
428
427 return GNUNET_OK; 429 return GNUNET_OK;
428 } 430 }
429 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 431 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
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);
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 7ff554280..9360dd02e 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -33,23 +33,6 @@
33 */ 33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35 35
36/**
37 * Struct with information for callbacks.
38 *
39 */
40struct BlockState
41{
42 /**
43 * Context for our asynchronous completion.
44 */
45 struct GNUNET_TESTING_AsyncContext ac;
46
47 /**
48 * The label of this command.
49 */
50 const char *label;
51};
52
53 36
54/** 37/**
55 * The cleanup function of this cmd frees resources the cmd allocated. 38 * The cleanup function of this cmd frees resources the cmd allocated.
@@ -77,6 +60,11 @@ block_until_external_trigger_traits (void *cls,
77 .trait_name = "async_context", 60 .trait_name = "async_context",
78 .ptr = (const void *) ac, 61 .ptr = (const void *) ac,
79 }, 62 },
63 {
64 .index = 1,
65 .trait_name = "block_state",
66 .ptr = (const void *) bs,
67 },
80 GNUNET_TESTING_trait_end () 68 GNUNET_TESTING_trait_end ()
81 }; 69 };
82 70
@@ -88,9 +76,27 @@ block_until_external_trigger_traits (void *cls,
88 76
89 77
90/** 78/**
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/**
91 * Function to get the trait with the async context. 97 * Function to get the trait with the async context.
92 * 98 *
93 * @param[out] ac GNUNET_TESTING_AsyncContext. 99 * @param[out] ac struct GNUNET_TESTING_AsyncContext.
94 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. 100 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
95 */ 101 */
96int 102int
@@ -114,10 +120,20 @@ block_until_all_peers_started_run (void *cls,
114 struct GNUNET_TESTING_Interpreter *is) 120 struct GNUNET_TESTING_Interpreter *is)
115{ 121{
116 struct BlockState *bs = cls; 122 struct BlockState *bs = cls;
123 struct GNUNET_TESTING_Command *cmd =
124 GNUNET_TESTING_interpreter_get_current_command (is);
117 125
118 LOG (GNUNET_ERROR_TYPE_DEBUG, 126 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "block %s running!\n", 127 "block %s running %u!\n",
120 bs->label); 128 bs->label,
129 bs->asynchronous_finish);
130 if (GNUNET_YES == bs->asynchronous_finish)
131 {
132 LOG (GNUNET_ERROR_TYPE_DEBUG,
133 "block %s running asynchronous!\n",
134 bs->label);
135 cmd->asynchronous_finish = bs->asynchronous_finish;
136 }
121} 137}
122 138
123 139
@@ -126,15 +142,18 @@ block_until_all_peers_started_run (void *cls,
126 * 142 *
127 * @param label name for command. 143 * @param label name for command.
128 * @param all_peers_started Flag which will be set from outside. 144 * @param all_peers_started Flag which will be set from outside.
145 * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL.
129 * @return command. 146 * @return command.
130 */ 147 */
131struct GNUNET_TESTING_Command 148struct GNUNET_TESTING_Command
132GNUNET_TESTING_cmd_block_until_external_trigger (const char *label) 149GNUNET_TESTING_cmd_block_until_external_trigger (
150 const char *label)
133{ 151{
134 struct BlockState *bs; 152 struct BlockState *bs;
135 153
136 bs = GNUNET_new (struct BlockState); 154 bs = GNUNET_new (struct BlockState);
137 bs->label = label; 155 bs->label = label;
156 bs->asynchronous_finish = GNUNET_NO;
138 { 157 {
139 struct GNUNET_TESTING_Command cmd = { 158 struct GNUNET_TESTING_Command cmd = {
140 .cls = bs, 159 .cls = bs,
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 2ff70c33e..6cd648c3a 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -193,11 +193,15 @@ netjail_start_run (void *cls,
193 NULL, 193 NULL,
194 script_name, 194 script_name,
195 script_argv); 195 script_argv);
196
196 } 197 }
197 ns->cwh = GNUNET_wait_child (ns->start_proc, 198 ns->cwh = GNUNET_wait_child (ns->start_proc,
198 &child_completed_callback, 199 &child_completed_callback,
199 ns); 200 ns);
200 GNUNET_break (NULL != ns->cwh); 201 GNUNET_break (NULL != ns->cwh);
202 GNUNET_free (read_file);
203 GNUNET_free (script_name);
204 GNUNET_free (data_dir);
201} 205}
202 206
203 207
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index e3bf7da62..f1b2260ab 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -87,6 +87,7 @@ netjail_stop_cleanup (void *cls)
87 GNUNET_OS_process_destroy (ns->stop_proc); 87 GNUNET_OS_process_destroy (ns->stop_proc);
88 ns->stop_proc = NULL; 88 ns->stop_proc = NULL;
89 } 89 }
90 GNUNET_free (ns);
90} 91}
91 92
92 93
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 3727d2543..e82ec33ab 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -53,6 +53,11 @@ struct GNUNET_TESTING_Interpreter
53 struct GNUNET_TESTING_Command *commands; 53 struct GNUNET_TESTING_Command *commands;
54 54
55 /** 55 /**
56 * Number of GNUNET_TESTING_Command in commands.
57 */
58 unsigned int cmds_n;
59
60 /**
56 * Interpreter task (if one is scheduled). 61 * Interpreter task (if one is scheduled).
57 */ 62 */
58 struct GNUNET_SCHEDULER_Task *task; 63 struct GNUNET_SCHEDULER_Task *task;
@@ -83,21 +88,32 @@ struct GNUNET_TESTING_Interpreter
83 88
84 89
85const struct GNUNET_TESTING_Command * 90const struct GNUNET_TESTING_Command *
86GNUNET_TESTING_interpreter_lookup_command ( 91get_command (struct GNUNET_TESTING_Interpreter *is,
87 struct GNUNET_TESTING_Interpreter *is, 92 const char *label,
88 const char *label) 93 unsigned int future)
89{ 94{
95 int start_i = GNUNET_NO == future ? is->ip : is->cmds_n - 1;
96 int end_i = GNUNET_NO == future ? 0 : is->ip + 1;
97
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
99 "start_i: %u end_i: %u\n",
100 start_i,
101 end_i);
90 if (NULL == label) 102 if (NULL == label)
91 { 103 {
92 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 104 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
93 "Attempt to lookup command for empty label\n"); 105 "Attempt to lookup command for empty label\n");
94 return NULL; 106 return NULL;
95 } 107 }
96 /* Search backwards as we most likely reference recent commands */ 108
97 for (int i = is->ip; i >= 0; i--) 109 for (int i = start_i; i >= end_i; i--)
98 { 110 {
99 const struct GNUNET_TESTING_Command *cmd = &is->commands[i]; 111 const struct GNUNET_TESTING_Command *cmd = &is->commands[i];
100 112
113 if (NULL != cmd->label)
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "label to compare %s\n",
116 cmd->label);
101 /* Give precedence to top-level commands. */ 117 /* Give precedence to top-level commands. */
102 if ( (NULL != cmd->label) && 118 if ( (NULL != cmd->label) &&
103 (0 == strcmp (cmd->label, 119 (0 == strcmp (cmd->label,
@@ -142,6 +158,40 @@ GNUNET_TESTING_interpreter_lookup_command (
142 158
143 159
144/** 160/**
161 * Lookup command by label.
162 * Only future commands are looked up.
163 *
164 * @param is interpreter to lookup command in
165 * @param label label of the command to lookup.
166 * @return the command, if it is found, or NULL.
167 */
168const struct GNUNET_TESTING_Command *
169GNUNET_TESTING_interpreter_lookup_future_command (
170 struct GNUNET_TESTING_Interpreter *is,
171 const char *label)
172{
173 return get_command (is, label, GNUNET_YES);
174}
175
176
177/**
178 * Lookup command by label.
179 * Only commands from current command to commands in the past are looked up.
180 *
181 * @param is interpreter to lookup command in
182 * @param label label of the command to lookup.
183 * @return the command, if it is found, or NULL.
184 */
185const struct GNUNET_TESTING_Command *
186GNUNET_TESTING_interpreter_lookup_command (
187 struct GNUNET_TESTING_Interpreter *is,
188 const char *label)
189{
190 return get_command (is, label, GNUNET_NO);
191}
192
193
194/**
145 * Finish the test run, return the final result. 195 * Finish the test run, return the final result.
146 * 196 *
147 * @param cls the `struct GNUNET_TESTING_Interpreter` 197 * @param cls the `struct GNUNET_TESTING_Interpreter`
@@ -267,6 +317,20 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
267} 317}
268 318
269 319
320/**
321 * Returns the actual running command.
322 *
323 * @param is Global state of the interpreter, used by a command
324 * to access information about other commands.
325 * @return The actual running command.
326 */
327struct GNUNET_TESTING_Command *
328GNUNET_TESTING_interpreter_get_current_command (
329 struct GNUNET_TESTING_Interpreter *is)
330{
331 return &is->commands[is->ip];
332}
333
270const char * 334const char *
271GNUNET_TESTING_interpreter_get_current_label ( 335GNUNET_TESTING_interpreter_get_current_label (
272 struct GNUNET_TESTING_Interpreter *is) 336 struct GNUNET_TESTING_Interpreter *is)
@@ -300,9 +364,17 @@ interpreter_run (void *cls)
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "Running command `%s'\n", 365 "Running command `%s'\n",
302 cmd->label); 366 cmd->label);
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "start time of %p expected 0 is `%lu'\n",
369 cmd,
370 cmd->start_time.abs_value_us);
303 cmd->start_time 371 cmd->start_time
304 = cmd->last_req_time 372 = cmd->last_req_time
305 = GNUNET_TIME_absolute_get (); 373 = GNUNET_TIME_absolute_get ();
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "start time of %p expected something is `%lu'\n",
376 cmd,
377 cmd->start_time.abs_value_us);
306 cmd->num_tries = 1; 378 cmd->num_tries = 1;
307 if (NULL != cmd->ac) 379 if (NULL != cmd->ac)
308 { 380 {
@@ -344,6 +416,37 @@ do_timeout (void *cls)
344} 416}
345 417
346 418
419/**
420 * Check if the command is running.
421 *
422 * @param cmd The command to check.
423 * @return GNUNET_NO if the command is not running, GNUNET_YES if it is running.
424 */
425enum GNUNET_GenericReturnValue
426GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command)
427{
428 return 0 != command->start_time.abs_value_us && 0 ==
429 command->finish_time.abs_value_us;
430}
431
432
433/**
434 * Check if a command is finished.
435 *
436 * @param cmd The command to check.
437 * @return GNUNET_NO if the command is not finished, GNUNET_YES if it is finished.
438 */
439enum GNUNET_GenericReturnValue
440GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command)
441{
442 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
443 struct GNUNET_TIME_Relative diff = GNUNET_TIME_absolute_get_difference (
444 command->finish_time,
445 now);
446 return 0 < diff.rel_value_us;
447}
448
449
347void 450void
348GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, 451GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
349 struct GNUNET_TIME_Relative timeout, 452 struct GNUNET_TIME_Relative timeout,
@@ -359,7 +462,8 @@ GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
359 /* get the number of commands */ 462 /* get the number of commands */
360 for (i = 0; NULL != commands[i].label; i++) 463 for (i = 0; NULL != commands[i].label; i++)
361 ; 464 ;
362 is->commands = GNUNET_new_array (i + 1, 465 is->cmds_n = i + 1;
466 is->commands = GNUNET_new_array (is->cmds_n,
363 struct GNUNET_TESTING_Command); 467 struct GNUNET_TESTING_Command);
364 memcpy (is->commands, 468 memcpy (is->commands,
365 commands, 469 commands,