Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
9161867d
Commit
9161867d
authored
Sep 24, 2015
by
Thomas Markwalder
Browse files
[master] Fixed fd/0 unit test issue
Merged branch 'trac4067'
parents
0d5ae827
0709db27
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
View file @
9161867d
...
...
@@ -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
)
{
...
...
src/lib/dhcp/tests/pkt_filter_test_stub.cc
View file @
9161867d
...
...
@@ -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
...
...
src/lib/dhcp/tests/pkt_filter_test_stub.h
View file @
9161867d
...
...
@@ -47,9 +47,11 @@ public:
/// @brief Simulate opening of the socket.
///
/// This function simulates opening a primary socket. In reality, it doesn't
/// open a socket but the socket descriptor returned in the SocketInfo
/// structure is always set to 0.
/// This function simulates opening a primary socket. Rather than open
/// an actual socket, the stub peforms a read-only open of "/dev/null".
/// 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 addr Address on the interface to be used to send packets.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment