summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-12-09 10:45:47 -0500
committerFlorin Coras <florin.coras@gmail.com>2019-12-09 21:19:47 +0000
commit6b3f25caff262b536a5449ac5461dd041c92a655 (patch)
tree89b0440162675b6ec4650cc30ec6908be84abb18 /src
parent5224b5cbd51ed48d1d2ce2a412998d8a944c480b (diff)
vlib: improve test coverage
Add tests. Remove unused rule-based parser code. Type: test Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I3ca3a9dd9da8ee8f3a47004c98f2f5644db10057
Diffstat (limited to 'src')
-rw-r--r--src/plugins/unittest/vlib_test.c41
-rw-r--r--src/vlib/CMakeLists.txt1
-rw-r--r--src/vlib/cli.c137
-rw-r--r--src/vlib/cli.h9
-rw-r--r--src/vlib/cli_funcs.h58
-rw-r--r--src/vlib/vlib.h1
6 files changed, 65 insertions, 182 deletions
diff --git a/src/plugins/unittest/vlib_test.c b/src/plugins/unittest/vlib_test.c
index 49c2ef20052..3154b7d21cf 100644
--- a/src/plugins/unittest/vlib_test.c
+++ b/src/plugins/unittest/vlib_test.c
@@ -133,7 +133,7 @@ test_vlib_command_fn (vlib_main_t * vm,
VLIB_CLI_COMMAND (test_vlib_command, static) =
{
.path = "test vlib",
- .short_help = "vlib code coverate unit test",
+ .short_help = "vlib code coverage unit test",
.function = test_vlib_command_fn,
};
/* *INDENT-ON* */
@@ -189,6 +189,45 @@ VLIB_CLI_COMMAND (test_format_vlib_command, static) =
};
/* *INDENT-ON* */
+static clib_error_t *
+test_vlib2_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ u8 *s;
+ u8 **result;
+
+ s = format (0, "show ");
+ result = vlib_cli_get_possible_completions (s);
+ vec_free (result);
+ vec_free (s);
+
+ s = 0;
+ vec_add1 (s, 0);
+ result = vlib_cli_get_possible_completions (s);
+ vec_free (result);
+ vec_free (s);
+
+ s = format (0, "show ?");
+ result = vlib_cli_get_possible_completions (s);
+ vec_free (result);
+ vec_free (s);
+
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (test_vlib2_command, static) =
+{
+ .path = "test vlib2",
+ .short_help = "vlib code coverage unit test #2",
+ .function = test_vlib2_command_fn,
+};
+/* *INDENT-ON* */
+
+
+
+
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlib/CMakeLists.txt b/src/vlib/CMakeLists.txt
index 1cecf5fb17d..cc27d886675 100644
--- a/src/vlib/CMakeLists.txt
+++ b/src/vlib/CMakeLists.txt
@@ -86,7 +86,6 @@ add_vpp_library(vlib
buffer_funcs.h
buffer.h
buffer_node.h
- cli_funcs.h
cli.h
counter.h
counter_types.h
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index ec27c481374..0ecdac386f3 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -210,29 +210,6 @@ unformat_vlib_cli_sub_command (unformat_input_t * i, va_list * args)
vlib_cli_main_t *cm = &vm->cli_main;
uword *match_bitmap, is_unique, index;
- {
- vlib_cli_sub_rule_t *sr;
- vlib_cli_parse_rule_t *r;
- vec_foreach (sr, c->sub_rules)
- {
- void **d;
- r = vec_elt_at_index (cm->parse_rules, sr->rule_index);
- vec_add2 (cm->parse_rule_data, d, 1);
- vec_reset_length (d[0]);
- if (r->data_size)
- d[0] = _vec_resize (d[0],
- /* length increment */ 1,
- r->data_size,
- /* header_bytes */ 0,
- /* data align */ sizeof (uword));
- if (unformat_user (i, r->unformat_function, vm, d[0]))
- {
- *result = vec_elt_at_index (cm->commands, sr->command_index);
- return 1;
- }
- }
- }
-
match_bitmap = vlib_cli_sub_command_match (c, i);
is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
index = ~0;
@@ -363,49 +340,11 @@ format_vlib_cli_command_help (u8 * s, va_list * args)
}
static u8 *
-format_vlib_cli_parse_rule_name (u8 * s, va_list * args)
-{
- vlib_cli_parse_rule_t *r = va_arg (*args, vlib_cli_parse_rule_t *);
- return format (s, "<%U>", format_c_identifier, r->name);
-}
-
-static u8 *
format_vlib_cli_path (u8 * s, va_list * args)
{
u8 *path = va_arg (*args, u8 *);
- int i, in_rule;
- in_rule = 0;
- for (i = 0; i < vec_len (path); i++)
- {
- switch (path[i])
- {
- case '%':
- in_rule = 1;
- vec_add1 (s, '<'); /* start of <RULE> */
- break;
-
- case '_':
- /* _ -> space in rules. */
- vec_add1 (s, in_rule ? ' ' : '_');
- break;
-
- case ' ':
- if (in_rule)
- {
- vec_add1 (s, '>'); /* end of <RULE> */
- in_rule = 0;
- }
- vec_add1 (s, ' ');
- break;
-
- default:
- vec_add1 (s, path[i]);
- break;
- }
- }
- if (in_rule)
- vec_add1 (s, '>'); /* terminate <RULE> */
+ s = format (s, "%v", path);
return s;
}
@@ -415,13 +354,10 @@ all_subs (vlib_cli_main_t * cm, vlib_cli_command_t * subs, u32 command_index)
{
vlib_cli_command_t *c = vec_elt_at_index (cm->commands, command_index);
vlib_cli_sub_command_t *sc;
- vlib_cli_sub_rule_t *sr;
if (c->function)
vec_add1 (subs, c[0]);
- vec_foreach (sr, c->sub_rules)
- subs = all_subs (cm, subs, sr->command_index);
vec_foreach (sc, c->sub_commands) subs = all_subs (cm, subs, sc->index);
return subs;
@@ -456,6 +392,8 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
unformat_input_t sub_input;
u8 *string;
uword is_main_dispatch = cm == &vm->cli_main;
+ uword value;
+ u8 *key;
parent = vec_elt_at_index (cm->commands, parent_command_index);
if (is_main_dispatch && unformat (input, "help"))
@@ -484,49 +422,34 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
vlib_cli_output (vm, "%U", format_vlib_cli_command_help, c,
/* is_long */ 1);
- else if (vec_len (c->sub_commands) + vec_len (c->sub_rules) == 0)
+ else if (vec_len (c->sub_commands) == 0)
vlib_cli_output (vm, "%v: no sub-commands", c->path);
else
{
- vlib_cli_sub_command_t *sc;
- vlib_cli_sub_rule_t *sr, *subs;
-
- subs = vec_dup (c->sub_rules);
-
- /* Add in rules if any. */
- vec_foreach (sc, c->sub_commands)
- {
- vec_add2 (subs, sr, 1);
- sr->name = sc->name;
- sr->command_index = sc->index;
- sr->rule_index = ~0;
- }
+ vlib_cli_sub_rule_t *sr, *subs = 0;
+
+ /* *INDENT-OFF* */
+ hash_foreach_mem (key, value, c->sub_command_index_by_name,
+ ({
+ (void) key;
+ vec_add2 (subs, sr, 1);
+ sr->name = c->sub_commands[value].name;
+ sr->command_index = value;
+ sr->rule_index = ~0;
+ }));
+ /* *INDENT-ON* */
vec_sort_with_function (subs, vlib_cli_cmp_rule);
for (i = 0; i < vec_len (subs); i++)
{
vlib_cli_command_t *d;
- vlib_cli_parse_rule_t *r;
d = vec_elt_at_index (cm->commands, subs[i].command_index);
- r =
- subs[i].rule_index != ~0 ? vec_elt_at_index (cm->parse_rules,
- subs
- [i].rule_index) :
- 0;
-
- if (r)
- vlib_cli_output
- (vm, " %-30U %U",
- format_vlib_cli_parse_rule_name, r,
- format_vlib_cli_command_help, d, /* is_long */ 0);
- else
- vlib_cli_output
- (vm, " %-30v %U",
- subs[i].name,
- format_vlib_cli_command_help, d, /* is_long */ 0);
+ vlib_cli_output
+ (vm, " %-30v %U", subs[i].name,
+ format_vlib_cli_command_help, d, /* is_long */ 0);
}
vec_free (subs);
@@ -669,8 +592,8 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
if (c_error)
{
vec_add1 (c_error->what, 0);
- ed->err = elog_string (&vm->elog_main,
- (char *) c_error->what);
+ ed->err =
+ elog_string (&vm->elog_main, (char *) c_error->what);
_vec_len (c_error->what) -= 1;
}
else
@@ -732,7 +655,6 @@ vlib_cli_input (vlib_main_t * vm,
vlib_cli_output_function_t * function, uword function_arg)
{
vlib_process_t *cp = vlib_get_current_process (vm);
- vlib_cli_main_t *cm = &vm->cli_main;
clib_error_t *error;
vlib_cli_output_function_t *save_function;
uword save_function_arg;
@@ -746,9 +668,8 @@ vlib_cli_input (vlib_main_t * vm,
do
{
- vec_reset_length (cm->parse_rule_data);
- error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input, /* parent */
- 0);
+ error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input,
+ /* parent */ 0);
}
while (!error && !unformat (input, "%U", unformat_eof));
@@ -1296,14 +1217,6 @@ add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
return;
}
- q = hash_get_mem (cm->parse_rule_index_by_name, sub_name);
- if (!q)
- {
- clib_error ("reference to unknown rule `%%%v' in path `%v'",
- sub_name, c->path);
- return;
- }
-
hash_set_mem (p->sub_rule_index_by_name, sub_name,
vec_len (p->sub_rules));
vec_add2 (p->sub_rules, sr, 1);
@@ -1492,6 +1405,8 @@ vlib_cli_register (vlib_main_t * vm, vlib_cli_command_t * c)
return 0;
}
+#if 0
+/* $$$ turn back on again someday, maybe */
clib_error_t *
vlib_cli_register_parse_rule (vlib_main_t * vm, vlib_cli_parse_rule_t * r_reg)
{
@@ -1524,8 +1439,6 @@ vlib_cli_register_parse_rule (vlib_main_t * vm, vlib_cli_parse_rule_t * r_reg)
return error;
}
-#if 0
-/* $$$ turn back on again someday, maybe */
static clib_error_t *vlib_cli_register_parse_rules (vlib_main_t * vm,
vlib_cli_parse_rule_t *
lo,
diff --git a/src/vlib/cli.h b/src/vlib/cli.h
index 6d6d7e2b7fa..df9ed7212bc 100644
--- a/src/vlib/cli.h
+++ b/src/vlib/cli.h
@@ -140,15 +140,6 @@ typedef struct
/* Hash table mapping normalized path to index into all_commands. */
uword *command_index_by_path;
- /* Vector of all known parse rules. */
- vlib_cli_parse_rule_t *parse_rules;
-
- /* Hash table mapping parse rule name to index into parse_rule vector. */
- uword *parse_rule_index_by_name;
-
- /* Data parsed for rules. */
- void **parse_rule_data;
-
/* registration list added by constructors */
vlib_cli_command_t *cli_command_registrations;
diff --git a/src/vlib/cli_funcs.h b/src/vlib/cli_funcs.h
deleted file mode 100644
index 78aef73ba2d..00000000000
--- a/src/vlib/cli_funcs.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * cli_funcs.h: VLIB CLI related functions/inlines
- *
- * Copyright (c) 2008 Eliot Dresselhaus
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef included_vlib_cli_funcs_h
-#define included_vlib_cli_funcs_h
-
-always_inline void *
-vlib_cli_get_parse_rule_result (vlib_main_t * vm, uword index)
-{
- vlib_cli_main_t *cm = &vm->cli_main;
- return vec_elt (cm->parse_rule_data, index);
-}
-
-#endif /* included_vlib_cli_funcs_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vlib/vlib.h b/src/vlib/vlib.h
index 8f59cae2cee..8f0ea83569d 100644
--- a/src/vlib/vlib.h
+++ b/src/vlib/vlib.h
@@ -70,7 +70,6 @@ typedef u32 vlib_log_class_t;
#include <vlib/threads.h>
#include <vlib/physmem_funcs.h>
#include <vlib/buffer_funcs.h>
-#include <vlib/cli_funcs.h>
#include <vlib/error_funcs.h>
#include <vlib/format_funcs.h>
#include <vlib/node_funcs.h>