Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 1 | /* tests for statistics */ |
| 2 | /* |
Vadim Yanitskiy | 03590fc | 2023-05-18 17:22:26 +0700 | [diff] [blame] | 3 | * (C) 2015 sysmocom - s.f.m.c. GmbH |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | * |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 21 | #include <osmocom/core/application.h> |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 22 | #include <osmocom/core/logging.h> |
| 23 | #include <osmocom/core/utils.h> |
| 24 | #include <osmocom/core/stat_item.h> |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 25 | #include <osmocom/core/rate_ctr.h> |
| 26 | #include <osmocom/core/stats.h> |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 27 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 28 | #include <stat_item_internal.h> |
| 29 | |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 30 | #include <stdio.h> |
Neels Hofmeyr | b41b48e | 2017-01-13 00:11:34 +0100 | [diff] [blame] | 31 | #include <inttypes.h> |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 32 | |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 33 | enum test_ctr { |
| 34 | TEST_A_CTR, |
| 35 | TEST_B_CTR, |
| 36 | }; |
| 37 | |
| 38 | static const struct rate_ctr_desc ctr_description[] = { |
Harald Welte | a7a5065 | 2017-10-03 17:49:21 +0800 | [diff] [blame] | 39 | [TEST_A_CTR] = { "ctr:a", "The A counter value"}, |
| 40 | [TEST_B_CTR] = { "ctr:b", "The B counter value"}, |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static const struct rate_ctr_group_desc ctrg_desc = { |
Harald Welte | a7a5065 | 2017-10-03 17:49:21 +0800 | [diff] [blame] | 44 | .group_name_prefix = "ctr-test:one", |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 45 | .group_description = "Counter test number 1", |
| 46 | .num_ctr = ARRAY_SIZE(ctr_description), |
| 47 | .ctr_desc = ctr_description, |
| 48 | .class_id = OSMO_STATS_CLASS_SUBSCRIBER, |
| 49 | }; |
| 50 | |
Harald Welte | 04c8812 | 2017-10-03 18:34:48 +0800 | [diff] [blame] | 51 | static const struct rate_ctr_desc ctr_description_dot[] = { |
| 52 | [TEST_A_CTR] = { "ctr.a", "The A counter value with ."}, |
| 53 | [TEST_B_CTR] = { "ctr.b", "The B counter value with ."}, |
| 54 | }; |
| 55 | |
| 56 | static const struct rate_ctr_group_desc ctrg_desc_dot = { |
| 57 | .group_name_prefix = "ctr-test.one_dot", |
| 58 | .group_description = "Counter test number 1dot", |
| 59 | .num_ctr = ARRAY_SIZE(ctr_description_dot), |
| 60 | .ctr_desc = ctr_description_dot, |
| 61 | .class_id = OSMO_STATS_CLASS_SUBSCRIBER, |
| 62 | }; |
| 63 | |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 64 | enum test_items { |
| 65 | TEST_A_ITEM, |
| 66 | TEST_B_ITEM, |
| 67 | }; |
| 68 | |
| 69 | static const struct osmo_stat_item_desc item_description[] = { |
| 70 | [TEST_A_ITEM] = { "item.a", "The A value", "ma", 4, -1 }, |
| 71 | [TEST_B_ITEM] = { "item.b", "The B value", "kb", 7, -1 }, |
| 72 | }; |
| 73 | |
| 74 | static const struct osmo_stat_item_group_desc statg_desc = { |
| 75 | .group_name_prefix = "test.one", |
| 76 | .group_description = "Test number 1", |
| 77 | .num_items = ARRAY_SIZE(item_description), |
| 78 | .item_desc = item_description, |
| 79 | .class_id = OSMO_STATS_CLASS_PEER, |
| 80 | }; |
| 81 | |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 82 | static void stat_test(void) |
| 83 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 84 | struct osmo_stat_item_group *statg = |
| 85 | osmo_stat_item_group_alloc(NULL, &statg_desc, 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 86 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 87 | struct osmo_stat_item_group *sgrp2; |
| 88 | const struct osmo_stat_item *sitem1, *sitem2; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 89 | int32_t value; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 90 | int i; |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 91 | int64_t sum1; |
| 92 | int64_t sum2; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 93 | |
| 94 | OSMO_ASSERT(statg != NULL); |
| 95 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 96 | sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 97 | OSMO_ASSERT(sgrp2 == statg); |
| 98 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 99 | sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 1); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 100 | OSMO_ASSERT(sgrp2 == NULL); |
| 101 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 102 | sgrp2 = osmo_stat_item_get_group_by_name_idx("test.two", 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 103 | OSMO_ASSERT(sgrp2 == NULL); |
| 104 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 105 | sitem1 = osmo_stat_item_get_by_name(statg, "item.c"); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 106 | OSMO_ASSERT(sitem1 == NULL); |
| 107 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 108 | sitem1 = osmo_stat_item_get_by_name(statg, "item.a"); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 109 | OSMO_ASSERT(sitem1 != NULL); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 110 | OSMO_ASSERT(sitem1 == osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 111 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 112 | sitem2 = osmo_stat_item_get_by_name(statg, "item.b"); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 113 | OSMO_ASSERT(sitem2 != NULL); |
| 114 | OSMO_ASSERT(sitem2 != sitem1); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 115 | OSMO_ASSERT(sitem2 == osmo_stat_item_group_get_item(statg, TEST_B_ITEM)); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 116 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 117 | /* No value set yet, expecting default value from osmo_stat_item_desc definition above. */ |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 118 | value = osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 119 | OSMO_ASSERT(value == -1); |
| 120 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 121 | /* No value set yet, expecting new value in all fields */ |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 122 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 1); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 123 | sum1 = 1; |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 124 | value = osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 125 | OSMO_ASSERT(value == 1); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 126 | OSMO_ASSERT(sitem1->value.n == 1); |
| 127 | OSMO_ASSERT(sitem1->value.min == 1); |
| 128 | OSMO_ASSERT(sitem1->value.last == 1); |
| 129 | OSMO_ASSERT(sitem1->value.max == 1); |
| 130 | OSMO_ASSERT(sitem1->value.sum == 1); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 131 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 132 | sum2 = 0; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 133 | for (i = 2; i <= 32; i++) { |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 134 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), i); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 135 | sum1 += i; |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 136 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_B_ITEM), 1000 + i); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 137 | sum2 += 1000 + i; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 138 | } |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 139 | OSMO_ASSERT(sitem1->value.n == 32); |
| 140 | OSMO_ASSERT(sitem1->value.min == 1); |
| 141 | OSMO_ASSERT(sitem1->value.last == 32); |
| 142 | OSMO_ASSERT(sitem1->value.max == 32); |
| 143 | OSMO_ASSERT(sitem1->value.sum == sum1); |
| 144 | |
| 145 | OSMO_ASSERT(sitem2->value.n == 31); |
| 146 | OSMO_ASSERT(sitem2->value.min == 1002); |
| 147 | OSMO_ASSERT(sitem2->value.last == 1032); |
| 148 | OSMO_ASSERT(sitem2->value.max == 1032); |
| 149 | OSMO_ASSERT(sitem2->value.sum == sum2); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 150 | |
Alexander Couzens | cc72cc4 | 2019-04-27 23:19:55 +0200 | [diff] [blame] | 151 | /* check if dec & inc is working */ |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 152 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 42); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 153 | sum1 += 42; |
| 154 | OSMO_ASSERT(sitem1->value.n == 33); |
| 155 | OSMO_ASSERT(sitem1->value.min == 1); |
| 156 | OSMO_ASSERT(sitem1->value.last == 42); |
| 157 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42); |
| 158 | OSMO_ASSERT(sitem1->value.max == 42); |
| 159 | OSMO_ASSERT(sitem1->value.sum == sum1); |
Alexander Couzens | cc72cc4 | 2019-04-27 23:19:55 +0200 | [diff] [blame] | 160 | |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 161 | osmo_stat_item_dec(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 21); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 162 | sum1 += 42 - 21; |
| 163 | OSMO_ASSERT(sitem1->value.n == 34); |
| 164 | OSMO_ASSERT(sitem1->value.min == 1); |
| 165 | OSMO_ASSERT(sitem1->value.last == 21); |
| 166 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 21); |
| 167 | OSMO_ASSERT(sitem1->value.max == 42); |
| 168 | OSMO_ASSERT(sitem1->value.sum == sum1); |
Alexander Couzens | cc72cc4 | 2019-04-27 23:19:55 +0200 | [diff] [blame] | 169 | |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 170 | osmo_stat_item_inc(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 21); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 171 | sum1 += 42; |
| 172 | OSMO_ASSERT(sitem1->value.n == 35); |
| 173 | OSMO_ASSERT(sitem1->value.min == 1); |
| 174 | OSMO_ASSERT(sitem1->value.last == 42); |
| 175 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42); |
| 176 | OSMO_ASSERT(sitem1->value.max == 42); |
| 177 | OSMO_ASSERT(sitem1->value.sum == sum1); |
Alexander Couzens | cc72cc4 | 2019-04-27 23:19:55 +0200 | [diff] [blame] | 178 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 179 | /* Test item flush, reporting period elapsing */ |
| 180 | osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
| 181 | OSMO_ASSERT(sitem1->value.n == 0); |
| 182 | OSMO_ASSERT(sitem1->value.min == 42); |
| 183 | OSMO_ASSERT(sitem1->value.last == 42); |
| 184 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42); |
| 185 | OSMO_ASSERT(sitem1->value.max == 42); |
| 186 | OSMO_ASSERT(sitem1->value.sum == 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 187 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 188 | /* Still see the previous reporting period in reported.* */ |
| 189 | OSMO_ASSERT(sitem1->reported.n == 35); |
| 190 | OSMO_ASSERT(sitem1->reported.min == 1); |
| 191 | OSMO_ASSERT(sitem1->reported.last == 42); |
| 192 | OSMO_ASSERT(sitem1->reported.max == 42); |
| 193 | OSMO_ASSERT(sitem1->reported.sum == sum1); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 194 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 195 | /* After a flush, the first item replaces the last, min and max */ |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 196 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 97); |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 197 | OSMO_ASSERT(sitem1->value.n == 1); |
| 198 | OSMO_ASSERT(sitem1->value.min == 97); |
| 199 | OSMO_ASSERT(sitem1->value.last == 97); |
| 200 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97); |
| 201 | OSMO_ASSERT(sitem1->value.max == 97); |
| 202 | OSMO_ASSERT(sitem1->value.sum == 97); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 203 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 204 | /* ...and still see the previous reporting period in reported.* */ |
| 205 | OSMO_ASSERT(sitem1->reported.n == 35); |
| 206 | OSMO_ASSERT(sitem1->reported.min == 1); |
| 207 | OSMO_ASSERT(sitem1->reported.last == 42); |
| 208 | OSMO_ASSERT(sitem1->reported.max == 42); |
| 209 | OSMO_ASSERT(sitem1->reported.sum == sum1); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 210 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 211 | /* If an entire reporting period elapses without a new value, the last seen value remains. */ |
| 212 | osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
| 213 | osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
| 214 | OSMO_ASSERT(sitem1->value.n == 0); |
| 215 | OSMO_ASSERT(sitem1->value.min == 97); |
| 216 | OSMO_ASSERT(sitem1->value.last == 97); |
| 217 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97); |
| 218 | OSMO_ASSERT(sitem1->value.max == 97); |
| 219 | OSMO_ASSERT(sitem1->value.sum == 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 220 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 221 | /* now the previous reporting period got turned around */ |
| 222 | OSMO_ASSERT(sitem1->reported.n == 0); |
| 223 | OSMO_ASSERT(sitem1->reported.min == 97); |
| 224 | OSMO_ASSERT(sitem1->reported.last == 97); |
| 225 | OSMO_ASSERT(sitem1->reported.max == 97); |
| 226 | OSMO_ASSERT(sitem1->reported.sum == 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 227 | |
Neels Hofmeyr | e90c717 | 2021-09-14 14:37:38 +0200 | [diff] [blame] | 228 | /* Another empty reporting period, everything remained the same. */ |
| 229 | osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
| 230 | OSMO_ASSERT(sitem1->value.n == 0); |
| 231 | OSMO_ASSERT(sitem1->value.min == 97); |
| 232 | OSMO_ASSERT(sitem1->value.last == 97); |
| 233 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97); |
| 234 | OSMO_ASSERT(sitem1->value.max == 97); |
| 235 | OSMO_ASSERT(sitem1->value.sum == 0); |
| 236 | OSMO_ASSERT(sitem1->reported.n == 0); |
| 237 | OSMO_ASSERT(sitem1->reported.min == 97); |
| 238 | OSMO_ASSERT(sitem1->reported.last == 97); |
| 239 | OSMO_ASSERT(sitem1->reported.max == 97); |
| 240 | OSMO_ASSERT(sitem1->reported.sum == 0); |
| 241 | |
| 242 | /* Test Reset, place back to default value. The previously reported value remains the same. */ |
| 243 | osmo_stat_item_reset(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); |
| 244 | OSMO_ASSERT(sitem1->value.n == 0); |
| 245 | OSMO_ASSERT(sitem1->value.min == -1); |
| 246 | OSMO_ASSERT(sitem1->value.last == -1); |
| 247 | OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == -1); |
| 248 | OSMO_ASSERT(sitem1->value.max == -1); |
| 249 | OSMO_ASSERT(sitem1->value.sum == 0); |
| 250 | OSMO_ASSERT(sitem1->reported.n == 0); |
| 251 | OSMO_ASSERT(sitem1->reported.min == 97); |
| 252 | OSMO_ASSERT(sitem1->reported.last == 97); |
| 253 | OSMO_ASSERT(sitem1->reported.max == 97); |
| 254 | OSMO_ASSERT(sitem1->reported.sum == 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 255 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 256 | osmo_stat_item_group_free(statg); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 257 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 258 | sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 259 | OSMO_ASSERT(sgrp2 == NULL); |
| 260 | } |
| 261 | |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 262 | /*** stats reporter tests ***/ |
| 263 | |
| 264 | /* define a special stats reporter for testing */ |
| 265 | |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 266 | static int sent_counter_vals; |
| 267 | static int sent_stat_item_vals; |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 268 | |
| 269 | enum { |
| 270 | OSMO_STATS_REPORTER_TEST = OSMO_STATS_REPORTER_LOG + 1, |
| 271 | }; |
| 272 | |
| 273 | static int stats_reporter_test_send_counter(struct osmo_stats_reporter *srep, |
| 274 | const struct rate_ctr_group *ctrg, |
| 275 | const struct rate_ctr_desc *desc, |
| 276 | int64_t value, int64_t delta) |
| 277 | { |
| 278 | const char *group_name = ctrg ? ctrg->desc->group_name_prefix : ""; |
| 279 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 280 | fprintf(stderr, " %s: counter p=%s g=%s i=%u n=%s v=%lld d=%lld\n", |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 281 | srep->name, |
| 282 | srep->name_prefix ? srep->name_prefix : "", |
| 283 | group_name, ctrg ? ctrg->idx : 0, |
| 284 | desc->name, (long long)value, (long long)delta); |
| 285 | |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 286 | sent_counter_vals++; |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int stats_reporter_test_send_item(struct osmo_stats_reporter *srep, |
| 291 | const struct osmo_stat_item_group *statg, |
Neels Hofmeyr | b41b48e | 2017-01-13 00:11:34 +0100 | [diff] [blame] | 292 | const struct osmo_stat_item_desc *desc, int64_t value) |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 293 | { |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 294 | fprintf(stderr, " %s: item p=%s g=%s i=%u n=%s v=%"PRId64" u=%s\n", |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 295 | srep->name, |
| 296 | srep->name_prefix ? srep->name_prefix : "", |
| 297 | statg->desc->group_name_prefix, statg->idx, |
| 298 | desc->name, value, desc->unit ? desc->unit : ""); |
| 299 | |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 300 | sent_stat_item_vals++; |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int stats_reporter_test_open(struct osmo_stats_reporter *srep) |
| 305 | { |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 306 | fprintf(stderr, " %s: open\n", srep->name); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int stats_reporter_test_close(struct osmo_stats_reporter *srep) |
| 311 | { |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 312 | fprintf(stderr, " %s: close\n", srep->name); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static struct osmo_stats_reporter *stats_reporter_create_test(const char *name) |
| 317 | { |
| 318 | struct osmo_stats_reporter *srep; |
| 319 | srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_TEST, name); |
| 320 | |
| 321 | srep->have_net_config = 0; |
| 322 | |
| 323 | srep->open = stats_reporter_test_open; |
| 324 | srep->close = stats_reporter_test_close; |
| 325 | srep->send_counter = stats_reporter_test_send_counter; |
| 326 | srep->send_item = stats_reporter_test_send_item; |
| 327 | |
| 328 | return srep; |
| 329 | } |
| 330 | |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 331 | static void _do_report(int expect_counter_vals, int expect_stat_item_vals, int line) |
| 332 | { |
| 333 | sent_counter_vals = 0; |
| 334 | sent_stat_item_vals = 0; |
| 335 | osmo_stats_report(); |
| 336 | fprintf(stderr, "reported: %d counter vals, %d stat item vals\n", sent_counter_vals, sent_stat_item_vals); |
| 337 | OSMO_ASSERT(sent_counter_vals == expect_counter_vals); |
| 338 | OSMO_ASSERT(sent_stat_item_vals == expect_stat_item_vals); |
| 339 | } |
| 340 | |
| 341 | #define do_report(A, B) _do_report(A, B, __LINE__) |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 342 | |
Harald Welte | e61d459 | 2022-11-03 11:05:58 +0100 | [diff] [blame] | 343 | static void test_reporting(void) |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 344 | { |
| 345 | struct osmo_stats_reporter *srep1, *srep2, *srep; |
| 346 | struct osmo_stat_item_group *statg1, *statg2; |
Max | 3ef14a2 | 2017-12-15 20:19:10 +0100 | [diff] [blame] | 347 | struct rate_ctr_group *ctrg1, *ctrg2, *ctrg3, *ctrg_dup; |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 348 | void *stats_ctx = talloc_named_const(NULL, 1, "stats test context"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 349 | |
| 350 | int rc; |
| 351 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 352 | fprintf(stderr, "Start test: %s\n", __func__); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 353 | |
| 354 | /* Allocate counters and items */ |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 355 | statg1 = osmo_stat_item_group_alloc(stats_ctx, &statg_desc, 1); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 356 | OSMO_ASSERT(statg1 != NULL); |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 357 | statg2 = osmo_stat_item_group_alloc(stats_ctx, &statg_desc, 2); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 358 | OSMO_ASSERT(statg2 != NULL); |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 359 | ctrg1 = rate_ctr_group_alloc(stats_ctx, &ctrg_desc, 1); |
Neels Hofmeyr | 554f7b8 | 2017-12-20 01:14:31 +0100 | [diff] [blame] | 360 | OSMO_ASSERT(ctrg1 && ctrg1->idx == 1); |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 361 | ctrg2 = rate_ctr_group_alloc(stats_ctx, &ctrg_desc, 2); |
Neels Hofmeyr | 554f7b8 | 2017-12-20 01:14:31 +0100 | [diff] [blame] | 362 | OSMO_ASSERT(ctrg2 && ctrg2->idx == 2); |
Max | 3ef14a2 | 2017-12-15 20:19:10 +0100 | [diff] [blame] | 363 | |
| 364 | ctrg_dup = rate_ctr_group_alloc(stats_ctx, &ctrg_desc, 2); |
Neels Hofmeyr | 554f7b8 | 2017-12-20 01:14:31 +0100 | [diff] [blame] | 365 | OSMO_ASSERT(ctrg_dup && ctrg_dup->idx == 3); |
| 366 | rate_ctr_group_free(ctrg_dup); |
Max | 3ef14a2 | 2017-12-15 20:19:10 +0100 | [diff] [blame] | 367 | |
Harald Welte | 04c8812 | 2017-10-03 18:34:48 +0800 | [diff] [blame] | 368 | ctrg3 = rate_ctr_group_alloc(stats_ctx, &ctrg_desc_dot, 3); |
Neels Hofmeyr | 554f7b8 | 2017-12-20 01:14:31 +0100 | [diff] [blame] | 369 | OSMO_ASSERT(ctrg3 && ctrg3->idx == 3); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 370 | |
| 371 | srep1 = stats_reporter_create_test("test1"); |
| 372 | OSMO_ASSERT(srep1 != NULL); |
| 373 | |
| 374 | srep2 = stats_reporter_create_test("test2"); |
| 375 | OSMO_ASSERT(srep2 != NULL); |
| 376 | |
| 377 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_TEST, "test1"); |
| 378 | OSMO_ASSERT(srep == srep1); |
| 379 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_TEST, "test2"); |
| 380 | OSMO_ASSERT(srep == srep2); |
| 381 | |
| 382 | rc = osmo_stats_reporter_enable(srep1); |
| 383 | OSMO_ASSERT(rc >= 0); |
| 384 | OSMO_ASSERT(srep1->force_single_flush); |
| 385 | rc = osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_SUBSCRIBER); |
| 386 | OSMO_ASSERT(rc >= 0); |
| 387 | |
| 388 | rc = osmo_stats_reporter_enable(srep2); |
| 389 | OSMO_ASSERT(rc >= 0); |
| 390 | OSMO_ASSERT(srep2->force_single_flush); |
| 391 | rc = osmo_stats_reporter_set_max_class(srep2, OSMO_STATS_CLASS_SUBSCRIBER); |
| 392 | OSMO_ASSERT(rc >= 0); |
| 393 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 394 | fprintf(stderr, "report (initial):\n"); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 395 | do_report(12, 8); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 396 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 397 | fprintf(stderr, "report (srep1 global):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 398 | /* force single flush */ |
| 399 | osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_GLOBAL); |
| 400 | srep1->force_single_flush = 1; |
| 401 | srep2->force_single_flush = 1; |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 402 | do_report(6, 4); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 403 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 404 | fprintf(stderr, "report (srep1 peer):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 405 | /* force single flush */ |
| 406 | osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_PEER); |
| 407 | srep1->force_single_flush = 1; |
| 408 | srep2->force_single_flush = 1; |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 409 | do_report(6, 8); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 410 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 411 | fprintf(stderr, "report (srep1 subscriber):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 412 | /* force single flush */ |
| 413 | osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_SUBSCRIBER); |
| 414 | srep1->force_single_flush = 1; |
| 415 | srep2->force_single_flush = 1; |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 416 | do_report(12, 8); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 417 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 418 | fprintf(stderr, "report (srep2 disabled):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 419 | /* force single flush */ |
| 420 | srep1->force_single_flush = 1; |
| 421 | srep2->force_single_flush = 1; |
| 422 | rc = osmo_stats_reporter_disable(srep2); |
| 423 | OSMO_ASSERT(rc >= 0); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 424 | do_report(6, 4); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 425 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 426 | fprintf(stderr, "report (srep2 enabled, no flush forced):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 427 | rc = osmo_stats_reporter_enable(srep2); |
| 428 | OSMO_ASSERT(rc >= 0); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 429 | do_report(6, 4); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 430 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 431 | fprintf(stderr, "report (should be empty):\n"); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 432 | do_report(0, 0); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 433 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 434 | fprintf(stderr, "report (group 1, counter 1 update):\n"); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 435 | rate_ctr_inc(rate_ctr_group_get_ctr(ctrg1, TEST_A_CTR)); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 436 | do_report(2, 0); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 437 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 438 | fprintf(stderr, "report (group 1, item 1 update):\n"); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 439 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 440 | do_report(0, 2); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 441 | |
Neels Hofmeyr | 6a59407 | 2021-09-14 21:49:00 +0200 | [diff] [blame] | 442 | fprintf(stderr, "report (group 1, item 1 update twice, with same value):\n"); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 443 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10); |
| 444 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10); |
Neels Hofmeyr | 6a59407 | 2021-09-14 21:49:00 +0200 | [diff] [blame] | 445 | do_report(0, 0); |
Daniel Willmann | 2aa527b | 2021-03-01 21:53:46 +0100 | [diff] [blame] | 446 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 447 | fprintf(stderr, "report (group 1, item 1 update twice, check max):\n"); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 448 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 20); |
| 449 | osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 450 | do_report(0, 2); |
Daniel Willmann | 2aa527b | 2021-03-01 21:53:46 +0100 | [diff] [blame] | 451 | |
Oliver Smith | a79a549 | 2021-08-19 10:07:44 +0200 | [diff] [blame] | 452 | fprintf(stderr, "report (group 1, item 1 no update, send last item (!= last max), OS#5215):\n"); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 453 | do_report(0, 2); |
Oliver Smith | a79a549 | 2021-08-19 10:07:44 +0200 | [diff] [blame] | 454 | |
| 455 | fprintf(stderr, "report (group 1, item 1 no update, nothing to send):\n"); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 456 | do_report(0, 0); |
Oliver Smith | a79a549 | 2021-08-19 10:07:44 +0200 | [diff] [blame] | 457 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 458 | fprintf(stderr, "report (remove statg1, ctrg1):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 459 | /* force single flush */ |
| 460 | srep1->force_single_flush = 1; |
| 461 | srep2->force_single_flush = 1; |
| 462 | osmo_stat_item_group_free(statg1); |
| 463 | rate_ctr_group_free(ctrg1); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 464 | do_report(8, 4); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 465 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 466 | fprintf(stderr, "report (remove srep1):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 467 | /* force single flush */ |
| 468 | srep1->force_single_flush = 1; |
| 469 | srep2->force_single_flush = 1; |
| 470 | osmo_stats_reporter_free(srep1); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 471 | do_report(4, 2); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 472 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 473 | fprintf(stderr, "report (remove statg2):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 474 | /* force single flush */ |
| 475 | srep2->force_single_flush = 1; |
| 476 | osmo_stat_item_group_free(statg2); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 477 | do_report(4, 0); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 478 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 479 | fprintf(stderr, "report (remove srep2):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 480 | /* force single flush */ |
| 481 | srep2->force_single_flush = 1; |
| 482 | osmo_stats_reporter_free(srep2); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 483 | do_report(0, 0); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 484 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 485 | fprintf(stderr, "report (remove ctrg2, should be empty):\n"); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 486 | rate_ctr_group_free(ctrg2); |
Neels Hofmeyr | 599601e | 2021-09-14 17:41:25 +0200 | [diff] [blame] | 487 | do_report(0, 0); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 488 | |
Harald Welte | 04c8812 | 2017-10-03 18:34:48 +0800 | [diff] [blame] | 489 | rate_ctr_group_free(ctrg3); |
| 490 | |
Jacob Erlbeck | f13de86 | 2015-11-10 11:36:58 +0100 | [diff] [blame] | 491 | /* Leak check */ |
| 492 | OSMO_ASSERT(talloc_total_blocks(stats_ctx) == 1); |
| 493 | talloc_free(stats_ctx); |
| 494 | |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 495 | fprintf(stderr, "End test: %s\n", __func__); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 498 | int main(int argc, char **argv) |
| 499 | { |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 500 | void *ctx = talloc_named_const(NULL, 0, "main"); |
| 501 | osmo_init_logging2(ctx, NULL); |
| 502 | |
| 503 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
| 504 | log_set_print_level(osmo_stderr_target, 1); |
| 505 | log_set_print_category(osmo_stderr_target, 1); |
| 506 | log_set_print_category_hex(osmo_stderr_target, 0); |
| 507 | log_set_use_color(osmo_stderr_target, 0); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 508 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 509 | osmo_stat_item_init(NULL); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 510 | |
| 511 | stat_test(); |
Jacob Erlbeck | 46b703d | 2015-11-09 17:25:27 +0100 | [diff] [blame] | 512 | test_reporting(); |
Oliver Smith | d89d35e | 2021-03-17 15:29:55 +0100 | [diff] [blame] | 513 | talloc_free(ctx); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 514 | return 0; |
| 515 | } |