From ac3a3fc91b9aaebfb4bd10093e9c7a1a0324e004 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Tue, 9 Nov 2021 03:35:44 +0300 Subject: tests/stats: add VTY transcript tests Change-Id: I85ac73f4c866617179e55821a292aad33b6edc99 Related: SYS#5713 --- tests/Makefile.am | 12 ++++ tests/stats/stats_vty_test.c | 88 +++++++++++++++++++++++ tests/stats/stats_vty_test.vty | 155 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 tests/stats/stats_vty_test.c create mode 100644 tests/stats/stats_vty_test.vty (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 0880561c..b72619f1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -73,6 +73,7 @@ endif if !EMBEDDED check_PROGRAMS += \ stats/stats_test \ + stats/stats_vty_test \ exec/exec_test endif @@ -89,6 +90,9 @@ stats_stats_test_SOURCES = stats/stats_test.c stats_stats_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la stats_stats_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src +stats_stats_vty_test_SOURCES = stats/stats_vty_test.c +stats_stats_vty_test_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 @@ -374,6 +378,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ comp128/comp128_test.ok bits/bitfield_test.ok \ utils/utils_test.ok utils/utils_test.err \ stats/stats_test.ok stats/stats_test.err \ + stats/stats_vty_test.vty \ bitvec/bitvec_test.ok msgb/msgb_test.ok bits/bitcomp_test.ok \ sim/sim_test.ok tlv/tlv_test.ok abis/abis_test.ok \ gsup/gsup_test.ok gsup/gsup_test.err \ @@ -677,12 +682,19 @@ vty-test-tdef: -r "$(top_builddir)/tests/tdef/tdef_vty_test_dynamic" \ $(U) $(srcdir)/tdef/tdef_vty_test_dynamic.vty +vty-test-stats: + osmo_verify_transcript_vty.py -v \ + -p 42042 \ + -r "$(top_builddir)/tests/stats/stats_vty_test" \ + $(U) $(srcdir)/stats/*.vty + # don't run vty tests concurrently so that the ports don't conflict vty-test: $(MAKE) vty-test-logging $(MAKE) vty-test-vty $(MAKE) vty-test-tdef $(MAKE) vty-test-ns2 + $(MAKE) vty-test-stats ctrl-test: echo "No CTRL tests exist currently" diff --git a/tests/stats/stats_vty_test.c b/tests/stats/stats_vty_test.c new file mode 100644 index 00000000..09b125ac --- /dev/null +++ b/tests/stats/stats_vty_test.c @@ -0,0 +1,88 @@ +/* + * (C) 2021 by sysmocom s.f.m.c. GmbH + * + * 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 . + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +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_dynif(root_ctx, NULL, vty_get_bind_addr(), 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..4ec03c99 --- /dev/null +++ b/tests/stats/stats_vty_test.vty @@ -0,0 +1,155 @@ +stats_vty_test> en +stats_vty_test# configure terminal +stats_vty_test(config)# list +... + stats reporter statsd + no stats reporter statsd + stats reporter log + no stats reporter log + stats 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 reporter statsd + disable + level global + no prefix +stats interval 5 +... + +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 + disable + 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 + disable + 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 + disable + 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 + disable + 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 + disable + 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 + disable + 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 + disable + remote-ip 192.168.1.200 + remote-port 6969 + level subscriber + prefix statsd-prefix + enable +stats reporter log + disable + level peer + prefix log-prefix + enable +... + + +stats_vty_test(config)# stats interval 1337 +stats_vty_test(config)# show running-config +... +stats interval 1337 +... -- cgit v1.2.3