diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-07-26 01:16:27 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-13 11:33:04 +0000 |
commit | 2aca45c01e84ab308475f216f95aba55bfe925be (patch) | |
tree | 742872886b3a64ba5ec63c6b6b21ca1aba40b93e | |
parent | 6e8df63c13c9d0a343e8d14de61e2635df797efa (diff) | |
download | phosphor-networkd-2aca45c01e84ab308475f216f95aba55bfe925be.tar.gz phosphor-networkd-2aca45c01e84ab308475f216f95aba55bfe925be.zip |
Add test cases for VlanInterface
Change-Id: Ifd2507b12f39c44857af8bcf6ea57f7d1daa7ac3
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rw-r--r-- | test/Makefile.am | 7 | ||||
-rw-r--r-- | test/test_vlan_interface.cpp | 199 |
2 files changed, 202 insertions, 4 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 7ccb4e1..f1d11d4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -8,10 +8,9 @@ test_SOURCES = \ test_util.cpp \ mock_syscall.cpp \ test_network_manager.cpp \ - test_config_parser.cpp -# #TODO openbmc/openbmc#2084 \ -# Disable due to test case failure -# test_ethernet_interface.cpp + test_ethernet_interface.cpp \ + test_config_parser.cpp \ + test_vlan_interface.cpp test_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) diff --git a/test/test_vlan_interface.cpp b/test/test_vlan_interface.cpp new file mode 100644 index 0000000..9711a1a --- /dev/null +++ b/test/test_vlan_interface.cpp @@ -0,0 +1,199 @@ +#include "network_manager.hpp" +#include "mock_syscall.hpp" +#include "config_parser.hpp" +#include "vlan_interface.hpp" +#include "ipaddress.hpp" + +#include <gtest/gtest.h> +#include <sdbusplus/bus.hpp> + +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <exception> +#include <experimental/filesystem> + +namespace phosphor +{ +namespace network +{ + +namespace fs = std::experimental::filesystem; + +class TestVlanInterface : public testing::Test +{ + public: + + sdbusplus::bus::bus bus; + Manager manager; + EthernetInterface interface; + std::string confDir; + TestVlanInterface() + : bus(sdbusplus::bus::new_default()), + manager(bus, "/xyz/openbmc_test/network", "/tmp"), + interface(bus, "/xyz/openbmc_test/network/test0", false, manager) + + { + setConfDir(); + } + + ~TestVlanInterface() + { + if(confDir != "") + { + fs::remove_all(confDir); + } + } + + void setConfDir() + { + char tmp[] = "/tmp/VlanInterface.XXXXXX"; + confDir = mkdtemp(tmp); + manager.setConfDir(confDir); + } + + void createVlan(VlanId id) + { + interface.createVLAN(id); + } + + void deleteVlan(const std::string& interfaceName) + { + interface.deleteVLANObject(interfaceName); + } + + int countIPObjects() + { + return interface.getAddresses().size(); + } + + bool isIPObjectExist(const std::string& ipaddress) + { + auto address = interface.getAddresses().find(ipaddress); + if (address == interface.getAddresses().end()) + { + return false; + } + return true; + + } + + bool deleteIPObject(const std::string& ipaddress) + { + auto address = interface.getAddresses().find(ipaddress); + if (address == interface.getAddresses().end()) + { + return false; + } + address->second->delete_(); + return true; + } + + void createIPObject(IP::Protocol addressType, + const std::string& ipaddress, + uint8_t subnetMask, + const std::string& gateway) + { + interface.iP(addressType, + ipaddress, + subnetMask, + gateway + ); + + } + + bool isValueFound(const std::vector<std::string>& values, + const std::string& expectedValue) + { + for (const auto& value : values) + { + if (expectedValue == value) + { + return true; + } + } + return false; + } +}; + +TEST_F(TestVlanInterface, createVLAN) +{ + createVlan(50); + fs::path filePath = confDir; + filePath /= "test0.50.netdev"; + + config::Parser parser(filePath.string()); + auto values = parser.getValues("NetDev", "Name"); + std::string expectedValue = "test0.50"; + bool found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + values = parser.getValues("NetDev", "Kind"); + expectedValue = "vlan"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + values = parser.getValues("VLAN", "Id"); + expectedValue = "50"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + +} + +TEST_F(TestVlanInterface, deleteVLAN) +{ + createVlan(50); + deleteVlan("test0.50"); + bool fileFound = false; + + fs::path filePath = confDir; + filePath /= "test0.50.netdev"; + if (fs::is_regular_file(filePath.string())) + { + fileFound = true; + } + EXPECT_EQ(fileFound, false); +} + +TEST_F(TestVlanInterface, createMultipleVLAN) +{ + createVlan(50); + createVlan(60); + + fs::path filePath = confDir; + filePath /= "test0.50.netdev"; + config::Parser parser(filePath.string()); + auto values = parser.getValues("NetDev", "Name"); + std::string expectedValue = "test0.50"; + bool found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + values = parser.getValues("NetDev", "Kind"); + expectedValue = "vlan"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + values = parser.getValues("VLAN", "Id"); + expectedValue = "50"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + filePath = confDir; + filePath /= "test0.60.netdev"; + parser.setFile(filePath.string()); + values = parser.getValues("NetDev", "Name"); + expectedValue = "test0.60"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + values = parser.getValues("VLAN", "Id"); + expectedValue = "60"; + found = isValueFound(values, expectedValue); + EXPECT_EQ(found, true); + + deleteVlan("test0.50"); + deleteVlan("test0.60"); +} + +}// namespce network +}// namespace phosphor |