]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2bb57c68 DL |
2 | /* |
3 | * generic CLI test helper functions | |
4 | * | |
5 | * Copyright (C) 2015 by David Lamparter, | |
6 | * for Open Source Routing / NetDEF, Inc. | |
2bb57c68 DL |
7 | */ |
8 | ||
9 | #include <zebra.h> | |
10 | ||
11 | #include "thread.h" | |
12 | #include "vty.h" | |
13 | #include "command.h" | |
14 | #include "memory.h" | |
1c0d8808 | 15 | #include "lib_vty.h" |
2bb57c68 DL |
16 | #include "log.h" |
17 | ||
ca49a76b | 18 | #include "common_cli.h" |
2bb57c68 DL |
19 | |
20 | struct thread_master *master; | |
21 | ||
d62a17ae | 22 | int dump_args(struct vty *vty, const char *descr, int argc, |
23 | struct cmd_token *argv[]) | |
2bb57c68 | 24 | { |
d62a17ae | 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; | |
2bb57c68 DL |
33 | } |
34 | ||
154b9e8f | 35 | static void vty_do_exit(int isexit) |
2bb57c68 | 36 | { |
d62a17ae | 37 | printf("\nend.\n"); |
38 | cmd_terminate(); | |
39 | vty_terminate(); | |
1c2facd1 RW |
40 | nb_terminate(); |
41 | yang_terminate(); | |
d62a17ae | 42 | thread_master_free(master); |
d62a17ae | 43 | |
9eed278b | 44 | log_memstats(stderr, "testcli"); |
154b9e8f DL |
45 | if (!isexit) |
46 | exit(0); | |
2bb57c68 DL |
47 | } |
48 | ||
f8f4aec3 | 49 | const struct frr_yang_module_info *const *test_yang_modules = NULL; |
865dd9fe | 50 | int test_log_prio = ZLOG_DISABLED; |
f8f4aec3 | 51 | |
2bb57c68 | 52 | /* main routine. */ |
d62a17ae | 53 | int main(int argc, char **argv) |
2bb57c68 | 54 | { |
d62a17ae | 55 | struct thread thread; |
f8f4aec3 | 56 | size_t yangcount; |
2bb57c68 | 57 | |
d62a17ae | 58 | /* Set umask before anything for security */ |
59 | umask(0027); | |
2bb57c68 | 60 | |
d62a17ae | 61 | /* master init. */ |
62 | master = thread_master_create(NULL); | |
2bb57c68 | 63 | |
865dd9fe | 64 | zlog_aux_init("NONE: ", test_log_prio); |
2bb57c68 | 65 | |
d62a17ae | 66 | /* Library inits. */ |
67 | cmd_init(1); | |
68 | cmd_hostname_set("test"); | |
e4cdd7cc | 69 | cmd_domainname_set("test.domain"); |
2bb57c68 | 70 | |
2950f5da | 71 | vty_init(master, false); |
1c0d8808 | 72 | lib_cmd_init(); |
f8f4aec3 DL |
73 | |
74 | for (yangcount = 0; test_yang_modules && test_yang_modules[yangcount]; | |
75 | yangcount++) | |
76 | ; | |
77 | nb_init(master, test_yang_modules, yangcount, false); | |
2bb57c68 | 78 | |
d62a17ae | 79 | test_init(argc, argv); |
2bb57c68 | 80 | |
d62a17ae | 81 | vty_stdio(vty_do_exit); |
2bb57c68 | 82 | |
d62a17ae | 83 | /* Fetch next active thread. */ |
84 | while (thread_fetch(master, &thread)) | |
85 | thread_call(&thread); | |
2bb57c68 | 86 | |
d62a17ae | 87 | /* Not reached. */ |
88 | exit(0); | |
2bb57c68 | 89 | } |