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 3, 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"
33 #define START_SERVICE GNUNET_YES
36 check_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
39 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
40 (unsigned long long) value, subsystem, name);
41 GNUNET_assert (0 == strcmp (name, "test-1"));
42 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
43 GNUNET_assert (value == 1);
44 GNUNET_assert (is_persistent == GNUNET_NO);
49 check_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
53 (unsigned long long) value, subsystem, name);
54 GNUNET_assert (0 == strcmp (name, "test-2"));
55 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
56 GNUNET_assert (value == 2);
57 GNUNET_assert (is_persistent == GNUNET_NO);
62 check_3 (void *cls, const char *subsystem, const char *name, uint64_t value,
65 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
66 (unsigned long long) value, subsystem, name);
67 GNUNET_assert (0 == strcmp (name, "test-3"));
68 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
69 GNUNET_assert (value == 3);
70 GNUNET_assert (is_persistent == GNUNET_YES);
74 static struct GNUNET_STATISTICS_Handle *h;
77 next_fin (void *cls, int success)
81 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
82 GNUNET_assert (success == GNUNET_OK);
87 next (void *cls, int success)
89 GNUNET_assert (success == GNUNET_OK);
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
92 GNUNET_STATISTICS_get (h, NULL, "test-2",
93 GNUNET_TIME_UNIT_SECONDS, &next_fin,
98 run (void *cls, char *const *args, const char *cfgfile,
99 const struct GNUNET_CONFIGURATION_Handle *cfg)
101 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
102 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
103 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
104 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
105 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
107 GNUNET_break (NULL !=
108 GNUNET_STATISTICS_get (h, NULL, "test-1",
109 GNUNET_TIME_UNIT_SECONDS, &next,
114 run_more (void *cls, char *const *args, const char *cfgfile,
115 const struct GNUNET_CONFIGURATION_Handle *cfg)
117 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
118 GNUNET_break (NULL !=
119 GNUNET_STATISTICS_get (h, NULL, "test-3",
120 GNUNET_TIME_UNIT_SECONDS, &next_fin,
129 char *const argv[] = { "test-statistics-api",
131 "test_statistics_api_data.conf",
135 struct GNUNET_GETOPT_CommandLineOption options[] = {
136 GNUNET_GETOPT_OPTION_END
139 struct GNUNET_OS_Process *proc;
142 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics",
143 "gnunet-service-statistics",
144 "-c", "test_statistics_api_data.conf", NULL);
146 GNUNET_assert (NULL != proc);
147 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run,
150 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
152 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
155 GNUNET_OS_process_wait (proc);
156 GNUNET_OS_process_destroy (proc);
163 /* restart to check persistence! */
165 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics",
166 "gnunet-service-statistics",
167 "-c", "test_statistics_api_data.conf", NULL);
169 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options,
172 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
174 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
177 GNUNET_OS_process_wait (proc);
178 GNUNET_OS_process_destroy (proc);
185 main (int argc, char *argv[])
189 GNUNET_log_setup ("test_statistics_api",
197 /* end of test_statistics_api.c */