diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2017-09-20 01:49:11 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2017-09-20 03:32:24 +0200 |
commit | b022c867e86333ceaad9027e2e7ee621ab3891e5 (patch) | |
tree | 78cffde4886b1650bf13c0f882f990ea7a245060 /tests | |
parent | 00b5ed3d921f2f39e60ed372809c33b8bce78ad8 (diff) |
vty_test: add artificial node levels for better testing
In vty_test, add three levels of parent nodes (level1, level2, level3) with
each having a leaf child (child1, child2, child3).
Use these to enhance the vty_test cfg files and test more diverse situations.
The current VTY code expects a go_parent_cb() to be present, otherwise it will
bump right back to the CONFIG_NODE, which will not work with more than one node
level below the CONFIG_NODE. Hence provide a minimal go_parent_cb().
Change-Id: Ib9bcf58b655fbd85e196f363fb7d8305d7dfc997
Diffstat (limited to 'tests')
-rw-r--r-- | tests/vty/fail_not_de-indented.cfg | 6 | ||||
-rw-r--r-- | tests/vty/fail_tabs_and_spaces.cfg | 8 | ||||
-rw-r--r-- | tests/vty/fail_too_much_indent.cfg | 6 | ||||
-rw-r--r-- | tests/vty/ok.cfg | 31 | ||||
-rw-r--r-- | tests/vty/ok_empty_parent.cfg | 24 | ||||
-rw-r--r-- | tests/vty/ok_ignore_blank.cfg | 15 | ||||
-rw-r--r-- | tests/vty/ok_ignore_comment.cfg | 9 | ||||
-rw-r--r-- | tests/vty/ok_indented_root.cfg | 8 | ||||
-rw-r--r-- | tests/vty/ok_more_spaces.cfg | 32 | ||||
-rw-r--r-- | tests/vty/ok_tabs.cfg | 32 | ||||
-rw-r--r-- | tests/vty/ok_tabs_and_spaces.cfg | 32 | ||||
-rw-r--r-- | tests/vty/vty_test.c | 120 | ||||
-rw-r--r-- | tests/vty/vty_test.ok | 156 |
13 files changed, 440 insertions, 39 deletions
diff --git a/tests/vty/fail_not_de-indented.cfg b/tests/vty/fail_not_de-indented.cfg index 5af833da..ca5a3cde 100644 --- a/tests/vty/fail_not_de-indented.cfg +++ b/tests/vty/fail_not_de-indented.cfg @@ -1,3 +1,3 @@ -line vty - no login - log stderr +level1 a + child1 a + level1 b diff --git a/tests/vty/fail_tabs_and_spaces.cfg b/tests/vty/fail_tabs_and_spaces.cfg index fa6ce059..4cb0cf5b 100644 --- a/tests/vty/fail_tabs_and_spaces.cfg +++ b/tests/vty/fail_tabs_and_spaces.cfg @@ -1,4 +1,4 @@ -line vty - no login - no login -log stderr +level1 a + child1 a + child1 b +level1 b diff --git a/tests/vty/fail_too_much_indent.cfg b/tests/vty/fail_too_much_indent.cfg index bacb3e1e..3446a059 100644 --- a/tests/vty/fail_too_much_indent.cfg +++ b/tests/vty/fail_too_much_indent.cfg @@ -1,3 +1,3 @@ -line vty - no login - log stderr +level1 a + child1 a + level1 b diff --git a/tests/vty/ok.cfg b/tests/vty/ok.cfg index d5ef23e4..f562348e 100644 --- a/tests/vty/ok.cfg +++ b/tests/vty/ok.cfg @@ -1,3 +1,28 @@ -line vty - no login -log stderr +level1 a + child1 a + level2 a + child2 a + level3 a + child3 a +level1 b + child1 b + level2 b + child2 b +level1 c + child1 c + level2 c + child2 c + level3 c + child3 c + level2 d + child2 d +level1 e + child1 e + level2 e + child2 e + level2 f + child2 f +level1 g + child1 g +level1 h + child1 h diff --git a/tests/vty/ok_empty_parent.cfg b/tests/vty/ok_empty_parent.cfg index fe04fcfa..40dd3725 100644 --- a/tests/vty/ok_empty_parent.cfg +++ b/tests/vty/ok_empty_parent.cfg @@ -1,2 +1,22 @@ -line vty -log stderr +level1 a + level2 a + level3 a +level1 b + level2 b +level1 c +level1 d + level2 e + level2 f + level3 f + level3 g + level2 g + level2 h +level1 h +level1 i +level1 j + level2 j + child1 j +level1 k + level2 k + level3 k + child1 k diff --git a/tests/vty/ok_ignore_blank.cfg b/tests/vty/ok_ignore_blank.cfg index d16ff64e..a4a8bcb8 100644 --- a/tests/vty/ok_ignore_blank.cfg +++ b/tests/vty/ok_ignore_blank.cfg @@ -1,7 +1,14 @@ -line vty +level1 - no login + level2 - no login + child2 + -log stderr + + level3 + + + child3 + +level1 diff --git a/tests/vty/ok_ignore_comment.cfg b/tests/vty/ok_ignore_comment.cfg index 5813fc7c..1d6d87ea 100644 --- a/tests/vty/ok_ignore_comment.cfg +++ b/tests/vty/ok_ignore_comment.cfg @@ -1,7 +1,8 @@ -line vty +level1 ! comment - no login + child1 ! comment - no login + level2 ! comment -log stderr + child2 +level1 diff --git a/tests/vty/ok_indented_root.cfg b/tests/vty/ok_indented_root.cfg index 313c6742..b7487f6b 100644 --- a/tests/vty/ok_indented_root.cfg +++ b/tests/vty/ok_indented_root.cfg @@ -1,3 +1,5 @@ - line vty - no login - log stderr + level1 a + child1 + level2 + child2 + level1 b diff --git a/tests/vty/ok_more_spaces.cfg b/tests/vty/ok_more_spaces.cfg index b66a9c21..263c6820 100644 --- a/tests/vty/ok_more_spaces.cfg +++ b/tests/vty/ok_more_spaces.cfg @@ -1,4 +1,28 @@ -line vty - no login - no login -log stderr +level1 a + child1 a + level2 a + child2 a + level3 a + child3 a +level1 b + child1 b + level2 b + child2 b +level1 c + child1 c + level2 c + child2 c + level3 c + child3 c + level2 d + child2 d +level1 e + child1 e + level2 e + child2 e + level2 f + child2 f +level1 g + child1 g +level1 h + child1 h diff --git a/tests/vty/ok_tabs.cfg b/tests/vty/ok_tabs.cfg index e94609b7..3f6085d2 100644 --- a/tests/vty/ok_tabs.cfg +++ b/tests/vty/ok_tabs.cfg @@ -1,4 +1,28 @@ -line vty - no login - no login -log stderr +level1 a + child1 a + level2 a + child2 a + level3 a + child3 a +level1 b + child1 b + level2 b + child2 b +level1 c + child1 c + level2 c + child2 c + level3 c + child3 c + level2 d + child2 d +level1 e + child1 e + level2 e + child2 e + level2 f + child2 f +level1 g + child1 g +level1 h + child1 h diff --git a/tests/vty/ok_tabs_and_spaces.cfg b/tests/vty/ok_tabs_and_spaces.cfg index 2049b732..1922aadd 100644 --- a/tests/vty/ok_tabs_and_spaces.cfg +++ b/tests/vty/ok_tabs_and_spaces.cfg @@ -1,4 +1,28 @@ -line vty - no login - no login -log stderr +level1 a + child1 a + level2 a + child2 a + level3 a + child3 a +level1 b + child1 b + level2 b + child2 b +level1 c + child1 c + level2 c + child2 c + level3 c + child3 c + level2 d + child2 d +level1 e + child1 e + level2 e + child2 e + level2 f + child2 f +level1 g + child1 g +level1 h + child1 h diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index d9af6aee..fe50e4c2 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -298,12 +298,128 @@ void test_exit_by_indent(const char *fname, int expect_rc) OSMO_ASSERT(rc == expect_rc); } +enum test_nodes { + LEVEL1_NODE = _LAST_OSMOVTY_NODE + 1, + LEVEL2_NODE, + LEVEL3_NODE, +}; + +struct cmd_node level1_node = { + LEVEL1_NODE, + "%s(config-level1)# ", + 1 +}; + +struct cmd_node level2_node = { + LEVEL2_NODE, + "%s(config-level1-level2)# ", + 1 +}; + +struct cmd_node level3_node = { + LEVEL3_NODE, + "%s(config-level1-level2-level3)# ", + 1 +}; + +DEFUN(cfg_level1, cfg_level1_cmd, + "level1 [MARKER]", + "Level 1 node for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + vty->index = NULL; + vty->node = LEVEL1_NODE; + printf("called level1 node %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +DEFUN(cfg_level1_child, cfg_level1_child_cmd, + "child1 [MARKER]", + "Level 1 child cmd for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + printf("called level1 child cmd %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +DEFUN(cfg_level2, cfg_level2_cmd, + "level2 [MARKER]", + "Level 2 node for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + vty->index = NULL; + vty->node = LEVEL2_NODE; + printf("called level2 node %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +DEFUN(cfg_level2_child, cfg_level2_child_cmd, + "child2 [MARKER]", + "Level 2 child cmd for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + printf("called level2 child cmd %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +DEFUN(cfg_level3, cfg_level3_cmd, + "level3 [MARKER]", + "Level 3 node for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + vty->index = NULL; + vty->node = LEVEL3_NODE; + printf("called level3 node %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +DEFUN(cfg_level3_child, cfg_level3_child_cmd, + "child3 [MARKER]", + "Level 3 child cmd for VTY testing purposes\n" + "optional string to mark the line for test debugging\n") +{ + printf("called level3 child cmd %s\n", argc? argv[0] : ""); + return CMD_SUCCESS; +} + +void test_vty_add_cmds() +{ + install_element(CONFIG_NODE, &cfg_level1_cmd); + install_node(&level1_node, NULL); + vty_install_default(LEVEL1_NODE); + install_element(LEVEL1_NODE, &cfg_level1_child_cmd); + install_element(LEVEL1_NODE, &cfg_level2_cmd); + + install_node(&level2_node, NULL); + vty_install_default(LEVEL2_NODE); + install_element(LEVEL2_NODE, &cfg_level2_child_cmd); + install_element(LEVEL2_NODE, &cfg_level3_cmd); + + install_node(&level3_node, NULL); + vty_install_default(LEVEL3_NODE); + install_element(LEVEL3_NODE, &cfg_level3_child_cmd); +} + +static int go_parent_cb(struct vty *vty) +{ + /* + * - For the interactive VTY tests above, it is expected to bounce back to + * the CONFIG_NODE. Hence do so in go_parent_cb(). + * - In the config file parsing tests, setting vty->node in go_parent_cb() has no + * effect, because we will subsequently pop a parent node from the parent stack + * and override to go to the node that was recorded as the actual parent. + */ + vty->node = CONFIG_NODE; + vty->index = NULL; + return 0; +} + int main(int argc, char **argv) { struct vty_app_info vty_info = { .name = "VtyTest", .version = 0, - .go_parent_cb = NULL, + .go_parent_cb = go_parent_cb, .is_config_node = NULL, }; @@ -329,6 +445,8 @@ int main(int argc, char **argv) logging_vty_add_cmds(); osmo_stats_vty_add_cmds(); + test_vty_add_cmds(); + test_cmd_string_from_valstr(); test_node_tree_structure(); test_stats_vty(); diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok index f9fea34d..bd6c5d66 100644 --- a/tests/vty/vty_test.ok +++ b/tests/vty/vty_test.ok @@ -109,25 +109,181 @@ Returned: 0, Current node: 4 '%s(config)# ' Going to execute 'no stats reporter statsd' Returned: 0, Current node: 4 '%s(config)# ' reading file ok.cfg, expecting rc=0 +called level1 node a +called level1 child cmd a +called level2 node a +called level2 child cmd a +called level3 node a +called level3 child cmd a +called level1 node b +called level1 child cmd b +called level2 node b +called level2 child cmd b +called level1 node c +called level1 child cmd c +called level2 node c +called level2 child cmd c +called level3 node c +called level3 child cmd c +called level2 node d +called level2 child cmd d +called level1 node e +called level1 child cmd e +called level2 node e +called level2 child cmd e +called level2 node f +called level2 child cmd f +called level1 node g +called level1 child cmd g +called level1 node h +called level1 child cmd h got rc=0 reading file ok_more_spaces.cfg, expecting rc=0 +called level1 node a +called level1 child cmd a +called level2 node a +called level2 child cmd a +called level3 node a +called level3 child cmd a +called level1 node b +called level1 child cmd b +called level2 node b +called level2 child cmd b +called level1 node c +called level1 child cmd c +called level2 node c +called level2 child cmd c +called level3 node c +called level3 child cmd c +called level2 node d +called level2 child cmd d +called level1 node e +called level1 child cmd e +called level2 node e +called level2 child cmd e +called level2 node f +called level2 child cmd f +called level1 node g +called level1 child cmd g +called level1 node h +called level1 child cmd h got rc=0 reading file ok_tabs.cfg, expecting rc=0 +called level1 node a +called level1 child cmd a +called level2 node a +called level2 child cmd a +called level3 node a +called level3 child cmd a +called level1 node b +called level1 child cmd b +called level2 node b +called level2 child cmd b +called level1 node c +called level1 child cmd c +called level2 node c +called level2 child cmd c +called level3 node c +called level3 child cmd c +called level2 node d +called level2 child cmd d +called level1 node e +called level1 child cmd e +called level2 node e +called level2 child cmd e +called level2 node f +called level2 child cmd f +called level1 node g +called level1 child cmd g +called level1 node h +called level1 child cmd h got rc=0 reading file ok_tabs_and_spaces.cfg, expecting rc=0 +called level1 node a +called level1 child cmd a +called level2 node a +called level2 child cmd a +called level3 node a +called level3 child cmd a +called level1 node b +called level1 child cmd b +called level2 node b +called level2 child cmd b +called level1 node c +called level1 child cmd c +called level2 node c +called level2 child cmd c +called level3 node c +called level3 child cmd c +called level2 node d +called level2 child cmd d +called level1 node e +called level1 child cmd e +called level2 node e +called level2 child cmd e +called level2 node f +called level2 child cmd f +called level1 node g +called level1 child cmd g +called level1 node h +called level1 child cmd h got rc=0 reading file ok_ignore_comment.cfg, expecting rc=0 +called level1 node +called level1 child cmd +called level2 node +called level2 child cmd +called level1 node got rc=0 reading file ok_ignore_blank.cfg, expecting rc=0 +called level1 node +called level2 node +called level2 child cmd +called level3 node +called level3 child cmd +called level1 node got rc=0 reading file fail_not_de-indented.cfg, expecting rc=-22 +called level1 node a +called level1 child cmd a got rc=-22 reading file fail_too_much_indent.cfg, expecting rc=-22 +called level1 node a +called level1 child cmd a got rc=-22 reading file fail_tabs_and_spaces.cfg, expecting rc=-22 +called level1 node a +called level1 child cmd a got rc=-22 reading file ok_indented_root.cfg, expecting rc=0 +called level1 node a +called level1 child cmd +called level2 node +called level2 child cmd +called level1 node b got rc=0 reading file ok_empty_parent.cfg, expecting rc=0 +called level1 node a +called level2 node a +called level3 node a +called level1 node b +called level2 node b +called level1 node c +called level1 node d +called level2 node e +called level2 node f +called level3 node f +called level3 node g +called level2 node g +called level2 node h +called level1 node h +called level1 node i +called level1 node j +called level2 node j +called level1 child cmd j +called level1 node k +called level2 node k +called level3 node k +called level1 child cmd k got rc=0 All tests passed |