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"
32 #define DEBUG_STATISTICS GNUNET_EXTRA_LOGGING
34 #define START_SERVICE GNUNET_YES
37 check_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
40 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
41 (unsigned long long) value, subsystem, name);
42 GNUNET_assert (0 == strcmp (name, "test-1"));
43 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
44 GNUNET_assert (value == 1);
45 GNUNET_assert (is_persistent == GNUNET_NO);
50 check_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
54 (unsigned long long) value, subsystem, name);
55 GNUNET_assert (0 == strcmp (name, "test-2"));
56 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
57 GNUNET_assert (value == 2);
58 GNUNET_assert (is_persistent == GNUNET_NO);
63 check_3 (void *cls, const char *subsystem, const char *name, uint64_t value,
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
67 (unsigned long long) value, subsystem, name);
68 GNUNET_assert (0 == strcmp (name, "test-3"));
69 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
70 GNUNET_assert (value == 3);
71 GNUNET_assert (is_persistent == GNUNET_YES);
75 static struct GNUNET_STATISTICS_Handle *h;
78 next_fin (void *cls, int success)
82 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
83 GNUNET_assert (success == GNUNET_OK);
88 next (void *cls, int success)
90 GNUNET_assert (success == GNUNET_OK);
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
93 GNUNET_STATISTICS_get (h, NULL, "test-2",
94 GNUNET_TIME_UNIT_SECONDS, &next_fin,
99 run (void *cls, char *const *args, const char *cfgfile,
100 const struct GNUNET_CONFIGURATION_Handle *cfg)
102 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
103 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
104 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
105 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
106 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
108 GNUNET_break (NULL !=
109 GNUNET_STATISTICS_get (h, NULL, "test-1",
110 GNUNET_TIME_UNIT_SECONDS, &next,
115 run_more (void *cls, char *const *args, const char *cfgfile,
116 const struct GNUNET_CONFIGURATION_Handle *cfg)
118 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
119 GNUNET_break (NULL !=
120 GNUNET_STATISTICS_get (h, NULL, "test-3",
121 GNUNET_TIME_UNIT_SECONDS, &next_fin,
130 char *const argv[] = { "test-statistics-api",
132 "test_statistics_api_data.conf",
140 struct GNUNET_GETOPT_CommandLineOption options[] = {
141 GNUNET_GETOPT_OPTION_END
144 struct GNUNET_OS_Process *proc;
147 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
148 "gnunet-service-statistics",
152 "-c", "test_statistics_api_data.conf", NULL);
154 GNUNET_assert (NULL != proc);
155 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run,
158 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
163 GNUNET_OS_process_wait (proc);
164 GNUNET_OS_process_close (proc);
171 /* restart to check persistence! */
173 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
174 "gnunet-service-statistics",
178 "-c", "test_statistics_api_data.conf", NULL);
180 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options,
183 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
185 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
188 GNUNET_OS_process_wait (proc);
189 GNUNET_OS_process_close (proc);
196 main (int argc, char *argv[])
200 GNUNET_log_setup ("test_statistics_api",
212 /* end of test_statistics_api.c */