aboutsummaryrefslogtreecommitdiffstats
path: root/tests/stats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stats')
-rw-r--r--tests/stats/stats_test.c418
-rw-r--r--tests/stats/stats_test.err163
-rw-r--r--tests/stats/stats_test.ok132
-rw-r--r--tests/stats/stats_vty_test.c88
-rw-r--r--tests/stats/stats_vty_test.vty217
5 files changed, 683 insertions, 335 deletions
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index 71f710a9..eda4129b 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -1,6 +1,6 @@
/* tests for statistics */
/*
- * (C) 2015 sysmocom - s.m.f.c. GmbH
+ * (C) 2015 sysmocom - s.f.m.c. GmbH
*
* All Rights Reserved
*
@@ -16,18 +16,17 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
+#include <osmocom/core/application.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/stats.h>
+#include <stat_item_internal.h>
+
#include <stdio.h>
#include <inttypes.h>
@@ -87,11 +86,10 @@ static void stat_test(void)
struct osmo_stat_item_group *sgrp2;
const struct osmo_stat_item *sitem1, *sitem2;
- int rc;
int32_t value;
- int32_t rd_a = 0;
- int32_t rd_b = 0;
int i;
+ int64_t sum1;
+ int64_t sum2;
OSMO_ASSERT(statg != NULL);
@@ -109,144 +107,151 @@ static void stat_test(void)
sitem1 = osmo_stat_item_get_by_name(statg, "item.a");
OSMO_ASSERT(sitem1 != NULL);
- OSMO_ASSERT(sitem1 == statg->items[TEST_A_ITEM]);
+ OSMO_ASSERT(sitem1 == osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
sitem2 = osmo_stat_item_get_by_name(statg, "item.b");
OSMO_ASSERT(sitem2 != NULL);
OSMO_ASSERT(sitem2 != sitem1);
- OSMO_ASSERT(sitem2 == statg->items[TEST_B_ITEM]);
+ OSMO_ASSERT(sitem2 == osmo_stat_item_group_get_item(statg, TEST_B_ITEM));
- value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]);
+ /* No value set yet, expecting default value from osmo_stat_item_desc definition above. */
+ value = osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
OSMO_ASSERT(value == -1);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 0);
-
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 1);
-
- value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]);
- OSMO_ASSERT(value == 1);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
+ /* No value set yet, expecting new value in all fields */
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 1);
+ sum1 = 1;
+ value = osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
OSMO_ASSERT(value == 1);
+ OSMO_ASSERT(sitem1->value.n == 1);
+ OSMO_ASSERT(sitem1->value.min == 1);
+ OSMO_ASSERT(sitem1->value.last == 1);
+ OSMO_ASSERT(sitem1->value.max == 1);
+ OSMO_ASSERT(sitem1->value.sum == 1);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 0);
-
+ sum2 = 0;
for (i = 2; i <= 32; i++) {
- osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == i);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 1000 + i);
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), i);
+ sum1 += i;
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_B_ITEM), 1000 + i);
+ sum2 += 1000 + i;
}
+ OSMO_ASSERT(sitem1->value.n == 32);
+ OSMO_ASSERT(sitem1->value.min == 1);
+ OSMO_ASSERT(sitem1->value.last == 32);
+ OSMO_ASSERT(sitem1->value.max == 32);
+ OSMO_ASSERT(sitem1->value.sum == sum1);
+
+ OSMO_ASSERT(sitem2->value.n == 31);
+ OSMO_ASSERT(sitem2->value.min == 1002);
+ OSMO_ASSERT(sitem2->value.last == 1032);
+ OSMO_ASSERT(sitem2->value.max == 1032);
+ OSMO_ASSERT(sitem2->value.sum == sum2);
/* check if dec & inc is working */
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 42);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 42);
-
- osmo_stat_item_dec(statg->items[TEST_A_ITEM], 21);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 21);
-
- osmo_stat_item_inc(statg->items[TEST_A_ITEM], 21);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 42);
-
- /* Keep 2 in FIFO */
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 33);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33);
-
- for (i = 34; i <= 64; i++) {
- osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == i-1);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 1000 + i-1);
- }
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 64);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 1000 + 64);
-
- /* Overrun FIFOs */
- for (i = 65; i <= 96; i++) {
- osmo_stat_item_set(statg->items[TEST_A_ITEM], i);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
- }
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 93);
-
- for (i = 94; i <= 96; i++) {
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == i);
- }
-
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 1000 + 90);
-
- for (i = 91; i <= 96; i++) {
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 1000 + i);
- }
-
- /* Test Discard (single item) */
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 97);
- rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
- OSMO_ASSERT(rc > 0);
-
- rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
- OSMO_ASSERT(rc == 0);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 0);
-
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 98);
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc > 0);
- OSMO_ASSERT(value == 98);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 0);
-
- /* Test Discard (all items) */
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 99);
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 100);
- osmo_stat_item_set(statg->items[TEST_A_ITEM], 101);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 99);
- osmo_stat_item_set(statg->items[TEST_B_ITEM], 100);
-
- rc = osmo_stat_item_discard_all(&rd_a);
- rc = osmo_stat_item_discard_all(&rd_b);
-
- rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 0);
- rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 0);
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 42);
+ sum1 += 42;
+ OSMO_ASSERT(sitem1->value.n == 33);
+ OSMO_ASSERT(sitem1->value.min == 1);
+ OSMO_ASSERT(sitem1->value.last == 42);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42);
+ OSMO_ASSERT(sitem1->value.max == 42);
+ OSMO_ASSERT(sitem1->value.sum == sum1);
+
+ osmo_stat_item_dec(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 21);
+ sum1 += 42 - 21;
+ OSMO_ASSERT(sitem1->value.n == 34);
+ OSMO_ASSERT(sitem1->value.min == 1);
+ OSMO_ASSERT(sitem1->value.last == 21);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 21);
+ OSMO_ASSERT(sitem1->value.max == 42);
+ OSMO_ASSERT(sitem1->value.sum == sum1);
+
+ osmo_stat_item_inc(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 21);
+ sum1 += 42;
+ OSMO_ASSERT(sitem1->value.n == 35);
+ OSMO_ASSERT(sitem1->value.min == 1);
+ OSMO_ASSERT(sitem1->value.last == 42);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42);
+ OSMO_ASSERT(sitem1->value.max == 42);
+ OSMO_ASSERT(sitem1->value.sum == sum1);
+
+ /* Test item flush, reporting period elapsing */
+ osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
+ OSMO_ASSERT(sitem1->value.n == 0);
+ OSMO_ASSERT(sitem1->value.min == 42);
+ OSMO_ASSERT(sitem1->value.last == 42);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 42);
+ OSMO_ASSERT(sitem1->value.max == 42);
+ OSMO_ASSERT(sitem1->value.sum == 0);
+
+ /* Still see the previous reporting period in reported.* */
+ OSMO_ASSERT(sitem1->reported.n == 35);
+ OSMO_ASSERT(sitem1->reported.min == 1);
+ OSMO_ASSERT(sitem1->reported.last == 42);
+ OSMO_ASSERT(sitem1->reported.max == 42);
+ OSMO_ASSERT(sitem1->reported.sum == sum1);
+
+ /* After a flush, the first item replaces the last, min and max */
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg, TEST_A_ITEM), 97);
+ OSMO_ASSERT(sitem1->value.n == 1);
+ OSMO_ASSERT(sitem1->value.min == 97);
+ OSMO_ASSERT(sitem1->value.last == 97);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97);
+ OSMO_ASSERT(sitem1->value.max == 97);
+ OSMO_ASSERT(sitem1->value.sum == 97);
+
+ /* ...and still see the previous reporting period in reported.* */
+ OSMO_ASSERT(sitem1->reported.n == 35);
+ OSMO_ASSERT(sitem1->reported.min == 1);
+ OSMO_ASSERT(sitem1->reported.last == 42);
+ OSMO_ASSERT(sitem1->reported.max == 42);
+ OSMO_ASSERT(sitem1->reported.sum == sum1);
+
+ /* If an entire reporting period elapses without a new value, the last seen value remains. */
+ osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
+ osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
+ OSMO_ASSERT(sitem1->value.n == 0);
+ OSMO_ASSERT(sitem1->value.min == 97);
+ OSMO_ASSERT(sitem1->value.last == 97);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97);
+ OSMO_ASSERT(sitem1->value.max == 97);
+ OSMO_ASSERT(sitem1->value.sum == 0);
+
+ /* now the previous reporting period got turned around */
+ OSMO_ASSERT(sitem1->reported.n == 0);
+ OSMO_ASSERT(sitem1->reported.min == 97);
+ OSMO_ASSERT(sitem1->reported.last == 97);
+ OSMO_ASSERT(sitem1->reported.max == 97);
+ OSMO_ASSERT(sitem1->reported.sum == 0);
+
+ /* Another empty reporting period, everything remained the same. */
+ osmo_stat_item_flush(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
+ OSMO_ASSERT(sitem1->value.n == 0);
+ OSMO_ASSERT(sitem1->value.min == 97);
+ OSMO_ASSERT(sitem1->value.last == 97);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == 97);
+ OSMO_ASSERT(sitem1->value.max == 97);
+ OSMO_ASSERT(sitem1->value.sum == 0);
+ OSMO_ASSERT(sitem1->reported.n == 0);
+ OSMO_ASSERT(sitem1->reported.min == 97);
+ OSMO_ASSERT(sitem1->reported.last == 97);
+ OSMO_ASSERT(sitem1->reported.max == 97);
+ OSMO_ASSERT(sitem1->reported.sum == 0);
+
+ /* Test Reset, place back to default value. The previously reported value remains the same. */
+ osmo_stat_item_reset(osmo_stat_item_group_get_item(statg, TEST_A_ITEM));
+ OSMO_ASSERT(sitem1->value.n == 0);
+ OSMO_ASSERT(sitem1->value.min == -1);
+ OSMO_ASSERT(sitem1->value.last == -1);
+ OSMO_ASSERT(osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)) == -1);
+ OSMO_ASSERT(sitem1->value.max == -1);
+ OSMO_ASSERT(sitem1->value.sum == 0);
+ OSMO_ASSERT(sitem1->reported.n == 0);
+ OSMO_ASSERT(sitem1->reported.min == 97);
+ OSMO_ASSERT(sitem1->reported.last == 97);
+ OSMO_ASSERT(sitem1->reported.max == 97);
+ OSMO_ASSERT(sitem1->reported.sum == 0);
osmo_stat_item_group_free(statg);
@@ -258,7 +263,8 @@ static void stat_test(void)
/* define a special stats reporter for testing */
-static int send_count;
+static int sent_counter_vals;
+static int sent_stat_item_vals;
enum {
OSMO_STATS_REPORTER_TEST = OSMO_STATS_REPORTER_LOG + 1,
@@ -271,13 +277,13 @@ static int stats_reporter_test_send_counter(struct osmo_stats_reporter *srep,
{
const char *group_name = ctrg ? ctrg->desc->group_name_prefix : "";
- printf(" %s: counter p=%s g=%s i=%u n=%s v=%lld d=%lld\n",
+ fprintf(stderr, " %s: counter p=%s g=%s i=%u n=%s v=%lld d=%lld\n",
srep->name,
srep->name_prefix ? srep->name_prefix : "",
group_name, ctrg ? ctrg->idx : 0,
desc->name, (long long)value, (long long)delta);
- send_count += 1;
+ sent_counter_vals++;
return 0;
}
@@ -285,25 +291,25 @@ static int stats_reporter_test_send_item(struct osmo_stats_reporter *srep,
const struct osmo_stat_item_group *statg,
const struct osmo_stat_item_desc *desc, int64_t value)
{
- printf(" %s: item p=%s g=%s i=%u n=%s v=%"PRId64" u=%s\n",
+ fprintf(stderr, " %s: item p=%s g=%s i=%u n=%s v=%"PRId64" u=%s\n",
srep->name,
srep->name_prefix ? srep->name_prefix : "",
statg->desc->group_name_prefix, statg->idx,
desc->name, value, desc->unit ? desc->unit : "");
- send_count += 1;
+ sent_stat_item_vals++;
return 0;
}
static int stats_reporter_test_open(struct osmo_stats_reporter *srep)
{
- printf(" %s: open\n", srep->name);
+ fprintf(stderr, " %s: open\n", srep->name);
return 0;
}
static int stats_reporter_test_close(struct osmo_stats_reporter *srep)
{
- printf(" %s: close\n", srep->name);
+ fprintf(stderr, " %s: close\n", srep->name);
return 0;
}
@@ -322,8 +328,19 @@ static struct osmo_stats_reporter *stats_reporter_create_test(const char *name)
return srep;
}
+static void _do_report(int expect_counter_vals, int expect_stat_item_vals, int line)
+{
+ sent_counter_vals = 0;
+ sent_stat_item_vals = 0;
+ osmo_stats_report();
+ fprintf(stderr, "reported: %d counter vals, %d stat item vals\n", sent_counter_vals, sent_stat_item_vals);
+ OSMO_ASSERT(sent_counter_vals == expect_counter_vals);
+ OSMO_ASSERT(sent_stat_item_vals == expect_stat_item_vals);
+}
+
+#define do_report(A, B) _do_report(A, B, __LINE__)
-static void test_reporting()
+static void test_reporting(void)
{
struct osmo_stats_reporter *srep1, *srep2, *srep;
struct osmo_stat_item_group *statg1, *statg2;
@@ -332,7 +349,7 @@ static void test_reporting()
int rc;
- printf("Start test: %s\n", __func__);
+ fprintf(stderr, "Start test: %s\n", __func__);
/* Allocate counters and items */
statg1 = osmo_stat_item_group_alloc(stats_ctx, &statg_desc, 1);
@@ -374,112 +391,100 @@ static void test_reporting()
rc = osmo_stats_reporter_set_max_class(srep2, OSMO_STATS_CLASS_SUBSCRIBER);
OSMO_ASSERT(rc >= 0);
- printf("report (initial):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 20);
+ fprintf(stderr, "report (initial):\n");
+ do_report(12, 8);
- printf("report (srep1 global):\n");
+ fprintf(stderr, "report (srep1 global):\n");
/* force single flush */
osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_GLOBAL);
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 10);
+ do_report(6, 4);
- printf("report (srep1 peer):\n");
+ fprintf(stderr, "report (srep1 peer):\n");
/* force single flush */
osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_PEER);
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 14);
+ do_report(6, 8);
- printf("report (srep1 subscriber):\n");
+ fprintf(stderr, "report (srep1 subscriber):\n");
/* force single flush */
osmo_stats_reporter_set_max_class(srep1, OSMO_STATS_CLASS_SUBSCRIBER);
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 20);
+ do_report(12, 8);
- printf("report (srep2 disabled):\n");
+ fprintf(stderr, "report (srep2 disabled):\n");
/* force single flush */
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
rc = osmo_stats_reporter_disable(srep2);
OSMO_ASSERT(rc >= 0);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 10);
+ do_report(6, 4);
- printf("report (srep2 enabled, no flush forced):\n");
+ fprintf(stderr, "report (srep2 enabled, no flush forced):\n");
rc = osmo_stats_reporter_enable(srep2);
OSMO_ASSERT(rc >= 0);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 10);
+ do_report(6, 4);
- printf("report (should be empty):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 0);
+ fprintf(stderr, "report (should be empty):\n");
+ do_report(0, 0);
- printf("report (group 1, counter 1 update):\n");
- rate_ctr_inc(&ctrg1->ctr[TEST_A_CTR]);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ fprintf(stderr, "report (group 1, counter 1 update):\n");
+ rate_ctr_inc(rate_ctr_group_get_ctr(ctrg1, TEST_A_CTR));
+ do_report(2, 0);
- printf("report (group 1, item 1 update):\n");
- osmo_stat_item_set(statg1->items[TEST_A_ITEM], 10);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ fprintf(stderr, "report (group 1, item 1 update):\n");
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10);
+ do_report(0, 2);
+
+ fprintf(stderr, "report (group 1, item 1 update twice, with same value):\n");
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10);
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10);
+ do_report(0, 0);
+
+ fprintf(stderr, "report (group 1, item 1 update twice, check max):\n");
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 20);
+ osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10);
+ do_report(0, 2);
+
+ fprintf(stderr, "report (group 1, item 1 no update, send last item (!= last max), OS#5215):\n");
+ do_report(0, 2);
+
+ fprintf(stderr, "report (group 1, item 1 no update, nothing to send):\n");
+ do_report(0, 0);
- printf("report (remove statg1, ctrg1):\n");
+ fprintf(stderr, "report (remove statg1, ctrg1):\n");
/* force single flush */
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
osmo_stat_item_group_free(statg1);
rate_ctr_group_free(ctrg1);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 12);
+ do_report(8, 4);
- printf("report (remove srep1):\n");
+ fprintf(stderr, "report (remove srep1):\n");
/* force single flush */
srep1->force_single_flush = 1;
srep2->force_single_flush = 1;
osmo_stats_reporter_free(srep1);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 6);
+ do_report(4, 2);
- printf("report (remove statg2):\n");
+ fprintf(stderr, "report (remove statg2):\n");
/* force single flush */
srep2->force_single_flush = 1;
osmo_stat_item_group_free(statg2);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 4);
+ do_report(4, 0);
- printf("report (remove srep2):\n");
+ fprintf(stderr, "report (remove srep2):\n");
/* force single flush */
srep2->force_single_flush = 1;
osmo_stats_reporter_free(srep2);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 0);
+ do_report(0, 0);
- printf("report (remove ctrg2, should be empty):\n");
+ fprintf(stderr, "report (remove ctrg2, should be empty):\n");
rate_ctr_group_free(ctrg2);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 0);
+ do_report(0, 0);
rate_ctr_group_free(ctrg3);
@@ -487,17 +492,24 @@ static void test_reporting()
OSMO_ASSERT(talloc_total_blocks(stats_ctx) == 1);
talloc_free(stats_ctx);
- printf("End test: %s\n", __func__);
+ fprintf(stderr, "End test: %s\n", __func__);
}
int main(int argc, char **argv)
{
- static const struct log_info log_info = {};
- log_init(&log_info, NULL);
+ void *ctx = talloc_named_const(NULL, 0, "main");
+ osmo_init_logging2(ctx, NULL);
+
+ log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
+ log_set_print_level(osmo_stderr_target, 1);
+ log_set_print_category(osmo_stderr_target, 1);
+ log_set_print_category_hex(osmo_stderr_target, 0);
+ log_set_use_color(osmo_stderr_target, 0);
osmo_stat_item_init(NULL);
stat_test();
test_reporting();
+ talloc_free(ctx);
return 0;
}
diff --git a/tests/stats/stats_test.err b/tests/stats/stats_test.err
new file mode 100644
index 00000000..4acd35d0
--- /dev/null
+++ b/tests/stats/stats_test.err
@@ -0,0 +1,163 @@
+Start test: test_reporting
+DLGLOBAL ERROR counter group 'ctr-test:one' already exists for index 2, instead using index 3. This is a software bug that needs fixing.
+DLGLOBAL ERROR 'ctr-test.one_dot' is not a valid counter group identifier
+DLGLOBAL NOTICE counter group name mangled: 'ctr-test.one_dot' -> 'ctr-test:one_dot'
+DLGLOBAL NOTICE counter group name mangled: 'ctr.a' -> 'ctr:a'
+DLGLOBAL NOTICE counter group name mangled: 'ctr.b' -> 'ctr:b'
+ test1: open
+ test2: open
+report (initial):
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 12 counter vals, 8 stat item vals
+report (srep1 global):
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 6 counter vals, 4 stat item vals
+report (srep1 peer):
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 6 counter vals, 8 stat item vals
+report (srep1 subscriber):
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 12 counter vals, 8 stat item vals
+report (srep2 disabled):
+ test2: close
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 6 counter vals, 4 stat item vals
+report (srep2 enabled, no flush forced):
+ test2: open
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
+reported: 6 counter vals, 4 stat item vals
+report (should be empty):
+reported: 0 counter vals, 0 stat item vals
+report (group 1, counter 1 update):
+ test1: counter p= g=ctr-test:one i=1 n=ctr:a v=1 d=1
+ test2: counter p= g=ctr-test:one i=1 n=ctr:a v=1 d=1
+reported: 2 counter vals, 0 stat item vals
+report (group 1, item 1 update):
+ test1: item p= g=test.one i=1 n=item.a v=10 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=10 u=ma
+reported: 0 counter vals, 2 stat item vals
+report (group 1, item 1 update twice, with same value):
+reported: 0 counter vals, 0 stat item vals
+report (group 1, item 1 update twice, check max):
+ test1: item p= g=test.one i=1 n=item.a v=20 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=20 u=ma
+reported: 0 counter vals, 2 stat item vals
+report (group 1, item 1 no update, send last item (!= last max), OS#5215):
+ test1: item p= g=test.one i=1 n=item.a v=10 u=ma
+ test2: item p= g=test.one i=1 n=item.a v=10 u=ma
+reported: 0 counter vals, 2 stat item vals
+report (group 1, item 1 no update, nothing to send):
+reported: 0 counter vals, 0 stat item vals
+report (remove statg1, ctrg1):
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+reported: 8 counter vals, 4 stat item vals
+report (remove srep1):
+ test1: close
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+ test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
+ test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
+reported: 4 counter vals, 2 stat item vals
+report (remove statg2):
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
+ test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
+reported: 4 counter vals, 0 stat item vals
+report (remove srep2):
+ test2: close
+reported: 0 counter vals, 0 stat item vals
+report (remove ctrg2, should be empty):
+reported: 0 counter vals, 0 stat item vals
+End test: test_reporting
diff --git a/tests/stats/stats_test.ok b/tests/stats/stats_test.ok
index 8628adb7..e69de29b 100644
--- a/tests/stats/stats_test.ok
+++ b/tests/stats/stats_test.ok
@@ -1,132 +0,0 @@
-Start test: test_reporting
- test1: open
- test2: open
-report (initial):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (srep1 global):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (srep1 peer):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (srep1 subscriber):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (srep2 disabled):
- test2: close
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (srep2 enabled, no flush forced):
- test2: open
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=1 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test2: item p= g=test.one i=1 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=1 n=item.b v=-1 u=kb
-report (should be empty):
-report (group 1, counter 1 update):
- test2: counter p= g=ctr-test:one i=1 n=ctr:a v=1 d=1
- test1: counter p= g=ctr-test:one i=1 n=ctr:a v=1 d=1
-report (group 1, item 1 update):
- test2: item p= g=test.one i=1 n=item.a v=10 u=ma
- test1: item p= g=test.one i=1 n=item.a v=10 u=ma
-report (remove statg1, ctrg1):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test1: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test1: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
- test1: item p= g=test.one i=2 n=item.b v=-1 u=kb
-report (remove srep1):
- test1: close
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
- test2: item p= g=test.one i=2 n=item.a v=-1 u=ma
- test2: item p= g=test.one i=2 n=item.b v=-1 u=kb
-report (remove statg2):
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one_dot i=3 n=ctr:b v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:a v=0 d=0
- test2: counter p= g=ctr-test:one i=2 n=ctr:b v=0 d=0
-report (remove srep2):
- test2: close
-report (remove ctrg2, should be empty):
-End test: test_reporting
diff --git a/tests/stats/stats_vty_test.c b/tests/stats/stats_vty_test.c
new file mode 100644
index 00000000..29cbf5ec
--- /dev/null
+++ b/tests/stats/stats_vty_test.c
@@ -0,0 +1,88 @@
+/*
+ * (C) 2021 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <signal.h>
+
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/stats.h>
+#include <osmocom/vty/vty.h>
+
+static void *root_ctx = NULL;
+static int quit = 0;
+
+static void signal_handler(int signal)
+{
+ fprintf(stdout, "signal %u received\n", signal);
+
+ switch (signal) {
+ case SIGINT:
+ case SIGTERM:
+ quit++;
+ break;
+ }
+}
+
+static struct vty_app_info vty_info = {
+ .name = "stats_vty_test",
+};
+
+static const struct log_info_cat default_categories[] = { };
+
+const struct log_info log_info = {
+ .cat = default_categories,
+ .num_cat = ARRAY_SIZE(default_categories),
+};
+
+int main(int argc, char **argv)
+{
+ int rc;
+
+ root_ctx = talloc_named_const(NULL, 0, "stats_vty_test");
+
+ osmo_init_logging2(root_ctx, &log_info);
+
+ vty_info.tall_ctx = root_ctx;
+ vty_init(&vty_info);
+
+ osmo_stats_vty_add_cmds();
+
+ rc = telnet_init_default(root_ctx, NULL, 42042);
+ if (rc < 0)
+ return 2;
+
+ signal(SIGINT, &signal_handler);
+ signal(SIGTERM, &signal_handler);
+ osmo_init_ignore_signals();
+
+ while (!quit)
+ osmo_select_main(0);
+
+ talloc_free(tall_vty_ctx);
+ talloc_free(root_ctx);
+
+ return 0;
+}
diff --git a/tests/stats/stats_vty_test.vty b/tests/stats/stats_vty_test.vty
new file mode 100644
index 00000000..8732d50b
--- /dev/null
+++ b/tests/stats/stats_vty_test.vty
@@ -0,0 +1,217 @@
+stats_vty_test> en
+stats_vty_test# configure terminal
+stats_vty_test(config)# list
+...
+ stats reporter statsd [NAME]
+ no stats reporter statsd [NAME]
+ stats reporter log [NAME]
+ no stats reporter log [NAME]
+ stats interval <0-65535>
+ stats-tcp interval <0-65535>
+...
+
+stats_vty_test(config)# ### No reporters shall be configured by default
+stats_vty_test(config)# show running-config
+... !stats reporter
+
+
+stats_vty_test(config)# ### Create a statsd reporter
+stats_vty_test(config)# stats reporter statsd
+stats_vty_test(config-stats)# list
+...
+ local-ip ADDR
+ no local-ip
+ remote-ip ADDR
+ remote-port <1-65535>
+ mtu <100-65535>
+ no mtu
+ prefix PREFIX
+ no prefix
+ level (global|peer|subscriber)
+ enable
+ disable
+ flush-period <0-65535>
+...
+
+stats_vty_test(config-stats)# show running-config
+...
+stats interval 5
+stats reporter statsd
+ level global
+ no prefix
+ disable
+...
+
+stats_vty_test(config-stats)# level subscriber
+stats_vty_test(config-stats)# prefix statsd-prefix
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+ level subscriber
+ prefix statsd-prefix
+...
+
+stats_vty_test(config-stats)# remote-ip 192.168.1.200
+stats_vty_test(config-stats)# remote-port 6969
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+... !local-ip
+
+stats_vty_test(config-stats)# local-ip 192.168.1.100
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ local-ip 192.168.1.100
+...
+
+stats_vty_test(config-stats)# no local-ip
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+... !local-ip
+
+stats_vty_test(config-stats)# mtu 1337
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ mtu 1337
+...
+
+stats_vty_test(config-stats)# no mtu
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+... !mtu
+
+stats_vty_test(config-stats)# flush-period 43556
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ level subscriber
+ prefix statsd-prefix
+ flush-period 43556
+...
+
+stats_vty_test(config-stats)# flush-period 0
+stats_vty_test(config-stats)# show running-config
+...
+stats reporter statsd
+... !flush-period
+
+stats_vty_test(config-stats)# enable
+stats_vty_test(config-stats)# exit
+stats_vty_test(config)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ level subscriber
+ prefix statsd-prefix
+ enable
+...
+
+
+stats_vty_test(config)# ### Create a statsd reporter
+stats_vty_test(config)# stats reporter log
+stats_vty_test(config-stats)# level peer
+stats_vty_test(config-stats)# prefix log-prefix
+stats_vty_test(config-stats)# enable
+stats_vty_test(config-stats)# exit
+stats_vty_test(config)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ level subscriber
+ prefix statsd-prefix
+ enable
+stats reporter log
+ level peer
+ prefix log-prefix
+ enable
+...
+
+
+stats_vty_test(config)# ### Create an additional statsd reporter
+stats_vty_test(config)# stats reporter statsd statsd-foo
+stats_vty_test(config-stats)# level global
+stats_vty_test(config-stats)# prefix statsd-one-prefix
+stats_vty_test(config-stats)# remote-ip 192.168.2.200
+stats_vty_test(config-stats)# remote-port 9696
+stats_vty_test(config-stats)# flush-period 1
+stats_vty_test(config-stats)# exit
+
+stats_vty_test(config)# ### Create an additional log reporter
+stats_vty_test(config)# stats reporter log log-bar
+stats_vty_test(config-stats)# level global
+stats_vty_test(config-stats)# prefix log-bar-prefix
+stats_vty_test(config-stats)# flush-period 2
+stats_vty_test(config-stats)# exit
+
+stats_vty_test(config)# ### Create an additional log reporter
+stats_vty_test(config)# stats reporter log log-zoo
+stats_vty_test(config-stats)# level global
+stats_vty_test(config-stats)# prefix log-zoo-prefix
+stats_vty_test(config-stats)# flush-period 3
+stats_vty_test(config-stats)# exit
+
+stats_vty_test(config)# ### We should have 5 reporters now
+stats_vty_test(config)# show running-config
+...
+stats reporter statsd
+ remote-ip 192.168.1.200
+ remote-port 6969
+ level subscriber
+ prefix statsd-prefix
+ enable
+stats reporter log
+ level peer
+ prefix log-prefix
+ enable
+stats reporter statsd statsd-foo
+ remote-ip 192.168.2.200
+ remote-port 9696
+ level global
+ prefix statsd-one-prefix
+ flush-period 1
+ disable
+stats reporter log log-bar
+ level global
+ prefix log-bar-prefix
+ flush-period 2
+ disable
+stats reporter log log-zoo
+ level global
+ prefix log-zoo-prefix
+ flush-period 3
+ disable
+...
+
+
+stats_vty_test(config)# ### Test removing reporters
+stats_vty_test(config)# no stats reporter statsd statsd-foo
+stats_vty_test(config)# no stats reporter log log-bar
+stats_vty_test(config)# no stats reporter log log-zoo
+stats_vty_test(config)# show running-config
+... !(foo|bar|zoo)
+
+stats_vty_test(config)# no stats reporter statsd statsd-foo
+% There is no such statsd reporter with name 'statsd-foo'
+stats_vty_test(config)# no stats reporter log log-zoo
+% There is no such log reporter with name 'log-zoo'
+
+
+stats_vty_test(config)# stats interval 1337
+stats_vty_test(config)# show running-config
+...
+stats interval 1337
+...