aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-05-08 19:18:18 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-05-09 20:08:58 +0000
commit7d31ab2a5cc2124ddd973ac5dfac2219619f345a (patch)
treec348cd84cf2c4edc0bb73890830ed2bc280117bf /src/plugins
parent016d4cc327f1980605db7a9e436597e8f36fe9ed (diff)
add mactime plugin unit / code coverage tests
The unit and code coverage tests are boring. The rest of the patch involves test and packet-generator infra cleanups. Teach the "make test-xxx" family of targets to set the api test plugin path correctly, to make "binary-api <api-message-name> <args>" debug CLI commands work correctly in the "make test" environment. Unfortunately involves both the top-level and test Makefiles. Add a minor pg cli feature, a CLI to manually set s->sw_if_index[VLIB_TX]. Consider the case where one configures an interface with both a device-input and an output feature. To test the output feature using the pg, it's necessary to inject packets into the interface output node with both b->sw_if_index[VLIB_TX] and b->sw_if_index[VLIB_RX] set correctly. For example: packet-generator new { name tx limit 15 size 128-128 interface local0 # rx: device input feature not configured on local0 tx-interface loop0 # tx: output node requires b->sw_if_index[VLIB_TX] node loop0-output data { hex 0x01005e7ffffa000dead0000008000102030405060708090a0b0c0d0e0f0102030405 } } Fix a longstanding bug in the packet generator stream setup. Remove kludges which set b->sw_if_index[VLIB_TX] to ~0 [in multiple places] instead of using the stream value s->sw_if_index[VLIB_TX], and setting THAT datum correctly. Change-Id: I1097a18e8db73661ded6b822c1d718f7e5cf36ed Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/mactime/mactime.c7
-rw-r--r--src/plugins/unittest/CMakeLists.txt1
-rw-r--r--src/plugins/unittest/mactime_test.c181
3 files changed, 184 insertions, 5 deletions
diff --git a/src/plugins/mactime/mactime.c b/src/plugins/mactime/mactime.c
index 6cbddbc7a44..1b053faa2e8 100644
--- a/src/plugins/mactime/mactime.c
+++ b/src/plugins/mactime/mactime.c
@@ -126,6 +126,8 @@ mactime_enable_disable_command_fn (vlib_main_t * vm,
else if (unformat (input, "%U", unformat_vnet_sw_interface,
mm->vnet_main, &sw_if_index))
;
+ else if (unformat (input, "sw_if_index %d", &sw_if_index))
+ ;
else
break;
}
@@ -145,11 +147,6 @@ mactime_enable_disable_command_fn (vlib_main_t * vm,
(0, "Invalid interface, only works on physical ports");
break;
- case VNET_API_ERROR_UNIMPLEMENTED:
- return clib_error_return (0,
- "Device driver doesn't support redirection");
- break;
-
default:
return clib_error_return (0, "mactime_enable_disable returned %d", rv);
}
diff --git a/src/plugins/unittest/CMakeLists.txt b/src/plugins/unittest/CMakeLists.txt
index 8e8142dee38..5b7e1f7655e 100644
--- a/src/plugins/unittest/CMakeLists.txt
+++ b/src/plugins/unittest/CMakeLists.txt
@@ -25,6 +25,7 @@ add_vpp_plugin(unittest
fib_test.c
ipsec_test.c
interface_test.c
+ mactime_test.c
mfib_test.c
punt_test.c
rbtree_test.c
diff --git a/src/plugins/unittest/mactime_test.c b/src/plugins/unittest/mactime_test.c
new file mode 100644
index 00000000000..907022f4d88
--- /dev/null
+++ b/src/plugins/unittest/mactime_test.c
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+#include <vlib/vlib.h>
+#include <vppinfra/time_range.h>
+
+static int
+test_time_range_main (unformat_input_t * input)
+{
+ clib_timebase_t _tb, *tb = &_tb;
+ clib_timebase_component_t _c, *cp = &_c;
+ clib_timebase_range_t *rp = 0;
+ clib_timebase_range_t *this_rp;
+ unformat_input_t _input2, *input2 = &_input2;
+ char *test_range_string;
+ f64 sunday_midnight;
+ f64 now, then;
+ f64 start_time, end_time;
+ f64 timezone_offset;
+
+ /* Init time base */
+ clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA);
+
+ /* Set up summer time cache */
+ now = clib_timebase_now (tb);
+
+ /* Test it */
+ now = clib_timebase_now (tb);
+
+ /* show current time */
+ fformat (stdout, "Current time in UTC%f, US daylight time rules:\n",
+ tb->timezone_offset / 3600.0);
+ fformat (stdout, "%U", format_clib_timebase_time, now);
+
+ /* Test conversion to component structure */
+ clib_timebase_time_to_components (now, cp);
+ now = clib_timebase_components_to_time (cp);
+ fformat (stdout, " -> %U\n", format_clib_timebase_time, now);
+
+ /*
+ * test a few other dates, to verify summer time operation
+ * 2011: started sunday 3/13, ended sunday 11/6
+ */
+
+ fformat (stdout, "Test daylight time rules:\n");
+
+ clib_memset (cp, 0, sizeof (*cp));
+
+ /* Just before DST starts */
+ cp->year = 2011;
+ cp->month = 2;
+ cp->day = 13;
+ cp->hour = 1;
+ cp->minute = 59;
+ cp->second = 59;
+ then = clib_timebase_components_to_time (cp);
+
+ timezone_offset = clib_timebase_summer_offset_fastpath (tb, then);
+
+ fformat (stdout, "%U should not be in DST, and it %s\n",
+ format_clib_timebase_time, then,
+ (timezone_offset != 0.0) ? "is" : "is not");
+
+ /* add two seconds */
+
+ then += 2.0;
+
+ timezone_offset = clib_timebase_summer_offset_fastpath (tb, then);
+
+ fformat (stdout, "%U should be in DST, and it %s\n",
+ format_clib_timebase_time, then,
+ (timezone_offset != 0.0) ? "is" : "is not");
+
+ /* Just before DST ends */
+ cp->year = 2011;
+ cp->month = 10;
+ cp->day = 6;
+ cp->hour = 1;
+ cp->minute = 59;
+ cp->second = 59;
+ then = clib_timebase_components_to_time (cp);
+
+ timezone_offset = clib_timebase_summer_offset_fastpath (tb, then);
+
+ fformat (stdout, "%U should be in DST, and it %s\n",
+ format_clib_timebase_time, then,
+ (timezone_offset != 0.0) ? "is" : "is not");
+
+ /* add two seconds. */
+
+ then += 2.0;
+
+ timezone_offset = clib_timebase_summer_offset_fastpath (tb, then);
+
+ fformat (stdout, "%U should not be in DST, and it %s\n",
+ format_clib_timebase_time, then,
+ (timezone_offset != 0.0) ? "is" : "is not");
+
+ /* Back to the future... */
+ clib_timebase_time_to_components (now, cp);
+
+ fformat (stdout, "Test time range calculations:\n");
+
+ /* Find previous Sunday midnight */
+ sunday_midnight = now = clib_timebase_find_sunday_midnight (now);
+
+ clib_timebase_time_to_components (now, cp);
+
+ fformat (stdout, "Sunday midnight: %U\n", format_clib_timebase_time, now);
+
+ test_range_string = "Mon 11 - 17 Tue 7 - 11 Wed - Fri 8 - 18";
+
+ unformat_init_string (input2, test_range_string,
+ strlen (test_range_string));
+
+ if (unformat (input2, "%U", unformat_clib_timebase_range_vector, &rp))
+ {
+ vec_foreach (this_rp, rp)
+ {
+ start_time = sunday_midnight + this_rp->start;
+ end_time = sunday_midnight + this_rp->end;
+ fformat (stdout, "range: %U - %U\n",
+ format_clib_timebase_time, start_time,
+ format_clib_timebase_time, end_time);
+ }
+ vec_free (rp);
+ }
+ else
+ {
+ fformat (stdout, "Time convert fail!\n");
+ return -1;
+ }
+
+ unformat_free (input2);
+
+ return 0;
+}
+
+
+static clib_error_t *
+test_time_range_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ int rv;
+
+ rv = test_time_range_main (input);
+
+ if (rv)
+ return clib_error_return (0, "test time range FAILED, error %d", rv);
+
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (test_time_range_command, static) =
+{
+ .path = "test time-range",
+ .short_help = "test time-range",
+ .function = test_time_range_command_fn,
+};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */