Commit cce3574a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3918] Unix socket tests now use KEA_SOCKET_TEST_DIR env var (if available)

parent 24d05f97
......@@ -28,6 +28,7 @@
#include <sys/select.h>
#include <sys/ioctl.h>
#include <cstdlib>
using namespace std;
using namespace isc::config;
......@@ -231,7 +232,12 @@ public:
boost::shared_ptr<NakedControlledDhcpv6Srv> server_;
CtrlChannelDhcpv6SrvTest() {
socket_path_ = string(TEST_DATA_BUILDDIR) + "/kea6.sock";
const char* env = getenv("KEA_SOCKET_TEST_DIR");
if (env) {
socket_path_ = string(env) + "/kea6.sock";
} else {
socket_path_ = string(TEST_DATA_BUILDDIR) + "/kea6.sock";
}
reset();
}
......
......@@ -19,6 +19,7 @@
#include <config/command_socket.h>
#include <config/command_socket_factory.h>
#include <cstdio>
#include <cstdlib>
using namespace isc::config;
using namespace isc::data;
......@@ -28,7 +29,9 @@ class CommandSocketFactoryTest : public ::testing::Test {
public:
/// Default constructor
CommandSocketFactoryTest() {
CommandSocketFactoryTest()
:SOCKET_NAME(getSocketPath()) {
// Remove any stale socket files
remove(SOCKET_NAME.c_str());
}
......@@ -40,11 +43,22 @@ public:
remove(SOCKET_NAME.c_str());
}
static const std::string SOCKET_NAME;
};
/// @brief Returns socket path (using either hardcoded path or env variable)
/// @return path to the unix socket
std::string getSocketPath() {
std::string socket_path;
const char* env = getenv("KEA_SOCKET_TEST_DIR");
if (env) {
socket_path = std::string(env) + "/test-socket";
} else {
socket_path = std::string(TEST_DATA_BUILDDIR) + "/test-socket";
}
return (socket_path);
}
const std::string CommandSocketFactoryTest::SOCKET_NAME =
std::string(TEST_DATA_BUILDDIR) + "/test-socket";
std::string SOCKET_NAME;
};
TEST_F(CommandSocketFactoryTest, unixCreate) {
// Null pointer is obviously a bad idea.
......@@ -74,4 +88,3 @@ TEST_F(CommandSocketFactoryTest, unixCreate) {
// It should be possible to close the socket.
EXPECT_NO_THROW(sock->close());
}
......@@ -25,6 +25,7 @@
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
......@@ -51,7 +52,6 @@ using namespace isc::util::io::internal;
namespace {
const char* const TEST_UNIX_FILE = TEST_DATA_TOPBUILDDIR "/test.unix";
const char* const TEST_PORT = "53535";
const char* const TEST_PORT2 = "53536"; // use this in case we need 2 ports
const char TEST_DATA[] = "Kea test";
......@@ -155,13 +155,30 @@ private:
class ForwardTest : public ::testing::Test {
protected:
ForwardTest() : listen_fd_(-1), forwarder_(TEST_UNIX_FILE),
/// @brief Returns socket path (using either hardcoded path or env variable)
/// @return path to the unix socket
std::string getSocketPath() {
std::string socket_path;
const char* env = getenv("KEA_SOCKET_TEST_DIR");
if (env) {
socket_path = string(env) + "/test.unix";
} else {
socket_path = string(TEST_DATA_BUILDDIR) + "/test.unix";
}
return (socket_path);
}
ForwardTest() : listen_fd_(-1), forwarder_(getSocketPath()),
large_text_(65535, 'a'),
test_un_len_(2 + strlen(TEST_UNIX_FILE))
test_un_len_(2 + strlen(getSocketPath().c_str()))
{
unlink(TEST_UNIX_FILE);
std::string unix_file = getSocketPath();
unlink(unix_file.c_str());
test_un_.sun_family = AF_UNIX;
strncpy(test_un_.sun_path, TEST_UNIX_FILE, sizeof(test_un_.sun_path));
strncpy(test_un_.sun_path, unix_file.c_str(), sizeof(test_un_.sun_path));
#ifdef HAVE_SA_LEN
test_un_.sun_len = test_un_len_;
#endif
......@@ -171,7 +188,7 @@ protected:
if (listen_fd_ != -1) {
close(listen_fd_);
}
unlink(TEST_UNIX_FILE);
unlink(getSocketPath().c_str());
}
// Start an internal "socket session server".
......@@ -238,7 +255,7 @@ protected:
// and it's a TCP socket, it will also start listening to new connection
// requests.
int createSocket(int family, int type, int protocol,
const SockAddrInfo& sainfo, bool do_listen)
const SockAddrInfo& sainfo, bool do_listen)
{
int s = socket(family, type, protocol);
if (s < 0) {
......@@ -378,7 +395,7 @@ TEST_F(ForwardTest, connect) {
EXPECT_THROW(forwarder.close(), BadValue);
// Set up the receiver and connect. It should succeed.
SocketSessionForwarder forwarder2(TEST_UNIX_FILE);
SocketSessionForwarder forwarder2(getSocketPath().c_str());
startListen();
forwarder2.connectToReceiver();
// And it can be closed successfully.
......@@ -396,14 +413,14 @@ TEST_F(ForwardTest, connect) {
// Connect then destroy. Should be internally closed, but unfortunately
// it's not easy to test it directly. We only check no disruption happens.
SocketSessionForwarder* forwarderp =
new SocketSessionForwarder(TEST_UNIX_FILE);
new SocketSessionForwarder(getSocketPath().c_str());
forwarderp->connectToReceiver();
delete forwarderp;
}
TEST_F(ForwardTest, close) {
// can't close before connect
EXPECT_THROW(SocketSessionForwarder(TEST_UNIX_FILE).close(), BadValue);
EXPECT_THROW(SocketSessionForwarder(getSocketPath().c_str()).close(), BadValue);
}
void
......@@ -674,7 +691,7 @@ TEST_F(ForwardTest, badPush) {
}
// A subroutine for pushTooFast, continuously pushing socket sessions
// with full-size DNS messages (65535 bytes) without receiving them.
// with full-size DNS messages (65535 bytes) without receiving them.
// the push attempts will eventually fill the socket send buffer and trigger
// an exception. Unfortunately exactly how many we can forward depends on
// the internal system implementation; it should be close to 3, because
......
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