From: Marcin Siodelski Date: Thu, 14 Aug 2014 11:08:08 +0000 (+0200) Subject: [3517] Corrected test for interface detection. X-Git-Tag: trac3482_base~37^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25bae983a92b9868edfdfcd82a0742353be85c13;p=thirdparty%2Fkea.git [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. --- diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index ce50efe82b..80c8c683e0 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -2642,46 +2642,48 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) { } TEST_F(IfaceMgrTest, detectIfaces) { - - NakedIfaceMgr* ifacemgr = new NakedIfaceMgr(); - IfaceMgr::IfaceCollection& detectedIfaces = ifacemgr->getIfacesLst(); + NakedIfaceMgr ifacemgr; // 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 // is only a short which, nowadays, can be negative - struct ifaddrs * iflist = 0, * ifptr = 0; - - if(getifaddrs(& iflist) != 0) { - isc_throw(Unexpected, "Cannot detect interfaces"); - } + struct ifaddrs *iflist = 0, *ifptr = 0; + ASSERT_EQ(0, getifaddrs(&iflist)) + << "Unit test failed to 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 (IfaceMgr::IfaceCollection::const_iterator i = detectedIfaces.begin(); - i != detectedIfaces.end(); ++ i) { - if (!strncmp(ifptr->ifa_name, (*i).getName().c_str(), - (*i).getName().size())) { - - // Typically unit-tests try to be silent. But interface detection - // is tricky enough to warrant additional prints. - std::cout << "Checking interface " << i->getName() << std::endl; + Iface* i = ifacemgr.getIface(std::string(ifptr->ifa_name)); + + // If the given interface was also detected by the IfaceMgr, + // check that its properties are correct. + if (i != NULL) { + // Check if interface index is reported properly + EXPECT_TRUE(checkIfIndex(*i, ifptr)) + << "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 - EXPECT_TRUE(checkIfIndex(*i, ifptr)); - - // Check if flags are reported properly - EXPECT_TRUE(checkIfFlags(*i, ifptr)); - - // Check if addresses are reported properly - EXPECT_TRUE(checkIfAddrs(*i, ifptr)); - - } + } else { + // The interface detected here seems to be missing in the + // IfaceMgr. + ADD_FAILURE() << "Interface " << ifptr->ifa_name + << " not detected by the Interface Manager"; } } freeifaddrs(iflist); iflist = 0; - - delete ifacemgr; } volatile bool callback_ok;