Commit ec3b132b authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[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
~
parent c1df754f
......@@ -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) {
......
......@@ -13,6 +13,9 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <dhcp/tests/pkt_filter_test_stub.h>
......@@ -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
......
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