aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-07 18:52:04 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-07 18:52:04 +0000
commit71c9ff44f0b1b1f6c3dc72e945644e47ab5ab921 (patch)
treea59a37230173cc956bd22f7cfb0557dccc19b515 /src/set
parent6da7b6a2dc5ec3645d5f8bdbd4ab77d6090b823f (diff)
downloadgnunet-71c9ff44f0b1b1f6c3dc72e945644e47ab5ab921.tar.gz
gnunet-71c9ff44f0b1b1f6c3dc72e945644e47ab5ab921.zip
improve test to check set union operation and to test with empty sets
Diffstat (limited to 'src/set')
-rw-r--r--src/set/Makefile.am5
-rw-r--r--src/set/test_set_union_result_full.c152
2 files changed, 114 insertions, 43 deletions
diff --git a/src/set/Makefile.am b/src/set/Makefile.am
index bda512be6..b91a54683 100644
--- a/src/set/Makefile.am
+++ b/src/set/Makefile.am
@@ -65,7 +65,9 @@ libgnunetset_la_LDFLAGS = \
65 65
66if HAVE_TESTING 66if HAVE_TESTING
67check_PROGRAMS = \ 67check_PROGRAMS = \
68 test_set_api test_set_union_result_full test_set_intersection_result_full 68 test_set_api \
69 test_set_union_result_full \
70 test_set_intersection_result_full
69endif 71endif
70 72
71if ENABLE_TEST_RUN 73if ENABLE_TEST_RUN
@@ -96,4 +98,3 @@ test_set_intersection_result_full_LDADD = \
96 98
97EXTRA_DIST = \ 99EXTRA_DIST = \
98 test_set.conf 100 test_set.conf
99
diff --git a/src/set/test_set_union_result_full.c b/src/set/test_set_union_result_full.c
index 4aa04ac8c..3ebdbe57c 100644
--- a/src/set/test_set_union_result_full.c
+++ b/src/set/test_set_union_result_full.c
@@ -28,35 +28,61 @@
28#include "gnunet_set_service.h" 28#include "gnunet_set_service.h"
29 29
30 30
31/**
32 * Value to return from #main().
33 */
31static int ret; 34static int ret;
32 35
33static struct GNUNET_PeerIdentity local_id; 36static struct GNUNET_PeerIdentity local_id;
34 37
35static struct GNUNET_HashCode app_id; 38static struct GNUNET_HashCode app_id;
36static struct GNUNET_SET_Handle *set1; 39static struct GNUNET_SET_Handle *set1;
40
37static struct GNUNET_SET_Handle *set2; 41static struct GNUNET_SET_Handle *set2;
42
38static struct GNUNET_SET_ListenHandle *listen_handle; 43static struct GNUNET_SET_ListenHandle *listen_handle;
39const static struct GNUNET_CONFIGURATION_Handle *config; 44
45static const struct GNUNET_CONFIGURATION_Handle *config;
40 46
41static int iter_count; 47static int iter_count;
42 48
49/**
50 * Are we testing correctness for the empty set union?
51 */
52static int empty;
53
54/**
55 * Number of elements found in set 1
56 */
57static unsigned int count_set1;
58
59/**
60 * Number of elements found in set 2
61 */
62static unsigned int count_set2;
63
43 64
44static void 65static void
45result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element, 66result_cb_set1 (void *cls,
67 const struct GNUNET_SET_Element *element,
46 enum GNUNET_SET_Status status) 68 enum GNUNET_SET_Status status)
47{ 69{
48 switch (status) 70 switch (status)
49 { 71 {
50 case GNUNET_SET_STATUS_OK: 72 case GNUNET_SET_STATUS_OK:
51 printf ("set 1: got element\n"); 73 count_set1++;
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
75 "set 1: got element\n");
52 break; 76 break;
53 case GNUNET_SET_STATUS_FAILURE: 77 case GNUNET_SET_STATUS_FAILURE:
54 printf ("set 1: failure\n"); 78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
79 "set 1: failure\n");
55 ret = 1; 80 ret = 1;
56 GNUNET_SCHEDULER_shutdown (); 81 GNUNET_SCHEDULER_shutdown ();
57 break; 82 break;
58 case GNUNET_SET_STATUS_DONE: 83 case GNUNET_SET_STATUS_DONE:
59 printf ("set 1: done\n"); 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "set 1: done\n");
60 GNUNET_SET_destroy (set1); 86 GNUNET_SET_destroy (set1);
61 set1 = NULL; 87 set1 = NULL;
62 if (NULL == set2) 88 if (NULL == set2)
@@ -69,21 +95,26 @@ result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element,
69 95
70 96
71static void 97static void
72result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element, 98result_cb_set2 (void *cls,
73 enum GNUNET_SET_Status status) 99 const struct GNUNET_SET_Element *element,
100 enum GNUNET_SET_Status status)
74{ 101{
75 switch (status) 102 switch (status)
76 { 103 {
77 case GNUNET_SET_STATUS_OK: 104 case GNUNET_SET_STATUS_OK:
78 printf ("set 2: got element\n"); 105 count_set2++;
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107 "set 2: got element\n");
79 break; 108 break;
80 case GNUNET_SET_STATUS_FAILURE: 109 case GNUNET_SET_STATUS_FAILURE:
81 printf ("set 2: failure\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "set 2: failure\n");
82 ret = 1; 112 ret = 1;
83 GNUNET_SCHEDULER_shutdown (); 113 GNUNET_SCHEDULER_shutdown ();
84 break; 114 break;
85 case GNUNET_SET_STATUS_DONE: 115 case GNUNET_SET_STATUS_DONE:
86 printf ("set 2: done\n"); 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "set 2: done\n");
87 GNUNET_SET_destroy (set2); 118 GNUNET_SET_destroy (set2);
88 set2 = NULL; 119 set2 = NULL;
89 if (NULL == set1) 120 if (NULL == set1)
@@ -104,13 +135,14 @@ listen_cb (void *cls,
104 struct GNUNET_SET_OperationHandle *oh; 135 struct GNUNET_SET_OperationHandle *oh;
105 136
106 GNUNET_assert (NULL != context_msg); 137 GNUNET_assert (NULL != context_msg);
107
108 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); 138 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST);
109 139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
110 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "listen cb called\n"); 140 "listen cb called\n");
111 GNUNET_SET_listen_cancel (listen_handle); 141 GNUNET_SET_listen_cancel (listen_handle);
112 142 oh = GNUNET_SET_accept (request,
113 oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_FULL, result_cb_set2, NULL); 143 GNUNET_SET_RESULT_FULL,
144 &result_cb_set2,
145 NULL);
114 GNUNET_SET_commit (oh, set2); 146 GNUNET_SET_commit (oh, set2);
115} 147}
116 148
@@ -129,11 +161,15 @@ start (void *cls)
129 context_msg.size = htons (sizeof context_msg); 161 context_msg.size = htons (sizeof context_msg);
130 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); 162 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST);
131 163
132 listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, 164 listen_handle = GNUNET_SET_listen (config,
133 &app_id, listen_cb, NULL); 165 GNUNET_SET_OPERATION_UNION,
134 oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg, 166 &app_id,
167 &listen_cb, NULL);
168 oh = GNUNET_SET_prepare (&local_id,
169 &app_id,
170 &context_msg,
135 GNUNET_SET_RESULT_FULL, 171 GNUNET_SET_RESULT_FULL,
136 result_cb_set1, NULL); 172 &result_cb_set1, NULL);
137 GNUNET_SET_commit (oh, set1); 173 GNUNET_SET_commit (oh, set1);
138} 174}
139 175
@@ -148,19 +184,31 @@ init_set2 (void *cls)
148{ 184{
149 struct GNUNET_SET_Element element; 185 struct GNUNET_SET_Element element;
150 186
151 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 188 "initializing set 2\n");
189 if (empty)
190 {
191 start (NULL);
192 return;
193 }
153 element.element_type = 0; 194 element.element_type = 0;
154
155 element.data = "hello"; 195 element.data = "hello";
156 element.size = strlen(element.data); 196 element.size = strlen(element.data);
157 GNUNET_SET_add_element (set2, &element, NULL, NULL); 197 GNUNET_SET_add_element (set2,
198 &element,
199 NULL,
200 NULL);
158 element.data = "quux"; 201 element.data = "quux";
159 element.size = strlen(element.data); 202 element.size = strlen(element.data);
160 GNUNET_SET_add_element (set2, &element, NULL, NULL); 203 GNUNET_SET_add_element (set2,
204 &element,
205 NULL,
206 NULL);
161 element.data = "baz"; 207 element.data = "baz";
162 element.size = strlen(element.data); 208 element.size = strlen(element.data);
163 GNUNET_SET_add_element (set2, &element, start, NULL); 209 GNUNET_SET_add_element (set2,
210 &element,
211 &start, NULL);
164} 212}
165 213
166 214
@@ -172,16 +220,26 @@ init_set1 (void)
172{ 220{
173 struct GNUNET_SET_Element element; 221 struct GNUNET_SET_Element element;
174 222
223 if (empty)
224 {
225 init_set2 (NULL);
226 return;
227 }
175 element.element_type = 0; 228 element.element_type = 0;
176
177 element.data = "hello"; 229 element.data = "hello";
178 element.size = strlen(element.data); 230 element.size = strlen(element.data);
179 GNUNET_SET_add_element (set1, &element, NULL, NULL); 231 GNUNET_SET_add_element (set1,
232 &element,
233 NULL,
234 NULL);
180 element.data = "bar"; 235 element.data = "bar";
181 element.size = strlen(element.data); 236 element.size = strlen(element.data);
182 GNUNET_SET_add_element (set1, &element, init_set2, NULL); 237 GNUNET_SET_add_element (set1,
183 238 &element,
184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); 239 &init_set2,
240 NULL);
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "initialized set 1\n");
185} 243}
186 244
187 245
@@ -195,7 +253,8 @@ iter_cb (void *cls,
195 GNUNET_SET_destroy (cls); 253 GNUNET_SET_destroy (cls);
196 return GNUNET_YES; 254 return GNUNET_YES;
197 } 255 }
198 printf ("iter: got element\n"); 256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "iter: got element\n");
199 iter_count++; 258 iter_count++;
200 return GNUNET_YES; 259 return GNUNET_YES;
201} 260}
@@ -207,10 +266,9 @@ test_iter ()
207 struct GNUNET_SET_Element element; 266 struct GNUNET_SET_Element element;
208 struct GNUNET_SET_Handle *iter_set; 267 struct GNUNET_SET_Handle *iter_set;
209 268
269 iter_count = 0;
210 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); 270 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
211
212 element.element_type = 0; 271 element.element_type = 0;
213
214 element.data = "hello"; 272 element.data = "hello";
215 element.size = strlen(element.data); 273 element.size = strlen(element.data);
216 GNUNET_SET_add_element (iter_set, &element, NULL, NULL); 274 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
@@ -221,7 +279,9 @@ test_iter ()
221 element.size = strlen(element.data); 279 element.size = strlen(element.data);
222 GNUNET_SET_add_element (iter_set, &element, NULL, NULL); 280 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
223 281
224 GNUNET_SET_iterate (iter_set, iter_cb, iter_set); 282 GNUNET_SET_iterate (iter_set,
283 &iter_cb,
284 iter_set);
225} 285}
226 286
227 287
@@ -255,15 +315,13 @@ run (void *cls,
255 const struct GNUNET_CONFIGURATION_Handle *cfg, 315 const struct GNUNET_CONFIGURATION_Handle *cfg,
256 struct GNUNET_TESTING_Peer *peer) 316 struct GNUNET_TESTING_Peer *peer)
257{ 317{
258
259 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 318 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
260 &timeout_fail, NULL); 319 &timeout_fail,
320 NULL);
261 321
262 config = cfg; 322 config = cfg;
263 GNUNET_CRYPTO_get_peer_identity (cfg, &local_id); 323 GNUNET_TESTING_peer_get_identity (peer,
264 printf ("my id (from CRYPTO): %s\n", GNUNET_i2s (&local_id)); 324 &local_id);
265 GNUNET_TESTING_peer_get_identity (peer, &local_id);
266 printf ("my id (from TESTING): %s\n", GNUNET_i2s (&local_id));
267 325
268 test_iter (); 326 test_iter ();
269 327
@@ -275,15 +333,27 @@ run (void *cls,
275 init_set1 (); 333 init_set1 ();
276} 334}
277 335
336
278int 337int
279main (int argc, char **argv) 338main (int argc, char **argv)
280{ 339{
340 empty = 1;
281 if (0 != GNUNET_TESTING_peer_run ("test_set_api", 341 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
282 "test_set.conf", 342 "test_set.conf",
283 &run, NULL)) 343 &run, NULL))
284 { 344 {
285 return 1; 345 return 1;
286 } 346 }
347 GNUNET_assert (0 == count_set1);
348 GNUNET_assert (0 == count_set2);
349 empty = 0;
350 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
351 "test_set.conf",
352 &run, NULL))
353 {
354 return 1;
355 }
356 GNUNET_assert (4 == count_set1);
357 GNUNET_assert (4 == count_set2);
287 return ret; 358 return ret;
288} 359}
289