summaryrefslogtreecommitdiffstats
path: root/tests/lib/cli
diff options
context:
space:
mode:
authorwhitespace / reindent <invalid@invalid.invalid>2017-07-17 14:03:14 +0200
committerwhitespace / reindent <invalid@invalid.invalid>2017-07-17 14:04:07 +0200
commitd62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch)
tree3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /tests/lib/cli
parent*: add indent control files (diff)
downloadfrr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.tar.xz
frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.zip
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/lib/cli')
-rw-r--r--tests/lib/cli/common_cli.c84
-rw-r--r--tests/lib/cli/common_cli.h22
-rw-r--r--tests/lib/cli/test_cli.c86
-rw-r--r--tests/lib/cli/test_commands.c575
4 files changed, 353 insertions, 414 deletions
diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c
index f1b07ce22..b6df6d3b8 100644
--- a/tests/lib/cli/common_cli.c
+++ b/tests/lib/cli/common_cli.c
@@ -32,65 +32,63 @@
struct thread_master *master;
-int dump_args(struct vty *vty, const char *descr,
- int argc, struct cmd_token *argv[])
+int dump_args(struct vty *vty, const char *descr, int argc,
+ struct cmd_token *argv[])
{
- int i;
- vty_out (vty, "%s with %d args.\n", descr, argc);
- for (i = 0; i < argc; i++)
- {
- vty_out (vty, "[%02d] %s@%s: %s\n", i, argv[i]->text, argv[i]->varname, argv[i]->arg);
- }
-
- return CMD_SUCCESS;
+ int i;
+ vty_out(vty, "%s with %d args.\n", descr, argc);
+ for (i = 0; i < argc; i++) {
+ vty_out(vty, "[%02d] %s@%s: %s\n", i, argv[i]->text,
+ argv[i]->varname, argv[i]->arg);
+ }
+
+ return CMD_SUCCESS;
}
static void vty_do_exit(void)
{
- printf ("\nend.\n");
- cmd_terminate ();
- vty_terminate ();
- thread_master_free (master);
- closezlog ();
-
- log_memstats_stderr ("testcli");
- exit (0);
+ printf("\nend.\n");
+ cmd_terminate();
+ vty_terminate();
+ thread_master_free(master);
+ closezlog();
+
+ log_memstats_stderr("testcli");
+ exit(0);
}
/* main routine. */
-int
-main (int argc, char **argv)
+int main(int argc, char **argv)
{
- struct thread thread;
+ struct thread thread;
- /* Set umask before anything for security */
- umask (0027);
+ /* Set umask before anything for security */
+ umask(0027);
- /* master init. */
- master = thread_master_create(NULL);
+ /* master init. */
+ master = thread_master_create(NULL);
- openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
- LOG_DAEMON);
- zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG);
+ openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
+ LOG_DAEMON);
+ zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG);
- /* Library inits. */
- cmd_init (1);
- cmd_hostname_set ("test");
+ /* Library inits. */
+ cmd_init(1);
+ cmd_hostname_set("test");
- vty_init (master);
- memory_init ();
+ vty_init(master);
+ memory_init();
- test_init (argc, argv);
+ test_init(argc, argv);
- vty_stdio (vty_do_exit);
+ vty_stdio(vty_do_exit);
- /* Fetch next active thread. */
- while (thread_fetch (master, &thread))
- thread_call (&thread);
+ /* Fetch next active thread. */
+ while (thread_fetch(master, &thread))
+ thread_call(&thread);
- /* Not reached. */
- exit (0);
+ /* Not reached. */
+ exit(0);
}
-
diff --git a/tests/lib/cli/common_cli.h b/tests/lib/cli/common_cli.h
index 9a0ef47c8..15abe3b85 100644
--- a/tests/lib/cli/common_cli.h
+++ b/tests/lib/cli/common_cli.h
@@ -27,22 +27,24 @@
#include "command.h"
/* function to be implemented by test */
-extern void test_init (int argc, char **argv);
+extern void test_init(int argc, char **argv);
/* functions provided by common cli
* (includes main())
*/
extern struct thread_master *master;
-extern int dump_args(struct vty *vty, const char *descr,
- int argc, struct cmd_token *argv[]);
+extern int dump_args(struct vty *vty, const char *descr, int argc,
+ struct cmd_token *argv[]);
-#define DUMMY_HELPSTR \
- "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n" \
- "10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n" \
- "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n"
-#define DUMMY_DEFUN(name, cmdstr) \
- DEFUN (name, name ## _cmd, cmdstr, DUMMY_HELPSTR) \
- { return dump_args(vty, #name, argc, argv); }
+#define DUMMY_HELPSTR \
+ "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n" \
+ "10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n" \
+ "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n"
+#define DUMMY_DEFUN(name, cmdstr) \
+ DEFUN(name, name##_cmd, cmdstr, DUMMY_HELPSTR) \
+ { \
+ return dump_args(vty, #name, argc, argv); \
+ }
#endif /* _COMMON_CLI_H */
diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c
index a4d3fb4e8..8f062d8b5 100644
--- a/tests/lib/cli/test_cli.c
+++ b/tests/lib/cli/test_cli.c
@@ -24,21 +24,22 @@
#include "prefix.h"
#include "common_cli.h"
-DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D");
-DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M");
-DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X$foo");
-DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M");
-DUMMY_DEFUN(cmd4, "arg range (5-15)");
-DUMMY_DEFUN(cmd5, "pat a < a|b>");
-DUMMY_DEFUN(cmd6, "pat b <a|b A.B.C.D$bar>");
-DUMMY_DEFUN(cmd7, "pat c <a | b|c> A.B.C.D");
-DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D$foo|bar X:X::X:X$bar| baz } [final]");
-DUMMY_DEFUN(cmd9, "pat e [ WORD ]");
+DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D");
+DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M");
+DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X$foo");
+DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M");
+DUMMY_DEFUN(cmd4, "arg range (5-15)");
+DUMMY_DEFUN(cmd5, "pat a < a|b>");
+DUMMY_DEFUN(cmd6, "pat b <a|b A.B.C.D$bar>");
+DUMMY_DEFUN(cmd7, "pat c <a | b|c> A.B.C.D");
+DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D$foo|bar X:X::X:X$bar| baz } [final]");
+DUMMY_DEFUN(cmd9, "pat e [ WORD ]");
DUMMY_DEFUN(cmd10, "pat f [key]");
DUMMY_DEFUN(cmd11, "alt a WORD");
DUMMY_DEFUN(cmd12, "alt a A.B.C.D");
DUMMY_DEFUN(cmd13, "alt a X:X::X:X");
-DUMMY_DEFUN(cmd14, "pat g { foo A.B.C.D$foo|foo|bar X:X::X:X$bar| baz } [final]");
+DUMMY_DEFUN(cmd14,
+ "pat g { foo A.B.C.D$foo|foo|bar X:X::X:X$bar| baz } [final]");
#include "tests/lib/cli/test_cli_clippy.c"
@@ -46,40 +47,41 @@ DEFPY(magic_test, magic_test_cmd,
"magic (0-100) {ipv4net A.B.C.D/M|X:X::X:X$ipv6}",
"1\n2\n3\n4\n5\n")
{
- char buf[256];
- vty_out(vty, "def: %s\n", self->string);
- vty_out(vty, "num: %ld\n", magic);
- vty_out(vty, "ipv4: %s\n", prefix2str(ipv4net, buf, sizeof(buf)));
- vty_out(vty, "ipv6: %s\n", inet_ntop(AF_INET6, &ipv6, buf, sizeof(buf)));
- return CMD_SUCCESS;
+ char buf[256];
+ vty_out(vty, "def: %s\n", self->string);
+ vty_out(vty, "num: %ld\n", magic);
+ vty_out(vty, "ipv4: %s\n", prefix2str(ipv4net, buf, sizeof(buf)));
+ vty_out(vty, "ipv6: %s\n",
+ inet_ntop(AF_INET6, &ipv6, buf, sizeof(buf)));
+ return CMD_SUCCESS;
}
void test_init(int argc, char **argv)
{
- size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223;
+ size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223;
- install_element (ENABLE_NODE, &cmd0_cmd);
- install_element (ENABLE_NODE, &cmd1_cmd);
- install_element (ENABLE_NODE, &cmd2_cmd);
- install_element (ENABLE_NODE, &cmd3_cmd);
- install_element (ENABLE_NODE, &cmd4_cmd);
- install_element (ENABLE_NODE, &cmd5_cmd);
- install_element (ENABLE_NODE, &cmd6_cmd);
- install_element (ENABLE_NODE, &cmd7_cmd);
- install_element (ENABLE_NODE, &cmd8_cmd);
- install_element (ENABLE_NODE, &cmd9_cmd);
- install_element (ENABLE_NODE, &cmd10_cmd);
- install_element (ENABLE_NODE, &cmd11_cmd);
- install_element (ENABLE_NODE, &cmd12_cmd);
- install_element (ENABLE_NODE, &cmd13_cmd);
- for (size_t i = 0; i < repeat; i++) {
- uninstall_element (ENABLE_NODE, &cmd5_cmd);
- install_element (ENABLE_NODE, &cmd5_cmd);
- }
- for (size_t i = 0; i < repeat; i++) {
- uninstall_element (ENABLE_NODE, &cmd13_cmd);
- install_element (ENABLE_NODE, &cmd13_cmd);
- }
- install_element (ENABLE_NODE, &cmd14_cmd);
- install_element (ENABLE_NODE, &magic_test_cmd);
+ install_element(ENABLE_NODE, &cmd0_cmd);
+ install_element(ENABLE_NODE, &cmd1_cmd);
+ install_element(ENABLE_NODE, &cmd2_cmd);
+ install_element(ENABLE_NODE, &cmd3_cmd);
+ install_element(ENABLE_NODE, &cmd4_cmd);
+ install_element(ENABLE_NODE, &cmd5_cmd);
+ install_element(ENABLE_NODE, &cmd6_cmd);
+ install_element(ENABLE_NODE, &cmd7_cmd);
+ install_element(ENABLE_NODE, &cmd8_cmd);
+ install_element(ENABLE_NODE, &cmd9_cmd);
+ install_element(ENABLE_NODE, &cmd10_cmd);
+ install_element(ENABLE_NODE, &cmd11_cmd);
+ install_element(ENABLE_NODE, &cmd12_cmd);
+ install_element(ENABLE_NODE, &cmd13_cmd);
+ for (size_t i = 0; i < repeat; i++) {
+ uninstall_element(ENABLE_NODE, &cmd5_cmd);
+ install_element(ENABLE_NODE, &cmd5_cmd);
+ }
+ for (size_t i = 0; i < repeat; i++) {
+ uninstall_element(ENABLE_NODE, &cmd13_cmd);
+ install_element(ENABLE_NODE, &cmd13_cmd);
+ }
+ install_element(ENABLE_NODE, &cmd14_cmd);
+ install_element(ENABLE_NODE, &magic_test_cmd);
}
diff --git a/tests/lib/cli/test_commands.c b/tests/lib/cli/test_commands.c
index 249a6f760..48dd99d28 100644
--- a/tests/lib/cli/test_commands.c
+++ b/tests/lib/cli/test_commands.c
@@ -48,360 +48,297 @@ struct thread_master *master; /* dummy for libfrr*/
static vector test_cmds;
static char test_buf[32768];
-static struct cmd_node bgp_node =
-{
- BGP_NODE,
- "%s(config-router)# ",
+static struct cmd_node bgp_node = {
+ BGP_NODE, "%s(config-router)# ",
};
-static struct cmd_node rip_node =
-{
- RIP_NODE,
- "%s(config-router)# ",
+static struct cmd_node rip_node = {
+ RIP_NODE, "%s(config-router)# ",
};
-static struct cmd_node isis_node =
-{
- ISIS_NODE,
- "%s(config-router)# ",
+static struct cmd_node isis_node = {
+ ISIS_NODE, "%s(config-router)# ",
};
-static struct cmd_node interface_node =
-{
- INTERFACE_NODE,
- "%s(config-if)# ",
+static struct cmd_node interface_node = {
+ INTERFACE_NODE, "%s(config-if)# ",
};
-static struct cmd_node rmap_node =
-{
- RMAP_NODE,
- "%s(config-route-map)# "
-};
+static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# "};
-static struct cmd_node zebra_node =
-{
- ZEBRA_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node zebra_node = {ZEBRA_NODE, "%s(config-router)# "};
-static struct cmd_node bgp_vpnv4_node =
-{
- BGP_VPNV4_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv4_node =
-{
- BGP_IPV4_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv4_node = {BGP_IPV4_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv4m_node =
-{
- BGP_IPV4M_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv4m_node = {BGP_IPV4M_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv6_node =
-{
- BGP_IPV6_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv6_node = {BGP_IPV6_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv6m_node =
-{
- BGP_IPV6M_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv6m_node = {BGP_IPV6M_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node ospf_node =
-{
- OSPF_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# "};
-static struct cmd_node ripng_node =
-{
- RIPNG_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node ripng_node = {RIPNG_NODE, "%s(config-router)# "};
-static struct cmd_node ospf6_node =
-{
- OSPF6_NODE,
- "%s(config-ospf6)# "
-};
+static struct cmd_node ospf6_node = {OSPF6_NODE, "%s(config-ospf6)# "};
-static struct cmd_node keychain_node =
-{
- KEYCHAIN_NODE,
- "%s(config-keychain)# "
-};
+static struct cmd_node keychain_node = {KEYCHAIN_NODE, "%s(config-keychain)# "};
-static struct cmd_node keychain_key_node =
-{
- KEYCHAIN_KEY_NODE,
- "%s(config-keychain-key)# "
-};
+static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE,
+ "%s(config-keychain-key)# "};
-static int
-test_callback(const struct cmd_element *cmd, struct vty *vty, int argc, struct cmd_token *argv[])
+static int test_callback(const struct cmd_element *cmd, struct vty *vty,
+ int argc, struct cmd_token *argv[])
{
- int offset;
- int rv;
- int i;
-
- offset = 0;
- rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string);
- if (rv < 0)
- abort();
-
- offset += rv;
-
- for (i = 0; i < argc; i++)
- {
- rv = snprintf(test_buf + offset, sizeof(test_buf) - offset, "%s'%s'",
- (i == 0) ? ": " : ", ", argv[i]->arg);
- if (rv < 0)
- abort();
- offset += rv;
- }
-
- return CMD_SUCCESS;
+ int offset;
+ int rv;
+ int i;
+
+ offset = 0;
+ rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string);
+ if (rv < 0)
+ abort();
+
+ offset += rv;
+
+ for (i = 0; i < argc; i++) {
+ rv = snprintf(test_buf + offset, sizeof(test_buf) - offset,
+ "%s'%s'", (i == 0) ? ": " : ", ", argv[i]->arg);
+ if (rv < 0)
+ abort();
+ offset += rv;
+ }
+
+ return CMD_SUCCESS;
}
-static void
-test_load(void)
+static void test_load(void)
{
- char line[4096];
-
- test_cmds = vector_init(VECTOR_MIN_SIZE);
-
- while (fgets(line, sizeof(line), stdin) != NULL)
- {
- if (strlen(line))
- line[strlen(line) - 1] = '\0';
- if (line[0] == '#')
- continue;
- vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line));
- }
+ char line[4096];
+
+ test_cmds = vector_init(VECTOR_MIN_SIZE);
+
+ while (fgets(line, sizeof(line), stdin) != NULL) {
+ if (strlen(line))
+ line[strlen(line) - 1] = '\0';
+ if (line[0] == '#')
+ continue;
+ vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line));
+ }
}
-static void
-test_init(void)
+static void test_init(void)
{
- unsigned int node;
- unsigned int i;
- struct cmd_node *cnode;
- struct cmd_element *cmd;
-
- cmd_init(1);
-
- install_node (&bgp_node, NULL);
- install_node (&rip_node, NULL);
- install_node (&interface_node, NULL);
- install_node (&rmap_node, NULL);
- install_node (&zebra_node, NULL);
- install_node (&bgp_vpnv4_node, NULL);
- install_node (&bgp_ipv4_node, NULL);
- install_node (&bgp_ipv4m_node, NULL);
- install_node (&bgp_ipv6_node, NULL);
- install_node (&bgp_ipv6m_node, NULL);
- install_node (&ospf_node, NULL);
- install_node (&ripng_node, NULL);
- install_node (&ospf6_node, NULL);
- install_node (&keychain_node, NULL);
- install_node (&keychain_key_node, NULL);
- install_node (&isis_node, NULL);
- install_node (&vty_node, NULL);
-
- test_init_cmd();
-
- for (node = 0; node < vector_active(cmdvec); node++)
- if ((cnode = vector_slot(cmdvec, node)) != NULL)
- for (i = 0; i < vector_active(cnode->cmd_vector); i++)
- if ((cmd = vector_slot(cnode->cmd_vector, i)) != NULL)
- {
- cmd->daemon = 0;
- cmd->func = test_callback;
- }
- test_load();
- vty_init_vtysh();
+ unsigned int node;
+ unsigned int i;
+ struct cmd_node *cnode;
+ struct cmd_element *cmd;
+
+ cmd_init(1);
+
+ install_node(&bgp_node, NULL);
+ install_node(&rip_node, NULL);
+ install_node(&interface_node, NULL);
+ install_node(&rmap_node, NULL);
+ install_node(&zebra_node, NULL);
+ install_node(&bgp_vpnv4_node, NULL);
+ install_node(&bgp_ipv4_node, NULL);
+ install_node(&bgp_ipv4m_node, NULL);
+ install_node(&bgp_ipv6_node, NULL);
+ install_node(&bgp_ipv6m_node, NULL);
+ install_node(&ospf_node, NULL);
+ install_node(&ripng_node, NULL);
+ install_node(&ospf6_node, NULL);
+ install_node(&keychain_node, NULL);
+ install_node(&keychain_key_node, NULL);
+ install_node(&isis_node, NULL);
+ install_node(&vty_node, NULL);
+
+ test_init_cmd();
+
+ for (node = 0; node < vector_active(cmdvec); node++)
+ if ((cnode = vector_slot(cmdvec, node)) != NULL)
+ for (i = 0; i < vector_active(cnode->cmd_vector); i++)
+ if ((cmd = vector_slot(cnode->cmd_vector, i))
+ != NULL) {
+ cmd->daemon = 0;
+ cmd->func = test_callback;
+ }
+ test_load();
+ vty_init_vtysh();
}
-static void
-test_terminate(void)
+static void test_terminate(void)
{
- unsigned int i;
+ unsigned int i;
- vty_terminate();
- for (i = 0; i < vector_active(test_cmds); i++)
- XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i));
- vector_free(test_cmds);
- cmd_terminate();
+ vty_terminate();
+ for (i = 0; i < vector_active(test_cmds); i++)
+ XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i));
+ vector_free(test_cmds);
+ cmd_terminate();
}
-static void
-test_run(struct prng *prng, struct vty *vty, const char *cmd, unsigned int edit_dist, unsigned int node_index, int verbose)
+static void test_run(struct prng *prng, struct vty *vty, const char *cmd,
+ unsigned int edit_dist, unsigned int node_index,
+ int verbose)
{
- const char *test_str;
- vector vline;
- int ret;
- unsigned int i;
- char **completions;
- unsigned int j;
- struct cmd_node *cnode;
- vector descriptions;
- int appended_null;
- int no_match;
-
- test_str = prng_fuzz(prng, cmd, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /", edit_dist);
- vline = cmd_make_strvec(test_str);
-
- if (vline == NULL)
- return;
-
- appended_null = 0;
- for (i = 0; i < vector_active(cmdvec); i++)
- if ((cnode = vector_slot(cmdvec, i)) != NULL)
- {
- if (node_index != (unsigned int)-1 && i != node_index)
- continue;
-
- if (appended_null)
- {
- vector_unset(vline, vector_active(vline) - 1);
- appended_null = 0;
- }
- vty->node = cnode->node;
- test_buf[0] = '\0';
- ret = cmd_execute_command(vline, vty, NULL, 0);
- no_match = (ret == CMD_ERR_NO_MATCH);
- if (verbose || !no_match)
- printf("execute relaxed '%s'@%d: rv==%d%s%s\n",
- test_str,
- cnode->node,
- ret,
- (test_buf[0] != '\0') ? ", " : "",
- test_buf);
-
- vty->node = cnode->node;
- test_buf[0] = '\0';
- ret = cmd_execute_command_strict(vline, vty, NULL);
- if (verbose || !no_match)
- printf("execute strict '%s'@%d: rv==%d%s%s\n",
- test_str,
- cnode->node,
- ret,
- (test_buf[0] != '\0') ? ", " : "",
- test_buf);
-
- if (isspace((int) test_str[strlen(test_str) - 1]))
- {
- vector_set (vline, NULL);
- appended_null = 1;
- }
-
- vty->node = cnode->node;
- completions = cmd_complete_command(vline, vty, &ret);
- if (verbose || !no_match)
- printf("complete '%s'@%d: rv==%d\n",
- test_str,
- cnode->node,
- ret);
- if (completions != NULL)
- {
- for (j = 0; completions[j] != NULL; j++)
- {
- printf(" '%s'\n", completions[j]);
- XFREE(MTYPE_TMP, completions[j]);
- }
- XFREE(MTYPE_TMP, completions);
- }
-
- vty->node = cnode->node;
- descriptions = cmd_describe_command(vline, vty, &ret);
- if (verbose || !no_match)
- printf("describe '%s'@%d: rv==%d\n",
- test_str,
- cnode->node,
- ret);
- if (descriptions != NULL)
- {
- for (j = 0; j < vector_active(descriptions); j++)
- {
- struct cmd_token *cmd = vector_slot(descriptions, j);
- printf(" '%s' '%s'\n", cmd->text, cmd->desc);
- }
- vector_free(descriptions);
- }
- }
- cmd_free_strvec(vline);
+ const char *test_str;
+ vector vline;
+ int ret;
+ unsigned int i;
+ char **completions;
+ unsigned int j;
+ struct cmd_node *cnode;
+ vector descriptions;
+ int appended_null;
+ int no_match;
+
+ test_str = prng_fuzz(
+ prng, cmd,
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /",
+ edit_dist);
+ vline = cmd_make_strvec(test_str);
+
+ if (vline == NULL)
+ return;
+
+ appended_null = 0;
+ for (i = 0; i < vector_active(cmdvec); i++)
+ if ((cnode = vector_slot(cmdvec, i)) != NULL) {
+ if (node_index != (unsigned int)-1 && i != node_index)
+ continue;
+
+ if (appended_null) {
+ vector_unset(vline, vector_active(vline) - 1);
+ appended_null = 0;
+ }
+ vty->node = cnode->node;
+ test_buf[0] = '\0';
+ ret = cmd_execute_command(vline, vty, NULL, 0);
+ no_match = (ret == CMD_ERR_NO_MATCH);
+ if (verbose || !no_match)
+ printf("execute relaxed '%s'@%d: rv==%d%s%s\n",
+ test_str, cnode->node, ret,
+ (test_buf[0] != '\0') ? ", " : "",
+ test_buf);
+
+ vty->node = cnode->node;
+ test_buf[0] = '\0';
+ ret = cmd_execute_command_strict(vline, vty, NULL);
+ if (verbose || !no_match)
+ printf("execute strict '%s'@%d: rv==%d%s%s\n",
+ test_str, cnode->node, ret,
+ (test_buf[0] != '\0') ? ", " : "",
+ test_buf);
+
+ if (isspace((int)test_str[strlen(test_str) - 1])) {
+ vector_set(vline, NULL);
+ appended_null = 1;
+ }
+
+ vty->node = cnode->node;
+ completions = cmd_complete_command(vline, vty, &ret);
+ if (verbose || !no_match)
+ printf("complete '%s'@%d: rv==%d\n", test_str,
+ cnode->node, ret);
+ if (completions != NULL) {
+ for (j = 0; completions[j] != NULL; j++) {
+ printf(" '%s'\n", completions[j]);
+ XFREE(MTYPE_TMP, completions[j]);
+ }
+ XFREE(MTYPE_TMP, completions);
+ }
+
+ vty->node = cnode->node;
+ descriptions = cmd_describe_command(vline, vty, &ret);
+ if (verbose || !no_match)
+ printf("describe '%s'@%d: rv==%d\n", test_str,
+ cnode->node, ret);
+ if (descriptions != NULL) {
+ for (j = 0; j < vector_active(descriptions);
+ j++) {
+ struct cmd_token *cmd =
+ vector_slot(descriptions, j);
+ printf(" '%s' '%s'\n", cmd->text,
+ cmd->desc);
+ }
+ vector_free(descriptions);
+ }
+ }
+ cmd_free_strvec(vline);
}
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- int opt;
- struct prng *prng;
- struct vty *vty;
- unsigned int edit_distance;
- unsigned int max_edit_distance;
- unsigned int node_index;
- int verbose;
- unsigned int test_cmd;
- unsigned int iteration;
- unsigned int num_iterations;
-
- max_edit_distance = 3;
- node_index = -1;
- verbose = 0;
-
- while ((opt = getopt(argc, argv, "e:n:v")) != -1)
- {
- switch (opt)
- {
- case 'e':
- max_edit_distance = atoi(optarg);
- break;
- case 'n':
- node_index = atoi(optarg);
- break;
- case 'v':
- verbose++;
- break;
- default:
- fprintf(stderr, "Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n", argv[0]);
- exit(1);
- break;
- }
- }
-
- test_init();
- prng = prng_new(0);
-
- vty = vty_new();
- vty->type = VTY_TERM;
-
- fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds));
- for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++)
- {
- for (edit_distance = 0;
- edit_distance <= max_edit_distance;
- edit_distance++)
- {
- num_iterations = 1 << edit_distance;
- num_iterations *= num_iterations * num_iterations;
-
- for (iteration = 0; iteration < num_iterations; iteration++)
- test_run(prng, vty, vector_slot(test_cmds, test_cmd), edit_distance, node_index, verbose);
- }
- fprintf(stderr, "\r%u/%u", test_cmd + 1, vector_active(test_cmds));
- }
- fprintf(stderr, "\nDone.\n");
-
- vty_close(vty);
- prng_free(prng);
- test_terminate();
- return 0;
+ int opt;
+ struct prng *prng;
+ struct vty *vty;
+ unsigned int edit_distance;
+ unsigned int max_edit_distance;
+ unsigned int node_index;
+ int verbose;
+ unsigned int test_cmd;
+ unsigned int iteration;
+ unsigned int num_iterations;
+
+ max_edit_distance = 3;
+ node_index = -1;
+ verbose = 0;
+
+ while ((opt = getopt(argc, argv, "e:n:v")) != -1) {
+ switch (opt) {
+ case 'e':
+ max_edit_distance = atoi(optarg);
+ break;
+ case 'n':
+ node_index = atoi(optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ default:
+ fprintf(stderr,
+ "Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n",
+ argv[0]);
+ exit(1);
+ break;
+ }
+ }
+
+ test_init();
+ prng = prng_new(0);
+
+ vty = vty_new();
+ vty->type = VTY_TERM;
+
+ fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds));
+ for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++) {
+ for (edit_distance = 0; edit_distance <= max_edit_distance;
+ edit_distance++) {
+ num_iterations = 1 << edit_distance;
+ num_iterations *= num_iterations * num_iterations;
+
+ for (iteration = 0; iteration < num_iterations;
+ iteration++)
+ test_run(prng, vty,
+ vector_slot(test_cmds, test_cmd),
+ edit_distance, node_index, verbose);
+ }
+ fprintf(stderr, "\r%u/%u", test_cmd + 1,
+ vector_active(test_cmds));
+ }
+ fprintf(stderr, "\nDone.\n");
+
+ vty_close(vty);
+ prng_free(prng);
+ test_terminate();
+ return 0;
}