aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-14 11:19:58 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-14 11:19:58 +0000
commitb0268a0ef60e6e68d29c4eb8baf2742da2326bf8 (patch)
tree8a82db52d17fc12513d4823ac95c55da5446f069 /src/set
parent2674f29dc3ace3b8f9243d8c9ba340743c67b449 (diff)
downloadgnunet-b0268a0ef60e6e68d29c4eb8baf2742da2326bf8.tar.gz
gnunet-b0268a0ef60e6e68d29c4eb8baf2742da2326bf8.zip
-fix testcase shutdown
Diffstat (limited to 'src/set')
-rw-r--r--src/set/test_set_union_copy.c95
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
48static void 49static void
49add_element_str (struct GNUNET_SET_Handle *set, char *str) 50add_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
61static void 65static void
62remove_element_str (struct GNUNET_SET_Handle *set, char *str) 66remove_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
87typedef void (*Continuation) (void *cls);
88
89 94
90struct CountIterClosure 95struct 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
127check_count (struct GNUNET_SET_Handle *set, 132check_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
145static void 153static void
146test_done (void *cls) 154test_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)
158static void 160static void
159check_new_set_count (void *cls) 161check_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
165static void 171static void
166copy_done (void *cls, struct GNUNET_SET_Handle *new_set) 172copy_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
182test_copy (void *cls) 190test_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 &copy_done,
195 NULL);
186} 196}
187 197
188 198
199/**
200 * Function run on shutdown.
201 *
202 * @param cls closure
203 */
204static void
205do_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;