Skip to content

Commit 5f6b004

Browse files
committed
Add NetMsgRegistrar tests
1 parent 8142375 commit 5f6b004

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

unittest/vslib/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ tests_SOURCES = main.cpp \
2121
TestMACsecAttr.cpp \
2222
TestMACsecEgressFilter.cpp \
2323
TestMACsecForwarder.cpp \
24-
TestMACsecIngressFilter.cpp
24+
TestMACsecIngressFilter.cpp \
25+
TestNetMsgRegistrar.cpp
2526

2627
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
2728
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "NetMsgRegistrar.h"
2+
3+
#include <gtest/gtest.h>
4+
5+
using namespace saivs;
6+
7+
static void callback(int, struct nl_object*)
8+
{
9+
// empty
10+
}
11+
12+
TEST(NetMsgRegistrar, registerCallback)
13+
{
14+
auto& reg = NetMsgRegistrar::getInstance();
15+
16+
auto index = reg.registerCallback(callback);
17+
18+
reg.unregisterCallback(index);
19+
}
20+
21+
TEST(NetMsgRegistrar, unregisterAll)
22+
{
23+
auto& reg = NetMsgRegistrar::getInstance();
24+
25+
reg.registerCallback(callback);
26+
27+
usleep(100*1000);
28+
29+
reg.unregisterAll();
30+
}
31+
32+
TEST(NetMsgRegistrar, resetIndex)
33+
{
34+
auto& reg = NetMsgRegistrar::getInstance();
35+
36+
reg.resetIndex();
37+
38+
auto index = reg.registerCallback(callback);
39+
40+
reg.unregisterAll();
41+
42+
auto index2 = reg.registerCallback(callback);
43+
44+
EXPECT_NE(index, index2);
45+
46+
reg.unregisterAll();
47+
48+
reg.resetIndex();
49+
50+
auto index3 = reg.registerCallback(callback);
51+
52+
EXPECT_EQ(index, index3);
53+
}

vslib/NetMsgRegistrar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void NetMsgRegistrar::unregisterCallback(
7777
}
7878
}
7979

80-
void NetMsgRegistrar::unregisteraAll()
80+
void NetMsgRegistrar::unregisterAll()
8181
{
8282
SWSS_LOG_ENTER();
8383

@@ -129,7 +129,7 @@ void NetMsgRegistrar::run()
129129
}
130130
catch (const std::exception& e)
131131
{
132-
SWSS_LOG_ERROR("exception: %s", e.what());
132+
SWSS_LOG_ERROR("NetMsgRegistrar::run: exception: %s", e.what());
133133
break;
134134
}
135135
}

vslib/NetMsgRegistrar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace saivs
4848
void unregisterCallback(
4949
_In_ uint64_t index);
5050

51-
void unregisteraAll();
51+
void unregisterAll();
5252

5353
void resetIndex();
5454

0 commit comments

Comments
 (0)