Skip to content

Commit

Permalink
Add HostInterfaceInfo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 5db4e72 commit 03e4923
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
26 changes: 26 additions & 0 deletions unittest/vslib/TestHostInterfaceInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "HostInterfaceInfo.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(HostInterfaceInfo, sendTo)
{
auto eq = std::make_shared<EventQueue>(std::make_shared<Signal>());

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);
}
2 changes: 1 addition & 1 deletion unittest/vslib/TestTrafficForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion vslib/HostInterfaceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

namespace saivs
{
class HostInterfaceInfo :
class HostInterfaceInfo:
public TrafficForwarder
{
private:
Expand Down

0 comments on commit 03e4923

Please sign in to comment.