diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-15 14:47:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-15 14:47:44 +0000 |
commit | 482d35a0c3148bcc69929c5778038db00d0839b9 (patch) | |
tree | 51b1e474192e0daf73aca4454835006f81069d8b /src/ats | |
parent | 13127bcace2ce4ae867f885e7ffb4b3885402ecd (diff) | |
download | gnunet-482d35a0c3148bcc69929c5778038db00d0839b9.tar.gz gnunet-482d35a0c3148bcc69929c5778038db00d0839b9.zip |
-fix crash in testcase
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/test_ats_api_performance_list_peer_addresses.c | 116 |
1 files changed, 66 insertions, 50 deletions
diff --git a/src/ats/test_ats_api_performance_list_peer_addresses.c b/src/ats/test_ats_api_performance_list_peer_addresses.c index 1f64a6ae9..bebec4881 100644 --- a/src/ats/test_ats_api_performance_list_peer_addresses.c +++ b/src/ats/test_ats_api_performance_list_peer_addresses.c | |||
@@ -56,6 +56,7 @@ struct GNUNET_ATS_AddressListHandle* phal; | |||
56 | 56 | ||
57 | static int ret; | 57 | static int ret; |
58 | 58 | ||
59 | |||
59 | struct Address | 60 | struct Address |
60 | { | 61 | { |
61 | char *plugin; | 62 | char *plugin; |
@@ -70,6 +71,7 @@ struct Address | |||
70 | void *session; | 71 | void *session; |
71 | }; | 72 | }; |
72 | 73 | ||
74 | |||
73 | struct PeerContext | 75 | struct PeerContext |
74 | { | 76 | { |
75 | struct GNUNET_PeerIdentity id; | 77 | struct GNUNET_PeerIdentity id; |
@@ -77,6 +79,7 @@ struct PeerContext | |||
77 | struct Address *addr; | 79 | struct Address *addr; |
78 | }; | 80 | }; |
79 | 81 | ||
82 | |||
80 | static struct PeerContext p[2]; | 83 | static struct PeerContext p[2]; |
81 | 84 | ||
82 | static struct Address p0_addresses[2]; | 85 | static struct Address p0_addresses[2]; |
@@ -86,11 +89,10 @@ struct GNUNET_HELLO_Address p0_ha[2]; | |||
86 | struct GNUNET_HELLO_Address p1_ha[2]; | 89 | struct GNUNET_HELLO_Address p1_ha[2]; |
87 | struct GNUNET_HELLO_Address *s_ha[2]; | 90 | struct GNUNET_HELLO_Address *s_ha[2]; |
88 | 91 | ||
89 | static void | ||
90 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | 92 | ||
92 | static void | 93 | static void |
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 94 | end (void *cls, |
95 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | 96 | ||
95 | 97 | ||
96 | static void | 98 | static void |
@@ -109,13 +111,14 @@ ats_perf_cb (void *cls, | |||
109 | if (2 == counter) | 111 | if (2 == counter) |
110 | { | 112 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 113 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
112 | "Done\n"); | 114 | "Done\n"); |
113 | GNUNET_SCHEDULER_add_now (end, NULL); | 115 | GNUNET_SCHEDULER_add_now (&end, |
116 | NULL); | ||
114 | } | 117 | } |
115 | else | 118 | else |
116 | { | 119 | { |
117 | GNUNET_break (0); | 120 | GNUNET_break (0); |
118 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | 121 | GNUNET_SCHEDULER_shutdown (); |
119 | } | 122 | } |
120 | return; | 123 | return; |
121 | } | 124 | } |
@@ -124,7 +127,8 @@ ats_perf_cb (void *cls, | |||
124 | if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) | 127 | if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) |
125 | { | 128 | { |
126 | GNUNET_break (0); | 129 | GNUNET_break (0); |
127 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | 130 | GNUNET_SCHEDULER_shutdown (); |
131 | return; | ||
128 | } | 132 | } |
129 | } | 133 | } |
130 | counter ++; | 134 | counter ++; |
@@ -137,51 +141,37 @@ stat_cb(void *cls, const char *subsystem, | |||
137 | int is_persistent) | 141 | int is_persistent) |
138 | { | 142 | { |
139 | 143 | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | 144 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
141 | subsystem,name, value); | 145 | "ATS statistics: `%s' `%s' %llu\n", |
146 | subsystem, | ||
147 | name, | ||
148 | value); | ||
142 | if (4 == value) | 149 | if (4 == value) |
143 | { | 150 | { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
145 | "All addresses added, connecting to performance\n"); | 152 | "All addresses added, connecting to performance\n"); |
146 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) | 153 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) |
147 | { | 154 | { |
148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
149 | "Failed to connect to performance API\n"); | 156 | "Failed to connect to performance API\n"); |
150 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | 157 | GNUNET_SCHEDULER_shutdown (); |
158 | return GNUNET_SYSERR; | ||
151 | } | 159 | } |
152 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, &p[0].id, GNUNET_YES, ats_perf_cb, NULL); | 160 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, |
161 | &p[0].id, | ||
162 | GNUNET_YES, | ||
163 | &ats_perf_cb, NULL); | ||
153 | } | 164 | } |
154 | return GNUNET_OK; | 165 | return GNUNET_OK; |
155 | } | 166 | } |
156 | 167 | ||
157 | static void | ||
158 | address_suggest_cb (void *cls, | ||
159 | const struct GNUNET_PeerIdentity *peer, | ||
160 | const struct GNUNET_HELLO_Address *address, | ||
161 | struct Session *session, | ||
162 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
163 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
164 | const struct GNUNET_ATS_Information *atsi, | ||
165 | uint32_t ats_count) | ||
166 | { | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
168 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | |||
173 | static void | ||
174 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | ||
176 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
177 | end ( NULL, NULL); | ||
178 | ret = GNUNET_SYSERR; | ||
179 | } | ||
180 | 168 | ||
181 | static void | 169 | static void |
182 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 170 | end (void *cls, |
171 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
183 | { | 172 | { |
184 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
174 | "Shutting down\n"); | ||
185 | if (die_task != GNUNET_SCHEDULER_NO_TASK ) | 175 | if (die_task != GNUNET_SCHEDULER_NO_TASK ) |
186 | { | 176 | { |
187 | GNUNET_SCHEDULER_cancel (die_task); | 177 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -194,13 +184,13 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
194 | sched_ats = NULL; | 184 | sched_ats = NULL; |
195 | } | 185 | } |
196 | 186 | ||
197 | if (phal != NULL ) | 187 | if (NULL != phal) |
198 | { | 188 | { |
199 | GNUNET_ATS_performance_list_addresses_cancel (phal); | 189 | GNUNET_ATS_performance_list_addresses_cancel (phal); |
200 | phal = NULL; | 190 | phal = NULL; |
201 | } | 191 | } |
202 | 192 | ||
203 | if (perf_ats != NULL ) | 193 | if (perf_ats != NULL) |
204 | { | 194 | { |
205 | GNUNET_ATS_performance_done (perf_ats); | 195 | GNUNET_ATS_performance_done (perf_ats); |
206 | perf_ats = NULL; | 196 | perf_ats = NULL; |
@@ -212,17 +202,40 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
212 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 202 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
213 | stats = NULL; | 203 | stats = NULL; |
214 | } | 204 | } |
205 | GNUNET_free_non_null (p0_addresses[0].addr); | ||
206 | GNUNET_free_non_null (p0_addresses[1].addr); | ||
207 | GNUNET_free_non_null (p1_addresses[0].addr); | ||
208 | GNUNET_free_non_null (p1_addresses[1].addr); | ||
215 | 209 | ||
210 | ret = 0; | ||
211 | } | ||
216 | 212 | ||
217 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
218 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
219 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
220 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
221 | 213 | ||
222 | ret = 0; | 214 | static void |
215 | end_badly (void *cls, | ||
216 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
217 | { | ||
218 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
219 | end (NULL, NULL); | ||
220 | ret = GNUNET_SYSERR; | ||
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
224 | static void | ||
225 | address_suggest_cb (void *cls, | ||
226 | const struct GNUNET_PeerIdentity *peer, | ||
227 | const struct GNUNET_HELLO_Address *address, | ||
228 | struct Session *session, | ||
229 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
230 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
231 | const struct GNUNET_ATS_Information *atsi, | ||
232 | uint32_t ats_count) | ||
233 | { | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
235 | "Did not expect suggestion callback!\n"); | ||
236 | GNUNET_SCHEDULER_shutdown (); | ||
237 | } | ||
238 | |||
226 | 239 | ||
227 | static void | 240 | static void |
228 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 241 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, |
@@ -286,10 +299,11 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
286 | 299 | ||
287 | /* Add addresses */ | 300 | /* Add addresses */ |
288 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); | 301 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); |
289 | if (sched_ats == NULL ) | 302 | if (NULL == sched_ats) |
290 | { | 303 | { |
291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
292 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 305 | "Could not setup peer!\n"); |
306 | GNUNET_SCHEDULER_shutdown (); | ||
293 | return; | 307 | return; |
294 | } | 308 | } |
295 | 309 | ||
@@ -300,12 +314,14 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
300 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | 314 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); |
301 | } | 315 | } |
302 | 316 | ||
317 | |||
303 | int | 318 | int |
304 | main (int argc, char *argv[]) | 319 | main (int argc, char *argv[]) |
305 | { | 320 | { |
306 | if (0 | 321 | if (0 != |
307 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | 322 | GNUNET_TESTING_peer_run ("test_ats_api_performance", |
308 | "test_ats_api.conf", &run, NULL )) | 323 | "test_ats_api.conf", |
324 | &run, NULL)) | ||
309 | return 1; | 325 | return 1; |
310 | return ret; | 326 | return ret; |
311 | } | 327 | } |