Change in libosmocore[master]: tests/stats: add VTY transcript tests

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Tue Nov 9 01:11:46 UTC 2021


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/26169 )


Change subject: tests/stats: add VTY transcript tests
......................................................................

tests/stats: add VTY transcript tests

Change-Id: I85ac73f4c866617179e55821a292aad33b6edc99
Related: SYS#5713
---
M tests/Makefile.am
A tests/stats/stats_vty_test.c
A tests/stats/stats_vty_test.vty
3 files changed, 256 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/69/26169/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0880561..b72619f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -73,6 +73,7 @@
 if !EMBEDDED
 check_PROGRAMS += \
 	stats/stats_test \
+	stats/stats_vty_test \
 	exec/exec_test
 endif
 
@@ -89,6 +90,9 @@
 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 @@
 	     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 @@
 		-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 0000000..f3742bd
--- /dev/null
+++ b/tests/stats/stats_vty_test.c
@@ -0,0 +1,89 @@
+/*
+ * (C) 2021 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <signal.h>
+
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/stats.h>
+#include <osmocom/vty/vty.h>
+
+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 0000000..4ec03c9
--- /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
+...

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/26169
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I85ac73f4c866617179e55821a292aad33b6edc99
Gerrit-Change-Number: 26169
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211109/f06a953e/attachment.htm>


More information about the gerrit-log mailing list