]> git.proxmox.com Git - mirror_frr.git/blame - tests/lib/cli/common_cli.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / tests / lib / cli / common_cli.c
CommitLineData
2bb57c68
DL
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 *
896014f4
DL
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
2bb57c68
DL
20 */
21
22#include <zebra.h>
23
24#include "thread.h"
25#include "vty.h"
26#include "command.h"
27#include "memory.h"
fc7948fa 28#include "memory_vty.h"
2bb57c68
DL
29#include "log.h"
30
ca49a76b 31#include "common_cli.h"
2bb57c68
DL
32
33struct thread_master *master;
34
35int dump_args(struct vty *vty, const char *descr,
6a23719c 36 int argc, struct cmd_token *argv[])
2bb57c68
DL
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 {
6a23719c 42 vty_out (vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE);
2bb57c68
DL
43 }
44
45 return CMD_SUCCESS;
46}
47
48static void vty_do_exit(void)
49{
50 printf ("\nend.\n");
3a8b1ac0
DL
51 cmd_terminate ();
52 vty_terminate ();
53 thread_master_free (master);
bf1013e6 54 closezlog ();
3a8b1ac0
DL
55
56 log_memstats_stderr ("testcli");
2bb57c68
DL
57 exit (0);
58}
59
60/* main routine. */
61int
62main (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
bf1013e6
DL
72 openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
73 LOG_DAEMON);
dd8376fe
DL
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);
2bb57c68
DL
77
78 /* Library inits. */
79 cmd_init (1);
bff9c3e9 80 cmd_hostname_set ("test");
2bb57c68
DL
81
82 vty_init (master);
83 memory_init ();
84
fdc3d1ab 85 test_init (argc, argv);
2bb57c68
DL
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