Skip to content

Commit

Permalink
Add Switch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent cc2e078 commit 484beb1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
4 changes: 3 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ tests_SOURCES = main.cpp \
TestTrafficForwarder.cpp \
TestHostInterfaceInfo.cpp \
TestTrafficFilterPipes.cpp \
TestSwitchConfig.cpp
TestSwitchConfig.cpp \
TestSwitchContainer.cpp \
TestSwitch.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
70 changes: 70 additions & 0 deletions unittest/vslib/TestSwitch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "Switch.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(Switch, ctr)
{
EXPECT_THROW(std::make_shared<Switch>(0), std::runtime_error);

EXPECT_THROW(std::make_shared<Switch>(0, 1, nullptr), std::runtime_error);

Switch s(0x2100000000);

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY;

Switch s2(0x2100000000, 1, &attr);
}

TEST(Switch, getSwitchId)
{
Switch s(0x2100000000);

EXPECT_EQ(s.getSwitchId(), 0x2100000000);
}

TEST(Switch, updateNotifications)
{
Switch s(0x2100000000);

EXPECT_THROW(s.updateNotifications(1, nullptr), std::runtime_error);

s.updateNotifications(0, nullptr);

sai_attribute_t attr;

attr.id = -1;

EXPECT_THROW(s.updateNotifications(1, &attr), std::runtime_error);

attr.id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY;
s.updateNotifications(1, &attr);

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
s.updateNotifications(1, &attr);
}

TEST(Switch, getSwitchNotifications)
{
Switch s(0x2100000000);

s.getSwitchNotifications();
}
8 changes: 6 additions & 2 deletions vslib/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ void Switch::updateNotifications(
* api when object is SWITCH.
*/

if (attrCount && attrList == nullptr)
{
SWSS_LOG_THROW("attrCount is %u, but attrList is nullptr", attrCount);
}

for (uint32_t index = 0; index < attrCount; ++index)
{
auto &attr = attrList[index];
Expand Down Expand Up @@ -101,8 +106,7 @@ void Switch::updateNotifications(
break;

default:
SWSS_LOG_ERROR("pointer for %s is not handled, FIXME!", meta->attridname);
break;
SWSS_LOG_THROW("pointer for %s is not handled, FIXME!", meta->attridname);
}
}
}
Expand Down

0 comments on commit 484beb1

Please sign in to comment.