aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_tree_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/test_mesh_tree_api.c')
-rw-r--r--src/mesh/test_mesh_tree_api.c142
1 files changed, 69 insertions, 73 deletions
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c
index 8df8fe19b..b1bdcd693 100644
--- a/src/mesh/test_mesh_tree_api.c
+++ b/src/mesh/test_mesh_tree_api.c
@@ -39,16 +39,16 @@
39 39
40int failed; 40int failed;
41int cb_call; 41int cb_call;
42struct GNUNET_PeerIdentity* pi[10]; 42struct GNUNET_PeerIdentity *pi[10];
43struct MeshTunnelTree *tree; 43struct MeshTunnelTree *tree;
44 44
45static void 45static void
46cb (void *cls, GNUNET_PEER_Id peer_id) 46cb (void *cls, GNUNET_PEER_Id peer_id)
47{ 47{
48 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); 48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
49 if(0 == cb_call) 49 if (0 == cb_call)
50 { 50 {
51 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); 51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
52 failed++; 52 failed++;
53 } 53 }
54 cb_call--; 54 cb_call--;
@@ -64,10 +64,8 @@ cb (void *cls, GNUNET_PEER_Id peer_id)
64 * @param first_hop Short ID of the expected first hop towards the peer. 64 * @param first_hop Short ID of the expected first hop towards the peer.
65 */ 65 */
66static void 66static void
67test_assert (GNUNET_PEER_Id peer_id, 67test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
68 enum MeshPeerState status, 68 unsigned int children, GNUNET_PEER_Id first_hop)
69 unsigned int children,
70 GNUNET_PEER_Id first_hop)
71{ 69{
72 struct MeshTunnelTreeNode *n; 70 struct MeshTunnelTreeNode *n;
73 struct MeshTunnelTreeNode *c; 71 struct MeshTunnelTreeNode *c;
@@ -75,58 +73,57 @@ test_assert (GNUNET_PEER_Id peer_id,
75 int pre_failed; 73 int pre_failed;
76 74
77 pre_failed = failed; 75 pre_failed = failed;
78 n = tree_find_peer(tree, peer_id); 76 n = tree_find_peer (tree, peer_id);
79 if (n->peer != peer_id) 77 if (n->peer != peer_id)
80 { 78 {
81 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 79 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
82 "Retrieved peer has wrong ID! (%u, %u)\n", 80 "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id);
83 n->peer, peer_id);
84 failed++; 81 failed++;
85 } 82 }
86 if (n->status != status) 83 if (n->status != status)
87 { 84 {
88 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 85 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
89 "Retrieved peer has wrong status! (%u, %u)\n", 86 "Retrieved peer has wrong status! (%u, %u)\n", n->status,
90 n->status, status); 87 status);
91 failed++; 88 failed++;
92 } 89 }
93 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++); 90 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ;
94 if (i != children) 91 if (i != children)
95 { 92 {
96 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
97 "Retrieved peer wrong has number of children! (%u, %u)\n", 94 "Retrieved peer wrong has number of children! (%u, %u)\n", i,
98 i, children); 95 children);
99 failed++; 96 failed++;
100 } 97 }
101 if (0 != first_hop && 98 if (0 != first_hop &&
102 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop) 99 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop)
103 { 100 {
104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n",
105 "Wrong first hop! (%u, %u)\n", 102 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)),
106 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)), 103 first_hop);
107 first_hop);
108 failed++; 104 failed++;
109 } 105 }
110 if (pre_failed != failed) 106 if (pre_failed != failed)
111 { 107 {
112 struct GNUNET_PeerIdentity id; 108 struct GNUNET_PeerIdentity id;
109
113 GNUNET_PEER_resolve (peer_id, &id); 110 GNUNET_PEER_resolve (peer_id, &id);
114 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 111 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
115 "*** Peer %s (%u) has failed %d checks! (real, expected)\n", 112 "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
116 GNUNET_i2s (&id), peer_id, failed - pre_failed); 113 GNUNET_i2s (&id), peer_id, failed - pre_failed);
117 } 114 }
118} 115}
119 116
120 117
121static void 118static void
122finish(void) 119finish (void)
123{ 120{
124 unsigned int i; 121 unsigned int i;
125 122
126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n"); 123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
127 for (i = 0; i < 10; i++) 124 for (i = 0; i < 10; i++)
128 { 125 {
129 GNUNET_free(pi[i]); 126 GNUNET_free (pi[i]);
130 } 127 }
131} 128}
132 129
@@ -138,7 +135,7 @@ get_pi (uint32_t id)
138{ 135{
139 struct GNUNET_PeerIdentity *pi; 136 struct GNUNET_PeerIdentity *pi;
140 137
141 pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 138 pi = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
142 pi->hashPubKey.bits[0] = id + 1; 139 pi->hashPubKey.bits[0] = id + 1;
143 return pi; 140 return pi;
144} 141}
@@ -164,11 +161,10 @@ main (int argc, char *argv[])
164 NULL); 161 NULL);
165 for (i = 0; i < 10; i++) 162 for (i = 0; i < 10; i++)
166 { 163 {
167 pi[i] = get_pi(i); 164 pi[i] = get_pi (i);
168 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 165 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i + 1,
170 i + 1, 167 GNUNET_h2s (&pi[i]->hashPubKey));
171 GNUNET_h2s(&pi[i]->hashPubKey));
172 } 168 }
173 tree = tree_new (1); 169 tree = tree_new (1);
174 tree->me = tree->root; 170 tree->me = tree->root;
@@ -179,37 +175,37 @@ main (int argc, char *argv[])
179 path->peers[3] = 4; 175 path->peers[3] = 4;
180 path->length = 4; 176 path->length = 4;
181 177
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
183 tree_add_path(tree, path, &cb, NULL); 179 tree_add_path (tree, path, &cb, NULL);
184 tree_debug(tree); 180 tree_debug (tree);
185 path1 = tree_get_path_to_peer(tree, 4); 181 path1 = tree_get_path_to_peer (tree, 4);
186 if (path->length != path1->length || 182 if (path->length != path1->length ||
187 memcmp(path->peers, path1->peers, path->length) != 0) 183 memcmp (path->peers, path1->peers, path->length) != 0)
188 { 184 {
189 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); 185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
190 failed++; 186 failed++;
191 } 187 }
192 path_destroy(path1); 188 path_destroy (path1);
193 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 189 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
194 test_assert (3, MESH_PEER_RELAY, 1, 0); 190 test_assert (3, MESH_PEER_RELAY, 1, 0);
195 test_assert (2, MESH_PEER_RELAY, 1, 0); 191 test_assert (2, MESH_PEER_RELAY, 1, 0);
196 test_assert (1, MESH_PEER_ROOT, 1, 0); 192 test_assert (1, MESH_PEER_ROOT, 1, 0);
197 193
198 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
199 path->length--; 195 path->length--;
200 tree_add_path(tree, path, &cb, NULL); 196 tree_add_path (tree, path, &cb, NULL);
201 tree_debug(tree); 197 tree_debug (tree);
202 198
203 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 199 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
204 test_assert (3, MESH_PEER_SEARCHING, 1, 2); 200 test_assert (3, MESH_PEER_SEARCHING, 1, 2);
205 test_assert (2, MESH_PEER_RELAY, 1, 0); 201 test_assert (2, MESH_PEER_RELAY, 1, 0);
206 test_assert (1, MESH_PEER_ROOT, 1, 0); 202 test_assert (1, MESH_PEER_ROOT, 1, 0);
207 203
208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
209 path->length++; 205 path->length++;
210 path->peers[3] = 5; 206 path->peers[3] = 5;
211 tree_add_path(tree, path, &cb, NULL); 207 tree_add_path (tree, path, &cb, NULL);
212 tree_debug(tree); 208 tree_debug (tree);
213 209
214 test_assert (5, MESH_PEER_SEARCHING, 0, 2); 210 test_assert (5, MESH_PEER_SEARCHING, 0, 2);
215 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 211 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
@@ -217,20 +213,20 @@ main (int argc, char *argv[])
217 test_assert (2, MESH_PEER_RELAY, 1, 0); 213 test_assert (2, MESH_PEER_RELAY, 1, 0);
218 test_assert (1, MESH_PEER_ROOT, 1, 0); 214 test_assert (1, MESH_PEER_ROOT, 1, 0);
219 215
220 node = tree_find_peer(tree, 5); 216 node = tree_find_peer (tree, 5);
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
222 node->status = MESH_PEER_READY; 218 node->status = MESH_PEER_READY;
223 cb_call = 1; 219 cb_call = 1;
224 node2 = tree_del_path(tree, 5, &cb, NULL); 220 node2 = tree_del_path (tree, 5, &cb, NULL);
225 tree_debug(tree); 221 tree_debug (tree);
226 if (cb_call != 0) 222 if (cb_call != 0)
227 { 223 {
228 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
229 failed++; 225 failed++;
230 } 226 }
231 if (node2->peer != 5) 227 if (node2->peer != 5)
232 { 228 {
233 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
234 failed++; 230 failed++;
235 } 231 }
236 232
@@ -239,20 +235,20 @@ main (int argc, char *argv[])
239 test_assert (2, MESH_PEER_RELAY, 1, 0); 235 test_assert (2, MESH_PEER_RELAY, 1, 0);
240 test_assert (1, MESH_PEER_ROOT, 1, 0); 236 test_assert (1, MESH_PEER_ROOT, 1, 0);
241 237
242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
243 GNUNET_free (node2); 239 GNUNET_free (node2);
244 240
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "test: Adding new shorter first path...\n"); 242 "test: Adding new shorter first path...\n");
247 path->length = 2; 243 path->length = 2;
248 path->peers[1] = 4; 244 path->peers[1] = 4;
249 cb_call = 1; 245 cb_call = 1;
250 tree_find_peer(tree, 4)->status = MESH_PEER_READY; 246 tree_find_peer (tree, 4)->status = MESH_PEER_READY;
251 tree_add_path(tree, path, &cb, NULL); 247 tree_add_path (tree, path, &cb, NULL);
252 tree_debug(tree); 248 tree_debug (tree);
253 if (cb_call != 0) 249 if (cb_call != 0)
254 { 250 {
255 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
256 failed++; 252 failed++;
257 } 253 }
258 254
@@ -265,35 +261,35 @@ main (int argc, char *argv[])
265 GNUNET_free (path); 261 GNUNET_free (path);
266 tree_destroy (tree); 262 tree_destroy (tree);
267 263
268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n"); 264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n");
269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
270 for (i = 0; i < 10; i++) 266 for (i = 0; i < 10; i++)
271 { 267 {
272 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 268 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
273 } 269 }
274 tree = tree_new(1); 270 tree = tree_new (1);
275 path = path_new (3); 271 path = path_new (3);
276 path->peers[0] = 1; 272 path->peers[0] = 1;
277 path->peers[1] = 2; 273 path->peers[1] = 2;
278 path->peers[2] = 3; 274 path->peers[2] = 3;
279 path->length = 3; 275 path->length = 3;
280 276
281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
282 tree_add_path(tree, path, &cb, NULL); 278 tree_add_path (tree, path, &cb, NULL);
283 tree_debug(tree); 279 tree_debug (tree);
284 tree_set_me (tree, 2); 280 tree_set_me (tree, 2);
285 281
286 test_assert (3, MESH_PEER_SEARCHING, 0, 3); 282 test_assert (3, MESH_PEER_SEARCHING, 0, 3);
287 test_assert (2, MESH_PEER_RELAY, 1, 0); 283 test_assert (2, MESH_PEER_RELAY, 1, 0);
288 test_assert (1, MESH_PEER_ROOT, 1, 0); 284 test_assert (1, MESH_PEER_ROOT, 1, 0);
289 285
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
291 tree_add_path(tree, path, &cb, NULL); 287 tree_add_path (tree, path, &cb, NULL);
292 288
293 GNUNET_free (path->peers); 289 GNUNET_free (path->peers);
294 GNUNET_free (path); 290 GNUNET_free (path);
295 tree_destroy (tree); 291 tree_destroy (tree);
296 finish(); 292 finish ();
297 if (failed > 0) 293 if (failed > 0)
298 { 294 {
299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);