diff options
Diffstat (limited to 'src/mesh/test_mesh_tree_api.c')
-rw-r--r-- | src/mesh/test_mesh_tree_api.c | 97 |
1 files changed, 72 insertions, 25 deletions
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c index cbe694c11..77fd799bd 100644 --- a/src/mesh/test_mesh_tree_api.c +++ b/src/mesh/test_mesh_tree_api.c | |||
@@ -72,18 +72,21 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
72 | unsigned int i; | 72 | unsigned int i; |
73 | int pre_failed; | 73 | int pre_failed; |
74 | 74 | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Checking peer %u\n", peer_id); | ||
75 | pre_failed = failed; | 76 | pre_failed = failed; |
76 | n = tree_find_peer (tree, peer_id); | 77 | n = tree_find_peer (tree, peer_id); |
77 | if (n->peer != peer_id) | 78 | if (n->peer != peer_id) |
78 | { | 79 | { |
79 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
80 | "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id); | 81 | "Retrieved peer has wrong ID! (Got %u, expected %u)\n", |
82 | n->peer, peer_id); | ||
81 | failed++; | 83 | failed++; |
82 | } | 84 | } |
83 | if (n->status != status) | 85 | if (n->status != status) |
84 | { | 86 | { |
85 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
86 | "Retrieved peer has wrong status! (%u, %u)\n", n->status, | 88 | "Retrieved peer has wrong status! (Got %u, expected %u)\n", |
89 | n->status, | ||
87 | status); | 90 | status); |
88 | failed++; | 91 | failed++; |
89 | } | 92 | } |
@@ -91,15 +94,15 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
91 | if (i != children) | 94 | if (i != children) |
92 | { | 95 | { |
93 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 96 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
94 | "Retrieved peer wrong has number of children! (%u, %u)\n", i, | 97 | "Retrieved peer wrong has number of children! (Got %u, expected %u)\n", |
95 | children); | 98 | i, children); |
96 | failed++; | 99 | failed++; |
97 | } | 100 | } |
98 | if (0 != first_hop && | 101 | if (0 != first_hop && |
99 | GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop) | 102 | GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)) != first_hop) |
100 | { | 103 | { |
101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n", | 104 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (Got %u, expected %u)\n", |
102 | GNUNET_PEER_search (path_get_first_hop (tree, peer_id)), | 105 | GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)), |
103 | first_hop); | 106 | first_hop); |
104 | failed++; | 107 | failed++; |
105 | } | 108 | } |
@@ -109,7 +112,7 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status, | |||
109 | 112 | ||
110 | GNUNET_PEER_resolve (peer_id, &id); | 113 | GNUNET_PEER_resolve (peer_id, &id); |
111 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 114 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
112 | "*** Peer %s (%u) has failed %d checks! (real, expected)\n", | 115 | "*** Peer %s (%u) has failed %d checks!\n", |
113 | GNUNET_i2s (&id), peer_id, failed - pre_failed); | 116 | GNUNET_i2s (&id), peer_id, failed - pre_failed); |
114 | } | 117 | } |
115 | } | 118 | } |
@@ -145,7 +148,6 @@ int | |||
145 | main (int argc, char *argv[]) | 148 | main (int argc, char *argv[]) |
146 | { | 149 | { |
147 | struct MeshTunnelTreeNode *node; | 150 | struct MeshTunnelTreeNode *node; |
148 | struct MeshTunnelTreeNode *node2; | ||
149 | struct MeshPeerPath *path; | 151 | struct MeshPeerPath *path; |
150 | struct MeshPeerPath *path1; | 152 | struct MeshPeerPath *path1; |
151 | unsigned int i; | 153 | unsigned int i; |
@@ -201,7 +203,7 @@ main (int argc, char *argv[]) | |||
201 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 203 | test_assert (2, MESH_PEER_RELAY, 1, 0); |
202 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 204 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
203 | 205 | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path 1 2 3 5\n"); |
205 | path->length++; | 207 | path->length++; |
206 | path->peers[3] = 5; | 208 | path->peers[3] = 5; |
207 | tree_add_path (tree, path, &cb, NULL); | 209 | tree_add_path (tree, path, &cb, NULL); |
@@ -213,18 +215,17 @@ main (int argc, char *argv[]) | |||
213 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 215 | test_assert (2, MESH_PEER_RELAY, 1, 0); |
214 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 216 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
215 | 217 | ||
216 | node = tree_find_peer (tree, 5); | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n"); |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); | 219 | tree_set_status(tree, 5, MESH_PEER_READY); |
218 | node->status = MESH_PEER_READY; | ||
219 | cb_call = 1; | 220 | cb_call = 1; |
220 | node2 = tree_del_path (tree, 5, &cb, NULL); | 221 | node = tree_del_path (tree, 5, &cb, NULL); |
221 | tree_debug (tree); | 222 | tree_debug (tree); |
222 | if (cb_call != 0) | 223 | if (cb_call != 0) |
223 | { | 224 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); |
225 | failed++; | 226 | failed++; |
226 | } | 227 | } |
227 | if (node2->peer != 5) | 228 | if (node->peer != 5) |
228 | { | 229 | { |
229 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | 230 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); |
230 | failed++; | 231 | failed++; |
@@ -236,7 +237,7 @@ main (int argc, char *argv[]) | |||
236 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 237 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
237 | 238 | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); |
239 | GNUNET_free (node2); | 240 | GNUNET_free (node); |
240 | 241 | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
242 | "test: Adding new shorter first path...\n"); | 243 | "test: Adding new shorter first path...\n"); |
@@ -261,30 +262,76 @@ main (int argc, char *argv[]) | |||
261 | GNUNET_free (path); | 262 | GNUNET_free (path); |
262 | tree_destroy (tree); | 263 | tree_destroy (tree); |
263 | 264 | ||
265 | /****************************************************************************/ | ||
266 | |||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n"); | 267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n"); |
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); | 268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); |
266 | for (i = 0; i < 10; i++) | 269 | for (i = 0; i < 10; i++) |
267 | { | 270 | { |
268 | GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); | 271 | GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i])); |
269 | } | 272 | } |
270 | tree = tree_new (1); | 273 | tree = tree_new (2); |
271 | path = path_new (3); | 274 | path = path_new (8); |
272 | path->peers[0] = 1; | 275 | path->peers[0] = 2; |
273 | path->peers[1] = 2; | 276 | path->peers[1] = 1; |
274 | path->peers[2] = 3; | 277 | path->peers[2] = 3; |
275 | path->length = 3; | 278 | path->length = 3; |
276 | 279 | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 2 1 3\n"); |
278 | tree_add_path (tree, path, &cb, NULL); | 281 | tree_add_path (tree, path, &cb, NULL); |
279 | tree_debug (tree); | 282 | tree_debug (tree); |
280 | tree_set_me (tree, 2); | ||
281 | 283 | ||
282 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); | 284 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); |
283 | test_assert (2, MESH_PEER_RELAY, 1, 0); | 285 | test_assert (1, MESH_PEER_RELAY, 1, 0); |
284 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 286 | test_assert (2, MESH_PEER_ROOT, 1, 0); |
287 | |||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding long path: 2 1 4 5 3\n"); | ||
289 | path->peers[2] = 4; | ||
290 | path->peers[3] = 5; | ||
291 | path->peers[4] = 3; | ||
292 | path->length = 5; | ||
293 | tree_add_path (tree, path, &cb, NULL); | ||
294 | tree_debug (tree); | ||
285 | 295 | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); | 296 | test_assert (3, MESH_PEER_SEARCHING, 0, 4); |
297 | test_assert (5, MESH_PEER_RELAY, 1, 4); | ||
298 | test_assert (4, MESH_PEER_RELAY, 1, 4); | ||
299 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
300 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
301 | |||
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "test: Even longer path: 2 6 1 7 8 4 5 3\n"); | ||
304 | path->peers[0] = 2; | ||
305 | path->peers[1] = 6; | ||
306 | path->peers[2] = 1; | ||
307 | path->peers[3] = 7; | ||
308 | path->peers[4] = 8; | ||
309 | path->peers[5] = 4; | ||
310 | path->peers[6] = 5; | ||
311 | path->peers[7] = 3; | ||
312 | path->length = 8; | ||
313 | tree_add_path (tree, path, &cb, NULL); | ||
314 | tree_debug (tree); | ||
315 | |||
316 | test_assert (3, MESH_PEER_SEARCHING, 0, 7); | ||
317 | test_assert (5, MESH_PEER_RELAY, 1, 7); | ||
318 | test_assert (4, MESH_PEER_RELAY, 1, 7); | ||
319 | test_assert (8, MESH_PEER_RELAY, 1, 7); | ||
320 | test_assert (7, MESH_PEER_RELAY, 1, 7); | ||
321 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
322 | test_assert (6, MESH_PEER_RELAY, 1, 0); | ||
323 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
324 | |||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 2 1 3\n"); | ||
326 | path->peers[1] = 1; | ||
327 | path->peers[2] = 3; | ||
328 | path->length = 3; | ||
287 | tree_add_path (tree, path, &cb, NULL); | 329 | tree_add_path (tree, path, &cb, NULL); |
330 | tree_debug (tree); | ||
331 | |||
332 | test_assert (3, MESH_PEER_SEARCHING, 0, 3); | ||
333 | test_assert (1, MESH_PEER_RELAY, 1, 0); | ||
334 | test_assert (2, MESH_PEER_ROOT, 1, 0); | ||
288 | 335 | ||
289 | GNUNET_free (path->peers); | 336 | GNUNET_free (path->peers); |
290 | GNUNET_free (path); | 337 | GNUNET_free (path); |