diff options
Diffstat (limited to 'src/statistics/test_statistics_api.c')
-rw-r--r-- | src/statistics/test_statistics_api.c | 284 |
1 files changed, 142 insertions, 142 deletions
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index b21fa5ef1..9ff02d510 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -33,152 +33,152 @@ static struct GNUNET_STATISTICS_GetHandle *g; | |||
33 | 33 | ||
34 | 34 | ||
35 | static void | 35 | static void |
36 | do_shutdown() | 36 | do_shutdown () |
37 | { | 37 | { |
38 | if (NULL != g) | 38 | if (NULL != g) |
39 | { | 39 | { |
40 | GNUNET_STATISTICS_get_cancel(g); | 40 | GNUNET_STATISTICS_get_cancel (g); |
41 | g = NULL; | 41 | g = NULL; |
42 | } | 42 | } |
43 | GNUNET_STATISTICS_destroy(h, GNUNET_NO); | 43 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); |
44 | h = NULL; | 44 | h = NULL; |
45 | } | 45 | } |
46 | 46 | ||
47 | 47 | ||
48 | static int | 48 | static int |
49 | check_1(void *cls, | 49 | check_1 (void *cls, |
50 | const char *subsystem, | 50 | const char *subsystem, |
51 | const char *name, | 51 | const char *name, |
52 | uint64_t value, | 52 | uint64_t value, |
53 | int is_persistent) | 53 | int is_persistent) |
54 | { | 54 | { |
55 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 55 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
56 | "Received value %llu for `%s:%s\n", | 56 | "Received value %llu for `%s:%s\n", |
57 | (unsigned long long)value, | 57 | (unsigned long long) value, |
58 | subsystem, | 58 | subsystem, |
59 | name); | 59 | name); |
60 | GNUNET_assert(0 == strcmp(name, "test-1")); | 60 | GNUNET_assert (0 == strcmp (name, "test-1")); |
61 | GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); | 61 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
62 | GNUNET_assert(value == 1); | 62 | GNUNET_assert (value == 1); |
63 | GNUNET_assert(is_persistent == GNUNET_NO); | 63 | GNUNET_assert (is_persistent == GNUNET_NO); |
64 | return GNUNET_OK; | 64 | return GNUNET_OK; |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static int | 68 | static int |
69 | check_2(void *cls, | 69 | check_2 (void *cls, |
70 | const char *subsystem, | 70 | const char *subsystem, |
71 | const char *name, | 71 | const char *name, |
72 | uint64_t value, | 72 | uint64_t value, |
73 | int is_persistent) | 73 | int is_persistent) |
74 | { | 74 | { |
75 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
76 | "Received value %llu for `%s:%s\n", | 76 | "Received value %llu for `%s:%s\n", |
77 | (unsigned long long)value, | 77 | (unsigned long long) value, |
78 | subsystem, | 78 | subsystem, |
79 | name); | 79 | name); |
80 | GNUNET_assert(0 == strcmp(name, "test-2")); | 80 | GNUNET_assert (0 == strcmp (name, "test-2")); |
81 | GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); | 81 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
82 | GNUNET_assert(value == 2); | 82 | GNUNET_assert (value == 2); |
83 | GNUNET_assert(is_persistent == GNUNET_NO); | 83 | GNUNET_assert (is_persistent == GNUNET_NO); |
84 | return GNUNET_OK; | 84 | return GNUNET_OK; |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static int | 88 | static int |
89 | check_3(void *cls, | 89 | check_3 (void *cls, |
90 | const char *subsystem, | 90 | const char *subsystem, |
91 | const char *name, | 91 | const char *name, |
92 | uint64_t value, | 92 | uint64_t value, |
93 | int is_persistent) | 93 | int is_persistent) |
94 | { | 94 | { |
95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
96 | "Received value %llu for `%s:%s\n", | 96 | "Received value %llu for `%s:%s\n", |
97 | (unsigned long long)value, | 97 | (unsigned long long) value, |
98 | subsystem, | 98 | subsystem, |
99 | name); | 99 | name); |
100 | GNUNET_assert(0 == strcmp(name, "test-3")); | 100 | GNUNET_assert (0 == strcmp (name, "test-3")); |
101 | GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); | 101 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
102 | GNUNET_assert(value == 3); | 102 | GNUNET_assert (value == 3); |
103 | GNUNET_assert(is_persistent == GNUNET_YES); | 103 | GNUNET_assert (is_persistent == GNUNET_YES); |
104 | return GNUNET_OK; | 104 | return GNUNET_OK; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | static void | 108 | static void |
109 | next_fin(void *cls, | 109 | next_fin (void *cls, |
110 | int success) | 110 | int success) |
111 | { | 111 | { |
112 | int *ok = cls; | 112 | int *ok = cls; |
113 | 113 | ||
114 | g = NULL; | 114 | g = NULL; |
115 | GNUNET_SCHEDULER_shutdown(); | 115 | GNUNET_SCHEDULER_shutdown (); |
116 | GNUNET_assert(success == GNUNET_OK); | 116 | GNUNET_assert (success == GNUNET_OK); |
117 | *ok = 0; | 117 | *ok = 0; |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | static void | 121 | static void |
122 | next(void *cls, int success) | 122 | next (void *cls, int success) |
123 | { | 123 | { |
124 | g = NULL; | 124 | g = NULL; |
125 | GNUNET_assert(success == GNUNET_OK); | 125 | GNUNET_assert (success == GNUNET_OK); |
126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
127 | "Issuing GET request\n"); | 127 | "Issuing GET request\n"); |
128 | GNUNET_break(NULL != | 128 | GNUNET_break (NULL != |
129 | GNUNET_STATISTICS_get(h, NULL, "test-2", | 129 | GNUNET_STATISTICS_get (h, NULL, "test-2", |
130 | &next_fin, | 130 | &next_fin, |
131 | &check_2, cls)); | 131 | &check_2, cls)); |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | static void | 135 | static void |
136 | run(void *cls, | 136 | run (void *cls, |
137 | char *const *args, | 137 | char *const *args, |
138 | const char *cfgfile, | 138 | const char *cfgfile, |
139 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 139 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
140 | { | 140 | { |
141 | h = GNUNET_STATISTICS_create("test-statistics-api", cfg); | 141 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); |
142 | if (NULL == h) | 142 | if (NULL == h) |
143 | { | 143 | { |
144 | GNUNET_break(0); | 144 | GNUNET_break (0); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 147 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
148 | NULL); | 148 | NULL); |
149 | GNUNET_STATISTICS_set(h, "test-1", 1, GNUNET_NO); | 149 | GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); |
150 | GNUNET_STATISTICS_set(h, "test-2", 2, GNUNET_NO); | 150 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); |
151 | GNUNET_STATISTICS_set(h, "test-3", 2, GNUNET_NO); | 151 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); |
152 | GNUNET_STATISTICS_update(h, "test-3", 1, GNUNET_YES); | 152 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); |
153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "Issuing GET request\n"); | 154 | "Issuing GET request\n"); |
155 | GNUNET_break(NULL != | 155 | GNUNET_break (NULL != |
156 | (g = GNUNET_STATISTICS_get(h, NULL, "test-1", | 156 | (g = GNUNET_STATISTICS_get (h, NULL, "test-1", |
157 | &next, | 157 | &next, |
158 | &check_1, cls))); | 158 | &check_1, cls))); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | static void | 162 | static void |
163 | run_more(void *cls, | 163 | run_more (void *cls, |
164 | char *const *args, | 164 | char *const *args, |
165 | const char *cfgfile, | 165 | const char *cfgfile, |
166 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 166 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
167 | { | 167 | { |
168 | h = GNUNET_STATISTICS_create("test-statistics-api", | 168 | h = GNUNET_STATISTICS_create ("test-statistics-api", |
169 | cfg); | 169 | cfg); |
170 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 170 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
171 | NULL); | 171 | NULL); |
172 | GNUNET_break(NULL != | 172 | GNUNET_break (NULL != |
173 | (g = GNUNET_STATISTICS_get(h, NULL, | 173 | (g = GNUNET_STATISTICS_get (h, NULL, |
174 | "test-3", | 174 | "test-3", |
175 | &next_fin, | 175 | &next_fin, |
176 | &check_3, cls))); | 176 | &check_3, cls))); |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | int | 180 | int |
181 | main(int argc, char *argv_ign[]) | 181 | main (int argc, char *argv_ign[]) |
182 | { | 182 | { |
183 | int ok = 1; | 183 | int ok = 1; |
184 | char *const argv[] = { "test-statistics-api", | 184 | char *const argv[] = { "test-statistics-api", |
@@ -192,60 +192,60 @@ main(int argc, char *argv_ign[]) | |||
192 | struct GNUNET_OS_Process *proc; | 192 | struct GNUNET_OS_Process *proc; |
193 | char *binary; | 193 | char *binary; |
194 | 194 | ||
195 | GNUNET_log_setup("test_statistics_api", | 195 | GNUNET_log_setup ("test_statistics_api", |
196 | "WARNING", | 196 | "WARNING", |
197 | NULL); | 197 | NULL); |
198 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); | 198 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); |
199 | proc = | 199 | proc = |
200 | GNUNET_OS_start_process(GNUNET_YES, | 200 | GNUNET_OS_start_process (GNUNET_YES, |
201 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 201 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
202 | NULL, NULL, NULL, | 202 | NULL, NULL, NULL, |
203 | binary, | 203 | binary, |
204 | "gnunet-service-statistics", | 204 | "gnunet-service-statistics", |
205 | "-c", "test_statistics_api_data.conf", NULL); | 205 | "-c", "test_statistics_api_data.conf", NULL); |
206 | GNUNET_assert(NULL != proc); | 206 | GNUNET_assert (NULL != proc); |
207 | GNUNET_PROGRAM_run(5, argv, | 207 | GNUNET_PROGRAM_run (5, argv, |
208 | "test-statistics-api", "nohelp", | 208 | "test-statistics-api", "nohelp", |
209 | options, &run, | 209 | options, &run, |
210 | &ok); | 210 | &ok); |
211 | if (0 != GNUNET_OS_process_kill(proc, | 211 | if (0 != GNUNET_OS_process_kill (proc, |
212 | GNUNET_TERM_SIG)) | 212 | GNUNET_TERM_SIG)) |
213 | { | 213 | { |
214 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 214 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
215 | ok = 1; | 215 | ok = 1; |
216 | } | 216 | } |
217 | GNUNET_OS_process_wait(proc); | 217 | GNUNET_OS_process_wait (proc); |
218 | GNUNET_OS_process_destroy(proc); | 218 | GNUNET_OS_process_destroy (proc); |
219 | proc = NULL; | 219 | proc = NULL; |
220 | if (ok != 0) | 220 | if (ok != 0) |
221 | { | 221 | { |
222 | GNUNET_free(binary); | 222 | GNUNET_free (binary); |
223 | return ok; | 223 | return ok; |
224 | } | 224 | } |
225 | ok = 1; | 225 | ok = 1; |
226 | /* restart to check persistence! */ | 226 | /* restart to check persistence! */ |
227 | proc = | 227 | proc = |
228 | GNUNET_OS_start_process(GNUNET_YES, | 228 | GNUNET_OS_start_process (GNUNET_YES, |
229 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 229 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
230 | NULL, NULL, NULL, | 230 | NULL, NULL, NULL, |
231 | binary, | 231 | binary, |
232 | "gnunet-service-statistics", | 232 | "gnunet-service-statistics", |
233 | "-c", "test_statistics_api_data.conf", | 233 | "-c", "test_statistics_api_data.conf", |
234 | NULL); | 234 | NULL); |
235 | GNUNET_PROGRAM_run(5, argv, | 235 | GNUNET_PROGRAM_run (5, argv, |
236 | "test-statistics-api", "nohelp", | 236 | "test-statistics-api", "nohelp", |
237 | options, | 237 | options, |
238 | &run_more, &ok); | 238 | &run_more, &ok); |
239 | if (0 != GNUNET_OS_process_kill(proc, | 239 | if (0 != GNUNET_OS_process_kill (proc, |
240 | GNUNET_TERM_SIG)) | 240 | GNUNET_TERM_SIG)) |
241 | { | 241 | { |
242 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 242 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
243 | ok = 1; | 243 | ok = 1; |
244 | } | 244 | } |
245 | GNUNET_OS_process_wait(proc); | 245 | GNUNET_OS_process_wait (proc); |
246 | GNUNET_OS_process_destroy(proc); | 246 | GNUNET_OS_process_destroy (proc); |
247 | proc = NULL; | 247 | proc = NULL; |
248 | GNUNET_free(binary); | 248 | GNUNET_free (binary); |
249 | return ok; | 249 | return ok; |
250 | } | 250 | } |
251 | 251 | ||