blob: f6efd3e2002ab56d2036689cd5bf20663be0b51e [file] [log] [blame]
Jacob Erlbeck9732cb42015-10-01 20:43:53 +02001/* tests for statistics */
2/*
3 * (C) 2015 Sysmocom s.m.f.c. GmbH
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <osmocom/core/logging.h>
24#include <osmocom/core/utils.h>
25#include <osmocom/core/stat_item.h>
Jacob Erlbeck46b703d2015-11-09 17:25:27 +010026#include <osmocom/core/rate_ctr.h>
27#include <osmocom/core/stats.h>
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020028
29#include <stdio.h>
30
Jacob Erlbeck46b703d2015-11-09 17:25:27 +010031enum test_ctr {
32 TEST_A_CTR,
33 TEST_B_CTR,
34};
35
36static const struct rate_ctr_desc ctr_description[] = {
37 [TEST_A_CTR] = { "ctr.a", "The A counter value"},
38 [TEST_B_CTR] = { "ctr.b", "The B counter value"},
39};
40
41static const struct rate_ctr_group_desc ctrg_desc = {
42 .group_name_prefix = "ctr-test.one",
43 .group_description = "Counter test number 1",
44 .num_ctr = ARRAY_SIZE(ctr_description),
45 .ctr_desc = ctr_description,
46 .class_id = OSMO_STATS_CLASS_SUBSCRIBER,
47};
48
49enum test_items {
50 TEST_A_ITEM,
51 TEST_B_ITEM,
52};
53
54static const struct osmo_stat_item_desc item_description[] = {
55 [TEST_A_ITEM] = { "item.a", "The A value", "ma", 4, -1 },
56 [TEST_B_ITEM] = { "item.b", "The B value", "kb", 7, -1 },
57};
58
59static const struct osmo_stat_item_group_desc statg_desc = {
60 .group_name_prefix = "test.one",
61 .group_description = "Test number 1",
62 .num_items = ARRAY_SIZE(item_description),
63 .item_desc = item_description,
64 .class_id = OSMO_STATS_CLASS_PEER,
65};
66
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020067static void stat_test(void)
68{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010069 struct osmo_stat_item_group *statg =
70 osmo_stat_item_group_alloc(NULL, &statg_desc, 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020071
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010072 struct osmo_stat_item_group *sgrp2;
73 const struct osmo_stat_item *sitem1, *sitem2;
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020074 int rc;
75 int32_t value;
76 int32_t rd_a = 0;
77 int32_t rd_b = 0;
78 int i;
79
80 OSMO_ASSERT(statg != NULL);
81
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010082 sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020083 OSMO_ASSERT(sgrp2 == statg);
84
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010085 sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 1);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020086 OSMO_ASSERT(sgrp2 == NULL);
87
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010088 sgrp2 = osmo_stat_item_get_group_by_name_idx("test.two", 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020089 OSMO_ASSERT(sgrp2 == NULL);
90
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010091 sitem1 = osmo_stat_item_get_by_name(statg, "item.c");
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020092 OSMO_ASSERT(sitem1 == NULL);
93
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010094 sitem1 = osmo_stat_item_get_by_name(statg, "item.a");
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020095 OSMO_ASSERT(sitem1 != NULL);
96 OSMO_ASSERT(sitem1 == statg->items[TEST_A_ITEM]);
97
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010098 sitem2 = osmo_stat_item_get_by_name(statg, "item.b");
Jacob Erlbeck9732cb42015-10-01 20:43:53 +020099 OSMO_ASSERT(sitem2 != NULL);
100 OSMO_ASSERT(sitem2 != sitem1);
101 OSMO_ASSERT(sitem2 == statg->items[TEST_B_ITEM]);
102
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100103 value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200104 OSMO_ASSERT(value == -1);
105
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100106 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200107 OSMO_ASSERT(rc == 0);
108
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100109 osmo_stat_item_set(statg->items[TEST_A_ITEM], 1);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200110
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100111 value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200112 OSMO_ASSERT(value == 1);
113
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100114 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200115 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200116 OSMO_ASSERT(value == 1);
117
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100118 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200119 OSMO_ASSERT(rc == 0);
120
121 for (i = 2; i <= 32; i++) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100122 osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
123 osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200124
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100125 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200126 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200127 OSMO_ASSERT(value == i);
128
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100129 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200130 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200131 OSMO_ASSERT(value == 1000 + i);
132 }
133
134 /* Keep 2 in FIFO */
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100135 osmo_stat_item_set(statg->items[TEST_A_ITEM], 33);
136 osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200137
138 for (i = 34; i <= 64; i++) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100139 osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
140 osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200141
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100142 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200143 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200144 OSMO_ASSERT(value == i-1);
145
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100146 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200147 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200148 OSMO_ASSERT(value == 1000 + i-1);
149 }
150
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100151 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200152 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200153 OSMO_ASSERT(value == 64);
154
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100155 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200156 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200157 OSMO_ASSERT(value == 1000 + 64);
158
159 /* Overrun FIFOs */
160 for (i = 65; i <= 96; i++) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100161 osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
162 osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200163 }
164
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100165 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200166 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200167 OSMO_ASSERT(value == 93);
168
169 for (i = 94; i <= 96; i++) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100170 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200171 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200172 OSMO_ASSERT(value == i);
173 }
174
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100175 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200176 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200177 OSMO_ASSERT(value == 1000 + 90);
178
179 for (i = 91; i <= 96; i++) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100180 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200181 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200182 OSMO_ASSERT(value == 1000 + i);
183 }
184
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200185 /* Test Discard (single item) */
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100186 osmo_stat_item_set(statg->items[TEST_A_ITEM], 97);
187 rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200188 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200189
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100190 rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200191 OSMO_ASSERT(rc == 0);
192
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100193 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200194 OSMO_ASSERT(rc == 0);
195
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100196 osmo_stat_item_set(statg->items[TEST_A_ITEM], 98);
197 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200198 OSMO_ASSERT(rc > 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200199 OSMO_ASSERT(value == 98);
200
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100201 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200202 OSMO_ASSERT(rc == 0);
203
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200204 /* Test Discard (all items) */
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100205 osmo_stat_item_set(statg->items[TEST_A_ITEM], 99);
206 osmo_stat_item_set(statg->items[TEST_A_ITEM], 100);
207 osmo_stat_item_set(statg->items[TEST_A_ITEM], 101);
208 osmo_stat_item_set(statg->items[TEST_B_ITEM], 99);
209 osmo_stat_item_set(statg->items[TEST_B_ITEM], 100);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200210
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100211 rc = osmo_stat_item_discard_all(&rd_a);
212 rc = osmo_stat_item_discard_all(&rd_b);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200213
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100214 rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200215 OSMO_ASSERT(rc == 0);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100216 rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
Jacob Erlbeckb27b3522015-10-12 18:47:09 +0200217 OSMO_ASSERT(rc == 0);
218
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100219 osmo_stat_item_group_free(statg);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200220
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100221 sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200222 OSMO_ASSERT(sgrp2 == NULL);
223}
224
Jacob Erlbeck46b703d2015-11-09 17:25:27 +0100225/*** stats reporter tests ***/
226
227/* define a special stats reporter for testing */
228
229static int send_count;
230
231enum {
232 OSMO_STATS_REPORTER_TEST = OSMO_STATS_REPORTER_LOG + 1,
233};
234
235static int stats_reporter_test_send_counter(struct osmo_stats_reporter *srep,
236 const struct rate_ctr_group *ctrg,
237 const struct rate_ctr_desc *desc,
238 int64_t value, int64_t delta)
239{
240 const char *group_name = ctrg ? ctrg->desc->group_name_prefix : "";
241
242 printf(" %s: counter p=%s g=%s i=%u n=%s v=%lld d=%lld\n",
243 srep->name,
244 srep->name_prefix ? srep->name_prefix : "",
245 group_name, ctrg ? ctrg->idx : 0,
246 desc->name, (long long)value, (long long)delta);
247
248 send_count += 1;
249 return 0;
250}
251
252static int stats_reporter_test_send_item(struct osmo_stats_reporter *srep,
253 const struct osmo_stat_item_group *statg,
254 const struct osmo_stat_item_desc *desc, int value)
255{
256 printf(" %s: item p=%s g=%s i=%u n=%s v=%d u=%s\n",
257 srep->name,
258 srep->name_prefix ? srep->name_prefix : "",
259 statg->desc->group_name_prefix, statg->idx,
260 desc->name, value, desc->unit ? desc->unit : "");
261
262 send_count += 1;
263 return 0;
264}
265
266static int stats_reporter_test_open(struct osmo_stats_reporter *srep)
267{
268 printf(" %s: open\n", srep->name);
269 return 0;
270}
271
272static int stats_reporter_test_close(struct osmo_stats_reporter *srep)
273{
274 printf(" %s: close\n", srep->name);
275 return 0;
276}
277
278static struct osmo_stats_reporter *stats_reporter_create_test(const char *name)
279{
280 struct osmo_stats_reporter *srep;
281 srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_TEST, name);
282
283 srep->have_net_config = 0;
284
285 srep->open = stats_reporter_test_open;
286 srep->close = stats_reporter_test_close;
287 srep->send_counter = stats_reporter_test_send_counter;
288 srep->send_item = stats_reporter_test_send_item;
289
290 return srep;
291}
292
293
294static void test_reporting()
295{
296 struct osmo_stats_reporter *srep1, *srep2, *srep;
297 struct osmo_stat_item_group *statg1, *statg2;
298 struct rate_ctr_group *ctrg1, *ctrg2;
299
300 int rc;
301
302 printf("Start test: %s\n", __func__);
303
304 /* Allocate counters and items */
305 statg1 = osmo_stat_item_group_alloc(NULL, &statg_desc, 1);
306 OSMO_ASSERT(statg1 != NULL);
307 statg2 = osmo_stat_item_group_alloc(NULL, &statg_desc, 2);
308 OSMO_ASSERT(statg2 != NULL);
309 ctrg1 = rate_ctr_group_alloc(NULL, &ctrg_desc, 1);
310 OSMO_ASSERT(ctrg1 != NULL);
311 ctrg2 = rate_ctr_group_alloc(NULL, &ctrg_desc, 2);
312 OSMO_ASSERT(ctrg2 != NULL);
313
314 srep1 = stats_reporter_create_test("test1");
315 OSMO_ASSERT(srep1 != NULL);
316
317 srep2 = stats_reporter_create_test("test2");
318 OSMO_ASSERT(srep2 != NULL);
319
320 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_TEST, "test1");
321 OSMO_ASSERT(srep == srep1);
322 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_TEST, "test2");
323 OSMO_ASSERT(srep == srep2);
324
325 rc = osmo_stats_reporter_enable(srep1);
326 OSMO_ASSERT(rc >= 0);
327 OSMO_ASSERT(srep1->force_single_flush);
328 rc = osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_SUBSCRIBER);
329 OSMO_ASSERT(rc >= 0);
330
331 rc = osmo_stats_reporter_enable(srep2);
332 OSMO_ASSERT(rc >= 0);
333 OSMO_ASSERT(srep2->force_single_flush);
334 rc = osmo_stats_reporter_set_max_class(srep2, OSMO_STATS_CLASS_SUBSCRIBER);
335 OSMO_ASSERT(rc >= 0);
336
337 printf("report (initial):\n");
338 send_count = 0;
339 osmo_stats_report();
340 OSMO_ASSERT(send_count == 16);
341
342 printf("report (srep1 global):\n");
343 /* force single flush */
344 osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_GLOBAL);
345 srep1->force_single_flush = 1;
346 srep2->force_single_flush = 1;
347 send_count = 0;
348 osmo_stats_report();
349 OSMO_ASSERT(send_count == 8);
350
351 printf("report (srep1 peer):\n");
352 /* force single flush */
353 osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_PEER);
354 srep1->force_single_flush = 1;
355 srep2->force_single_flush = 1;
356 send_count = 0;
357 osmo_stats_report();
358 OSMO_ASSERT(send_count == 12);
359
360 printf("report (srep1 subscriber):\n");
361 /* force single flush */
362 osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_SUBSCRIBER);
363 srep1->force_single_flush = 1;
364 srep2->force_single_flush = 1;
365 send_count = 0;
366 osmo_stats_report();
367 OSMO_ASSERT(send_count == 16);
368
369 printf("report (srep2 disabled):\n");
370 /* force single flush */
371 srep1->force_single_flush = 1;
372 srep2->force_single_flush = 1;
373 rc = osmo_stats_reporter_disable(srep2);
374 OSMO_ASSERT(rc >= 0);
375 send_count = 0;
376 osmo_stats_report();
377 OSMO_ASSERT(send_count == 8);
378
379 printf("report (srep2 enabled, no flush forced):\n");
380 rc = osmo_stats_reporter_enable(srep2);
381 OSMO_ASSERT(rc >= 0);
382 send_count = 0;
383 osmo_stats_report();
384 OSMO_ASSERT(send_count == 8);
385
386 printf("report (should be empty):\n");
387 send_count = 0;
388 osmo_stats_report();
389 OSMO_ASSERT(send_count == 0);
390
391 printf("report (group 1, counter 1 update):\n");
392 rate_ctr_inc(&ctrg1->ctr[TEST_A_CTR]);
393 send_count = 0;
394 osmo_stats_report();
395 OSMO_ASSERT(send_count == 2);
396
397 printf("report (group 1, item 1 update):\n");
398 osmo_stat_item_set(statg1->items[TEST_A_ITEM], 10);
399 send_count = 0;
400 osmo_stats_report();
401 OSMO_ASSERT(send_count == 2);
402
403 printf("report (remove statg1, ctrg1):\n");
404 /* force single flush */
405 srep1->force_single_flush = 1;
406 srep2->force_single_flush = 1;
407 osmo_stat_item_group_free(statg1);
408 rate_ctr_group_free(ctrg1);
409 send_count = 0;
410 osmo_stats_report();
411 OSMO_ASSERT(send_count == 8);
412
413 printf("report (remove srep1):\n");
414 /* force single flush */
415 srep1->force_single_flush = 1;
416 srep2->force_single_flush = 1;
417 osmo_stats_reporter_free(srep1);
418 send_count = 0;
419 osmo_stats_report();
420 OSMO_ASSERT(send_count == 4);
421
422 printf("report (remove statg2):\n");
423 /* force single flush */
424 srep2->force_single_flush = 1;
425 osmo_stat_item_group_free(statg2);
426 send_count = 0;
427 osmo_stats_report();
428 OSMO_ASSERT(send_count == 2);
429
430 printf("report (remove srep2):\n");
431 /* force single flush */
432 srep2->force_single_flush = 1;
433 osmo_stats_reporter_free(srep2);
434 send_count = 0;
435 osmo_stats_report();
436 OSMO_ASSERT(send_count == 0);
437
438 printf("report (remove ctrg2, should be empty):\n");
439 rate_ctr_group_free(ctrg2);
440 send_count = 0;
441 osmo_stats_report();
442 OSMO_ASSERT(send_count == 0);
443
444 printf("End test: %s\n", __func__);
445}
446
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200447int main(int argc, char **argv)
448{
449 static const struct log_info log_info = {};
450 log_init(&log_info, NULL);
451
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100452 osmo_stat_item_init(NULL);
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200453
454 stat_test();
Jacob Erlbeck46b703d2015-11-09 17:25:27 +0100455 test_reporting();
Jacob Erlbeck9732cb42015-10-01 20:43:53 +0200456 return 0;
457}