fix #3284: support lib/MULTIARCH/ paths in installation, use GNUNET_PREFIX=@libdir...
[oweals/gnunet.git] / src / statistics / test_statistics_api_loop.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file statistics/test_statistics_api_loop.c
22  * @brief testcase for statistics_api.c
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include "gnunet_statistics_service.h"
27
28 #define ROUNDS (1024 * 1024)
29
30 static struct GNUNET_STATISTICS_Handle *h;
31
32
33 static int
34 check_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
35          int is_persistent)
36 {
37   GNUNET_assert (0 == strcmp (name, "test-0"));
38   GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop"));
39   GNUNET_assert (is_persistent == GNUNET_NO);
40   return GNUNET_OK;
41 }
42
43
44 static void
45 next (void *cls, int success)
46 {
47   int *ok = cls;
48
49   GNUNET_STATISTICS_destroy (h, GNUNET_NO);
50   GNUNET_assert (success == GNUNET_OK);
51   *ok = 0;
52 }
53
54
55 static void
56 run (void *cls, char *const *args, const char *cfgfile,
57      const struct GNUNET_CONFIGURATION_Handle *cfg)
58 {
59   unsigned int i;
60   char name[128];
61
62   h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg);
63   for (i = 0; i < ROUNDS; i++)
64   {
65     GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256);
66     GNUNET_STATISTICS_set (h, name, i, GNUNET_NO);
67     GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128);
68     GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO);
69   }
70   i = 0;
71   GNUNET_break (NULL !=
72                 GNUNET_STATISTICS_get (h, NULL, "test-0",
73                                        GNUNET_TIME_UNIT_MINUTES, &next,
74                                        &check_1, cls));
75 }
76
77
78 int
79 main (int argc, char *argv_ign[])
80 {
81   int ok = 1;
82
83   char *const argv[] = { "test-statistics-api",
84     "-c",
85     "test_statistics_api_data.conf",
86     NULL
87   };
88   struct GNUNET_GETOPT_CommandLineOption options[] = {
89     GNUNET_GETOPT_OPTION_END
90   };
91   struct GNUNET_OS_Process *proc;
92   char *binary;
93
94   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
95   proc =
96     GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
97                              NULL, NULL,
98                              binary,
99                              "gnunet-service-statistics",
100                              "-c", "test_statistics_api_data.conf", NULL);
101   GNUNET_assert (NULL != proc);
102   GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
103                       &ok);
104   if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
105   {
106     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
107     ok = 1;
108   }
109   GNUNET_OS_process_wait (proc);
110   GNUNET_OS_process_destroy (proc);
111   proc = NULL;
112   GNUNET_free (binary);
113   return ok;
114 }
115
116 /* end of test_statistics_api_loop.c */