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