aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_statistics_api_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_statistics_api_loop.c')
-rw-r--r--src/statistics/test_statistics_api_loop.c101
1 files changed, 50 insertions, 51 deletions
diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c
index 2438fd95a..61cf1130a 100644
--- a/src/statistics/test_statistics_api_loop.c
+++ b/src/statistics/test_statistics_api_loop.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file statistics/test_statistics_api_loop.c 21 * @file statistics/test_statistics_api_loop.c
22 * @brief testcase for statistics_api.c 22 * @brief testcase for statistics_api.c
@@ -31,91 +31,90 @@ static struct GNUNET_STATISTICS_Handle *h;
31 31
32 32
33static int 33static int
34check_1 (void *cls, 34check_1(void *cls,
35 const char *subsystem, 35 const char *subsystem,
36 const char *name, 36 const char *name,
37 uint64_t value, 37 uint64_t value,
38 int is_persistent) 38 int is_persistent)
39{ 39{
40 GNUNET_assert (0 == strcmp (name, "test-0")); 40 GNUNET_assert(0 == strcmp(name, "test-0"));
41 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop")); 41 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api-loop"));
42 GNUNET_assert (is_persistent == GNUNET_NO); 42 GNUNET_assert(is_persistent == GNUNET_NO);
43 return GNUNET_OK; 43 return GNUNET_OK;
44} 44}
45 45
46 46
47static void 47static void
48next (void *cls, 48next(void *cls,
49 int success) 49 int success)
50{ 50{
51 int *ok = cls; 51 int *ok = cls;
52 52
53 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 53 GNUNET_STATISTICS_destroy(h, GNUNET_NO);
54 GNUNET_assert (success == GNUNET_OK); 54 GNUNET_assert(success == GNUNET_OK);
55 *ok = 0; 55 *ok = 0;
56} 56}
57 57
58 58
59static void 59static void
60run (void *cls, 60run(void *cls,
61 char *const *args, 61 char *const *args,
62 const char *cfgfile, 62 const char *cfgfile,
63 const struct GNUNET_CONFIGURATION_Handle *cfg) 63 const struct GNUNET_CONFIGURATION_Handle *cfg)
64{ 64{
65 unsigned int i; 65 unsigned int i;
66 char name[128]; 66 char name[128];
67 67
68 h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg); 68 h = GNUNET_STATISTICS_create("test-statistics-api-loop", cfg);
69 for (i = 0; i < ROUNDS; i++) 69 for (i = 0; i < ROUNDS; i++)
70 { 70 {
71 GNUNET_snprintf (name, sizeof (name), "test-%d", i % 32); 71 GNUNET_snprintf(name, sizeof(name), "test-%d", i % 32);
72 GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); 72 GNUNET_STATISTICS_set(h, name, i, GNUNET_NO);
73 GNUNET_snprintf (name, sizeof (name), "test-%d", i % 16); 73 GNUNET_snprintf(name, sizeof(name), "test-%d", i % 16);
74 GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); 74 GNUNET_STATISTICS_update(h, name, 1, GNUNET_NO);
75 } 75 }
76 i = 0; 76 i = 0;
77 GNUNET_break (NULL != 77 GNUNET_break(NULL !=
78 GNUNET_STATISTICS_get (h, NULL, "test-0", 78 GNUNET_STATISTICS_get(h, NULL, "test-0",
79 &next, 79 &next,
80 &check_1, cls)); 80 &check_1, cls));
81} 81}
82 82
83 83
84int 84int
85main (int argc, char *argv_ign[]) 85main(int argc, char *argv_ign[])
86{ 86{
87 int ok = 1; 87 int ok = 1;
88 88
89 char *const argv[] = { "test-statistics-api", 89 char *const argv[] = { "test-statistics-api",
90 "-c", 90 "-c",
91 "test_statistics_api_data.conf", 91 "test_statistics_api_data.conf",
92 NULL 92 NULL };
93 };
94 struct GNUNET_GETOPT_CommandLineOption options[] = { 93 struct GNUNET_GETOPT_CommandLineOption options[] = {
95 GNUNET_GETOPT_OPTION_END 94 GNUNET_GETOPT_OPTION_END
96 }; 95 };
97 struct GNUNET_OS_Process *proc; 96 struct GNUNET_OS_Process *proc;
98 char *binary; 97 char *binary;
99 98
100 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); 99 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics");
101 proc = 100 proc =
102 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 101 GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
103 NULL, NULL, NULL, 102 NULL, NULL, NULL,
104 binary, 103 binary,
105 "gnunet-service-statistics", 104 "gnunet-service-statistics",
106 "-c", "test_statistics_api_data.conf", NULL); 105 "-c", "test_statistics_api_data.conf", NULL);
107 GNUNET_assert (NULL != proc); 106 GNUNET_assert(NULL != proc);
108 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run, 107 GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run,
109 &ok); 108 &ok);
110 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) 109 if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG))
111 { 110 {
112 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 111 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
113 ok = 1; 112 ok = 1;
114 } 113 }
115 GNUNET_OS_process_wait (proc); 114 GNUNET_OS_process_wait(proc);
116 GNUNET_OS_process_destroy (proc); 115 GNUNET_OS_process_destroy(proc);
117 proc = NULL; 116 proc = NULL;
118 GNUNET_free (binary); 117 GNUNET_free(binary);
119 return ok; 118 return ok;
120} 119}
121 120