2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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 2, or (at your
8 option) any later version.
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.
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.
21 * @file statistics/test_statistics_api.c
22 * @brief testcase for statistics_api.c
25 #include "gnunet_common.h"
26 #include "gnunet_getopt_lib.h"
27 #include "gnunet_os_lib.h"
28 #include "gnunet_program_lib.h"
29 #include "gnunet_scheduler_lib.h"
30 #include "gnunet_statistics_service.h"
32 #define VERBOSE GNUNET_NO
36 const char *subsystem,
37 const char *name, uint64_t value, int is_persistent)
39 GNUNET_assert (0 == strcmp (name, "test-1"));
40 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
41 GNUNET_assert (value == 1);
42 GNUNET_assert (is_persistent == GNUNET_NO);
48 const char *subsystem,
49 const char *name, uint64_t value, int is_persistent)
51 GNUNET_assert (0 == strcmp (name, "test-2"));
52 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
53 GNUNET_assert (value == 2);
54 GNUNET_assert (is_persistent == GNUNET_NO);
60 const char *subsystem,
61 const char *name, uint64_t value, int is_persistent)
63 GNUNET_assert (0 == strcmp (name, "test-3"));
64 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
65 GNUNET_assert (value == 3);
66 GNUNET_assert (is_persistent == GNUNET_YES);
70 static struct GNUNET_STATISTICS_Handle *h;
73 next_fin (void *cls, int success)
77 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
78 GNUNET_assert (success == GNUNET_OK);
83 next (void *cls, int success)
85 GNUNET_assert (success == GNUNET_OK);
87 GNUNET_STATISTICS_get (h, NULL, "test-2",
88 GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, cls));
93 struct GNUNET_SCHEDULER_Handle *sched,
96 const struct GNUNET_CONFIGURATION_Handle *cfg)
99 h = GNUNET_STATISTICS_create (sched, "test-statistics-api", cfg);
100 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
101 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
102 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
103 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
104 GNUNET_break (NULL !=
105 GNUNET_STATISTICS_get (h, NULL, "test-1",
106 GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls));
111 struct GNUNET_SCHEDULER_Handle *sched,
114 const struct GNUNET_CONFIGURATION_Handle *cfg)
116 h = GNUNET_STATISTICS_create (sched, "test-statistics-api", cfg);
117 GNUNET_break (NULL !=
118 GNUNET_STATISTICS_get (h, NULL, "test-3",
119 GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_3, cls));
127 char *const argv[] = { "test-statistics-api",
129 "test_statistics_api_data.conf",
132 struct GNUNET_GETOPT_CommandLineOption options[] = {
133 GNUNET_GETOPT_OPTION_END
135 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
136 "gnunet-service-statistics",
140 "-c", "test_statistics_api_data.conf", NULL);
141 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp",
143 if (0 != PLIBC_KILL (pid, SIGTERM))
145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
148 GNUNET_OS_process_wait(pid);
152 /* restart to check persistence! */
153 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
154 "gnunet-service-statistics",
158 "-c", "test_statistics_api_data.conf", NULL);
159 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp",
160 options, &run_more, &ok);
161 if (0 != PLIBC_KILL (pid, SIGTERM))
163 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
166 GNUNET_OS_process_wait(pid);
171 main (int argc, char *argv[])
180 /* end of test_statistics_api.c */