Commit 25bae983 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3517] Corrected test for interface detection.

The original version of this test incorrectly matched the names of the
interfaces detected by the IfaceMgr and those detected by the unit test.
As a result, the interfaces with similar names (e.g. virbr0 and virbr0-nic)
where compared for the equality of indexes, addresses and flags.
parent 8998eb0d
...@@ -2642,46 +2642,48 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) { ...@@ -2642,46 +2642,48 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) {
} }
TEST_F(IfaceMgrTest, detectIfaces) { TEST_F(IfaceMgrTest, detectIfaces) {
NakedIfaceMgr ifacemgr;
NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
IfaceMgr::IfaceCollection& detectedIfaces = ifacemgr->getIfacesLst();
// We are using struct ifaddrs as it is the only good portable one // We are using struct ifaddrs as it is the only good portable one
// ifreq and ioctls are far from portabe. For BSD ifreq::ifa_flags field // ifreq and ioctls are far from portabe. For BSD ifreq::ifa_flags field
// is only a short which, nowadays, can be negative // is only a short which, nowadays, can be negative
struct ifaddrs * iflist = 0, * ifptr = 0; struct ifaddrs *iflist = 0, *ifptr = 0;
ASSERT_EQ(0, getifaddrs(&iflist))
if(getifaddrs(& iflist) != 0) { << "Unit test failed to detect interfaces.";
isc_throw(Unexpected, "Cannot detect interfaces");
}
// Go over all interfaces detected by the unit test and see if they
// match with the interfaces detected by IfaceMgr.
for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) { for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
for (IfaceMgr::IfaceCollection::const_iterator i = detectedIfaces.begin(); Iface* i = ifacemgr.getIface(std::string(ifptr->ifa_name));
i != detectedIfaces.end(); ++ i) {
if (!strncmp(ifptr->ifa_name, (*i).getName().c_str(), // If the given interface was also detected by the IfaceMgr,
(*i).getName().size())) { // check that its properties are correct.
if (i != NULL) {
// Typically unit-tests try to be silent. But interface detection // Check if interface index is reported properly
// is tricky enough to warrant additional prints. EXPECT_TRUE(checkIfIndex(*i, ifptr))
std::cout << "Checking interface " << i->getName() << std::endl; << "Non-matching index of the detected interface "
<< i->getName();
// Check if flags are reported properly
EXPECT_TRUE(checkIfFlags(*i, ifptr))
<< "Non-matching flags of the detected interface "
<< i->getName();
// Check if addresses are reported properly
EXPECT_TRUE(checkIfAddrs(*i, ifptr))
<< "Non-matching addresses on the detected interface "
<< i->getName();
// Check if interface index is reported properly } else {
EXPECT_TRUE(checkIfIndex(*i, ifptr)); // The interface detected here seems to be missing in the
// IfaceMgr.
// Check if flags are reported properly ADD_FAILURE() << "Interface " << ifptr->ifa_name
EXPECT_TRUE(checkIfFlags(*i, ifptr)); << " not detected by the Interface Manager";
// Check if addresses are reported properly
EXPECT_TRUE(checkIfAddrs(*i, ifptr));
}
} }
} }
freeifaddrs(iflist); freeifaddrs(iflist);
iflist = 0; iflist = 0;
delete ifacemgr;
} }
volatile bool callback_ok; volatile bool callback_ok;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment