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