aboutsummaryrefslogtreecommitdiffstats
path: root/tests/vty
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-11-03 13:47:11 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-08-22 01:31:31 +0000
commitca6602f476775e1b55c5a1d41bc323c49b9e4290 (patch)
tree6e9610f4debe8a3ef6bad74055508d702f56ab89 /tests/vty
parentee2657f6af4b81f98cfdfd900a82d9a350ff3642 (diff)
vty/test: Refactor vty creation/deletion into separate functions
Currently this is part of the only test function that uses the vty directly. In preperation for more such test cases, this commit moves this code into separate functions. Sponsored-by: On-Waves ehf
Diffstat (limited to 'tests/vty')
-rw-r--r--tests/vty/vty_test.c75
1 files changed, 46 insertions, 29 deletions
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index 2a7347f..258a144 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -86,40 +86,36 @@ static int vty_event_cb(unsigned int subsys, unsigned int signal,
return 0;
}
-static void test_node_tree_structure(void)
-{
- struct vty_app_info vty_info = {
- .name = "VtyTest",
- .version = 0,
- .go_parent_cb = NULL,
- .is_config_node = NULL,
- };
-
- const struct log_info_cat default_categories[] = {};
-
- const struct log_info log_info = {
- .cat = default_categories,
- .num_cat = ARRAY_SIZE(default_categories),
- };
-
- struct vty *vty;
+struct vty_test {
int sock[2];
+};
- printf("Going to test VTY node tree structure\n");
-
- /* Fake logging. */
- osmo_init_logging(&log_info);
+static struct vty* create_test_vty(struct vty_test *data)
+{
+ struct vty *vty;
+ /* Fake connection. */
+ socketpair(AF_UNIX, SOCK_STREAM, 0, data->sock);
- vty_init(&vty_info);
+ vty = vty_create(data->sock[0], NULL);
+ OSMO_ASSERT(vty != NULL);
+ OSMO_ASSERT(vty->status != VTY_CLOSE);
- logging_vty_add_cmds(&log_info);
+ return vty;
+}
- /* Fake connection. */
- socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
+static void destroy_test_vty(struct vty_test *data, struct vty *vty)
+{
+ vty_close(vty);
+ OSMO_ASSERT(last_vty_connection_event == VTY_CLOSED);
+}
- vty = vty_create(sock[0], NULL);
+static void test_node_tree_structure(void)
+{
+ struct vty_test test;
+ struct vty *vty;
- OSMO_ASSERT(vty != NULL);
+ printf("Going to test VTY node tree structure\n");
+ vty = create_test_vty(&test);
OSMO_ASSERT(do_vty_command(vty, "enable") == CMD_SUCCESS);
OSMO_ASSERT(vty->node == ENABLE_NODE);
@@ -174,16 +170,37 @@ static void test_node_tree_structure(void)
OSMO_ASSERT(vty->node == ENABLE_NODE);
OSMO_ASSERT(vty->status == VTY_CLOSE);
- vty_close(vty);
- OSMO_ASSERT(last_vty_connection_event == VTY_CLOSED);
+ destroy_test_vty(&test, vty);
}
int main(int argc, char **argv)
{
+ struct vty_app_info vty_info = {
+ .name = "VtyTest",
+ .version = 0,
+ .go_parent_cb = NULL,
+ .is_config_node = NULL,
+ };
+
+ const struct log_info_cat default_categories[] = {};
+
+ const struct log_info log_info = {
+ .cat = default_categories,
+ .num_cat = ARRAY_SIZE(default_categories),
+ };
osmo_signal_register_handler(SS_L_VTY, vty_event_cb, NULL);
+ /* Fake logging. */
+ osmo_init_logging(&log_info);
+
+ vty_init(&vty_info);
+
+ /* Setup VTY commands */
+ logging_vty_add_cmds(&log_info);
+
test_cmd_string_from_valstr();
test_node_tree_structure();
+
printf("All tests passed\n");
return 0;