]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/cli/common_cli.c
Merge pull request #9649 from proelbtn/add-support-for-end-dt4
[mirror_frr.git] / tests / lib / cli / common_cli.c
1 /*
2 * generic CLI test helper functions
3 *
4 * Copyright (C) 2015 by David Lamparter,
5 * for Open Source Routing / NetDEF, Inc.
6 *
7 * Quagga is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * Quagga is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23
24 #include "thread.h"
25 #include "vty.h"
26 #include "command.h"
27 #include "memory.h"
28 #include "lib_vty.h"
29 #include "log.h"
30
31 #include "common_cli.h"
32
33 struct thread_master *master;
34
35 int dump_args(struct vty *vty, const char *descr, int argc,
36 struct cmd_token *argv[])
37 {
38 int i;
39 vty_out(vty, "%s with %d args.\n", descr, argc);
40 for (i = 0; i < argc; i++) {
41 vty_out(vty, "[%02d] %s@%s: %s\n", i, argv[i]->text,
42 argv[i]->varname, argv[i]->arg);
43 }
44
45 return CMD_SUCCESS;
46 }
47
48 static void vty_do_exit(int isexit)
49 {
50 printf("\nend.\n");
51 cmd_terminate();
52 vty_terminate();
53 nb_terminate();
54 yang_terminate();
55 thread_master_free(master);
56
57 log_memstats(stderr, "testcli");
58 if (!isexit)
59 exit(0);
60 }
61
62 const struct frr_yang_module_info *const *test_yang_modules = NULL;
63 int test_log_prio = ZLOG_DISABLED;
64
65 /* main routine. */
66 int main(int argc, char **argv)
67 {
68 struct thread thread;
69 size_t yangcount;
70
71 /* Set umask before anything for security */
72 umask(0027);
73
74 /* master init. */
75 master = thread_master_create(NULL);
76
77 zlog_aux_init("NONE: ", test_log_prio);
78
79 /* Library inits. */
80 cmd_init(1);
81 cmd_hostname_set("test");
82 cmd_domainname_set("test.domain");
83
84 vty_init(master, false);
85 lib_cmd_init();
86
87 for (yangcount = 0; test_yang_modules && test_yang_modules[yangcount];
88 yangcount++)
89 ;
90 nb_init(master, test_yang_modules, yangcount, false);
91
92 test_init(argc, argv);
93
94 vty_stdio(vty_do_exit);
95
96 /* Fetch next active thread. */
97 while (thread_fetch(master, &thread))
98 thread_call(&thread);
99
100 /* Not reached. */
101 exit(0);
102 }