summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/vty/vty_test.c127
-rw-r--r--tests/vty/vty_test.ok67
2 files changed, 194 insertions, 0 deletions
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index 258a144d..865c93e9 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -27,6 +27,7 @@
#include <osmocom/core/application.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/stats.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/signal.h>
#include <osmocom/vty/misc.h>
@@ -34,6 +35,7 @@
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/vty/logging.h>
+#include <osmocom/vty/stats.h>
static enum event last_vty_connection_event = -1;
@@ -173,6 +175,121 @@ static void test_node_tree_structure(void)
destroy_test_vty(&test, vty);
}
+static void check_srep_vty_config(struct vty* vty,
+ struct osmo_stats_reporter *srep)
+{
+ OSMO_ASSERT(srep->enabled == 0);
+
+ OSMO_ASSERT(do_vty_command(vty, "prefix myprefix") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->name_prefix != NULL);
+ OSMO_ASSERT(strcmp(srep->name_prefix, "myprefix") == 0);
+ OSMO_ASSERT(do_vty_command(vty, "no prefix") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->name_prefix == NULL || strlen(srep->name_prefix) == 0);
+
+ OSMO_ASSERT(srep->max_class == OSMO_STATS_CLASS_GLOBAL);
+ OSMO_ASSERT(do_vty_command(vty, "level peer") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->max_class == OSMO_STATS_CLASS_PEER);
+ OSMO_ASSERT(do_vty_command(vty, "level subscriber") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->max_class == OSMO_STATS_CLASS_SUBSCRIBER);
+ OSMO_ASSERT(do_vty_command(vty, "level global") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->max_class == OSMO_STATS_CLASS_GLOBAL);
+ OSMO_ASSERT(do_vty_command(vty, "level foobar") == CMD_ERR_NO_MATCH);
+
+ if (srep->have_net_config) {
+ OSMO_ASSERT(do_vty_command(vty, "remote-ip 127.0.0.99") ==
+ CMD_SUCCESS);
+ OSMO_ASSERT(srep->dest_addr_str &&
+ strcmp(srep->dest_addr_str, "127.0.0.99") == 0);
+ OSMO_ASSERT(do_vty_command(vty, "remote-ip 678.0.0.99") ==
+ CMD_WARNING);
+ OSMO_ASSERT(srep->dest_addr_str &&
+ strcmp(srep->dest_addr_str, "127.0.0.99") == 0);
+
+ OSMO_ASSERT(do_vty_command(vty, "remote-port 12321") ==
+ CMD_SUCCESS);
+ OSMO_ASSERT(srep->dest_port == 12321);
+
+ OSMO_ASSERT(srep->bind_addr_str == NULL);
+ OSMO_ASSERT(do_vty_command(vty, "local-ip 127.0.0.98") ==
+ CMD_SUCCESS);
+ OSMO_ASSERT(srep->bind_addr_str &&
+ strcmp(srep->bind_addr_str, "127.0.0.98") == 0);
+ OSMO_ASSERT(do_vty_command(vty, "no local-ip") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->bind_addr_str == NULL);
+
+ OSMO_ASSERT(srep->mtu == 0);
+ OSMO_ASSERT(do_vty_command(vty, "mtu 987") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->mtu == 987);
+ OSMO_ASSERT(do_vty_command(vty, "no mtu") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->mtu == 0);
+ };
+
+ OSMO_ASSERT(do_vty_command(vty, "enable") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->enabled != 0);
+ OSMO_ASSERT(do_vty_command(vty, "disable") == CMD_SUCCESS);
+ OSMO_ASSERT(srep->enabled == 0);
+}
+
+static void test_stats_vty(void)
+{
+ struct osmo_stats_reporter *srep;
+ struct vty_test test;
+ struct vty *vty;
+
+ printf("Going to test VTY configuration of the stats subsystem\n");
+ vty = create_test_vty(&test);
+
+ /* Go to config node */
+ OSMO_ASSERT(do_vty_command(vty, "enable") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == ENABLE_NODE);
+ OSMO_ASSERT(do_vty_command(vty, "configure terminal") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == CONFIG_NODE);
+
+ /* Try to create invalid reporter */
+ OSMO_ASSERT(do_vty_command(vty, "stats reporter foobar") ==
+ CMD_ERR_NO_MATCH);
+
+ /* Set reporting interval */
+ OSMO_ASSERT(do_vty_command(vty, "stats interval 42") == CMD_SUCCESS);
+ OSMO_ASSERT(osmo_stats_config->interval == 42);
+
+ /* Create log reporter */
+ srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
+ OSMO_ASSERT(srep == NULL);
+ OSMO_ASSERT(do_vty_command(vty, "stats reporter log") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == CFG_STATS_NODE);
+ srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
+ OSMO_ASSERT(srep != NULL);
+ OSMO_ASSERT(srep->type == OSMO_STATS_REPORTER_LOG);
+ check_srep_vty_config(vty, srep);
+ OSMO_ASSERT(do_vty_command(vty, "exit") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == CONFIG_NODE);
+
+ /* Create statsd reporter */
+ srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
+ OSMO_ASSERT(srep == NULL);
+ OSMO_ASSERT(do_vty_command(vty, "stats reporter statsd") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == CFG_STATS_NODE);
+ srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
+ OSMO_ASSERT(srep != NULL);
+ OSMO_ASSERT(srep->type == OSMO_STATS_REPORTER_STATSD);
+ check_srep_vty_config(vty, srep);
+ OSMO_ASSERT(do_vty_command(vty, "exit") == CMD_SUCCESS);
+ OSMO_ASSERT(vty->node == CONFIG_NODE);
+
+ /* Destroy log reporter */
+ OSMO_ASSERT(osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL));
+ OSMO_ASSERT(do_vty_command(vty, "no stats reporter log") == CMD_SUCCESS);
+ OSMO_ASSERT(!osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL));
+
+ /* Destroy statsd reporter */
+ OSMO_ASSERT(osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL));
+ OSMO_ASSERT(do_vty_command(vty, "no stats reporter statsd") == CMD_SUCCESS);
+ OSMO_ASSERT(!osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL));
+
+ destroy_test_vty(&test, vty);
+}
+
int main(int argc, char **argv)
{
struct vty_app_info vty_info = {
@@ -188,18 +305,28 @@ int main(int argc, char **argv)
.cat = default_categories,
.num_cat = ARRAY_SIZE(default_categories),
};
+ void *stats_ctx = talloc_named_const(NULL, 1, "stats test context");
+
osmo_signal_register_handler(SS_L_VTY, vty_event_cb, NULL);
/* Fake logging. */
osmo_init_logging(&log_info);
+ /* Init stats */
+ osmo_stats_init(stats_ctx);
+
vty_init(&vty_info);
/* Setup VTY commands */
logging_vty_add_cmds(&log_info);
+ osmo_stats_vty_add_cmds();
test_cmd_string_from_valstr();
test_node_tree_structure();
+ test_stats_vty();
+
+ /* Leak check */
+ OSMO_ASSERT(talloc_total_blocks(stats_ctx) == 1);
printf("All tests passed\n");
diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok
index c6365907..a9e283d9 100644
--- a/tests/vty/vty_test.ok
+++ b/tests/vty/vty_test.ok
@@ -43,4 +43,71 @@ Going to execute 'end'
Returned: 0, Current node: 3 '%s# '
Going to execute 'exit'
Returned: 0, Current node: 3 '%s# '
+Going to test VTY configuration of the stats subsystem
+Going to execute 'enable'
+Returned: 0, Current node: 3 '%s# '
+Going to execute 'configure terminal'
+Returned: 0, Current node: 4 '%s(config)# '
+Going to execute 'stats reporter foobar'
+Returned: 2, Current node: 4 '%s(config)# '
+Going to execute 'stats interval 42'
+Returned: 0, Current node: 4 '%s(config)# '
+Going to execute 'stats reporter log'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'prefix myprefix'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'no prefix'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level peer'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level subscriber'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level global'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level foobar'
+Returned: 2, Current node: 8 '%s(config-stats)# '
+Going to execute 'enable'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'disable'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'exit'
+Returned: 0, Current node: 4 '%s(config)# '
+Going to execute 'stats reporter statsd'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'prefix myprefix'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'no prefix'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level peer'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level subscriber'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level global'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'level foobar'
+Returned: 2, Current node: 8 '%s(config-stats)# '
+Going to execute 'remote-ip 127.0.0.99'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'remote-ip 678.0.0.99'
+Returned: 1, Current node: 8 '%s(config-stats)# '
+Going to execute 'remote-port 12321'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'local-ip 127.0.0.98'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'no local-ip'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'mtu 987'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'no mtu'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'enable'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'disable'
+Returned: 0, Current node: 8 '%s(config-stats)# '
+Going to execute 'exit'
+Returned: 0, Current node: 4 '%s(config)# '
+Going to execute 'no stats reporter log'
+Returned: 0, Current node: 4 '%s(config)# '
+Going to execute 'no stats reporter statsd'
+Returned: 0, Current node: 4 '%s(config)# '
All tests passed