diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-17 15:58:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-17 15:58:30 +0000 |
commit | 8d1e110fce531925bf66a70722198081370799cd (patch) | |
tree | 7136b4259bc57ad3afca617afb04e3da17edd220 /src/core/test_core_quota_compliance.c | |
parent | 8fb486de8ffe62372483e3941e67976f4cc77a83 (diff) | |
download | gnunet-8d1e110fce531925bf66a70722198081370799cd.tar.gz gnunet-8d1e110fce531925bf66a70722198081370799cd.zip |
Quota compliance testcases should ready to be commited...
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 120 |
1 files changed, 105 insertions, 15 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index a54cf4e0b..efdcefac5 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -34,8 +34,9 @@ | |||
34 | #include "gnunet_program_lib.h" | 34 | #include "gnunet_program_lib.h" |
35 | #include "gnunet_scheduler_lib.h" | 35 | #include "gnunet_scheduler_lib.h" |
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | #include "gnunet_statistics_service.h" | ||
37 | 38 | ||
38 | #define VERBOSE GNUNET_YES | 39 | #define VERBOSE GNUNET_NO |
39 | #define DEBUG_TRANSMISSION GNUNET_NO | 40 | #define DEBUG_TRANSMISSION GNUNET_NO |
40 | 41 | ||
41 | #define SYMMETRIC 0 | 42 | #define SYMMETRIC 0 |
@@ -84,6 +85,7 @@ struct PeerContext | |||
84 | struct GNUNET_PeerIdentity id; | 85 | struct GNUNET_PeerIdentity id; |
85 | struct GNUNET_TRANSPORT_Handle *th; | 86 | struct GNUNET_TRANSPORT_Handle *th; |
86 | struct GNUNET_MessageHeader *hello; | 87 | struct GNUNET_MessageHeader *hello; |
88 | struct GNUNET_STATISTICS_Handle *stats; | ||
87 | int connect_status; | 89 | int connect_status; |
88 | #if START_ARM | 90 | #if START_ARM |
89 | struct GNUNET_OS_Process *arm_proc; | 91 | struct GNUNET_OS_Process *arm_proc; |
@@ -151,6 +153,37 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
151 | ok = 42; | 153 | ok = 42; |
152 | } | 154 | } |
153 | 155 | ||
156 | |||
157 | /** | ||
158 | * Callback function to process statistic values. | ||
159 | * | ||
160 | * @param cls closure | ||
161 | * @param subsystem name of subsystem that created the statistic | ||
162 | * @param name the name of the datum | ||
163 | * @param value the current value | ||
164 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | ||
165 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
166 | */ | ||
167 | static int | ||
168 | print_stat (void *cls, | ||
169 | const char *subsystem, | ||
170 | const char *name, | ||
171 | uint64_t value, | ||
172 | int is_persistent) | ||
173 | { | ||
174 | if (cls==&p1) | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
176 | "Peer1 %50s = %12llu\n", | ||
177 | name, | ||
178 | (unsigned long long) value); | ||
179 | if (cls==&p2) | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
181 | "Peer2 %50s = %12llu\n", | ||
182 | name, | ||
183 | (unsigned long long) value); | ||
184 | return GNUNET_OK; | ||
185 | } | ||
186 | |||
154 | static void | 187 | static void |
155 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 188 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
156 | { | 189 | { |
@@ -185,33 +218,86 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
185 | quota_delta = max_quota_out / 10; | 218 | quota_delta = max_quota_out / 10; |
186 | 219 | ||
187 | if ((throughput_out < (max_quota_out/1024)) && (throughput_out < (max_quota_in/1024))) | 220 | if ((throughput_out < (max_quota_out/1024)) && (throughput_out < (max_quota_in/1024))) |
188 | { | ||
189 | ok = 0; | 221 | ok = 0; |
190 | } | ||
191 | else | 222 | else |
192 | { | ||
193 | ok = 1; | 223 | ok = 1; |
224 | |||
225 | GNUNET_STATISTICS_get (p1.stats, | ||
226 | "core", | ||
227 | "# discarded CORE_SEND requests", | ||
228 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
229 | NULL, | ||
230 | &print_stat, &p1); | ||
231 | |||
232 | GNUNET_STATISTICS_get (p1.stats, | ||
233 | "core", | ||
234 | "# discarded CORE_SEND request bytes", | ||
235 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
236 | NULL, | ||
237 | &print_stat, &p1); | ||
238 | GNUNET_STATISTICS_get (p1.stats, | ||
239 | "core", | ||
240 | "# discarded lower priority CORE_SEND requests", | ||
241 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
242 | NULL, | ||
243 | &print_stat, NULL); | ||
244 | GNUNET_STATISTICS_get (p1.stats, | ||
245 | "core", | ||
246 | "# discarded lower priority CORE_SEND request bytes", | ||
247 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
248 | NULL, | ||
249 | &print_stat, &p1); | ||
250 | GNUNET_STATISTICS_get (p2.stats, | ||
251 | "core", | ||
252 | "# discarded CORE_SEND requests", | ||
253 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
254 | NULL, | ||
255 | &print_stat, &p2); | ||
256 | |||
257 | GNUNET_STATISTICS_get (p2.stats, | ||
258 | "core", | ||
259 | "# discarded CORE_SEND request bytes", | ||
260 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
261 | NULL, | ||
262 | &print_stat, &p2); | ||
263 | GNUNET_STATISTICS_get (p2.stats, | ||
264 | "core", | ||
265 | "# discarded lower priority CORE_SEND requests", | ||
266 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
267 | NULL, | ||
268 | &print_stat, &p2); | ||
269 | GNUNET_STATISTICS_get (p2.stats, | ||
270 | "core", | ||
271 | "# discarded lower priority CORE_SEND request bytes", | ||
272 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
273 | NULL, | ||
274 | &print_stat, &p2); | ||
275 | |||
276 | enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; | ||
277 | if (ok==1) | ||
278 | { | ||
279 | kind = GNUNET_ERROR_TYPE_ERROR; | ||
194 | } | 280 | } |
195 | switch (test) | 281 | switch (test) |
196 | { | 282 | { |
197 | case SYMMETRIC: | 283 | case SYMMETRIC: |
198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with symmetric quotas\n"); | 284 | GNUNET_log (kind,"Core quota compliance test with symmetric quotas: %s\n", (ok==0)?"PASSED":"FAILED"); |
199 | break; | 285 | break; |
200 | case ASYMMETRIC_SEND_LIMITED: | 286 | case ASYMMETRIC_SEND_LIMITED: |
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with limited sender quota\n",throughput_in,total_bytes_recv, delta/1000); | 287 | GNUNET_log (kind,"Core quota compliance test with limited sender quota: %s\n", (ok==0)?"PASSED":"FAILED"); |
202 | break; | 288 | break; |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with limited receiver quota\n",throughput_in,total_bytes_recv, delta/1000); | ||
204 | case ASYMMETRIC_RECV_LIMITED: | 289 | case ASYMMETRIC_RECV_LIMITED: |
290 | GNUNET_log (kind,"Core quota compliance test with limited receiver quota: %s\n", (ok==0)?"PASSED":"FAILED"); | ||
205 | break; | 291 | break; |
206 | }; | 292 | }; |
207 | 293 | GNUNET_log (kind,"Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000); | |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000); | 294 | GNUNET_log (kind,"Peer 1 send quota: %llu kB/s\n",current_quota_p1_out / 1024); |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000); | 295 | GNUNET_log (kind,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000); |
210 | 296 | GNUNET_log (kind,"Peer 2 receive quota: %llu kB/s\n",current_quota_p2_in / 1024); | |
211 | 297 | /* | |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024); | 298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024); |
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); |
214 | 300 | */ | |
215 | GNUNET_SCHEDULER_cancel (err_task); | 301 | GNUNET_SCHEDULER_cancel (err_task); |
216 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | 302 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
217 | 303 | ||
@@ -293,6 +379,7 @@ connect_notify (void *cls, | |||
293 | "Asking core (1) for transmission to peer `%4s'\n", | 379 | "Asking core (1) for transmission to peer `%4s'\n", |
294 | GNUNET_i2s (&p2.id)); | 380 | GNUNET_i2s (&p2.id)); |
295 | #endif | 381 | #endif |
382 | if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (err_task); | ||
296 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 383 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
297 | &terminate_task_error, | 384 | &terminate_task_error, |
298 | NULL); | 385 | NULL); |
@@ -515,6 +602,8 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
515 | "-c", cfgname, NULL); | 602 | "-c", cfgname, NULL); |
516 | #endif | 603 | #endif |
517 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 604 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
605 | p->stats = GNUNET_STATISTICS_create ("core",p->cfg); | ||
606 | GNUNET_assert (p->stats!=NULL); | ||
518 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 607 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
519 | GNUNET_assert (p->th != NULL); | 608 | GNUNET_assert (p->th != NULL); |
520 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 609 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
@@ -529,6 +618,9 @@ run (void *cls, | |||
529 | { | 618 | { |
530 | GNUNET_assert (ok == 1); | 619 | GNUNET_assert (ok == 1); |
531 | OKPP; | 620 | OKPP; |
621 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
622 | &terminate_task_error, | ||
623 | NULL); | ||
532 | if (test == SYMMETRIC) | 624 | if (test == SYMMETRIC) |
533 | { | 625 | { |
534 | setup_peer (&p1, "test_core_quota_peer1.conf"); | 626 | setup_peer (&p1, "test_core_quota_peer1.conf"); |
@@ -640,8 +732,6 @@ main (int argc, char *argv[]) | |||
640 | "WARNING", | 732 | "WARNING", |
641 | #endif | 733 | #endif |
642 | NULL); | 734 | NULL); |
643 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
644 | "argv[0] %s",argv[0]); | ||
645 | ret = check (); | 735 | ret = check (); |
646 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 736 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
647 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 737 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |