Commit 9161867d authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[master] Fixed fd/0 unit test issue

    Merged branch 'trac4067'
parents 0d5ae827 0709db27
...@@ -76,26 +76,12 @@ public: ...@@ -76,26 +76,12 @@ public:
socket_path_ = string(TEST_DATA_BUILDDIR) + "/kea4.sock"; socket_path_ = string(TEST_DATA_BUILDDIR) + "/kea4.sock";
} }
reset(); 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 /// @brief Destructor
~CtrlChannelDhcpv4SrvTest() { ~CtrlChannelDhcpv4SrvTest() {
server_.reset(); server_.reset();
reset(); reset();
// close dummy descriptor
close(dummy_fd_);
}; };
void createUnixChannelServer() { void createUnixChannelServer() {
...@@ -197,11 +183,6 @@ public: ...@@ -197,11 +183,6 @@ public:
client->disconnectFromServer(); client->disconnectFromServer();
ASSERT_NO_THROW(server_->receivePacket(0)); ASSERT_NO_THROW(server_->receivePacket(0));
} }
/// @brief dummy file descriptor
///
/// See ctor for details.
int dummy_fd_;
}; };
TEST_F(CtrlChannelDhcpv4SrvTest, commands) { TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
// PERFORMANCE OF THIS SOFTWARE. // PERFORMANCE OF THIS SOFTWARE.
#include <config.h> #include <config.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <dhcp/tests/pkt_filter_test_stub.h> #include <dhcp/tests/pkt_filter_test_stub.h>
...@@ -33,7 +36,14 @@ SocketInfo ...@@ -33,7 +36,14 @@ SocketInfo
PktFilterTestStub::openSocket(Iface&, PktFilterTestStub::openSocket(Iface&,
const isc::asiolink::IOAddress& addr, const isc::asiolink::IOAddress& addr,
const uint16_t port, const bool, const bool) { 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 Pkt4Ptr
......
...@@ -47,9 +47,11 @@ public: ...@@ -47,9 +47,11 @@ public:
/// @brief Simulate opening of the socket. /// @brief Simulate opening of the socket.
/// ///
/// This function simulates opening a primary socket. In reality, it doesn't /// This function simulates opening a primary socket. Rather than open
/// open a socket but the socket descriptor returned in the SocketInfo /// an actual socket, the stub peforms a read-only open of "/dev/null".
/// structure is always set to 0. /// The fd returned by this open saved as the socket's descriptor in the
/// SocketInfo structure. This way the filter consumes an actual
/// descriptor and retains it until its socket is closed.
/// ///
/// @param iface An interface descriptor. /// @param iface An interface descriptor.
/// @param addr Address on the interface to be used to send packets. /// @param addr Address on the interface to be used to send packets.
......
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