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