]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/cli/common_cli.c
*: make consistent & update GPLv2 file headers
[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 "memory_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,
36 int argc, struct cmd_token *argv[])
37 {
38 int i;
39 vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE);
40 for (i = 0; i < argc; i++)
41 {
42 vty_out (vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE);
43 }
44
45 return CMD_SUCCESS;
46 }
47
48 static void vty_do_exit(void)
49 {
50 printf ("\nend.\n");
51 cmd_terminate ();
52 vty_terminate ();
53 thread_master_free (master);
54 closezlog ();
55
56 log_memstats_stderr ("testcli");
57 exit (0);
58 }
59
60 /* main routine. */
61 int
62 main (int argc, char **argv)
63 {
64 struct thread thread;
65
66 /* Set umask before anything for security */
67 umask (0027);
68
69 /* master init. */
70 master = thread_master_create ();
71
72 openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
73 LOG_DAEMON);
74 zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
75 zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED);
76 zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG);
77
78 /* Library inits. */
79 cmd_init (1);
80 cmd_hostname_set ("test");
81
82 vty_init (master);
83 memory_init ();
84
85 test_init (argc, argv);
86
87 vty_stdio (vty_do_exit);
88
89 /* Fetch next active thread. */
90 while (thread_fetch (master, &thread))
91 thread_call (&thread);
92
93 /* Not reached. */
94 exit (0);
95 }
96