diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-14 11:19:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-14 11:19:58 +0000 |
commit | b0268a0ef60e6e68d29c4eb8baf2742da2326bf8 (patch) | |
tree | 8a82db52d17fc12513d4823ac95c55da5446f069 /src/set | |
parent | 2674f29dc3ace3b8f9243d8c9ba340743c67b449 (diff) | |
download | gnunet-b0268a0ef60e6e68d29c4eb8baf2742da2326bf8.tar.gz gnunet-b0268a0ef60e6e68d29c4eb8baf2742da2326bf8.zip |
-fix testcase shutdown
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/test_set_union_copy.c | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c index 7fedf426b..6fd78d43a 100644 --- a/src/set/test_set_union_copy.c +++ b/src/set/test_set_union_copy.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2015 GNUnet e.V. | 3 | Copyright (C) 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -21,6 +21,7 @@ | |||
21 | /** | 21 | /** |
22 | * @file set/test_set_union_copy.c | 22 | * @file set/test_set_union_copy.c |
23 | * @brief testcase for lazy copying of union sets | 23 | * @brief testcase for lazy copying of union sets |
24 | * @author Florian Dold | ||
24 | */ | 25 | */ |
25 | #include "platform.h" | 26 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
@@ -46,28 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
46 | 47 | ||
47 | 48 | ||
48 | static void | 49 | static void |
49 | add_element_str (struct GNUNET_SET_Handle *set, char *str) | 50 | add_element_str (struct GNUNET_SET_Handle *set, |
51 | char *str) | ||
50 | { | 52 | { |
51 | struct GNUNET_SET_Element element; | 53 | struct GNUNET_SET_Element element; |
52 | 54 | ||
53 | element.element_type = 0; | 55 | element.element_type = 0; |
54 | element.data = str; | 56 | element.data = str; |
55 | element.size = strlen (str); | 57 | element.size = strlen (str); |
56 | 58 | GNUNET_SET_add_element (set, | |
57 | GNUNET_SET_add_element (set, &element, NULL, NULL); | 59 | &element, |
60 | NULL, | ||
61 | NULL); | ||
58 | } | 62 | } |
59 | 63 | ||
60 | 64 | ||
61 | static void | 65 | static void |
62 | remove_element_str (struct GNUNET_SET_Handle *set, char *str) | 66 | remove_element_str (struct GNUNET_SET_Handle *set, |
67 | char *str) | ||
63 | { | 68 | { |
64 | struct GNUNET_SET_Element element; | 69 | struct GNUNET_SET_Element element; |
65 | 70 | ||
66 | element.element_type = 0; | 71 | element.element_type = 0; |
67 | element.data = str; | 72 | element.data = str; |
68 | element.size = strlen (str); | 73 | element.size = strlen (str); |
69 | 74 | GNUNET_SET_remove_element (set, | |
70 | GNUNET_SET_remove_element (set, &element, NULL, NULL); | 75 | &element, |
76 | NULL, | ||
77 | NULL); | ||
71 | } | 78 | } |
72 | 79 | ||
73 | 80 | ||
@@ -84,14 +91,12 @@ timeout_fail (void *cls) | |||
84 | ret = 1; | 91 | ret = 1; |
85 | } | 92 | } |
86 | 93 | ||
87 | typedef void (*Continuation) (void *cls); | ||
88 | |||
89 | 94 | ||
90 | struct CountIterClosure | 95 | struct CountIterClosure |
91 | { | 96 | { |
92 | unsigned int expected_count; | 97 | unsigned int expected_count; |
93 | unsigned int ongoing_count; | 98 | unsigned int ongoing_count; |
94 | Continuation cont; | 99 | GNUNET_SCHEDULER_TaskCallback cont; |
95 | void *cont_cls; | 100 | void *cont_cls; |
96 | char *what; | 101 | char *what; |
97 | }; | 102 | }; |
@@ -127,7 +132,7 @@ static void | |||
127 | check_count (struct GNUNET_SET_Handle *set, | 132 | check_count (struct GNUNET_SET_Handle *set, |
128 | char *what, | 133 | char *what, |
129 | unsigned int expected_count, | 134 | unsigned int expected_count, |
130 | Continuation cont, | 135 | GNUNET_SCHEDULER_TaskCallback cont, |
131 | void *cont_cls) | 136 | void *cont_cls) |
132 | { | 137 | { |
133 | struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); | 138 | struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); |
@@ -138,19 +143,16 @@ check_count (struct GNUNET_SET_Handle *set, | |||
138 | ci_cls->cont_cls = cont_cls; | 143 | ci_cls->cont_cls = cont_cls; |
139 | ci_cls->what = what; | 144 | ci_cls->what = what; |
140 | 145 | ||
141 | GNUNET_assert (GNUNET_YES == GNUNET_SET_iterate (set, check_count_iter, ci_cls)); | 146 | GNUNET_assert (GNUNET_YES == |
147 | GNUNET_SET_iterate (set, | ||
148 | &check_count_iter, | ||
149 | ci_cls)); | ||
142 | } | 150 | } |
143 | 151 | ||
144 | 152 | ||
145 | static void | 153 | static void |
146 | test_done (void *cls) | 154 | test_done (void *cls) |
147 | { | 155 | { |
148 | if (NULL != set1) | ||
149 | GNUNET_SET_destroy (set1); | ||
150 | if (NULL != set2) | ||
151 | GNUNET_SET_destroy (set2); | ||
152 | GNUNET_SCHEDULER_cancel (tt); | ||
153 | tt = NULL; | ||
154 | GNUNET_SCHEDULER_shutdown (); | 156 | GNUNET_SCHEDULER_shutdown (); |
155 | } | 157 | } |
156 | 158 | ||
@@ -158,12 +160,17 @@ test_done (void *cls) | |||
158 | static void | 160 | static void |
159 | check_new_set_count (void *cls) | 161 | check_new_set_count (void *cls) |
160 | { | 162 | { |
161 | check_count (set2, "new set", 4, &test_done, NULL); | 163 | check_count (set2, |
164 | "new set", | ||
165 | 4, | ||
166 | &test_done, | ||
167 | NULL); | ||
162 | } | 168 | } |
163 | 169 | ||
164 | 170 | ||
165 | static void | 171 | static void |
166 | copy_done (void *cls, struct GNUNET_SET_Handle *new_set) | 172 | copy_done (void *cls, |
173 | struct GNUNET_SET_Handle *new_set) | ||
167 | { | 174 | { |
168 | printf ("copy done\n"); | 175 | printf ("copy done\n"); |
169 | set2 = new_set; | 176 | set2 = new_set; |
@@ -174,7 +181,8 @@ copy_done (void *cls, struct GNUNET_SET_Handle *new_set) | |||
174 | remove_element_str (set2, "new3"); | 181 | remove_element_str (set2, "new3"); |
175 | // Check that set1 didn't change. | 182 | // Check that set1 didn't change. |
176 | check_count (set1, "old set", 3, | 183 | check_count (set1, "old set", 3, |
177 | &check_new_set_count, NULL); | 184 | &check_new_set_count, |
185 | NULL); | ||
178 | } | 186 | } |
179 | 187 | ||
180 | 188 | ||
@@ -182,14 +190,41 @@ static void | |||
182 | test_copy (void *cls) | 190 | test_copy (void *cls) |
183 | { | 191 | { |
184 | printf ("about to copy\n"); | 192 | printf ("about to copy\n"); |
185 | GNUNET_SET_copy_lazy (set1, copy_done, NULL); | 193 | GNUNET_SET_copy_lazy (set1, |
194 | ©_done, | ||
195 | NULL); | ||
186 | } | 196 | } |
187 | 197 | ||
188 | 198 | ||
199 | /** | ||
200 | * Function run on shutdown. | ||
201 | * | ||
202 | * @param cls closure | ||
203 | */ | ||
204 | static void | ||
205 | do_shutdown (void *cls) | ||
206 | { | ||
207 | if (NULL != tt) | ||
208 | { | ||
209 | GNUNET_SCHEDULER_cancel (tt); | ||
210 | tt = NULL; | ||
211 | } | ||
212 | if (NULL != set1) | ||
213 | { | ||
214 | GNUNET_SET_destroy (set1); | ||
215 | set1 = NULL; | ||
216 | } | ||
217 | if (NULL != set2) | ||
218 | { | ||
219 | GNUNET_SET_destroy (set2); | ||
220 | set2 = NULL; | ||
221 | } | ||
222 | } | ||
223 | |||
189 | 224 | ||
190 | /** | 225 | /** |
191 | * Signature of the 'main' function for a (single-peer) testcase that | 226 | * Signature of the 'main' function for a (single-peer) testcase that |
192 | * is run using 'GNUNET_TESTING_peer_run'. | 227 | * is run using #GNUNET_TESTING_peer_run(). |
193 | * | 228 | * |
194 | * @param cls closure | 229 | * @param cls closure |
195 | * @param cfg configuration of the peer that was started | 230 | * @param cfg configuration of the peer that was started |
@@ -202,8 +237,9 @@ run (void *cls, | |||
202 | { | 237 | { |
203 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 238 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), |
204 | &timeout_fail, | 239 | &timeout_fail, |
205 | NULL); | 240 | NULL); |
206 | 241 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | |
242 | NULL); | ||
207 | config = cfg; | 243 | config = cfg; |
208 | GNUNET_TESTING_peer_get_identity (peer, | 244 | GNUNET_TESTING_peer_get_identity (peer, |
209 | &local_id); | 245 | &local_id); |
@@ -221,7 +257,11 @@ run (void *cls, | |||
221 | remove_element_str (set1, "foo"); | 257 | remove_element_str (set1, "foo"); |
222 | add_element_str (set1, "eggs"); | 258 | add_element_str (set1, "eggs"); |
223 | 259 | ||
224 | check_count (set1, "initial test", 3, &test_copy, NULL); | 260 | check_count (set1, |
261 | "initial test", | ||
262 | 3, | ||
263 | &test_copy, | ||
264 | NULL); | ||
225 | } | 265 | } |
226 | 266 | ||
227 | 267 | ||
@@ -232,7 +272,8 @@ main (int argc, char **argv) | |||
232 | "test_set.conf", | 272 | "test_set.conf", |
233 | &run, NULL)) | 273 | &run, NULL)) |
234 | { | 274 | { |
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failed to start testing peer\n"); | 275 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
276 | "failed to start testing peer\n"); | ||
236 | return 1; | 277 | return 1; |
237 | } | 278 | } |
238 | return ret; | 279 | return ret; |