diff --git a/unittest/vslib/Makefile.am b/unittest/vslib/Makefile.am index 1ecb899e3dc0..dc9ab5fafcb8 100644 --- a/unittest/vslib/Makefile.am +++ b/unittest/vslib/Makefile.am @@ -23,7 +23,8 @@ tests_SOURCES = main.cpp \ TestMACsecForwarder.cpp \ TestMACsecIngressFilter.cpp \ TestNetMsgRegistrar.cpp \ - TestRealObjectIdManager.cpp + TestRealObjectIdManager.cpp \ + TestResourceLimiter.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/TestResourceLimiter.cpp b/unittest/vslib/TestResourceLimiter.cpp new file mode 100644 index 000000000000..0198b128183b --- /dev/null +++ b/unittest/vslib/TestResourceLimiter.cpp @@ -0,0 +1,49 @@ +#include "ResourceLimiter.h" + +#include + +using namespace saivs; + +TEST(ResourceLimiter, ctr) +{ + ResourceLimiter rl(0); +} + +TEST(ResourceLimiter, getObjectTypeLimit) +{ + ResourceLimiter rl(0); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); + + rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); +} + +TEST(ResourceLimiter, removeObjectTypeLimit) +{ + ResourceLimiter rl(0); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); + + rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); + + rl.removeObjectTypeLimit(SAI_OBJECT_TYPE_PORT); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); +} + +TEST(ResourceLimiter, clearLimits) +{ + ResourceLimiter rl(0); + + rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); + + rl.clearLimits(); + + EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); +}