Skip to content

Commit

Permalink
Add SwitchConfig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 724ce74 commit cc2e078
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
79 changes: 79 additions & 0 deletions unittest/vslib/TestSwitchConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "SwitchConfig.h"

#include "saivs.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(SwitchConfig, parseSaiSwitchType)
{
sai_switch_type_t type;

EXPECT_FALSE(SwitchConfig::parseSaiSwitchType(nullptr, type));

EXPECT_FALSE(SwitchConfig::parseSaiSwitchType("foo", type));

EXPECT_TRUE(SwitchConfig::parseSaiSwitchType(SAI_VALUE_SAI_SWITCH_TYPE_NPU, type));
EXPECT_EQ(type, SAI_SWITCH_TYPE_NPU);

EXPECT_TRUE(SwitchConfig::parseSaiSwitchType(SAI_VALUE_SAI_SWITCH_TYPE_PHY, type));
EXPECT_EQ(type, SAI_SWITCH_TYPE_PHY);
}

TEST(SwitchConfig, parseSwitchType)
{
sai_vs_switch_type_t type;

EXPECT_FALSE(SwitchConfig::parseSwitchType(nullptr, type));
EXPECT_FALSE(SwitchConfig::parseSwitchType("foo", type));

EXPECT_TRUE(SwitchConfig::parseSwitchType(SAI_VALUE_VS_SWITCH_TYPE_BCM56850, type));
EXPECT_EQ(type, SAI_VS_SWITCH_TYPE_BCM56850);

EXPECT_TRUE(SwitchConfig::parseSwitchType(SAI_VALUE_VS_SWITCH_TYPE_BCM81724, type));
EXPECT_EQ(type, SAI_VS_SWITCH_TYPE_BCM81724);

EXPECT_TRUE(SwitchConfig::parseSwitchType(SAI_VALUE_VS_SWITCH_TYPE_MLNX2700, type));
EXPECT_EQ(type, SAI_VS_SWITCH_TYPE_MLNX2700);
}


TEST(SwitchConfig, parseBootType)
{
sai_vs_boot_type_t type;

EXPECT_TRUE(SwitchConfig::parseBootType(nullptr, type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_COLD);

EXPECT_FALSE(SwitchConfig::parseBootType("foo", type));

EXPECT_TRUE(SwitchConfig::parseBootType("cold", type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_COLD);

EXPECT_TRUE(SwitchConfig::parseBootType(SAI_VALUE_VS_BOOT_TYPE_COLD, type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_COLD);

EXPECT_TRUE(SwitchConfig::parseBootType("warm", type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_WARM);

EXPECT_TRUE(SwitchConfig::parseBootType(SAI_VALUE_VS_BOOT_TYPE_WARM, type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_WARM);

EXPECT_TRUE(SwitchConfig::parseBootType("fast", type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_FAST);

EXPECT_TRUE(SwitchConfig::parseBootType(SAI_VALUE_VS_BOOT_TYPE_FAST, type));
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_FAST);
}

TEST(SwitchConfig, parseUseTapDevice)
{
EXPECT_FALSE(SwitchConfig::parseUseTapDevice(nullptr));

EXPECT_FALSE(SwitchConfig::parseUseTapDevice("foo"));

EXPECT_FALSE(SwitchConfig::parseUseTapDevice("false"));

EXPECT_TRUE(SwitchConfig::parseUseTapDevice("true"));
}
6 changes: 3 additions & 3 deletions vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "swss/logger.h"

#include <cstring>

using namespace saivs;

SwitchConfig::SwitchConfig(
Expand Down Expand Up @@ -120,9 +122,7 @@ bool SwitchConfig::parseUseTapDevice(

if (useTapDeviceStr)
{
std::string utd = useTapDeviceStr;

return utd == "true";
return strcmp(useTapDeviceStr, "true") == 0;
}

return false;
Expand Down

0 comments on commit cc2e078

Please sign in to comment.