Skip to content

Commit

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

#include <gtest/gtest.h>

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);
}

0 comments on commit 9381f2d

Please sign in to comment.