From 9732cb4a92a883c7e9f7dcd928b6e22976a797ca Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 1 Oct 2015 20:43:53 +0200 Subject: stats: Add stat_item for value monitoring This commit adds instrumentation function to gather measurement and statistical values similar to counter groups. Multiple values can be stored per item, which can be retrieved in FIFO order. Getting values from the item does not modify its state to allow for multiple independant backends (e.g. VTY and statd). When a new value is set, the oldest value gets silently overwritten. Lost values are skipped when getting values from the item. Sponsored-by: On-Waves ehf --- tests/Makefile.am | 7 +- tests/stats/stats_test.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++ tests/stats/stats_test.ok | 0 tests/testsuite.at | 6 ++ 4 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 tests/stats/stats_test.c create mode 100644 tests/stats/stats_test.ok (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index cf0977de..223535ff 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,7 +9,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \ kasumi/kasumi_test logging/logging_test fr/fr_test \ loggingrb/loggingrb_test strrb/strrb_test \ vty/vty_test comp128/comp128_test utils/utils_test \ - smscb/gsm0341_test + smscb/gsm0341_test stats/stats_test if ENABLE_MSGFILE check_PROGRAMS += msgfile/msgfile_test @@ -18,6 +18,9 @@ endif utils_utils_test_SOURCES = utils/utils_test.c utils_utils_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la +stats_stats_test_SOURCES = stats/stats_test.c +stats_stats_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la + a5_a5_test_SOURCES = a5/a5_test.c a5_a5_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libgsmint.la @@ -120,7 +123,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ fr/fr_test.ok loggingrb/logging_test.ok \ loggingrb/logging_test.err strrb/strrb_test.ok \ vty/vty_test.ok comp128/comp128_test.ok \ - utils/utils_test.ok + utils/utils_test.ok stats/stats_test.ok DISTCLEANFILES = atconfig diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c new file mode 100644 index 00000000..b4143853 --- /dev/null +++ b/tests/stats/stats_test.c @@ -0,0 +1,198 @@ +/* tests for statistics */ +/* + * (C) 2015 Sysmocom s.m.f.c. GmbH + * + * All Rights Reserved + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include + +#include + +static void stat_test(void) +{ + enum test_items { + TEST_A_ITEM, + TEST_B_ITEM, + }; + + static const struct stat_item_desc item_description[] = { + { "item.a", "The A value", "ma", 4, -1 }, + { "item.b", "The B value", "kb", 7, -1 }, + }; + + static const struct stat_item_group_desc statg_desc = { + .group_name_prefix = "test.one", + .group_description = "Test number 1", + .num_items = ARRAY_SIZE(item_description), + .item_desc = item_description, + }; + + struct stat_item_group *statg = + stat_item_group_alloc(NULL, &statg_desc, 0); + + struct stat_item_group *sgrp2; + const struct stat_item *sitem1, *sitem2; + int rc; + int32_t value; + int32_t rd_a = 0; + int32_t rd_b = 0; + int i; + + OSMO_ASSERT(statg != NULL); + + sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + OSMO_ASSERT(sgrp2 == statg); + + sgrp2 = stat_item_get_group_by_name_idx("test.one", 1); + OSMO_ASSERT(sgrp2 == NULL); + + sgrp2 = stat_item_get_group_by_name_idx("test.two", 0); + OSMO_ASSERT(sgrp2 == NULL); + + sitem1 = stat_item_get_by_name(statg, "item.c"); + OSMO_ASSERT(sitem1 == NULL); + + sitem1 = stat_item_get_by_name(statg, "item.a"); + OSMO_ASSERT(sitem1 != NULL); + OSMO_ASSERT(sitem1 == statg->items[TEST_A_ITEM]); + + sitem2 = stat_item_get_by_name(statg, "item.b"); + OSMO_ASSERT(sitem2 != NULL); + OSMO_ASSERT(sitem2 != sitem1); + OSMO_ASSERT(sitem2 == statg->items[TEST_B_ITEM]); + + value = stat_item_get_last(statg->items[TEST_A_ITEM]); + OSMO_ASSERT(value == -1); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 0); + + stat_item_set(statg->items[TEST_A_ITEM], 1); + + value = stat_item_get_last(statg->items[TEST_A_ITEM]); + OSMO_ASSERT(value == 1); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 1); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 0); + + for (i = 2; i <= 32; i++) { + stat_item_set(statg->items[TEST_A_ITEM], i); + stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == i); + + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 1000 + i); + } + + /* Keep 2 in FIFO */ + stat_item_set(statg->items[TEST_A_ITEM], 33); + stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33); + + for (i = 34; i <= 64; i++) { + stat_item_set(statg->items[TEST_A_ITEM], i); + stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == i-1); + + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 1000 + i-1); + } + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 64); + + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 1000 + 64); + + /* Overrun FIFOs */ + for (i = 65; i <= 96; i++) { + stat_item_set(statg->items[TEST_A_ITEM], i); + stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + } + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 93 - 65 + 1); + OSMO_ASSERT(value == 93); + + for (i = 94; i <= 96; i++) { + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == i); + } + + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 90 - 65 + 1); + OSMO_ASSERT(value == 1000 + 90); + + for (i = 91; i <= 96; i++) { + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 1000 + i); + } + + /* Test Discard */ + stat_item_set(statg->items[TEST_A_ITEM], 97); + rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + OSMO_ASSERT(rc == 1); + + rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + OSMO_ASSERT(rc == 0); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 0); + + stat_item_set(statg->items[TEST_A_ITEM], 98); + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(value == 98); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 0); + + stat_item_group_free(statg); + + sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + OSMO_ASSERT(sgrp2 == NULL); +} + +int main(int argc, char **argv) +{ + static const struct log_info log_info = {}; + log_init(&log_info, NULL); + + stat_item_init(NULL); + + stat_test(); + return 0; +} diff --git a/tests/stats/stats_test.ok b/tests/stats/stats_test.ok new file mode 100644 index 00000000..e69de29b diff --git a/tests/testsuite.at b/tests/testsuite.at index fe30363c..a5427986 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -136,6 +136,12 @@ cat $abs_srcdir/utils/utils_test.ok > expout AT_CHECK([$abs_top_builddir/tests/utils/utils_test], [0], [expout], [ignore]) AT_CLEANUP +AT_SETUP([stats]) +AT_KEYWORDS([stats]) +cat $abs_srcdir/stats/stats_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/stats/stats_test], [0], [expout], [ignore]) +AT_CLEANUP + AT_SETUP([bssgp-fc]) AT_KEYWORDS([bssgp-fc]) cat $abs_srcdir/gb/bssgp_fc_tests.ok > expout -- cgit v1.2.3 From 738d9e22108a8e472458fad42509fd8d96994d6c Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 6 Oct 2015 15:21:56 +0200 Subject: stats: Add vty_out_stat_item_group This functions dumps a whole stat item group to the VTY. Sponsored-by: On-Waves ehf --- tests/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 223535ff..6065c0d0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -67,19 +67,19 @@ ussd_ussd_test_SOURCES = ussd/ussd_test.c ussd_ussd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la gb_bssgp_fc_test_SOURCES = gb/bssgp_fc_test.c -gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la +gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(top_builddir)/src/vty/libosmovty.la gb_gprs_bssgp_test_SOURCES = gb/gprs_bssgp_test.c -gb_gprs_bssgp_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(LIBRARY_DL) +gb_gprs_bssgp_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(top_builddir)/src/vty/libosmovty.la $(LIBRARY_DL) gb_gprs_ns_test_SOURCES = gb/gprs_ns_test.c -gb_gprs_ns_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(LIBRARY_DL) +gb_gprs_ns_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(top_builddir)/src/vty/libosmovty.la $(LIBRARY_DL) logging_logging_test_SOURCES = logging/logging_test.c logging_logging_test_LDADD = $(top_builddir)/src/libosmocore.la fr_fr_test_SOURCES = fr/fr_test.c -fr_fr_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(LIBRARY_DL) +fr_fr_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(top_builddir)/src/vty/libosmovty.la $(LIBRARY_DL) loggingrb_loggingrb_test_SOURCES = loggingrb/loggingrb_test.c loggingrb_loggingrb_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/vty/libosmovty.la -- cgit v1.2.3 From b27b352e937dd0760da1e7fb05f9207be05702b8 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 12 Oct 2015 18:47:09 +0200 Subject: stats: Use a global index for stat item values Currently each stat item has a separate index value which basically counts each single value added to the item and which can be used by a reporter to get all new values that have not been reported yet. The drawback is, that such an index must be stored for each stat item. This commit introduces a global index which is incremented for each new stat item value. This index is then stored together with the item value. So a single stored index per reporter is sufficient to make sure that only new values are reported. Sponsored-by: On-Waves ehf --- tests/stats/stats_test.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c index b4143853..9da49a4f 100644 --- a/tests/stats/stats_test.c +++ b/tests/stats/stats_test.c @@ -91,7 +91,7 @@ static void stat_test(void) OSMO_ASSERT(value == 1); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); @@ -102,11 +102,11 @@ static void stat_test(void) stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } @@ -119,20 +119,20 @@ static void stat_test(void) stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i-1); rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i-1); } rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 64); rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 64); /* Overrun FIFOs */ @@ -142,29 +142,29 @@ static void stat_test(void) } rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 93 - 65 + 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 93); for (i = 94; i <= 96; i++) { rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); } rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); - OSMO_ASSERT(rc == 90 - 65 + 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + 90); for (i = 91; i <= 96; i++) { rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } - /* Test Discard */ + /* Test Discard (single item) */ stat_item_set(statg->items[TEST_A_ITEM], 97); rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); OSMO_ASSERT(rc == 0); @@ -174,12 +174,27 @@ static void stat_test(void) stat_item_set(statg->items[TEST_A_ITEM], 98); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); - OSMO_ASSERT(rc == 1); + OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 98); rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); + /* Test Discard (all items) */ + stat_item_set(statg->items[TEST_A_ITEM], 99); + stat_item_set(statg->items[TEST_A_ITEM], 100); + stat_item_set(statg->items[TEST_A_ITEM], 101); + stat_item_set(statg->items[TEST_B_ITEM], 99); + stat_item_set(statg->items[TEST_B_ITEM], 100); + + rc = stat_item_discard_all(&rd_a); + rc = stat_item_discard_all(&rd_b); + + rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + OSMO_ASSERT(rc == 0); + rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + OSMO_ASSERT(rc == 0); + stat_item_group_free(statg); sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); -- cgit v1.2.3 From adc900e0e38373193c8451c0310fe742d62c2c8e Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 20 Oct 2015 19:05:52 +0200 Subject: stats/vty: Add stats configuration This commit provides stats configuration similar to the log configuration. The following vty commands are added to the config node: stats reporter statsd Create/Modify a statsd reporter no stats reporter statsd Remove a statsd reporter To actually configure a reporter, the config-stats node is entered when the "stats reporter" command has succeeded. The following new vty commands are available there: local-ip ADDR Set the IP address to which we bind locally no local-ip Do not bind to a certain IP address remote-ip ADDR Set the remote IP address to which we connect remote-port <1-65535> Set the remote port to which we connect prefix PREFIX Set the item/counter name prefix no prefix Do not use a prefix enable Enable the reporter disable Disable the reporter Sponsored-by: On-Waves ehf --- tests/vty/vty_test.ok | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok index 0ea2dabf..c6365907 100644 --- a/tests/vty/vty_test.ok +++ b/tests/vty/vty_test.ok @@ -24,11 +24,11 @@ Returned: 0, Current node: 3 '%s# ' Going to execute 'configure terminal' Returned: 0, Current node: 4 '%s(config)# ' Going to execute 'line vty' -Returned: 0, Current node: 8 '%s(config-line)# ' +Returned: 0, Current node: 9 '%s(config-line)# ' Going to execute 'exit' Returned: 0, Current node: 4 '%s(config)# ' Going to execute 'line vty' -Returned: 0, Current node: 8 '%s(config-line)# ' +Returned: 0, Current node: 9 '%s(config-line)# ' Going to execute 'end' Returned: 0, Current node: 3 '%s# ' Going to execute 'configure terminal' @@ -36,7 +36,7 @@ Returned: 0, Current node: 4 '%s(config)# ' Going to execute 'log stderr' Returned: 0, Current node: 7 '%s(config-log)# ' Going to execute 'line vty' -Returned: 0, Current node: 8 '%s(config-line)# ' +Returned: 0, Current node: 9 '%s(config-line)# ' Going to execute 'log stderr' Returned: 0, Current node: 7 '%s(config-log)# ' Going to execute 'end' -- cgit v1.2.3 From fc9533d6c4bde795dc0e18f02f91f54ab92888a2 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 29 Oct 2015 00:55:58 +0100 Subject: stats: Add osmo_ name prefix to identifiers Since the the stat_item and stats functions and data types are meant to be exported, they get an osmo_ prefix. Sponsored-by: On-Waves ehf [hfreyther: Prepended the enum values too. This was requested by Jacob] --- tests/stats/stats_test.c | 110 +++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 55 deletions(-) (limited to 'tests') diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c index 9da49a4f..f8c7dc00 100644 --- a/tests/stats/stats_test.c +++ b/tests/stats/stats_test.c @@ -33,23 +33,23 @@ static void stat_test(void) TEST_B_ITEM, }; - static const struct stat_item_desc item_description[] = { + static const struct osmo_stat_item_desc item_description[] = { { "item.a", "The A value", "ma", 4, -1 }, { "item.b", "The B value", "kb", 7, -1 }, }; - static const struct stat_item_group_desc statg_desc = { + static const struct osmo_stat_item_group_desc statg_desc = { .group_name_prefix = "test.one", .group_description = "Test number 1", .num_items = ARRAY_SIZE(item_description), .item_desc = item_description, }; - struct stat_item_group *statg = - stat_item_group_alloc(NULL, &statg_desc, 0); + struct osmo_stat_item_group *statg = + osmo_stat_item_group_alloc(NULL, &statg_desc, 0); - struct stat_item_group *sgrp2; - const struct stat_item *sitem1, *sitem2; + struct osmo_stat_item_group *sgrp2; + const struct osmo_stat_item *sitem1, *sitem2; int rc; int32_t value; int32_t rd_a = 0; @@ -58,146 +58,146 @@ static void stat_test(void) OSMO_ASSERT(statg != NULL); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); OSMO_ASSERT(sgrp2 == statg); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 1); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 1); OSMO_ASSERT(sgrp2 == NULL); - sgrp2 = stat_item_get_group_by_name_idx("test.two", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.two", 0); OSMO_ASSERT(sgrp2 == NULL); - sitem1 = stat_item_get_by_name(statg, "item.c"); + sitem1 = osmo_stat_item_get_by_name(statg, "item.c"); OSMO_ASSERT(sitem1 == NULL); - sitem1 = stat_item_get_by_name(statg, "item.a"); + sitem1 = osmo_stat_item_get_by_name(statg, "item.a"); OSMO_ASSERT(sitem1 != NULL); OSMO_ASSERT(sitem1 == statg->items[TEST_A_ITEM]); - sitem2 = stat_item_get_by_name(statg, "item.b"); + 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]); - value = stat_item_get_last(statg->items[TEST_A_ITEM]); + value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == -1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - stat_item_set(statg->items[TEST_A_ITEM], 1); + osmo_stat_item_set(statg->items[TEST_A_ITEM], 1); - value = stat_item_get_last(statg->items[TEST_A_ITEM]); + value = osmo_stat_item_get_last(statg->items[TEST_A_ITEM]); OSMO_ASSERT(value == 1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); for (i = 2; i <= 32; i++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 1000 + i); } /* Keep 2 in FIFO */ - stat_item_set(statg->items[TEST_A_ITEM], 33); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + 33); + 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++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i-1); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + 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 = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == 64); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + 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++) { - stat_item_set(statg->items[TEST_A_ITEM], i); - stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); + osmo_stat_item_set(statg->items[TEST_A_ITEM], i); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 1000 + i); } - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + 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 = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc > 0); OSMO_ASSERT(value == i); } - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + 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 = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + 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) */ - stat_item_set(statg->items[TEST_A_ITEM], 97); - rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + 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 = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); + rc = osmo_stat_item_discard(statg->items[TEST_A_ITEM], &rd_a); OSMO_ASSERT(rc == 0); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - stat_item_set(statg->items[TEST_A_ITEM], 98); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + 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 = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); /* Test Discard (all items) */ - stat_item_set(statg->items[TEST_A_ITEM], 99); - stat_item_set(statg->items[TEST_A_ITEM], 100); - stat_item_set(statg->items[TEST_A_ITEM], 101); - stat_item_set(statg->items[TEST_B_ITEM], 99); - stat_item_set(statg->items[TEST_B_ITEM], 100); + 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 = stat_item_discard_all(&rd_a); - rc = stat_item_discard_all(&rd_b); + rc = osmo_stat_item_discard_all(&rd_a); + rc = osmo_stat_item_discard_all(&rd_b); - rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value); OSMO_ASSERT(rc == 0); - rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); + rc = osmo_stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value); OSMO_ASSERT(rc == 0); - stat_item_group_free(statg); + osmo_stat_item_group_free(statg); - sgrp2 = stat_item_get_group_by_name_idx("test.one", 0); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); OSMO_ASSERT(sgrp2 == NULL); } @@ -206,7 +206,7 @@ int main(int argc, char **argv) static const struct log_info log_info = {}; log_init(&log_info, NULL); - stat_item_init(NULL); + osmo_stat_item_init(NULL); stat_test(); return 0; -- cgit v1.2.3