From 03e4923f113049c6e3ae4137d8a4cd1c15dffe8a Mon Sep 17 00:00:00 2001 From: kcudnik Date: Fri, 20 Aug 2021 08:40:00 +0200 Subject: [PATCH] Add HostInterfaceInfo tests --- unittest/vslib/Makefile.am | 3 ++- unittest/vslib/TestHostInterfaceInfo.cpp | 26 ++++++++++++++++++++++++ unittest/vslib/TestTrafficForwarder.cpp | 2 +- vslib/HostInterfaceInfo.h | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 unittest/vslib/TestHostInterfaceInfo.cpp diff --git a/unittest/vslib/Makefile.am b/unittest/vslib/Makefile.am index f89ff61ed375..420ec80e0683 100644 --- a/unittest/vslib/Makefile.am +++ b/unittest/vslib/Makefile.am @@ -31,7 +31,8 @@ tests_SOURCES = main.cpp \ TestSelectableFd.cpp \ TestSignal.cpp \ TestSwitchConfigContainer.cpp \ - TestTrafficForwarder.cpp + TestTrafficForwarder.cpp \ + TestHostInterfaceInfo.cpp tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \ diff --git a/unittest/vslib/TestHostInterfaceInfo.cpp b/unittest/vslib/TestHostInterfaceInfo.cpp new file mode 100644 index 000000000000..54291fcbf636 --- /dev/null +++ b/unittest/vslib/TestHostInterfaceInfo.cpp @@ -0,0 +1,26 @@ +#include "HostInterfaceInfo.h" + +#include + +using namespace saivs; + +TEST(HostInterfaceInfo, sendTo) +{ + auto eq = std::make_shared(std::make_shared()); + + int s = socket(AF_INET, SOCK_DGRAM, 0); + int fd = socket(AF_INET, SOCK_DGRAM, 0); + + HostInterfaceInfo hii(0, s, fd, "tap", 0, eq); + + usleep(100*1000); + + unsigned char buf[2]; + + EXPECT_EQ(hii.sendTo(s, buf, 0), true); + + close(s); + close(fd); + + EXPECT_EQ(hii.sendTo(s, buf, 0), false); +} diff --git a/unittest/vslib/TestTrafficForwarder.cpp b/unittest/vslib/TestTrafficForwarder.cpp index 0bd4bfc8915b..21cfe95e1386 100644 --- a/unittest/vslib/TestTrafficForwarder.cpp +++ b/unittest/vslib/TestTrafficForwarder.cpp @@ -18,7 +18,7 @@ static_assert(sizeof(control) >= (sizeof(cmsghdr) + sizeof(tpacket_auxdata)), "c TEST(TrafficForwarder, addVlanTag) { - uint8_t buffer[0x1000]; + uint8_t buffer[ETH_FRAME_BUFFER_SIZE]; size_t length = 1; diff --git a/vslib/HostInterfaceInfo.h b/vslib/HostInterfaceInfo.h index 77575fd41fdb..9d6da9a3d533 100644 --- a/vslib/HostInterfaceInfo.h +++ b/vslib/HostInterfaceInfo.h @@ -16,7 +16,7 @@ extern "C" { namespace saivs { - class HostInterfaceInfo : + class HostInterfaceInfo: public TrafficForwarder { private: