From 9585885012dd6cd43516b81a85b6b25ae2b044ab Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Dec 2019 15:51:29 +0100 Subject: [WIP] prometheus module fake_stats test Based on 51053ebb9ea7068b7a4e6bff11a470d4c4dedb37 --- tests/Makefile.am | 4 ++ tests/stats/fake_stats.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 tests/stats/fake_stats.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index bf7017b1..506edc5d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -63,6 +63,7 @@ endif if !EMBEDDED check_PROGRAMS += \ stats/stats_test \ + stats/fake_stats \ exec/exec_test endif @@ -76,6 +77,9 @@ utils_utils_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la stats_stats_test_SOURCES = stats/stats_test.c stats_stats_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la +stats_fake_stats_SOURCES = stats/fake_stats.c +stats_fake_stats_LDADD = $(LDADD) $(top_builddir)/src/vty/libosmovty.la + a5_a5_test_SOURCES = a5/a5_test.c a5_a5_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libgsmint.la diff --git a/tests/stats/fake_stats.c b/tests/stats/fake_stats.c new file mode 100644 index 00000000..ab30207a --- /dev/null +++ b/tests/stats/fake_stats.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct vty_app_info vty_info = { + .name = "fake_stats", + .version = "1", +}; + +static const struct log_info_cat categories[] = { +}; + +const struct log_info log_info = { + .cat = categories, + .num_cat = ARRAY_SIZE(categories), +}; + +int main(int argc, char **argv) +{ + int rc; + void *ctx = talloc_named_const(NULL, 1, "fake_stats"); + vty_info.tall_ctx = ctx; + + osmo_init_logging2(ctx, &log_info); + + osmo_stats_init(ctx); + // osmo_prom_init(ctx, 12346); + +//int osmo_stat_item_init(void *tall_ctx); + + vty_init(&vty_info); + osmo_stats_vty_add_cmds(); + + logging_vty_add_cmds(); + osmo_talloc_vty_add_cmds(); + + enum test_ctr { + TEST_A_CTR, + TEST_B_CTR, + }; + static const struct rate_ctr_desc ctr_description[] = { + [TEST_A_CTR] = { "ctr:a", "The A counter value"}, + [TEST_B_CTR] = { "ctr:b", "The B counter value"}, + }; + static const struct rate_ctr_group_desc ctrg_desc = { + .group_name_prefix = "ctr-test:one", + .group_description = "Counter test number 1", + .num_ctr = ARRAY_SIZE(ctr_description), + .ctr_desc = ctr_description, + .class_id = OSMO_STATS_CLASS_SUBSCRIBER, + }; + struct rate_ctr_group *ctrg1 = rate_ctr_group_alloc(ctx, &ctrg_desc, 1); + + +enum test_items { + TEST_A_ITEM, + TEST_B_ITEM, +}; +static const struct osmo_stat_item_desc item_description[] = { + [TEST_A_ITEM] = { "item.a", "The A value", "ma", 4, -1 }, + [TEST_B_ITEM] = { "item.b", "The B value", "kb", 7, -1 }, +}; +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, + .class_id = OSMO_STATS_CLASS_PEER, +}; + + struct osmo_stat_item_group *statg = + osmo_stat_item_group_alloc(NULL, &statg_desc, 0); + + osmo_stat_item_set(statg->items[TEST_A_ITEM], 23); + osmo_stat_item_set(statg->items[TEST_B_ITEM], 42); + +//void rate_ctr_add(struct rate_ctr *ctr, int inc); +// osmo_stat_item + + /* start telnet after reading config for vty_get_bind_addr() */ + rc = telnet_init_dynif(ctx, NULL, + vty_get_bind_addr(), 12345); + if (rc < 0) + return 2; + + // TODO replace vty_get_bind_addr? + rc = osmo_prom_init_dynif(ctx, vty_get_bind_addr(), 12346); + if (rc < 0) + return 2; + + int a = 0; + int b = 0; + + while (1) { + log_reset_context(); + osmo_select_main_ctx(0); + rate_ctr_add(&ctrg1->ctr[TEST_A_CTR], 1); + + osmo_stat_item_set(statg->items[TEST_A_ITEM], a); + osmo_stat_item_set(statg->items[TEST_B_ITEM], b); + + a = (a + 1) % 23; + b = (b + 1) % 42; + } + return 0; +} + +// telnet localhost 12345 -- cgit v1.2.3