aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2021-09-14 17:41:25 +0200
committerneels <nhofmeyr@sysmocom.de>2021-09-20 13:05:32 +0000
commit599601e12c21af1fdc927a90f08c142c125d57e2 (patch)
tree7509e47e1dacc377041fc17615ff201f4b68477a /tests
parent049fd5ccc0f70f60b6f076c7e4594740e4f727b6 (diff)
stats_test: assert counter and stat item val counts separately
Instead of just a send_count, keep one such count for the counter updates, and a separate one for the stat item updates. Print those numbers in the test output. An upcoming patch will tweak stat_item reporting so that only an actually changed value results in sending a new stat value. This patch allows illustrating that change clearly. Related: SYS#5542 Change-Id: I2da003ee6ec15f1c3959efe69e01b4ee24af82bb
Diffstat (limited to 'tests')
-rw-r--r--tests/stats/stats_test.c90
-rw-r--r--tests/stats/stats_test.err18
2 files changed, 51 insertions, 57 deletions
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index 2f2c6ecc..9489e603 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -246,7 +246,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,
@@ -265,7 +266,7 @@ static int stats_reporter_test_send_counter(struct osmo_stats_reporter *srep,
group_name, ctrg ? ctrg->idx : 0,
desc->name, (long long)value, (long long)delta);
- send_count += 1;
+ sent_counter_vals++;
return 0;
}
@@ -279,7 +280,7 @@ static int stats_reporter_test_send_item(struct osmo_stats_reporter *srep,
statg->desc->group_name_prefix, statg->idx,
desc->name, value, desc->unit ? desc->unit : "");
- send_count += 1;
+ sent_stat_item_vals++;
return 0;
}
@@ -310,6 +311,17 @@ 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()
{
@@ -363,36 +375,28 @@ static void test_reporting()
OSMO_ASSERT(rc >= 0);
fprintf(stderr, "report (initial):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 20);
+ do_report(12, 8);
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);
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);
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);
fprintf(stderr, "report (srep2 disabled):\n");
/* force single flush */
@@ -400,57 +404,39 @@ static void test_reporting()
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);
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);
fprintf(stderr, "report (should be empty):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 0);
+ do_report(0, 0);
fprintf(stderr, "report (group 1, counter 1 update):\n");
rate_ctr_inc(rate_ctr_group_get_ctr(ctrg1, TEST_A_CTR));
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ do_report(2, 0);
fprintf(stderr, "report (group 1, item 1 update):\n");
osmo_stat_item_set(osmo_stat_item_group_get_item(statg1, TEST_A_ITEM), 10);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ do_report(0, 2);
fprintf(stderr, "report (group 1, item 1 update twice):\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);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ do_report(0, 2);
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);
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ do_report(0, 2);
fprintf(stderr, "report (group 1, item 1 no update, send last item (!= last max), OS#5215):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 2);
+ do_report(0, 2);
fprintf(stderr, "report (group 1, item 1 no update, nothing to send):\n");
- send_count = 0;
- osmo_stats_report();
- OSMO_ASSERT(send_count == 0);
+ do_report(0, 0);
fprintf(stderr, "report (remove statg1, ctrg1):\n");
/* force single flush */
@@ -458,40 +444,30 @@ static void test_reporting()
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);
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);
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);
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);
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);
diff --git a/tests/stats/stats_test.err b/tests/stats/stats_test.err
index daa3e5ce..92d6ce16 100644
--- a/tests/stats/stats_test.err
+++ b/tests/stats/stats_test.err
@@ -31,6 +31,7 @@ report (initial):
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
+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
@@ -42,6 +43,7 @@ report (srep1 global):
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
@@ -57,6 +59,7 @@ report (srep1 peer):
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
+reported: 6 counter vals, 8 stat item vals
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
@@ -78,6 +81,7 @@ report (srep1 subscriber):
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
+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
@@ -90,6 +94,7 @@ report (srep2 disabled):
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
@@ -102,23 +107,31 @@ report (srep2 enabled, no flush forced):
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):
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
+reported: 2 counter vals, 0 stat item vals
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
+reported: 0 counter vals, 2 stat item vals
report (group 1, item 1 update twice):
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
+reported: 0 counter vals, 2 stat item vals
report (group 1, item 1 update twice, check max):
test2: item p= g=test.one i=1 n=item.a v=20 u=ma
test1: 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):
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
+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):
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
@@ -132,6 +145,7 @@ report (remove statg1, ctrg1):
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
+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
@@ -140,12 +154,16 @@ report (remove srep1):
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