From ec3b132b582acc0a089f41b19e1dd6a6d217603d Mon Sep 17 00:00:00 2001 From: Thomas Markwalder Date: Thu, 24 Sep 2015 09:01:49 -0400 Subject: [PATCH] [4067] PktFilterTestStub no longer used fd 0 src/lib/dhcp/tests/pkt_filter_test_stub.cc - PktFilterTestStub::openSocket() - the filter's SocketInfo::sock_fd_ is now set with value returend by opening "/dev/null" as read_only. This provides a valid, consumed fd that the filter retains until its socket is closed. src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc CtrlChannelDhcp4SrvTest removed the fd/0 work-around as it is no longer needed ~ --- .../dhcp4/tests/ctrl_dhcp4_srv_unittest.cc | 19 ------------------- src/lib/dhcp/tests/pkt_filter_test_stub.cc | 12 +++++++++++- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index b286a5a4d6..af2f5e676a 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -76,26 +76,12 @@ public: socket_path_ = string(TEST_DATA_BUILDDIR) + "/kea4.sock"; } reset(); - - // This is a workaround for odd problems with gtest. gtest does - // shady with socket decriptors. In particular, sometimes we - // get 0 as descriptor for socket() call. Technically it is valid, - // but then gtest closes descriptor 0 and the socket becomes - // unusable. This workaround opens up one file decriptor. In case - // 0 is available, it will be consumed here. - dummy_fd_ = socket(AF_INET, SOCK_DGRAM, 0); - if (dummy_fd_ == 0) { - std::cout << "Socket descriptor 0 workaround is useful." << std::endl; - } } /// @brief Destructor ~CtrlChannelDhcpv4SrvTest() { server_.reset(); reset(); - - // close dummy descriptor - close(dummy_fd_); }; void createUnixChannelServer() { @@ -197,11 +183,6 @@ public: client->disconnectFromServer(); ASSERT_NO_THROW(server_->receivePacket(0)); } - - /// @brief dummy file descriptor - /// - /// See ctor for details. - int dummy_fd_; }; TEST_F(CtrlChannelDhcpv4SrvTest, commands) { diff --git a/src/lib/dhcp/tests/pkt_filter_test_stub.cc b/src/lib/dhcp/tests/pkt_filter_test_stub.cc index 124604e42e..a50233067a 100644 --- a/src/lib/dhcp/tests/pkt_filter_test_stub.cc +++ b/src/lib/dhcp/tests/pkt_filter_test_stub.cc @@ -13,6 +13,9 @@ // PERFORMANCE OF THIS SOFTWARE. #include +#include +#include +#include #include @@ -33,7 +36,14 @@ SocketInfo PktFilterTestStub::openSocket(Iface&, const isc::asiolink::IOAddress& addr, const uint16_t port, const bool, const bool) { - return (SocketInfo(addr, port, 0)); + int fd = open("/dev/null", O_RDONLY); + if (fd < 0) { + const char* errmsg = strerror(errno); + isc_throw(Unexpected, + "PktFilterTestStub: cannot open /dev/null:" << errmsg); + } + + return (SocketInfo(addr, port, fd)); } Pkt4Ptr -- 2.47.3