stats_test: restore stat_item_get_next asserts
This is a partial revert of b27b352e ("stats: Use a global index for
stat item values"). Now that osmo_stat_item_get_next correctly returns
how many values have been skipped, we can use the accurate asserts on
its return value again.
Fix the initial values of next_id_a,b (1 instead of 0), so we don't get
a skipped value on the first read. This is needed, because b27b352e
refactored osmo_stat_item_get_next to have the next id as parameter
instead of the last read one, and the initial value was not adjusted in
the tests.
Related: OS#5088
Change-Id: I9d4cda2487a62f52361c24058363dfa90e502c63
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index b6b4be9..1d53aaa 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -90,8 +90,8 @@
const struct osmo_stat_item *sitem1, *sitem2;
int rc;
int32_t value;
- int32_t next_id_a = 0;
- int32_t next_id_b = 0;
+ int32_t next_id_a = 1;
+ int32_t next_id_b = 1;
int i;
OSMO_ASSERT(statg != NULL);
@@ -129,7 +129,7 @@
OSMO_ASSERT(value == 1);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 1);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
@@ -140,28 +140,28 @@
osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == i);
rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 1000 + i);
}
/* 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], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
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], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
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], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 42);
/* Keep 2 in FIFO */
@@ -173,20 +173,20 @@
osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == i-1);
rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 1000 + i-1);
}
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 64);
rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 1000 + 64);
/* Overrun FIFOs */
@@ -196,29 +196,29 @@
}
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 93 - 65 + 1);
OSMO_ASSERT(value == 93);
for (i = 94; i <= 96; i++) {
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == i);
}
rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 90 - 65 + 1);
OSMO_ASSERT(value == 1000 + 90);
for (i = 91; i <= 96; i++) {
rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &next_id_b, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
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], &next_id_a);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &next_id_a);
OSMO_ASSERT(rc == 0);
@@ -228,7 +228,7 @@
osmo_stat_item_set(statg->items[TEST_A_ITEM], 98);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);
- OSMO_ASSERT(rc > 0);
+ OSMO_ASSERT(rc == 1);
OSMO_ASSERT(value == 98);
rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &next_id_a, &value);