merge
[oweals/gnunet.git] / src / core / test_core_quota_compliance.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @file core/test_core_quota_compliance.c
20  * @brief testcase for core_api.c focusing quota compliance on core level
21  * @author Christian Grothoff
22  */
23 #include "platform.h"
24 #include "gnunet_arm_service.h"
25 #include "gnunet_core_service.h"
26 #include "gnunet_util_lib.h"
27 #include "gnunet_ats_service.h"
28 #include "gnunet_transport_service.h"
29 #include "gnunet_transport_hello_service.h"
30 #include "gnunet_statistics_service.h"
31
32
33 #define SYMMETRIC 0
34 #define ASYMMETRIC_SEND_LIMITED 1
35 #define ASYMMETRIC_RECV_LIMITED 2
36
37 /**
38  * Note that this value must not significantly exceed
39  * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
40  * messages may be dropped even for a reliable transport.
41  */
42 #define TOTAL_MSGS (60000 * 10)
43
44 /**
45  * How long until we give up on transmitting the message?
46  */
47 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
48
49 /**
50  * What delay do we request from the core service for transmission?
51  */
52 #define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150)
53
54 #define MTYPE 12345
55 #define MESSAGESIZE (1024 - 8)
56 #define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
57
58 static unsigned long long total_bytes_sent;
59 static unsigned long long total_bytes_recv;
60
61 static struct GNUNET_TIME_Absolute start_time;
62
63 static struct GNUNET_SCHEDULER_Task *err_task;
64
65 static struct GNUNET_SCHEDULER_Task *measure_task;
66
67
68 struct PeerContext
69 {
70   struct GNUNET_CONFIGURATION_Handle *cfg;
71   struct GNUNET_CORE_Handle *ch;
72   struct GNUNET_MQ_Handle *mq;
73   struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
74   struct GNUNET_PeerIdentity id;
75   struct GNUNET_MessageHeader *hello;
76   struct GNUNET_STATISTICS_Handle *stats;
77   struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
78   struct GNUNET_ATS_ConnectivityHandle *ats;
79   struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
80   int connect_status;
81   struct GNUNET_OS_Process *arm_proc;
82 };
83
84 static struct PeerContext p1;
85 static struct PeerContext p2;
86
87 static unsigned long long current_quota_p1_in;
88 static unsigned long long current_quota_p1_out;
89 static unsigned long long current_quota_p2_in;
90 static unsigned long long current_quota_p2_out;
91
92 static int ok;
93 static int test;
94 static int32_t tr_n;
95
96 static int running;
97
98
99 #if VERBOSE
100 #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
101 #else
102 #define OKPP do { ok++; } while (0)
103 #endif
104
105 struct TestMessage
106 {
107   struct GNUNET_MessageHeader header;
108   uint32_t num GNUNET_PACKED;
109   uint8_t pad[MESSAGESIZE];
110 };
111
112
113 static void
114 terminate_peer (struct PeerContext *p)
115 {
116   if (NULL != p->ch)
117   {
118     GNUNET_CORE_disconnect (p->ch);
119     p->ch = NULL;
120   }
121   if (NULL != p->ghh)
122   {
123     GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
124     p->ghh = NULL;
125   }
126   if (NULL != p->oh)
127   {
128     GNUNET_TRANSPORT_offer_hello_cancel (p->oh);
129     p->oh = NULL;
130   }
131   if (NULL != p->ats_sh)
132   {
133     GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh);
134     p->ats_sh = NULL;
135   }
136   if (NULL != p->ats)
137   {
138     GNUNET_ATS_connectivity_done (p->ats);
139     p->ats = NULL;
140   }
141   if (NULL != p->stats)
142   {
143     GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO);
144     p->stats = NULL;
145   }
146   if (NULL != p->hello)
147   {
148     GNUNET_free (p->hello);
149     p->hello = NULL;
150   }
151 }
152
153
154 static void
155 shutdown_task (void *cls)
156 {
157   if (NULL != err_task)
158   {
159     GNUNET_SCHEDULER_cancel (err_task);
160     err_task = NULL;
161   }
162   if (NULL != measure_task)
163   {
164     GNUNET_SCHEDULER_cancel (measure_task);
165     measure_task = NULL;
166   }
167   terminate_peer (&p1);
168   terminate_peer (&p2);
169 }
170
171
172 static void
173 terminate_task_error (void *cls)
174 {
175   err_task = NULL;
176   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177               "Testcase failed (timeout)!\n");
178   GNUNET_SCHEDULER_shutdown ();
179   ok = 42;
180 }
181
182
183 /**
184  * Callback function to process statistic values.
185  *
186  * @param cls closure
187  * @param subsystem name of subsystem that created the statistic
188  * @param name the name of the datum
189  * @param value the current value
190  * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
191  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
192  */
193 static int
194 print_stat (void *cls,
195             const char *subsystem,
196             const char *name,
197             uint64_t value,
198             int is_persistent)
199 {
200   if (cls == &p1)
201     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202                 "Peer1 %50s = %12llu\n",
203                 name,
204                 (unsigned long long) value);
205   if (cls == &p2)
206     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207                 "Peer2 %50s = %12llu\n",
208                 name,
209                 (unsigned long long) value);
210   return GNUNET_OK;
211 }
212
213
214 static void
215 measurement_stop (void *cls)
216 {
217   unsigned long long delta;
218   unsigned long long throughput_out;
219   unsigned long long throughput_in;
220   unsigned long long max_quota_in;
221   unsigned long long max_quota_out;
222   unsigned long long quota_delta;
223   enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
224
225   measure_task = NULL;
226   FPRINTF (stdout, "%s",  "\n");
227   running = GNUNET_NO;
228
229   delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
230   if (0 == delta)
231     delta = 1;
232   throughput_out = total_bytes_sent * 1000000LL / delta;     /* convert to bytes/s */
233   throughput_in = total_bytes_recv * 1000000LL / delta;      /* convert to bytes/s */
234
235   max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
236   max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
237   if (max_quota_out < max_quota_in)
238     quota_delta = max_quota_in / 3;
239   else
240     quota_delta = max_quota_out / 3;
241
242   if ((throughput_out > (max_quota_out + quota_delta)) ||
243       (throughput_in > (max_quota_in + quota_delta)))
244     ok = 1; /* fail */
245   else
246     ok = 0; /* pass */
247   GNUNET_STATISTICS_get (p1.stats,
248                          "core",
249                          "# discarded CORE_SEND requests",
250                          NULL,
251                          &print_stat,
252                          &p1);
253   GNUNET_STATISTICS_get (p1.stats,
254                          "core",
255                          "# discarded CORE_SEND request bytes",
256                          NULL,
257                          &print_stat,
258                          &p1);
259   GNUNET_STATISTICS_get (p1.stats,
260                          "core",
261                          "# discarded lower priority CORE_SEND requests",
262                          NULL,
263                          &print_stat,
264                          NULL);
265   GNUNET_STATISTICS_get (p1.stats,
266                          "core",
267                          "# discarded lower priority CORE_SEND request bytes",
268                          NULL,
269                          &print_stat,
270                          &p1);
271   GNUNET_STATISTICS_get (p2.stats,
272                          "core",
273                          "# discarded CORE_SEND requests",
274                          NULL,
275                          &print_stat,
276                          &p2);
277
278   GNUNET_STATISTICS_get (p2.stats,
279                          "core",
280                          "# discarded CORE_SEND request bytes",
281                          NULL,
282                          &print_stat,
283                          &p2);
284   GNUNET_STATISTICS_get (p2.stats,
285                          "core",
286                          "# discarded lower priority CORE_SEND requests",
287                          NULL,
288                          &print_stat,
289                          &p2);
290   GNUNET_STATISTICS_get (p2.stats,
291                          "core",
292                          "# discarded lower priority CORE_SEND request bytes",
293                          NULL,
294                          &print_stat,
295                          &p2);
296
297   if (ok != 0)
298     kind = GNUNET_ERROR_TYPE_ERROR;
299   switch (test)
300   {
301   case SYMMETRIC:
302     GNUNET_log (kind,
303                 "Core quota compliance test with symmetric quotas: %s\n",
304                 (0 == ok) ? "PASSED" : "FAILED");
305     break;
306   case ASYMMETRIC_SEND_LIMITED:
307     GNUNET_log (kind,
308                 "Core quota compliance test with limited sender quota: %s\n",
309                 (0 == ok) ? "PASSED" : "FAILED");
310     break;
311   case ASYMMETRIC_RECV_LIMITED:
312     GNUNET_log (kind,
313                 "Core quota compliance test with limited receiver quota: %s\n",
314                 (0 == ok) ? "PASSED" : "FAILED");
315     break;
316   };
317   GNUNET_log (kind,
318               "Peer 1 send  rate: %llu b/s (%llu bytes in %llu ms)\n",
319               throughput_out,
320               total_bytes_sent,
321               delta);
322   GNUNET_log (kind,
323               "Peer 1 send quota: %llu b/s\n",
324               current_quota_p1_out);
325   GNUNET_log (kind,
326               "Peer 2 receive  rate: %llu b/s (%llu bytes in %llu ms)\n",
327               throughput_in,
328               total_bytes_recv,
329               delta);
330   GNUNET_log (kind,
331               "Peer 2 receive quota: %llu b/s\n",
332               current_quota_p2_in);
333 /*
334   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound  quota allowed: %llu b/s\n",max_quota_in );
335   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
336 */
337   GNUNET_SCHEDULER_shutdown ();
338 }
339
340
341 static void
342 do_transmit (void *cls)
343 {
344   struct TestMessage *hdr;
345   struct GNUNET_MQ_Envelope *env;
346
347   env = GNUNET_MQ_msg (hdr,
348                        MTYPE);
349   hdr->num = htonl (tr_n);
350   memset (&hdr->pad,
351           tr_n,
352           MESSAGESIZE);
353   tr_n++;
354   GNUNET_SCHEDULER_cancel (err_task);
355   err_task =
356       GNUNET_SCHEDULER_add_delayed (TIMEOUT,
357                                     &terminate_task_error,
358                                     NULL);
359   total_bytes_sent += sizeof (struct TestMessage);
360   GNUNET_MQ_send (p1.mq,
361                   env);
362 }
363
364
365 static void *
366 connect_notify (void *cls,
367                 const struct GNUNET_PeerIdentity *peer,
368                 struct GNUNET_MQ_Handle *mq)
369 {
370   struct PeerContext *pc = cls;
371
372   if (0 == memcmp (&pc->id,
373                    peer,
374                    sizeof (struct GNUNET_PeerIdentity)))
375     return NULL;                     /* loopback */
376   GNUNET_assert (0 == pc->connect_status);
377   pc->connect_status = 1;
378   pc->mq = mq;
379   if (pc == &p1)
380   {
381     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382                 "Encrypted connection established to peer `%s'\n",
383                 GNUNET_i2s (peer));
384     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385                 "Asking core (1) for transmission to peer `%s'\n",
386                 GNUNET_i2s (&p2.id));
387     GNUNET_SCHEDULER_cancel (err_task);
388     err_task =
389         GNUNET_SCHEDULER_add_delayed (TIMEOUT,
390                                       &terminate_task_error,
391                                       NULL);
392     start_time = GNUNET_TIME_absolute_get ();
393     running = GNUNET_YES;
394     measure_task =
395         GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH,
396                                       &measurement_stop,
397                                       NULL);
398     do_transmit (NULL);
399   }
400   return pc;
401 }
402
403
404 static void
405 disconnect_notify (void *cls,
406                    const struct GNUNET_PeerIdentity *peer,
407                    void *internal_cls)
408 {
409   struct PeerContext *pc = cls;
410
411   if (NULL == internal_cls)
412     return;                     /* loopback */
413   pc->connect_status = 0;
414   pc->mq = NULL;
415   if (NULL != measure_task)
416   {
417     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
418                 "Measurement aborted due to disconnect!\n");
419     GNUNET_SCHEDULER_cancel (measure_task);
420     measure_task = NULL;
421   }
422   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423               "Encrypted connection to `%s' cut\n",
424               GNUNET_i2s (peer));
425 }
426
427
428
429 static void
430 handle_test (void *cls,
431              const struct TestMessage *hdr)
432 {
433   static int n;
434
435   total_bytes_recv += sizeof (struct TestMessage);
436   if (ntohl (hdr->num) != n)
437   {
438     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
439                 "Expected message %u, got message %u\n",
440                 n,
441                 ntohl (hdr->num));
442     GNUNET_SCHEDULER_cancel (err_task);
443     err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
444                                          NULL);
445     return;
446   }
447   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448               "Got message %u\n",
449               ntohl (hdr->num));
450   n++;
451   if (0 == (n % 10))
452     FPRINTF (stderr, "%s",  ".");
453
454   if (GNUNET_YES == running)
455     do_transmit (NULL);
456 }
457
458
459 static void
460 init_notify (void *cls,
461              const struct GNUNET_PeerIdentity *my_identity)
462 {
463   struct PeerContext *p = cls;
464   struct GNUNET_MQ_MessageHandler handlers[] = {
465     GNUNET_MQ_hd_fixed_size (test,
466                              MTYPE,
467                              struct TestMessage,
468                              NULL),
469     GNUNET_MQ_handler_end ()
470   };
471
472   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473               "Connection to CORE service of `%s' established\n",
474               GNUNET_i2s (my_identity));
475   GNUNET_assert (NULL != my_identity);
476   p->id = *my_identity;
477   if (cls == &p1)
478   {
479     GNUNET_assert (ok == 2);
480     OKPP;
481     /* connect p2 */
482     p2.ch = GNUNET_CORE_connect (p2.cfg,
483                                  &p2,
484                                  &init_notify,
485                                  &connect_notify,
486                                  &disconnect_notify,
487                                  handlers);
488   }
489   else
490   {
491     GNUNET_assert (ok == 3);
492     OKPP;
493     GNUNET_assert (cls == &p2);
494     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495                 "Asking core (1) to connect to peer `%s' and vice-versa\n",
496                 GNUNET_i2s (&p2.id));
497     p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats,
498                                                  &p2.id,
499                                                  1);
500     p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats,
501                                                  &p1.id,
502                                                  1);
503   }
504 }
505
506
507 static void
508 offer_hello_done (void *cls)
509 {
510   struct PeerContext *p = cls;
511
512   p->oh = NULL;
513 }
514
515
516 static void
517 process_hello (void *cls,
518                const struct GNUNET_MessageHeader *message)
519 {
520   struct PeerContext *p = cls;
521
522   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523               "Received (my) HELLO from transport service\n");
524   GNUNET_assert (message != NULL);
525   p->hello = GNUNET_malloc (ntohs (message->size));
526   GNUNET_memcpy (p->hello, message, ntohs (message->size));
527   if ( (p == &p1) &&
528        (NULL == p2.oh) )
529     p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
530                                           message,
531                                           &offer_hello_done,
532                                           &p2);
533   if ( (p == &p2) &&
534        (NULL == p1.oh) )
535     p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message,
536                                           &offer_hello_done,
537                                           &p1);
538
539   if ( (p == &p1) &&
540        (NULL != p2.hello) &&
541        (NULL == p1.oh) )
542     p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
543                                           p2.hello,
544                                           &offer_hello_done,
545                                           &p1);
546   if ( (p == &p2) &&
547        (NULL != p1.hello) &&
548        (NULL == p2.oh) )
549     p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
550                                           p1.hello,
551                                           &offer_hello_done,
552                                           &p2);
553 }
554
555
556 static void
557 setup_peer (struct PeerContext *p,
558             const char *cfgname)
559 {
560   char *binary;
561
562   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
563   p->cfg = GNUNET_CONFIGURATION_create ();
564   p->arm_proc =
565     GNUNET_OS_start_process (GNUNET_YES,
566                              GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
567                              NULL, NULL, NULL,
568                              binary,
569                              "gnunet-service-arm",
570                              "-c",
571                              cfgname,
572                              NULL);
573   GNUNET_assert (GNUNET_OK ==
574                  GNUNET_CONFIGURATION_load (p->cfg,
575                                             cfgname));
576   p->stats = GNUNET_STATISTICS_create ("core",
577                                        p->cfg);
578   GNUNET_assert (NULL != p->stats);
579   p->ats = GNUNET_ATS_connectivity_init (p->cfg);
580   GNUNET_assert (NULL != p->ats);
581   p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
582                                        GNUNET_TRANSPORT_AC_ANY,
583                                        &process_hello,
584                                        p);
585   GNUNET_free (binary);
586 }
587
588
589 static void
590 run (void *cls,
591      char *const *args,
592      const char *cfgfile,
593      const struct GNUNET_CONFIGURATION_Handle *cfg)
594 {
595   struct GNUNET_MQ_MessageHandler handlers[] = {
596     GNUNET_MQ_hd_fixed_size (test,
597                              MTYPE,
598                              struct TestMessage,
599                              NULL),
600     GNUNET_MQ_handler_end ()
601   };
602
603   GNUNET_assert (ok == 1);
604   OKPP;
605   err_task =
606       GNUNET_SCHEDULER_add_delayed (TIMEOUT,
607                                     &terminate_task_error,
608                                     NULL);
609   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
610                                  NULL);
611   if (test == SYMMETRIC)
612   {
613     setup_peer (&p1,
614                 "test_core_quota_peer1.conf");
615     setup_peer (&p2,
616                 "test_core_quota_peer2.conf");
617   }
618   else if (test == ASYMMETRIC_SEND_LIMITED)
619   {
620     setup_peer (&p1,
621                 "test_core_quota_asymmetric_send_limit_peer1.conf");
622     setup_peer (&p2,
623                 "test_core_quota_asymmetric_send_limit_peer2.conf");
624   }
625   else if (test == ASYMMETRIC_RECV_LIMITED)
626   {
627     setup_peer (&p1,
628                 "test_core_quota_asymmetric_recv_limited_peer1.conf");
629     setup_peer (&p2,
630                 "test_core_quota_asymmetric_recv_limited_peer2.conf");
631   }
632
633   GNUNET_assert (test != -1);
634   GNUNET_assert (GNUNET_SYSERR !=
635                  GNUNET_CONFIGURATION_get_value_size (p1.cfg,
636                                                       "ATS",
637                                                       "WAN_QUOTA_IN",
638                                                       &current_quota_p1_in));
639   GNUNET_assert (GNUNET_SYSERR !=
640                  GNUNET_CONFIGURATION_get_value_size (p2.cfg,
641                                                       "ATS",
642                                                       "WAN_QUOTA_IN",
643                                                       &current_quota_p2_in));
644   GNUNET_assert (GNUNET_SYSERR !=
645                  GNUNET_CONFIGURATION_get_value_size (p1.cfg,
646                                                       "ATS",
647                                                       "WAN_QUOTA_OUT",
648                                                       &current_quota_p1_out));
649   GNUNET_assert (GNUNET_SYSERR !=
650                  GNUNET_CONFIGURATION_get_value_size (p2.cfg,
651                                                       "ATS",
652                                                       "WAN_QUOTA_OUT",
653                                                       &current_quota_p2_out));
654
655   p1.ch = GNUNET_CORE_connect (p1.cfg,
656                                &p1,
657                                &init_notify,
658                                &connect_notify,
659                                &disconnect_notify,
660                                handlers);
661 }
662
663
664 static void
665 stop_arm (struct PeerContext *p)
666 {
667   if (0 != GNUNET_OS_process_kill (p->arm_proc,
668                                    GNUNET_TERM_SIG))
669     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
670                          "kill");
671   if (GNUNET_OK !=
672       GNUNET_OS_process_wait (p->arm_proc))
673     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
674                          "waitpid");
675   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676               "ARM process %u stopped\n",
677               GNUNET_OS_process_get_pid (p->arm_proc));
678   GNUNET_OS_process_destroy (p->arm_proc);
679   p->arm_proc = NULL;
680   GNUNET_CONFIGURATION_destroy (p->cfg);
681 }
682
683
684 static int
685 check ()
686 {
687   char *const argv[] = {
688     "test-core-quota-compliance",
689     "-c",
690     "test_core_api_data.conf",
691     NULL
692   };
693   struct GNUNET_GETOPT_CommandLineOption options[] = {
694     GNUNET_GETOPT_OPTION_END
695   };
696   ok = 1;
697   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
698                       argv,
699                       "test-core-quota-compliance",
700                       "nohelp",
701                       options,
702                       &run,
703                       &ok);
704   stop_arm (&p1);
705   stop_arm (&p2);
706   return ok;
707 }
708
709
710 static void
711 cleanup_directory (int test)
712 {
713   switch (test) {
714   case SYMMETRIC:
715     GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
716     GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
717     break;
718   case ASYMMETRIC_SEND_LIMITED:
719     GNUNET_DISK_directory_remove
720         ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
721     GNUNET_DISK_directory_remove
722         ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
723     break;
724   case ASYMMETRIC_RECV_LIMITED:
725     GNUNET_DISK_directory_remove
726         ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
727     GNUNET_DISK_directory_remove
728         ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
729     break;
730   }
731 }
732
733
734 int
735 main (int argc,
736       char *argv[])
737 {
738   int ret;
739
740   test = -1;
741   if (NULL != strstr (argv[0],
742                       "_symmetric"))
743   {
744     test = SYMMETRIC;
745   }
746   else if (NULL != strstr (argv[0],
747                            "_asymmetric_send"))
748   {
749     test = ASYMMETRIC_SEND_LIMITED;
750   }
751   else if (NULL != strstr (argv[0],
752                            "_asymmetric_recv"))
753   {
754     test = ASYMMETRIC_RECV_LIMITED;
755   }
756   GNUNET_assert (test != -1);
757   cleanup_directory (test);
758   GNUNET_log_setup ("test-core-quota-compliance",
759                     "WARNING",
760                     NULL);
761   ret = check ();
762   cleanup_directory (test);
763   return ret;
764 }
765
766
767 /* end of test_core_quota_compliance.c */