aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/test_mesh_path_api.c302
1 files changed, 88 insertions, 214 deletions
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index 58bc6bd20..d5aea7ebc 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -39,7 +39,7 @@ int cb_call;
39struct GNUNET_PeerIdentity* pi[10]; 39struct GNUNET_PeerIdentity* pi[10];
40struct MeshTunnelTree *tree; 40struct MeshTunnelTree *tree;
41 41
42void 42static void
43cb (const struct MeshTunnelTreeNode *n) 43cb (const struct MeshTunnelTreeNode *n)
44{ 44{
45 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", n->peer); 45 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", n->peer);
@@ -52,7 +52,70 @@ cb (const struct MeshTunnelTreeNode *n)
52} 52}
53 53
54 54
55void 55/**
56 * Check if a node has all expected properties.
57 *
58 * @param peer_id Short ID of the peer to test.
59 * @param status Expected status of the peer.
60 * @param children Expected number of children of the peer.
61 * @param first_hop Short ID of the expected first hop towards the peer.
62 */
63static void
64test_assert (GNUNET_PEER_Id peer_id,
65 enum MeshPeerState status,
66 unsigned int children,
67 GNUNET_PEER_Id first_hop)
68{
69 struct MeshTunnelTreeNode *n;
70 struct MeshTunnelTreeNode *c;
71 unsigned int i;
72 int pre_failed;
73
74 pre_failed = failed;
75 n = tree_find_peer(tree->root, peer_id);
76 if (n->peer != peer_id)
77 {
78 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
79 "Retrieved peer != original (%u, %u)\n",
80 n->peer, peer_id);
81 failed++;
82 }
83 if (n->status != status)
84 {
85 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
86 "Retrieved peer has wrong status! (%u, %u)\n",
87 n->status, status);
88 failed++;
89 }
90 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++);
91 if (i != children)
92 {
93 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
94 "Retrieved peer wrong has number of children! (%u, %u)\n",
95 i, children);
96 failed++;
97 }
98 if (0 != first_hop &&
99 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop)
100 {
101 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
102 "Wrong first hop! (%u, %u)\n",
103 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)),
104 first_hop);
105 failed++;
106 }
107 if (pre_failed != failed)
108 {
109 struct GNUNET_PeerIdentity id;
110 GNUNET_PEER_resolve (peer_id, &id);
111 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
112 "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
113 GNUNET_i2s (&id), peer_id, failed - pre_failed);
114 }
115}
116
117
118static void
56finish(void) 119finish(void)
57{ 120{
58 unsigned int i; 121 unsigned int i;
@@ -129,116 +192,20 @@ main (int argc, char *argv[])
129 failed++; 192 failed++;
130 } 193 }
131 path_destroy(path1); 194 path_destroy(path1);
132 node = tree_find_peer(tree->root, 4); 195 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
133 if (node->peer != 4) 196 test_assert (3, MESH_PEER_RELAY, 1, 0);
134 { 197 test_assert (2, MESH_PEER_RELAY, 1, 0);
135 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 198 test_assert (1, MESH_PEER_ROOT, 1, 0);
136 failed++;
137 }
138 if (node->status != MESH_PEER_SEARCHING)
139 {
140 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
141 failed++;
142 }
143 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 2)
144 {
145 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
146 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "4 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 4)));
147 failed++;
148 }
149
150 node = tree_find_peer(tree->root, 3);
151 if (node->peer != 3)
152 {
153 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
154 failed++;
155 }
156 if (node->status != MESH_PEER_RELAY)
157 {
158 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
159 failed++;
160 }
161 if (node->children_head != node->children_tail)
162 {
163 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
164 failed++;
165 }
166 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 2)
167 {
168 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
169 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "4 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 4)));
170 failed++;
171 }
172
173 node = tree_find_peer(tree->root, 2);
174 if (node->peer != 2)
175 {
176 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
177 failed++;
178 }
179 if (node->status != MESH_PEER_RELAY)
180 {
181 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
182 failed++;
183 }
184 if (node->children_head != node->children_tail)
185 {
186 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
187 failed++;
188 }
189 199
190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); 200 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
191 path->length--; 201 path->length--;
192 tree_add_path(tree, path, &cb); 202 tree_add_path(tree, path, &cb);
193 tree_debug(tree); 203 tree_debug(tree);
194 204
195 node = tree_find_peer(tree->root, 4); 205 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
196 if (node->peer != 4) 206 test_assert (3, MESH_PEER_SEARCHING, 1, 2);
197 { 207 test_assert (2, MESH_PEER_RELAY, 1, 0);
198 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 208 test_assert (1, MESH_PEER_ROOT, 1, 0);
199 failed++;
200 }
201 if (node->status != MESH_PEER_SEARCHING)
202 {
203 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
204 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, " expected SEARCHING, got %u\n", node->status);
205 failed++;
206 }
207 if (node->children_head != node->children_tail)
208 {
209 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
210 failed++;
211 }
212 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 2)
213 {
214 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
215 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "4 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 4)));
216 failed++;
217 }
218 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 2)
219 {
220 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
221 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "3 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 3)));
222 failed++;
223 }
224
225 node = tree_find_peer(tree->root, 2);
226 if (node->peer != 2)
227 {
228 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
229 failed++;
230 }
231 if (node->status != MESH_PEER_RELAY)
232 {
233 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
234 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, " expected RELAY\n");
235 failed++;
236 }
237 if (node->children_head != node->children_tail)
238 {
239 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
240 failed++;
241 }
242 209
243 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); 210 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
244 path->length++; 211 path->length++;
@@ -246,57 +213,13 @@ main (int argc, char *argv[])
246 tree_add_path(tree, path, &cb); 213 tree_add_path(tree, path, &cb);
247 tree_debug(tree); 214 tree_debug(tree);
248 215
249 node = tree_find_peer(tree->root, 3); 216 test_assert (5, MESH_PEER_SEARCHING, 0, 2);
250 if (node->peer != 3) 217 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
251 { 218 test_assert (3, MESH_PEER_SEARCHING, 2, 2);
252 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 219 test_assert (2, MESH_PEER_RELAY, 1, 0);
253 failed++; 220 test_assert (1, MESH_PEER_ROOT, 1, 0);
254 }
255 if (node->status != MESH_PEER_SEARCHING)
256 {
257 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
258 failed++;
259 }
260 if (node->children_head->next != node->children_tail)
261 {
262 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
263 failed++;
264 }
265 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 2)
266 {
267 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
268 failed++;
269 }
270 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 2)
271 {
272 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
273 failed++;
274 }
275
276 node = tree_find_peer(tree->root, 2);
277 if (node->peer != 2)
278 {
279 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
280 failed++;
281 }
282 if (node->status != MESH_PEER_RELAY)
283 {
284 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
285 failed++;
286 }
287 if (node->children_head != node->children_tail)
288 {
289 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
290 failed++;
291 }
292 221
293 node = tree_find_peer(tree->root, 5); 222 node = tree_find_peer(tree->root, 5);
294 if (node->peer != 5)
295 {
296 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
297 failed++;
298 }
299
300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); 223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
301 node->status = MESH_PEER_READY; 224 node->status = MESH_PEER_READY;
302 cb_call = 1; 225 cb_call = 1;
@@ -312,23 +235,11 @@ main (int argc, char *argv[])
312 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 235 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
313 failed++; 236 failed++;
314 } 237 }
315 238
316 node = tree_find_peer(tree->root, 3); 239 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
317 if (node->peer != 3) 240 test_assert (3, MESH_PEER_SEARCHING, 1, 2);
318 { 241 test_assert (2, MESH_PEER_RELAY, 1, 0);
319 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 242 test_assert (1, MESH_PEER_ROOT, 1, 0);
320 failed++;
321 }
322 if (node->status != MESH_PEER_SEARCHING)
323 {
324 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
325 failed++;
326 }
327 if (node->children_head != node->children_tail)
328 {
329 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
330 failed++;
331 }
332 243
333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); 244 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
334 GNUNET_free (node2); 245 GNUNET_free (node2);
@@ -344,50 +255,12 @@ main (int argc, char *argv[])
344 { 255 {
345 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 256 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
346 failed++; 257 failed++;
347 }
348 node = tree_find_peer(tree->root, 3);
349 if (node->peer != 3)
350 {
351 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
352 failed++;
353 }
354 if (node->status != MESH_PEER_SEARCHING)
355 {
356 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
357 failed++;
358 }
359 if (node->children_head != NULL)
360 {
361 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
362 failed++;
363 }
364 node = tree_find_peer(tree->root, 4);
365 if (node->peer != 4)
366 {
367 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
368 failed++;
369 }
370 if (node->status != MESH_PEER_SEARCHING)
371 {
372 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
373 failed++;
374 }
375 if (node->children_head != NULL)
376 {
377 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
378 failed++;
379 }
380 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 2)
381 {
382 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
383 failed++;
384 }
385 if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 4)
386 {
387 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
388 failed++;
389 } 258 }
390 259
260 test_assert (4, MESH_PEER_SEARCHING, 0, 4);
261 test_assert (3, MESH_PEER_SEARCHING, 0, 2);
262 test_assert (2, MESH_PEER_RELAY, 1, 0);
263 test_assert (1, MESH_PEER_ROOT, 2, 0);
391 264
392 if (failed > 0) 265 if (failed > 0)
393 { 266 {
@@ -395,6 +268,7 @@ main (int argc, char *argv[])
395 return 1; 268 return 1;
396 } 269 }
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n"); 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
271 GNUNET_free (path->peers);
398 GNUNET_free (path); 272 GNUNET_free (path);
399 finish(); 273 finish();
400 274