aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c99
1 files changed, 64 insertions, 35 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 02cedc744..4ccf93c6b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -33,7 +33,7 @@
33#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_arm_service.h" 34#include "gnunet_arm_service.h"
35#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
36#include "gnunet_testing_ng_lib.h" 36#include "gnunet_testing_netjail_lib.h"
37#include "testing_cmds.h" 37#include "testing_cmds.h"
38 38
39#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 39#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -2102,6 +2102,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2102 struct GNUNET_HashCode hc; 2102 struct GNUNET_HashCode hc;
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 struct GNUNET_TESTING_NodeConnection *node_connections = NULL;
2105 2106
2106 LOG (GNUNET_ERROR_TYPE_DEBUG, 2107 LOG (GNUNET_ERROR_TYPE_DEBUG,
2107 "gaga 1\n"); 2108 "gaga 1\n");
@@ -2121,6 +2122,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2121 sizeof (*hkey)); 2122 sizeof (*hkey));
2122 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, 2123 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
2123 hkey); 2124 hkey);
2125 node_connections = node->node_connections_head;
2124 } 2126 }
2125 else 2127 else
2126 { 2128 {
@@ -2147,10 +2149,11 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2147 sizeof (*hkey)); 2149 sizeof (*hkey));
2148 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, 2150 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2149 hkey); 2151 hkey);
2152 node_connections = node->node_connections_head;
2150 } 2153 }
2151 2154
2152 GNUNET_free (hkey); 2155 GNUNET_free (hkey);
2153 return node->node_connections_head; 2156 return node_connections;
2154} 2157}
2155 2158
2156 2159
@@ -2355,16 +2358,14 @@ GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
2355 2358
2356 2359
2357/** 2360/**
2358 * Getting the topology from file. 2361 * Parse the topology data.
2359 * 2362 *
2360 * @param filename The name of the topology file. 2363 * @param data The topology data.
2361 * @return The GNUNET_TESTING_NetjailTopology 2364 * @return The GNUNET_TESTING_NetjailTopology
2362 */ 2365 */
2363struct GNUNET_TESTING_NetjailTopology * 2366struct GNUNET_TESTING_NetjailTopology *
2364GNUNET_TESTING_get_topo_from_file (const char *filename) 2367GNUNET_TESTING_get_topo_from_string (char *data)
2365{ 2368{
2366 uint64_t fs;
2367 char *data;
2368 char *token; 2369 char *token;
2369 char *key = NULL; 2370 char *key = NULL;
2370 unsigned int out; 2371 unsigned int out;
@@ -2379,36 +2380,9 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2379 struct GNUNET_ShortHashCode *hkey; 2380 struct GNUNET_ShortHashCode *hkey;
2380 struct GNUNET_HashCode hc; 2381 struct GNUNET_HashCode hc;
2381 2382
2382 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
2383 {
2384 LOG (GNUNET_ERROR_TYPE_ERROR,
2385 _ ("Topology file %s not found\n"),
2386 filename);
2387 return NULL;
2388 }
2389 if (GNUNET_OK !=
2390 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
2391 {
2392 LOG (GNUNET_ERROR_TYPE_ERROR,
2393 _ ("Topology file %s has no data\n"),
2394 filename);
2395 return NULL;
2396 }
2397 data = GNUNET_malloc (fs);
2398 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2399 {
2400 LOG (GNUNET_ERROR_TYPE_ERROR,
2401 _ ("Topology file %s cannot be read\n"),
2402 filename);
2403 GNUNET_free (data);
2404 return NULL;
2405 }
2406
2407 LOG (GNUNET_ERROR_TYPE_DEBUG, 2383 LOG (GNUNET_ERROR_TYPE_DEBUG,
2408 "data: %s\n", 2384 "data %s\n",
2409 data); 2385 data);
2410
2411 data[fs] = '\0';
2412 token = strtok_r (data, "\n", &rest); 2386 token = strtok_r (data, "\n", &rest);
2413 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); 2387 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology);
2414 topo->map_namespaces = 2388 topo->map_namespaces =
@@ -2626,7 +2600,62 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2626 node_connections (token, node); 2600 node_connections (token, node);
2627 } 2601 }
2628 token = strtok_r (NULL, "\n", &rest); 2602 token = strtok_r (NULL, "\n", &rest);
2603 if (NULL != token)
2604 LOG (GNUNET_ERROR_TYPE_ERROR,
2605 "Next token %s\n",
2606 token);
2607 }
2608
2609 return topo;
2610}
2611
2612
2613/**
2614 * Getting the topology from file.
2615 *
2616 * @param filename The name of the topology file.
2617 * @return The GNUNET_TESTING_NetjailTopology
2618 */
2619struct GNUNET_TESTING_NetjailTopology *
2620GNUNET_TESTING_get_topo_from_file (const char *filename)
2621{
2622 uint64_t fs;
2623 char *data;
2624 struct GNUNET_TESTING_NetjailTopology *topo;
2625
2626 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
2627 {
2628 LOG (GNUNET_ERROR_TYPE_ERROR,
2629 _ ("Topology file %s not found\n"),
2630 filename);
2631 return NULL;
2632 }
2633 if (GNUNET_OK !=
2634 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
2635 {
2636 LOG (GNUNET_ERROR_TYPE_ERROR,
2637 _ ("Topology file %s has no data\n"),
2638 filename);
2639 return NULL;
2629 } 2640 }
2641 data = GNUNET_malloc (fs);
2642 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2643 {
2644 LOG (GNUNET_ERROR_TYPE_ERROR,
2645 _ ("Topology file %s cannot be read\n"),
2646 filename);
2647 GNUNET_free (data);
2648 return NULL;
2649 }
2650
2651 LOG (GNUNET_ERROR_TYPE_DEBUG,
2652 "data: %s\n",
2653 data);
2654
2655 data[fs] = '\0';
2656
2657 topo = GNUNET_TESTING_get_topo_from_string (data);
2658
2630 GNUNET_free (data); 2659 GNUNET_free (data);
2631 2660
2632 return topo; 2661 return topo;