aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-11-19 10:36:41 -0500
committerDamjan Marion <dmarion@me.com>2019-11-20 17:38:49 +0000
commite51a9bbe7693294e2e1021f13697fa97b02a89fb (patch)
tree6c5411e70a534533d4370c0662f17b3d7cef828b
parenta548d134ae53c52de17fb02c8c925153cbd0fdf5 (diff)
vlib: improve code coverage, part deux
Type: test Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: If31f4b50da7a6e4a9704ceb3415c582143c08355
-rw-r--r--src/plugins/unittest/vlib_test.c63
-rw-r--r--src/vlib/counter.c24
-rw-r--r--src/vlib/counter.h5
-rw-r--r--test/test_vlib.py18
4 files changed, 80 insertions, 30 deletions
diff --git a/src/plugins/unittest/vlib_test.c b/src/plugins/unittest/vlib_test.c
index 275584e01eb..49c2ef20052 100644
--- a/src/plugins/unittest/vlib_test.c
+++ b/src/plugins/unittest/vlib_test.c
@@ -14,6 +14,7 @@
*/
#include <vlib/vlib.h>
+#include <vnet/vnet.h>
u8 *vlib_validate_buffers (vlib_main_t * vm,
u32 * buffers,
@@ -34,6 +35,8 @@ test_vlib_command_fn (vlib_main_t * vm,
u8 junk[4] = { 1, 2, 3, 4 };
vlib_packet_template_t _t, *t = &_t;
u8 *data_copy = 0;
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_interface_main_t *im = &vnm->interface_main;
/* Cover vlib_packet_template_get_packet */
t->packet_data = format (0, "silly packet data");
@@ -70,6 +73,7 @@ test_vlib_command_fn (vlib_main_t * vm,
/* Dump the resulting two-chunk pkt */
vlib_cli_output (vm, "%U", format_vlib_buffer_and_data, b);
+ vlib_cli_output (vm, "%U", format_vlib_buffer_data, b->data, 17);
vec_validate (data_copy, vlib_buffer_length_in_chain (vm, b) - 1);
vlib_cli_output (vm, "%u", vlib_buffer_contents (vm, bi, data_copy));
@@ -109,13 +113,19 @@ test_vlib_command_fn (vlib_main_t * vm,
if (res)
return clib_error_return (0, "%v", res);
- /* It will not be allocated, exercise error path */
+ /* Misc */
+ vlib_cli_output
+ (vm, "%u",
+ vlib_combined_counter_n_counters (im->combined_sw_if_counters));
+
+ /* buffer will not be allocated at this point, exercise error path */
res = vlib_validate_buffers (vm, &bi, 0 /* stride */ ,
1, VLIB_BUFFER_KNOWN_ALLOCATED,
1 /* follow_buffer_next */ );
if (res)
return clib_error_return (0, "%v", res);
+ /* NOTREACHED */
return 0;
}
@@ -128,6 +138,57 @@ VLIB_CLI_COMMAND (test_vlib_command, static) =
};
/* *INDENT-ON* */
+static clib_error_t *
+test_format_vlib_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ unformat_input_t _i, *i = &_i;
+ int enable = -1, disable = -1;
+ int twenty_seven = -1;;
+ int rxtx = -1;
+
+ memset (i, 0, sizeof (*i));
+ unformat_init_string (i, "enable disable rx tx 27", 23);
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", unformat_vlib_enable_disable, &enable))
+ ;
+ else if (unformat (i, "%U", unformat_vlib_enable_disable, &disable))
+ ;
+ else if (unformat (i, "%U", unformat_vlib_number, &twenty_seven))
+ ;
+ else if (unformat (i, "%U", unformat_vlib_rx_tx, &rxtx))
+ ;
+ else
+ break;
+ }
+
+ rxtx = VLIB_TX;
+ vlib_cli_output (vm, "%U", format_vlib_read_write, rxtx);
+ vlib_cli_output (vm, "%U", format_vlib_rx_tx, rxtx);
+
+ rxtx = VLIB_RX;
+ vlib_cli_output (vm, "%U", format_vlib_read_write, rxtx);
+ vlib_cli_output (vm, "%U", format_vlib_rx_tx, rxtx);
+ rxtx = 12345;
+ vlib_cli_output (vm, "%U", format_vlib_read_write, rxtx);
+ vlib_cli_output (vm, "%U", format_vlib_rx_tx, rxtx);
+
+ unformat_free (i);
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (test_format_vlib_command, static) =
+{
+ .path = "test format-vlib",
+ .short_help = "vlib format code coverate unit test",
+ .function = test_format_vlib_command_fn,
+};
+/* *INDENT-ON* */
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlib/counter.c b/src/vlib/counter.c
index faf106942b7..8573b794fd9 100644
--- a/src/vlib/counter.c
+++ b/src/vlib/counter.c
@@ -119,30 +119,6 @@ vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm)
return (vec_len (cm->counters[0]));
}
-void
-serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
-{
- clib_warning ("unimplemented");
-}
-
-void
-unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
-{
- clib_warning ("unimplemented");
-}
-
-void
-serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
-{
- clib_warning ("unimplemented");
-}
-
-void
-unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
-{
- clib_warning ("unimplemented");
-}
-
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlib/counter.h b/src/vlib/counter.h
index 092bd00c879..292e137681e 100644
--- a/src/vlib/counter.h
+++ b/src/vlib/counter.h
@@ -323,11 +323,6 @@ void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm,
*/
#define vlib_counter_len(cm) vec_len((cm)->maxi)
-serialize_function_t serialize_vlib_simple_counter_main,
- unserialize_vlib_simple_counter_main;
-serialize_function_t serialize_vlib_combined_counter_main,
- unserialize_vlib_combined_counter_main;
-
#endif /* included_vlib_counter_h */
/*
diff --git a/test/test_vlib.py b/test/test_vlib.py
index 36a4340fa57..85b561db471 100644
--- a/test/test_vlib.py
+++ b/test/test_vlib.py
@@ -127,6 +127,7 @@ class TestVlib(VppTestCase):
" }\n",
"}\n",
"pa en",
+ "clear interfaces",
"test vlib",
"show buffers",
]
@@ -139,5 +140,22 @@ class TestVlib(VppTestCase):
else:
self.logger.info(cmd + " FAIL retval " + str(r.retval))
+ def test_vlib_format_unittest(self):
+ """ Vlib format.c Code Coverage Test """
+
+ cmds = ["loopback create",
+ "classify filter pcap mask l2 proto ipv6 match l2 proto 86dd",
+ "classify filter del",
+ "test format-vlib",
+ ]
+
+ for cmd in cmds:
+ r = self.vapi.cli_return_response(cmd)
+ if r.retval != 0:
+ if hasattr(r, 'reply'):
+ self.logger.info(cmd + " FAIL reply " + r.reply)
+ else:
+ self.logger.info(cmd + " FAIL retval " + str(r.retval))
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)