diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-19 11:59:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-19 11:59:34 +0000 |
commit | 50e7453045035b43f2a412e21f0cca2a5fd62b84 (patch) | |
tree | fd959ec45be58eae675437b1ed6eb97c6e328b68 /src/transport/test_transport_ats.c | |
parent | 0e688ba4f7430b63acdac289077e406480498297 (diff) | |
download | gnunet-50e7453045035b43f2a412e21f0cca2a5fd62b84.tar.gz gnunet-50e7453045035b43f2a412e21f0cca2a5fd62b84.zip |
run glpk code and tests only if gplk installed, fewer ifdefs
Diffstat (limited to 'src/transport/test_transport_ats.c')
-rw-r--r-- | src/transport/test_transport_ats.c | 128 |
1 files changed, 46 insertions, 82 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index 57110d5e5..fe8b6e87b 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c | |||
@@ -29,9 +29,14 @@ | |||
29 | #define VERBOSE GNUNET_YES | 29 | #define VERBOSE GNUNET_YES |
30 | 30 | ||
31 | static struct ATS_Handle * ats; | 31 | static struct ATS_Handle * ats; |
32 | |||
32 | static struct GNUNET_CONFIGURATION_Handle * cfg; | 33 | static struct GNUNET_CONFIGURATION_Handle * cfg; |
33 | 34 | ||
34 | void ats_result_cb () | 35 | static struct TransportConfiguration *tc; |
36 | |||
37 | |||
38 | static void | ||
39 | ats_result_cb () | ||
35 | { | 40 | { |
36 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 41 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
37 | "ATS Result callback\n"); | 42 | "ATS Result callback\n"); |
@@ -49,40 +54,11 @@ struct TransportConfiguration | |||
49 | struct ATS_mechanism * m_tail; | 54 | struct ATS_mechanism * m_tail; |
50 | }; | 55 | }; |
51 | 56 | ||
52 | struct TransportConfiguration *tc; | ||
53 | |||
54 | /* | ||
55 | void create_topology (int c_peers, int c_mechanisms) | ||
56 | { | ||
57 | int c; | ||
58 | peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer)); | ||
59 | for (c=0 ; c<c_peers; c++) | ||
60 | { | ||
61 | peers[c].f = 1.0 / c_peers; | ||
62 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &peers[c].peer.hashPubKey); | ||
63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s \n", GNUNET_i2s (&peers[c].peer)); | ||
64 | peers[c].m_head = NULL; | ||
65 | peers[c].m_tail = NULL; | ||
66 | } | ||
67 | mechanisms = GNUNET_malloc ( c_mechanisms * sizeof (struct ATS_mechanism)); | ||
68 | for (c=0 ; c<c_mechanisms; c++) | ||
69 | { | ||
70 | mechanisms[c].peer = &peers[c]; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | void delete_topology (void) | ||
76 | { | ||
77 | GNUNET_free (peers); | ||
78 | GNUNET_free (mechanisms); | ||
79 | }*/ | ||
80 | |||
81 | |||
82 | void create_ats_information (struct ATS_peer **p, int * c_p, | ||
83 | struct ATS_mechanism ** m, int * c_m) | ||
84 | { | ||
85 | 57 | ||
58 | static void | ||
59 | create_ats_information (struct ATS_peer **p, int * c_p, | ||
60 | struct ATS_mechanism ** m, int * c_m) | ||
61 | { | ||
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 62 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
87 | "ATS needs addresses\n"); | 63 | "ATS needs addresses\n"); |
88 | 64 | ||
@@ -90,28 +66,27 @@ void create_ats_information (struct ATS_peer **p, int * c_p, | |||
90 | (*c_p) = tc->mechanisms; | 66 | (*c_p) = tc->mechanisms; |
91 | (*m) = tc->m_head; | 67 | (*m) = tc->m_head; |
92 | (*c_m) = tc->mechanisms; | 68 | (*c_m) = tc->mechanisms; |
93 | |||
94 | } | 69 | } |
95 | 70 | ||
96 | int run_ats (void) | 71 | |
72 | static | ||
73 | int run_ats () | ||
97 | { | 74 | { |
98 | int ret = 0; | 75 | int ret = 0; |
99 | #if HAVE_LIBGLPK | ||
100 | ats_calculate_bandwidth_distribution (ats); | 76 | ats_calculate_bandwidth_distribution (ats); |
101 | #endif | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 77 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
103 | "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); | 78 | "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); |
104 | return ret; | 79 | return ret; |
105 | } | 80 | } |
106 | 81 | ||
107 | int init_ats (void) | 82 | |
83 | static int | ||
84 | init_ats () | ||
108 | { | 85 | { |
109 | int ret = 0; | 86 | int ret = 0; |
110 | #if HAVE_LIBGLPK | ||
111 | ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, | 87 | ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, |
112 | create_ats_information, | 88 | create_ats_information, |
113 | ats_result_cb); | 89 | ats_result_cb); |
114 | #endif | ||
115 | //GNUNET_assert (ats != NULL); | 90 | //GNUNET_assert (ats != NULL); |
116 | 91 | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -120,49 +95,56 @@ int init_ats (void) | |||
120 | } | 95 | } |
121 | 96 | ||
122 | 97 | ||
123 | int shutdown_ats (void) | 98 | static int |
99 | shutdown_ats () | ||
124 | { | 100 | { |
125 | int ret = 0; | 101 | int ret = 0; |
126 | #if HAVE_LIBGLPK | ||
127 | ats_delete_problem (ats); | 102 | ats_delete_problem (ats); |
128 | ats_shutdown (ats); | 103 | ats_shutdown (ats); |
129 | #endif | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
131 | "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); | 105 | "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); |
132 | return ret; | 106 | return ret; |
133 | } | 107 | } |
134 | 108 | ||
109 | |||
135 | /* To make compiler happy */ | 110 | /* To make compiler happy */ |
136 | void dummy(void) | 111 | void |
112 | dummy() | ||
137 | { | 113 | { |
138 | struct ATS_quality_metric * q = qm; | 114 | struct ATS_quality_metric * q = qm; |
139 | q = NULL; | 115 | q = NULL; |
140 | struct ATS_ressource * r = ressources; | 116 | struct ATS_ressource * r = ressources; |
141 | r = NULL; | 117 | r = NULL; |
118 | q++; | ||
119 | r++; | ||
142 | } | 120 | } |
143 | 121 | ||
144 | void iterate_peer_values (void *cls, | 122 | |
145 | const char *section, | 123 | static void |
146 | const char *option, | 124 | iterate_peer_values (void *cls, |
147 | const char *value) | 125 | const char *section, |
126 | const char *option, | ||
127 | const char *value) | ||
148 | { | 128 | { |
149 | if (strcmp (option, "f") == 0) | 129 | if (strcmp (option, "f") == 0) |
150 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
151 | "\t %s %s\n", option, value); | 131 | "\t %s %s\n", option, value); |
152 | } | 132 | } |
153 | 133 | ||
154 | void iterate_mech_values (void *cls, | 134 | static void |
155 | const char *section, | 135 | iterate_mech_values (void *cls, |
156 | const char *option, | 136 | const char *section, |
157 | const char *value) | 137 | const char *option, |
138 | const char *value) | ||
158 | { | 139 | { |
159 | if (strcmp (option, "f") == 0) | 140 | if (strcmp (option, "f") == 0) |
160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 141 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
161 | "\t %s %s\n", option, value); | 142 | "\t %s %s\n", option, value); |
162 | } | 143 | } |
163 | 144 | ||
164 | void iterate_sections (void *cls, | 145 | static void |
165 | const char *section) | 146 | iterate_sections (void *cls, |
147 | const char *section) | ||
166 | { | 148 | { |
167 | struct TransportConfiguration * tc = cls; | 149 | struct TransportConfiguration * tc = cls; |
168 | /* Peer definition */ | 150 | /* Peer definition */ |
@@ -183,22 +165,22 @@ void iterate_sections (void *cls, | |||
183 | } | 165 | } |
184 | } | 166 | } |
185 | 167 | ||
186 | void destroy_transport_configuration (char * filename) | ||
187 | { | ||
188 | GNUNET_CONFIGURATION_destroy (cfg); | ||
189 | 168 | ||
190 | } | 169 | static struct TransportConfiguration * |
191 | 170 | load_transport_configuration (char * filename) | |
192 | struct TransportConfiguration * load_transport_configuration (char * filename) | ||
193 | { | 171 | { |
194 | struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration)); | 172 | struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration)); |
195 | cfg = GNUNET_CONFIGURATION_create(); | ||
196 | GNUNET_CONFIGURATION_load(cfg, filename); | ||
197 | GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret); | ||
198 | 173 | ||
174 | cfg = GNUNET_CONFIGURATION_create(); | ||
175 | GNUNET_assert (GNUNET_OK == | ||
176 | GNUNET_CONFIGURATION_load(cfg, filename)); | ||
177 | GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret); | ||
178 | GNUNET_CONFIGURATION_destroy (cfg); | ||
179 | cfg = NULL; | ||
199 | return ret; | 180 | return ret; |
200 | } | 181 | } |
201 | 182 | ||
183 | |||
202 | int | 184 | int |
203 | main (int argc, char *argv[]) | 185 | main (int argc, char *argv[]) |
204 | { | 186 | { |
@@ -211,29 +193,11 @@ main (int argc, char *argv[]) | |||
211 | "INFO", | 193 | "INFO", |
212 | #endif | 194 | #endif |
213 | NULL); | 195 | NULL); |
214 | #if !HAVE_LIBGLPK | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
216 | "HAVE_LIBGLPK not set, exiting testcase\n"); | ||
217 | #endif | ||
218 | |||
219 | #if !HAVE_LIBGLPK | ||
220 | return ret; | ||
221 | #endif | ||
222 | |||
223 | return 0; | ||
224 | |||
225 | tc = load_transport_configuration ("test.ats"); | 196 | tc = load_transport_configuration ("test.ats"); |
226 | |||
227 | return ret; | ||
228 | |||
229 | /* Testing */ | ||
230 | ats = NULL; | 197 | ats = NULL; |
231 | |||
232 | ret += init_ats (); | 198 | ret += init_ats (); |
233 | ret += run_ats (); | 199 | ret += run_ats (); |
234 | ret += shutdown_ats (); | 200 | ret += shutdown_ats (); |
235 | |||
236 | /* Shutdown */ | ||
237 | return ret; | 201 | return ret; |
238 | 202 | ||
239 | } | 203 | } |