diff options
Diffstat (limited to 'src/statistics/test_statistics_api.c')
-rw-r--r-- | src/statistics/test_statistics_api.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index ddebfa356..5fb506ff7 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -20,17 +20,15 @@ | |||
20 | /** | 20 | /** |
21 | * @file statistics/test_statistics_api.c | 21 | * @file statistics/test_statistics_api.c |
22 | * @brief testcase for statistics_api.c | 22 | * @brief testcase for statistics_api.c |
23 | * @author Christian Grothoff | ||
23 | */ | 24 | */ |
24 | #include "platform.h" | 25 | #include "platform.h" |
25 | #include "gnunet_common.h" | 26 | #include "gnunet_util_lib.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" | 27 | #include "gnunet_statistics_service.h" |
31 | 28 | ||
32 | 29 | ||
33 | #define START_SERVICE GNUNET_YES | 30 | static struct GNUNET_STATISTICS_Handle *h; |
31 | |||
34 | 32 | ||
35 | static int | 33 | static int |
36 | check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | 34 | check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, |
@@ -45,6 +43,7 @@ check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
45 | return GNUNET_OK; | 43 | return GNUNET_OK; |
46 | } | 44 | } |
47 | 45 | ||
46 | |||
48 | static int | 47 | static int |
49 | check_2 (void *cls, const char *subsystem, const char *name, uint64_t value, | 48 | check_2 (void *cls, const char *subsystem, const char *name, uint64_t value, |
50 | int is_persistent) | 49 | int is_persistent) |
@@ -58,6 +57,7 @@ check_2 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
58 | return GNUNET_OK; | 57 | return GNUNET_OK; |
59 | } | 58 | } |
60 | 59 | ||
60 | |||
61 | static int | 61 | static int |
62 | check_3 (void *cls, const char *subsystem, const char *name, uint64_t value, | 62 | check_3 (void *cls, const char *subsystem, const char *name, uint64_t value, |
63 | int is_persistent) | 63 | int is_persistent) |
@@ -71,7 +71,6 @@ check_3 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
71 | return GNUNET_OK; | 71 | return GNUNET_OK; |
72 | } | 72 | } |
73 | 73 | ||
74 | static struct GNUNET_STATISTICS_Handle *h; | ||
75 | 74 | ||
76 | static void | 75 | static void |
77 | next_fin (void *cls, int success) | 76 | next_fin (void *cls, int success) |
@@ -83,6 +82,7 @@ next_fin (void *cls, int success) | |||
83 | *ok = 0; | 82 | *ok = 0; |
84 | } | 83 | } |
85 | 84 | ||
85 | |||
86 | static void | 86 | static void |
87 | next (void *cls, int success) | 87 | next (void *cls, int success) |
88 | { | 88 | { |
@@ -94,6 +94,7 @@ next (void *cls, int success) | |||
94 | &check_2, cls)); | 94 | &check_2, cls)); |
95 | } | 95 | } |
96 | 96 | ||
97 | |||
97 | static void | 98 | static void |
98 | run (void *cls, char *const *args, const char *cfgfile, | 99 | run (void *cls, char *const *args, const char *cfgfile, |
99 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 100 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -110,6 +111,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
110 | &check_1, cls)); | 111 | &check_1, cls)); |
111 | } | 112 | } |
112 | 113 | ||
114 | |||
113 | static void | 115 | static void |
114 | run_more (void *cls, char *const *args, const char *cfgfile, | 116 | run_more (void *cls, char *const *args, const char *cfgfile, |
115 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 117 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -121,8 +123,9 @@ run_more (void *cls, char *const *args, const char *cfgfile, | |||
121 | &check_3, cls)); | 123 | &check_3, cls)); |
122 | } | 124 | } |
123 | 125 | ||
124 | static int | 126 | |
125 | check () | 127 | int |
128 | main (int argc, char *argv_ign[]) | ||
126 | { | 129 | { |
127 | int ok = 1; | 130 | int ok = 1; |
128 | 131 | ||
@@ -135,18 +138,21 @@ check () | |||
135 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 138 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
136 | GNUNET_GETOPT_OPTION_END | 139 | GNUNET_GETOPT_OPTION_END |
137 | }; | 140 | }; |
138 | #if START_SERVICE | ||
139 | struct GNUNET_OS_Process *proc; | 141 | struct GNUNET_OS_Process *proc; |
142 | char *binary; | ||
140 | 143 | ||
144 | GNUNET_log_setup ("test_statistics_api", | ||
145 | "WARNING", | ||
146 | NULL); | ||
147 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); | ||
141 | proc = | 148 | proc = |
142 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", | 149 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, |
150 | binary, | ||
143 | "gnunet-service-statistics", | 151 | "gnunet-service-statistics", |
144 | "-c", "test_statistics_api_data.conf", NULL); | 152 | "-c", "test_statistics_api_data.conf", NULL); |
145 | #endif | ||
146 | GNUNET_assert (NULL != proc); | 153 | GNUNET_assert (NULL != proc); |
147 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, | 154 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, |
148 | &ok); | 155 | &ok); |
149 | #if START_SERVICE | ||
150 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 156 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
151 | { | 157 | { |
152 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
@@ -155,20 +161,20 @@ check () | |||
155 | GNUNET_OS_process_wait (proc); | 161 | GNUNET_OS_process_wait (proc); |
156 | GNUNET_OS_process_destroy (proc); | 162 | GNUNET_OS_process_destroy (proc); |
157 | proc = NULL; | 163 | proc = NULL; |
158 | #endif | ||
159 | if (ok != 0) | 164 | if (ok != 0) |
165 | { | ||
166 | GNUNET_free (binary); | ||
160 | return ok; | 167 | return ok; |
168 | } | ||
161 | ok = 1; | 169 | ok = 1; |
162 | #if START_SERVICE | ||
163 | /* restart to check persistence! */ | 170 | /* restart to check persistence! */ |
164 | proc = | 171 | proc = |
165 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", | 172 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, |
173 | binary, | ||
166 | "gnunet-service-statistics", | 174 | "gnunet-service-statistics", |
167 | "-c", "test_statistics_api_data.conf", NULL); | 175 | "-c", "test_statistics_api_data.conf", NULL); |
168 | #endif | ||
169 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, | 176 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, |
170 | &run_more, &ok); | 177 | &run_more, &ok); |
171 | #if START_SERVICE | ||
172 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 178 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
173 | { | 179 | { |
174 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 180 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
@@ -177,21 +183,8 @@ check () | |||
177 | GNUNET_OS_process_wait (proc); | 183 | GNUNET_OS_process_wait (proc); |
178 | GNUNET_OS_process_destroy (proc); | 184 | GNUNET_OS_process_destroy (proc); |
179 | proc = NULL; | 185 | proc = NULL; |
180 | #endif | 186 | GNUNET_free (binary); |
181 | return ok; | 187 | return ok; |
182 | } | 188 | } |
183 | 189 | ||
184 | int | ||
185 | main (int argc, char *argv[]) | ||
186 | { | ||
187 | int ret; | ||
188 | |||
189 | GNUNET_log_setup ("test_statistics_api", | ||
190 | "WARNING", | ||
191 | NULL); | ||
192 | ret = check (); | ||
193 | |||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | /* end of test_statistics_api.c */ | 190 | /* end of test_statistics_api.c */ |