]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/cli/common_cli.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / lib / cli / common_cli.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * generic CLI test helper functions
4 *
5 * Copyright (C) 2015 by David Lamparter,
6 * for Open Source Routing / NetDEF, Inc.
7 */
8
9 #include <zebra.h>
10
11 #include "thread.h"
12 #include "vty.h"
13 #include "command.h"
14 #include "memory.h"
15 #include "lib_vty.h"
16 #include "log.h"
17
18 #include "common_cli.h"
19
20 struct thread_master *master;
21
22 int dump_args(struct vty *vty, const char *descr, int argc,
23 struct cmd_token *argv[])
24 {
25 int i;
26 vty_out(vty, "%s with %d args.\n", descr, argc);
27 for (i = 0; i < argc; i++) {
28 vty_out(vty, "[%02d] %s@%s: %s\n", i, argv[i]->text,
29 argv[i]->varname, argv[i]->arg);
30 }
31
32 return CMD_SUCCESS;
33 }
34
35 static void vty_do_exit(int isexit)
36 {
37 printf("\nend.\n");
38 cmd_terminate();
39 vty_terminate();
40 nb_terminate();
41 yang_terminate();
42 thread_master_free(master);
43
44 log_memstats(stderr, "testcli");
45 if (!isexit)
46 exit(0);
47 }
48
49 const struct frr_yang_module_info *const *test_yang_modules = NULL;
50 int test_log_prio = ZLOG_DISABLED;
51
52 /* main routine. */
53 int main(int argc, char **argv)
54 {
55 struct thread thread;
56 size_t yangcount;
57
58 /* Set umask before anything for security */
59 umask(0027);
60
61 /* master init. */
62 master = thread_master_create(NULL);
63
64 zlog_aux_init("NONE: ", test_log_prio);
65
66 /* Library inits. */
67 cmd_init(1);
68 cmd_hostname_set("test");
69 cmd_domainname_set("test.domain");
70
71 vty_init(master, false);
72 lib_cmd_init();
73
74 for (yangcount = 0; test_yang_modules && test_yang_modules[yangcount];
75 yangcount++)
76 ;
77 nb_init(master, test_yang_modules, yangcount, false);
78
79 test_init(argc, argv);
80
81 vty_stdio(vty_do_exit);
82
83 /* Fetch next active thread. */
84 while (thread_fetch(master, &thread))
85 thread_call(&thread);
86
87 /* Not reached. */
88 exit(0);
89 }