NAMESTORE/JSON: fix parsing exp and flags
[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      SPDX-License-Identifier: AGPL3.0-or-later
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   if (0 == delta)
233     delta = 1;
234   throughput_out = total_bytes_sent * 1000000LL / delta;     /* convert to bytes/s */
235   throughput_in = total_bytes_recv * 1000000LL / delta;      /* convert to bytes/s */
236
237   max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
238   max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
239   if (max_quota_out < max_quota_in)
240     quota_delta = max_quota_in / 3;
241   else
242     quota_delta = max_quota_out / 3;
243
244   if ((throughput_out > (max_quota_out + quota_delta)) ||
245       (throughput_in > (max_quota_in + quota_delta)))
246     ok = 1; /* fail */
247   else
248     ok = 0; /* pass */
249   GNUNET_STATISTICS_get (p1.stats,
250                          "core",
251                          "# discarded CORE_SEND requests",
252                          NULL,
253                          &print_stat,
254                          &p1);
255   GNUNET_STATISTICS_get (p1.stats,
256                          "core",
257                          "# discarded CORE_SEND request bytes",
258                          NULL,
259                          &print_stat,
260                          &p1);
261   GNUNET_STATISTICS_get (p1.stats,
262                          "core",
263                          "# discarded lower priority CORE_SEND requests",
264                          NULL,
265                          &print_stat,
266                          NULL);
267   GNUNET_STATISTICS_get (p1.stats,
268                          "core",
269                          "# discarded lower priority CORE_SEND request bytes",
270                          NULL,
271                          &print_stat,
272                          &p1);
273   GNUNET_STATISTICS_get (p2.stats,
274                          "core",
275                          "# discarded CORE_SEND requests",
276                          NULL,
277                          &print_stat,
278                          &p2);
279
280   GNUNET_STATISTICS_get (p2.stats,
281                          "core",
282                          "# discarded CORE_SEND request bytes",
283                          NULL,
284                          &print_stat,
285                          &p2);
286   GNUNET_STATISTICS_get (p2.stats,
287                          "core",
288                          "# discarded lower priority CORE_SEND requests",
289                          NULL,
290                          &print_stat,
291                          &p2);
292   GNUNET_STATISTICS_get (p2.stats,
293                          "core",
294                          "# discarded lower priority CORE_SEND request bytes",
295                          NULL,
296                          &print_stat,
297                          &p2);
298
299   if (ok != 0)
300     kind = GNUNET_ERROR_TYPE_ERROR;
301   switch (test)
302   {
303   case SYMMETRIC:
304     GNUNET_log (kind,
305                 "Core quota compliance test with symmetric quotas: %s\n",
306                 (0 == ok) ? "PASSED" : "FAILED");
307     break;
308   case ASYMMETRIC_SEND_LIMITED:
309     GNUNET_log (kind,
310                 "Core quota compliance test with limited sender quota: %s\n",
311                 (0 == ok) ? "PASSED" : "FAILED");
312     break;
313   case ASYMMETRIC_RECV_LIMITED:
314     GNUNET_log (kind,
315                 "Core quota compliance test with limited receiver quota: %s\n",
316                 (0 == ok) ? "PASSED" : "FAILED");
317     break;
318   };
319   GNUNET_log (kind,
320               "Peer 1 send  rate: %llu b/s (%llu bytes in %llu ms)\n",
321               throughput_out,
322               total_bytes_sent,
323               delta);
324   GNUNET_log (kind,
325               "Peer 1 send quota: %llu b/s\n",
326               current_quota_p1_out);
327   GNUNET_log (kind,
328               "Peer 2 receive  rate: %llu b/s (%llu bytes in %llu ms)\n",
329               throughput_in,
330               total_bytes_recv,
331               delta);
332   GNUNET_log (kind,
333               "Peer 2 receive quota: %llu b/s\n",
334               current_quota_p2_in);
335 /*
336   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound  quota allowed: %llu b/s\n",max_quota_in );
337   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
338 */
339   GNUNET_SCHEDULER_shutdown ();
340 }
341
342
343 static void
344 do_transmit (void *cls)
345 {
346   struct TestMessage *hdr;
347   struct GNUNET_MQ_Envelope *env;
348
349   env = GNUNET_MQ_msg (hdr,
350                        MTYPE);
351   hdr->num = htonl (tr_n);
352   memset (&hdr->pad,
353           tr_n,
354           MESSAGESIZE);
355   tr_n++;
356   GNUNET_SCHEDULER_cancel (err_task);
357   err_task =
358       GNUNET_SCHEDULER_add_delayed (TIMEOUT,
359                                     &terminate_task_error,
360                                     NULL);
361   total_bytes_sent += sizeof (struct TestMessage);
362   GNUNET_MQ_send (p1.mq,
363                   env);
364 }
365
366
367 static void *
368 connect_notify (void *cls,
369                 const struct GNUNET_PeerIdentity *peer,
370                 struct GNUNET_MQ_Handle *mq)
371 {
372   struct PeerContext *pc = cls;
373
374   if (0 == memcmp (&pc->id,
375                    peer,
376                    sizeof (struct GNUNET_PeerIdentity)))
377     return NULL;                     /* loopback */
378   GNUNET_assert (0 == pc->connect_status);
379   pc->connect_status = 1;
380   pc->mq = mq;
381   if (pc == &p1)
382   {
383     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
384                 "Encrypted connection established to peer `%s'\n",
385                 GNUNET_i2s (peer));
386     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387                 "Asking core (1) for transmission to peer `%s'\n",
388                 GNUNET_i2s (&p2.id));
389     GNUNET_SCHEDULER_cancel (err_task);
390     err_task =
391         GNUNET_SCHEDULER_add_delayed (TIMEOUT,
392                                       &terminate_task_error,
393                                       NULL);
394     start_time = GNUNET_TIME_absolute_get ();
395     running = GNUNET_YES;
396     measure_task =
397         GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH,
398                                       &measurement_stop,
399                                       NULL);
400     do_transmit (NULL);
401   }
402   return pc;
403 }
404
405
406 static void
407 disconnect_notify (void *cls,
408                    const struct GNUNET_PeerIdentity *peer,
409                    void *internal_cls)
410 {
411   struct PeerContext *pc = cls;
412
413   if (NULL == internal_cls)
414     return;                     /* loopback */
415   pc->connect_status = 0;
416   pc->mq = NULL;
417   if (NULL != measure_task)
418   {
419     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
420                 "Measurement aborted due to disconnect!\n");
421     GNUNET_SCHEDULER_cancel (measure_task);
422     measure_task = NULL;
423   }
424   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425               "Encrypted connection to `%s' cut\n",
426               GNUNET_i2s (peer));
427 }
428
429
430
431 static void
432 handle_test (void *cls,
433              const struct TestMessage *hdr)
434 {
435   static int n;
436
437   total_bytes_recv += sizeof (struct TestMessage);
438   if (ntohl (hdr->num) != n)
439   {
440     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
441                 "Expected message %u, got message %u\n",
442                 n,
443                 ntohl (hdr->num));
444     GNUNET_SCHEDULER_cancel (err_task);
445     err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
446                                          NULL);
447     return;
448   }
449   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
450               "Got message %u\n",
451               ntohl (hdr->num));
452   n++;
453   if (0 == (n % 10))
454     FPRINTF (stderr, "%s",  ".");
455
456   if (GNUNET_YES == running)
457     do_transmit (NULL);
458 }
459
460
461 static void
462 init_notify (void *cls,
463              const struct GNUNET_PeerIdentity *my_identity)
464 {
465   struct PeerContext *p = cls;
466   struct GNUNET_MQ_MessageHandler handlers[] = {
467     GNUNET_MQ_hd_fixed_size (test,
468                              MTYPE,
469                              struct TestMessage,
470                              NULL),
471     GNUNET_MQ_handler_end ()
472   };
473
474   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475               "Connection to CORE service of `%s' established\n",
476               GNUNET_i2s (my_identity));
477   GNUNET_assert (NULL != my_identity);
478   p->id = *my_identity;
479   if (cls == &p1)
480   {
481     GNUNET_assert (ok == 2);
482     OKPP;
483     /* connect p2 */
484     p2.ch = GNUNET_CORE_connect (p2.cfg,
485                                  &p2,
486                                  &init_notify,
487                                  &connect_notify,
488                                  &disconnect_notify,
489                                  handlers);
490   }
491   else
492   {
493     GNUNET_assert (ok == 3);
494     OKPP;
495     GNUNET_assert (cls == &p2);
496     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497                 "Asking core (1) to connect to peer `%s' and vice-versa\n",
498                 GNUNET_i2s (&p2.id));
499     p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats,
500                                                  &p2.id,
501                                                  1);
502     p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats,
503                                                  &p1.id,
504                                                  1);
505   }
506 }
507
508
509 static void
510 offer_hello_done (void *cls)
511 {
512   struct PeerContext *p = cls;
513
514   p->oh = NULL;
515 }
516
517
518 static void
519 process_hello (void *cls,
520                const struct GNUNET_MessageHeader *message)
521 {
522   struct PeerContext *p = cls;
523
524   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525               "Received (my) HELLO from transport service\n");
526   GNUNET_assert (message != NULL);
527   p->hello = GNUNET_malloc (ntohs (message->size));
528   GNUNET_memcpy (p->hello, message, ntohs (message->size));
529   if ( (p == &p1) &&
530        (NULL == p2.oh) )
531     p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
532                                           message,
533                                           &offer_hello_done,
534                                           &p2);
535   if ( (p == &p2) &&
536        (NULL == p1.oh) )
537     p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message,
538                                           &offer_hello_done,
539                                           &p1);
540
541   if ( (p == &p1) &&
542        (NULL != p2.hello) &&
543        (NULL == p1.oh) )
544     p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
545                                           p2.hello,
546                                           &offer_hello_done,
547                                           &p1);
548   if ( (p == &p2) &&
549        (NULL != p1.hello) &&
550        (NULL == p2.oh) )
551     p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
552                                           p1.hello,
553                                           &offer_hello_done,
554                                           &p2);
555 }
556
557
558 static void
559 setup_peer (struct PeerContext *p,
560             const char *cfgname)
561 {
562   char *binary;
563
564   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
565   p->cfg = GNUNET_CONFIGURATION_create ();
566   p->arm_proc =
567     GNUNET_OS_start_process (GNUNET_YES,
568                              GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
569                              NULL, NULL, NULL,
570                              binary,
571                              "gnunet-service-arm",
572                              "-c",
573                              cfgname,
574                              NULL);
575   GNUNET_assert (GNUNET_OK ==
576                  GNUNET_CONFIGURATION_load (p->cfg,
577                                             cfgname));
578   p->stats = GNUNET_STATISTICS_create ("core",
579                                        p->cfg);
580   GNUNET_assert (NULL != p->stats);
581   p->ats = GNUNET_ATS_connectivity_init (p->cfg);
582   GNUNET_assert (NULL != p->ats);
583   p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
584                                        GNUNET_TRANSPORT_AC_ANY,
585                                        &process_hello,
586                                        p);
587   GNUNET_free (binary);
588 }
589
590
591 static void
592 run (void *cls,
593      char *const *args,
594      const char *cfgfile,
595      const struct GNUNET_CONFIGURATION_Handle *cfg)
596 {
597   struct GNUNET_MQ_MessageHandler handlers[] = {
598     GNUNET_MQ_hd_fixed_size (test,
599                              MTYPE,
600                              struct TestMessage,
601                              NULL),
602     GNUNET_MQ_handler_end ()
603   };
604
605   GNUNET_assert (ok == 1);
606   OKPP;
607   err_task =
608       GNUNET_SCHEDULER_add_delayed (TIMEOUT,
609                                     &terminate_task_error,
610                                     NULL);
611   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
612                                  NULL);
613   if (test == SYMMETRIC)
614   {
615     setup_peer (&p1,
616                 "test_core_quota_peer1.conf");
617     setup_peer (&p2,
618                 "test_core_quota_peer2.conf");
619   }
620   else if (test == ASYMMETRIC_SEND_LIMITED)
621   {
622     setup_peer (&p1,
623                 "test_core_quota_asymmetric_send_limit_peer1.conf");
624     setup_peer (&p2,
625                 "test_core_quota_asymmetric_send_limit_peer2.conf");
626   }
627   else if (test == ASYMMETRIC_RECV_LIMITED)
628   {
629     setup_peer (&p1,
630                 "test_core_quota_asymmetric_recv_limited_peer1.conf");
631     setup_peer (&p2,
632                 "test_core_quota_asymmetric_recv_limited_peer2.conf");
633   }
634
635   GNUNET_assert (test != -1);
636   GNUNET_assert (GNUNET_SYSERR !=
637                  GNUNET_CONFIGURATION_get_value_size (p1.cfg,
638                                                       "ATS",
639                                                       "WAN_QUOTA_IN",
640                                                       &current_quota_p1_in));
641   GNUNET_assert (GNUNET_SYSERR !=
642                  GNUNET_CONFIGURATION_get_value_size (p2.cfg,
643                                                       "ATS",
644                                                       "WAN_QUOTA_IN",
645                                                       &current_quota_p2_in));
646   GNUNET_assert (GNUNET_SYSERR !=
647                  GNUNET_CONFIGURATION_get_value_size (p1.cfg,
648                                                       "ATS",
649                                                       "WAN_QUOTA_OUT",
650                                                       &current_quota_p1_out));
651   GNUNET_assert (GNUNET_SYSERR !=
652                  GNUNET_CONFIGURATION_get_value_size (p2.cfg,
653                                                       "ATS",
654                                                       "WAN_QUOTA_OUT",
655                                                       &current_quota_p2_out));
656
657   p1.ch = GNUNET_CORE_connect (p1.cfg,
658                                &p1,
659                                &init_notify,
660                                &connect_notify,
661                                &disconnect_notify,
662                                handlers);
663 }
664
665
666 static void
667 stop_arm (struct PeerContext *p)
668 {
669   if (0 != GNUNET_OS_process_kill (p->arm_proc,
670                                    GNUNET_TERM_SIG))
671     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
672                          "kill");
673   if (GNUNET_OK !=
674       GNUNET_OS_process_wait (p->arm_proc))
675     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
676                          "waitpid");
677   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678               "ARM process %u stopped\n",
679               GNUNET_OS_process_get_pid (p->arm_proc));
680   GNUNET_OS_process_destroy (p->arm_proc);
681   p->arm_proc = NULL;
682   GNUNET_CONFIGURATION_destroy (p->cfg);
683 }
684
685
686 static int
687 check ()
688 {
689   char *const argv[] = {
690     "test-core-quota-compliance",
691     "-c",
692     "test_core_api_data.conf",
693     NULL
694   };
695   struct GNUNET_GETOPT_CommandLineOption options[] = {
696     GNUNET_GETOPT_OPTION_END
697   };
698   ok = 1;
699   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
700                       argv,
701                       "test-core-quota-compliance",
702                       "nohelp",
703                       options,
704                       &run,
705                       &ok);
706   stop_arm (&p1);
707   stop_arm (&p2);
708   return ok;
709 }
710
711
712 static void
713 cleanup_directory (int test)
714 {
715   switch (test) {
716   case SYMMETRIC:
717     GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
718     GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
719     break;
720   case ASYMMETRIC_SEND_LIMITED:
721     GNUNET_DISK_directory_remove
722         ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
723     GNUNET_DISK_directory_remove
724         ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
725     break;
726   case ASYMMETRIC_RECV_LIMITED:
727     GNUNET_DISK_directory_remove
728         ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
729     GNUNET_DISK_directory_remove
730         ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
731     break;
732   }
733 }
734
735
736 int
737 main (int argc,
738       char *argv[])
739 {
740   int ret;
741
742   test = -1;
743   if (NULL != strstr (argv[0],
744                       "_symmetric"))
745   {
746     test = SYMMETRIC;
747   }
748   else if (NULL != strstr (argv[0],
749                            "_asymmetric_send"))
750   {
751     test = ASYMMETRIC_SEND_LIMITED;
752   }
753   else if (NULL != strstr (argv[0],
754                            "_asymmetric_recv"))
755   {
756     test = ASYMMETRIC_RECV_LIMITED;
757   }
758   GNUNET_assert (test != -1);
759   cleanup_directory (test);
760   GNUNET_log_setup ("test-core-quota-compliance",
761                     "WARNING",
762                     NULL);
763   ret = check ();
764   cleanup_directory (test);
765   return ret;
766 }
767
768
769 /* end of test_core_quota_compliance.c */