Create a unit-test plugin

Move the tcp unit test to the plugin
Add a bihash unit test and a "make test" program to call it
Adjust framework.py to load the plugin, which is disabled by default

Change-Id: Ic229d386a56a9d28dbd54974f231149053ca8f93
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2018-07-23 18:00:54 -04:00
committed by Florin Coras
parent 1678236897
commit 8b5dc4fd5e
11 changed files with 650 additions and 32 deletions

View File

@ -326,6 +326,7 @@ PLUGIN_ENABLED(srv6as)
PLUGIN_ENABLED(stn)
PLUGIN_ENABLED(tlsmbedtls)
PLUGIN_ENABLED(tlsopenssl)
PLUGIN_ENABLED(unittest)
###############################################################################
# Dependency checks

View File

@ -139,6 +139,10 @@ if ENABLE_TLSOPENSSL_PLUGIN
include tlsopenssl.am
endif
if ENABLE_UNITTEST_PLUGIN
include unittest.am
endif
include ../suffix-rules.mk
# Remove *.la files

22
src/plugins/unittest.am Normal file
View File

@ -0,0 +1,22 @@
# Copyright (c) <current-year> <your-organization>
# 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.
vppplugins_LTLIBRARIES += unittest_plugin.la
unittest_plugin_la_SOURCES = \
unittest/unittest.c \
unittest/tcp_test.c \
unittest/bihash_test.c
# vi:syntax=automake

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
/*
* unittest.c - vpp unit-test plugin
*
* Copyright (c) 2018 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 <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <vpp/app/version.h>
/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER () =
{
.version = VPP_BUILD_VER,
.description = "C unit tests",
.default_disabled = 1,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2018 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>
static clib_error_t *
test_crash_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
u64 *p = (u64 *) 0xdefec8ed;
/* *INDENT-OFF* */
ELOG_TYPE_DECLARE (e) =
{
.format = "deliberate crash: touching %x",
.format_args = "i4",
};
/* *INDENT-ON* */
elog (&vm->elog_main, &e, 0xdefec8ed);
*p = 0xdeadbeef;
/* Not so much... */
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_crash_command, static) =
{
.path = "test crash",
.short_help = "crash the bus!",
.function = test_crash_command_fn,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -501,7 +501,6 @@ libvnet_la_SOURCES += \
vnet/tcp/tcp_output.c \
vnet/tcp/tcp_input.c \
vnet/tcp/tcp_newreno.c \
vnet/tcp/tcp_test.c \
vnet/tcp/tcp.c
nobase_include_HEADERS += \

View File

@ -391,36 +391,6 @@ vlib_app_num_thread_stacks_needed (void)
* messages!
*/
#if CLIB_DEBUG > 0
static clib_error_t *
test_crash_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
u64 *p = (u64 *) 0xdefec8ed;
ELOG_TYPE_DECLARE (e) =
{
.format = "deliberate crash: touching %x",.format_args = "i4",};
elog (&vm->elog_main, &e, 0xdefec8ed);
*p = 0xdeadbeef;
/* Not so much... */
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_crash_command, static) = {
.path = "test crash",
.short_help = "crash the bus!",
.function = test_crash_command_fn,
};
/* *INDENT-ON* */
#endif
/*
* fd.io coding-style-patch-verification: ON
*

View File

@ -246,7 +246,8 @@ class VppTestCase(unittest.TestCase):
coredump_size, "}", "api-trace", "{", "on", "}",
"api-segment", "{", "prefix", cls.shm_prefix, "}",
"plugins", "{", "plugin", "dpdk_plugin.so", "{",
"disable", "}", "}", ]
"disable", "}", "plugin", "unittest_plugin.so",
"{", "enable", "}", "}", ]
if plugin_path is not None:
cls.vpp_cmdline.extend(["plugin_path", plugin_path])
cls.logger.info("vpp_cmdline: %s" % cls.vpp_cmdline)

40
test/test_bihash.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import unittest
from framework import VppTestCase, VppTestRunner
from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
class TestTCP(VppTestCase):
""" Bihash Test Cases """
@classmethod
def setUpClass(cls):
super(TestTCP, cls).setUpClass()
def setUp(self):
super(TestTCP, self).setUp()
def tearDown(self):
super(TestTCP, self).tearDown()
def test_bihash_unittest(self):
""" Bihash Add/Del Test """
error = self.vapi.cli("test bihash ")
if error:
self.logger.critical(error)
self.assertEqual(error.find("failed"), -1)
def test_bihash_thread(self):
""" Bihash Thread Test """
error = self.vapi.cli("test bihash threads 2 nbuckets 64000")
if error:
self.logger.critical(error)
self.assertEqual(error.find("failed"), -1)
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)