Skip to content

Commit

Permalink
Add NetMsgRegistrar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 8142375 commit 5f6b004
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ tests_SOURCES = main.cpp \
TestMACsecAttr.cpp \
TestMACsecEgressFilter.cpp \
TestMACsecForwarder.cpp \
TestMACsecIngressFilter.cpp
TestMACsecIngressFilter.cpp \
TestNetMsgRegistrar.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
53 changes: 53 additions & 0 deletions unittest/vslib/TestNetMsgRegistrar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "NetMsgRegistrar.h"

#include <gtest/gtest.h>

using namespace saivs;

static void callback(int, struct nl_object*)
{
// empty
}

TEST(NetMsgRegistrar, registerCallback)
{
auto& reg = NetMsgRegistrar::getInstance();

auto index = reg.registerCallback(callback);

reg.unregisterCallback(index);
}

TEST(NetMsgRegistrar, unregisterAll)
{
auto& reg = NetMsgRegistrar::getInstance();

reg.registerCallback(callback);

usleep(100*1000);

reg.unregisterAll();
}

TEST(NetMsgRegistrar, resetIndex)
{
auto& reg = NetMsgRegistrar::getInstance();

reg.resetIndex();

auto index = reg.registerCallback(callback);

reg.unregisterAll();

auto index2 = reg.registerCallback(callback);

EXPECT_NE(index, index2);

reg.unregisterAll();

reg.resetIndex();

auto index3 = reg.registerCallback(callback);

EXPECT_EQ(index, index3);
}
4 changes: 2 additions & 2 deletions vslib/NetMsgRegistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void NetMsgRegistrar::unregisterCallback(
}
}

void NetMsgRegistrar::unregisteraAll()
void NetMsgRegistrar::unregisterAll()
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -129,7 +129,7 @@ void NetMsgRegistrar::run()
}
catch (const std::exception& e)
{
SWSS_LOG_ERROR("exception: %s", e.what());
SWSS_LOG_ERROR("NetMsgRegistrar::run: exception: %s", e.what());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion vslib/NetMsgRegistrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace saivs
void unregisterCallback(
_In_ uint64_t index);

void unregisteraAll();
void unregisterAll();

void resetIndex();

Expand Down

0 comments on commit 5f6b004

Please sign in to comment.