diff options
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 381 |
1 files changed, 380 insertions, 1 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 991c11a6c..fcde39901 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -33,6 +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 | 37 | ||
37 | #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) |
38 | 39 | ||
@@ -1308,7 +1309,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1308 | peer->nports = nports; | 1309 | peer->nports = nports; |
1309 | return peer; | 1310 | return peer; |
1310 | 1311 | ||
1311 | err_ret: | 1312 | err_ret: |
1312 | GNUNET_free (ss_instances); | 1313 | GNUNET_free (ss_instances); |
1313 | GNUNET_free (ports); | 1314 | GNUNET_free (ports); |
1314 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); | 1315 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); |
@@ -1773,4 +1774,382 @@ GNUNET_TESTING_get_testname_from_underscore (const char *argv0) | |||
1773 | } | 1774 | } |
1774 | 1775 | ||
1775 | 1776 | ||
1777 | static unsigned int | ||
1778 | get_first_value (char *line) | ||
1779 | { | ||
1780 | char *copy; | ||
1781 | size_t slen; | ||
1782 | char *token; | ||
1783 | unsigned int ret; | ||
1784 | char *rest = NULL; | ||
1785 | |||
1786 | slen = strlen (line) + 1; | ||
1787 | copy = malloc (slen); | ||
1788 | memcpy (copy, line, slen); | ||
1789 | token = strtok_r (copy, ":", &rest); | ||
1790 | token = strtok_r (NULL, ":", &rest); | ||
1791 | sscanf (token, "%u", &ret); | ||
1792 | free (copy); | ||
1793 | return ret; | ||
1794 | } | ||
1795 | |||
1796 | |||
1797 | static char * | ||
1798 | get_key (char *line) | ||
1799 | { | ||
1800 | char *copy; | ||
1801 | size_t slen; | ||
1802 | char *token; | ||
1803 | char *ret; | ||
1804 | char *rest = NULL; | ||
1805 | |||
1806 | slen = strlen (line) + 1; | ||
1807 | copy = malloc (slen); | ||
1808 | memcpy (copy, line, slen); | ||
1809 | token = strtok_r (copy, ":", &rest); | ||
1810 | ret = malloc (2); | ||
1811 | memcpy (ret, token, 2); | ||
1812 | free (copy); | ||
1813 | return ret; | ||
1814 | } | ||
1815 | |||
1816 | |||
1817 | static char * | ||
1818 | get_first_string_value (char *line) | ||
1819 | { | ||
1820 | char *copy; | ||
1821 | size_t slen, slen_token; | ||
1822 | char *token; | ||
1823 | char *ret; | ||
1824 | char *rest = NULL; | ||
1825 | |||
1826 | slen = strlen (line) + 1; | ||
1827 | copy = malloc (slen); | ||
1828 | memcpy (copy, line, slen); | ||
1829 | token = strtok_r (copy, ":", &rest); | ||
1830 | token = strtok_r (NULL, ":", &rest); | ||
1831 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1832 | "first token %s\n", | ||
1833 | token); | ||
1834 | slen_token = strlen (token); | ||
1835 | ret = malloc (slen_token + 1); | ||
1836 | memcpy (ret, token, slen_token + 1); | ||
1837 | free (copy); | ||
1838 | return ret; | ||
1839 | } | ||
1840 | |||
1841 | |||
1842 | static unsigned int | ||
1843 | get_second_value (char *line) | ||
1844 | { | ||
1845 | char *copy; | ||
1846 | size_t slen; | ||
1847 | char *token; | ||
1848 | unsigned int ret; | ||
1849 | char *rest = NULL; | ||
1850 | |||
1851 | slen = strlen (line) + 1; | ||
1852 | copy = malloc (slen); | ||
1853 | memcpy (copy, line, slen); | ||
1854 | token = strtok_r (copy, ":", &rest); | ||
1855 | token = strtok_r (NULL, ":", &rest); | ||
1856 | token = strtok_r (NULL, ":", &rest); | ||
1857 | sscanf (token, "%u", &ret); | ||
1858 | free (copy); | ||
1859 | return ret; | ||
1860 | } | ||
1861 | |||
1862 | |||
1863 | static char * | ||
1864 | get_value (char *key, char *line) | ||
1865 | { | ||
1866 | char *copy; | ||
1867 | size_t slen, slen_token; | ||
1868 | char *token; | ||
1869 | char *token2; | ||
1870 | char *temp; | ||
1871 | char *rest = NULL; | ||
1872 | char *ret; | ||
1873 | |||
1874 | slen = strlen (line) + 1; | ||
1875 | copy = malloc (slen); | ||
1876 | memcpy (copy, line, slen); | ||
1877 | temp = strstr (copy, key); | ||
1878 | if (NULL == temp) | ||
1879 | return NULL; | ||
1880 | token = strtok_r (temp, ":", &rest); | ||
1881 | token = strtok_r (NULL, ":", &rest); | ||
1882 | token2 = strtok_r (token, "}", &rest); | ||
1883 | slen_token = strlen (token2); | ||
1884 | ret = malloc (slen_token + 1); | ||
1885 | memcpy (ret, token2, slen_token + 1); | ||
1886 | free (copy); | ||
1887 | return ret; | ||
1888 | } | ||
1889 | |||
1890 | |||
1891 | /** | ||
1892 | * Getting the topology from file. | ||
1893 | * | ||
1894 | * @param filename The name of the topology file. | ||
1895 | * @return The GNUNET_TESTING_NetjailTopology | ||
1896 | */ | ||
1897 | struct GNUNET_TESTING_NetjailTopology * | ||
1898 | GNUNET_TESTING_get_topo_from_file (const char *filename) | ||
1899 | { | ||
1900 | uint64_t fs; | ||
1901 | char *data; | ||
1902 | char *token; | ||
1903 | char *key; | ||
1904 | unsigned int out; | ||
1905 | char *rest = NULL; | ||
1906 | char *value; | ||
1907 | int ret; | ||
1908 | struct GNUNET_TESTING_NetjailTopology *topo = GNUNET_new (struct | ||
1909 | GNUNET_TESTING_NetjailTopology); | ||
1910 | struct GNUNET_TESTING_NetjailNode *node; | ||
1911 | struct GNUNET_TESTING_NetjailRouter *router; | ||
1912 | struct GNUNET_TESTING_NetjailNamespace *namespace; | ||
1913 | struct GNUNET_ShortHashCode *hkey; | ||
1914 | struct GNUNET_HashCode hc; | ||
1915 | topo->map_namespaces = | ||
1916 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
1917 | topo->map_globals = | ||
1918 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | ||
1919 | |||
1920 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
1921 | { | ||
1922 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1923 | _ ("Topology file %s not found\n"), | ||
1924 | filename); | ||
1925 | return NULL; | ||
1926 | } | ||
1927 | if (GNUNET_OK != | ||
1928 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
1929 | { | ||
1930 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1931 | _ ("Topology file %s has no data\n"), | ||
1932 | filename); | ||
1933 | return NULL; | ||
1934 | } | ||
1935 | data = GNUNET_malloc (fs); | ||
1936 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) | ||
1937 | { | ||
1938 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1939 | _ ("Topology file %s cannot be read\n"), | ||
1940 | filename); | ||
1941 | GNUNET_free (data); | ||
1942 | return NULL; | ||
1943 | } | ||
1944 | |||
1945 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1946 | "data: %s\n", | ||
1947 | data); | ||
1948 | |||
1949 | token = strtok_r (data, "\n", &rest); | ||
1950 | |||
1951 | while (NULL != token) | ||
1952 | { | ||
1953 | key = get_key (token); | ||
1954 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1955 | "In the loop with token: %s beginning with %s\n", | ||
1956 | token, | ||
1957 | key); | ||
1958 | if (0 == strcmp (key, "M")) | ||
1959 | { | ||
1960 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1961 | "Get first Value for M.\n"); | ||
1962 | out = get_first_value (token); | ||
1963 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1964 | "M: %u\n", | ||
1965 | out); | ||
1966 | topo->nodes_m = out; | ||
1967 | } | ||
1968 | else if (0 == strcmp (key, "N")) | ||
1969 | { | ||
1970 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1971 | "Get first Value for N.\n"); | ||
1972 | out = get_first_value (token); | ||
1973 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1974 | "N: %u\n", | ||
1975 | out); | ||
1976 | topo->namespaces_n = out; | ||
1977 | } | ||
1978 | else if (0 == strcmp (key, "X")) | ||
1979 | { | ||
1980 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1981 | "Get first Value for X.\n"); | ||
1982 | out = get_first_value (token); | ||
1983 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1984 | "X: %u\n", | ||
1985 | out); | ||
1986 | topo->nodes_x = out; | ||
1987 | } | ||
1988 | else if (0 == strcmp (key, "T")) | ||
1989 | { | ||
1990 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1991 | "Get first string value for T.\n"); | ||
1992 | value = get_first_string_value (token); | ||
1993 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1994 | "value: %s\n", | ||
1995 | value); | ||
1996 | topo->plugin = value; | ||
1997 | } | ||
1998 | else if (0 == strcmp (key, "K")) | ||
1999 | { | ||
2000 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2001 | node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); | ||
2002 | |||
2003 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2004 | "Get first Value for K.\n"); | ||
2005 | out = get_first_value (token); | ||
2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2007 | "K: %u\n", | ||
2008 | out); | ||
2009 | node->node_n = out; | ||
2010 | GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); | ||
2011 | memcpy (hkey, | ||
2012 | &hc, | ||
2013 | sizeof (*hkey)); | ||
2014 | node->is_global = GNUNET_YES; | ||
2015 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2016 | "Get value for key value on K.\n"); | ||
2017 | value = get_value ("plugin", token); | ||
2018 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2019 | "value: %s\n", | ||
2020 | value); | ||
2021 | if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_globals, | ||
2022 | hkey)) | ||
2023 | GNUNET_break (0); | ||
2024 | else | ||
2025 | GNUNET_CONTAINER_multishortmap_put (topo->map_globals, | ||
2026 | hkey, | ||
2027 | node, | ||
2028 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2029 | } | ||
2030 | else if (0 == strcmp (key, "R")) | ||
2031 | { | ||
2032 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2033 | router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter); | ||
2034 | node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); | ||
2035 | |||
2036 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2037 | "Get first Value for R.\n"); | ||
2038 | out = get_first_value (token); | ||
2039 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2040 | "R: %u\n", | ||
2041 | out); | ||
2042 | node->node_n = out; | ||
2043 | GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); | ||
2044 | memcpy (hkey, | ||
2045 | &hc, | ||
2046 | sizeof (*hkey)); | ||
2047 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2048 | "Get value for key tcp_port on R.\n"); | ||
2049 | value = get_value ("tcp_port", token); | ||
2050 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2051 | "tcp_port: %s\n", | ||
2052 | value); | ||
2053 | ret = sscanf (value, "%u", &(router->tcp_port)); | ||
2054 | |||
2055 | GNUNET_break (0 == ret || 1 < router->tcp_port); | ||
2056 | |||
2057 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2058 | "Get value for key udp_port on R.\n"); | ||
2059 | value = get_value ("udp_port", token); | ||
2060 | ret = sscanf (value, "%u", &(router->udp_port)); | ||
2061 | GNUNET_break (0 == ret || 1 < router->udp_port); | ||
2062 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2063 | "udp_port: %s\n", | ||
2064 | value); | ||
2065 | |||
2066 | if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces, | ||
2067 | hkey)) | ||
2068 | { | ||
2069 | namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces, | ||
2070 | hkey); | ||
2071 | } | ||
2072 | else | ||
2073 | { | ||
2074 | namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace); | ||
2075 | namespace->namespace_n = out; | ||
2076 | GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces, | ||
2077 | hkey, | ||
2078 | namespace, | ||
2079 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2080 | } | ||
2081 | namespace->router = router; | ||
2082 | |||
2083 | } | ||
2084 | else if (0 == strcmp (key, "P")) | ||
2085 | { | ||
2086 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2087 | node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); | ||
2088 | |||
2089 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2090 | "Get first Value for P.\n"); | ||
2091 | out = get_first_value (token); | ||
2092 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2093 | "P: %u\n", | ||
2094 | out); | ||
2095 | GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); | ||
2096 | memcpy (hkey, | ||
2097 | &hc, | ||
2098 | sizeof (*hkey)); | ||
2099 | |||
2100 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2101 | "Get value for key plugin on P.\n"); | ||
2102 | value = get_value ("plugin", token); | ||
2103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2104 | "plugin: %s\n", | ||
2105 | value); | ||
2106 | if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces, | ||
2107 | hkey)) | ||
2108 | { | ||
2109 | namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces, | ||
2110 | hkey); | ||
2111 | } | ||
2112 | else | ||
2113 | { | ||
2114 | namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace); | ||
2115 | namespace->namespace_n = out; | ||
2116 | GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces, | ||
2117 | hkey, | ||
2118 | namespace, | ||
2119 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2120 | } | ||
2121 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2122 | "Get second Value for P.\n"); | ||
2123 | out = get_second_value (token); | ||
2124 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2125 | "P: %u\n", | ||
2126 | out); | ||
2127 | GNUNET_CRYPTO_hash (&out, sizeof(out), &hc); | ||
2128 | memcpy (hkey, | ||
2129 | &hc, | ||
2130 | sizeof (*hkey)); | ||
2131 | if (0 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes, | ||
2132 | hkey)) | ||
2133 | { | ||
2134 | GNUNET_break (0); | ||
2135 | } | ||
2136 | else | ||
2137 | { | ||
2138 | node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); | ||
2139 | GNUNET_CONTAINER_multishortmap_put (namespace->nodes, | ||
2140 | hkey, | ||
2141 | node, | ||
2142 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2143 | node->plugin = value; | ||
2144 | node->node_n = out; | ||
2145 | node->namespace_n = namespace->namespace_n; | ||
2146 | } | ||
2147 | } | ||
2148 | token = strtok_r (NULL, "\n", &rest); | ||
2149 | } | ||
2150 | |||
2151 | return topo; | ||
2152 | } | ||
2153 | |||
2154 | |||
1776 | /* end of testing.c */ | 2155 | /* end of testing.c */ |