#include <config/command_socket.h>
#include <config/command_socket_factory.h>
#include <cstdio>
+#include <cstdlib>
using namespace isc::config;
using namespace isc::data;
public:
/// Default constructor
- CommandSocketFactoryTest() {
+ CommandSocketFactoryTest()
+ :SOCKET_NAME(getSocketPath()) {
+
// Remove any stale socket files
remove(SOCKET_NAME.c_str());
}
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.
// It should be possible to close the socket.
EXPECT_NO_THROW(sock->close());
}
-
#include <cerrno>
#include <cstring>
+#include <cstdlib>
#include <algorithm>
#include <string>
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";
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
if (listen_fd_ != -1) {
close(listen_fd_);
}
- unlink(TEST_UNIX_FILE);
+ unlink(getSocketPath().c_str());
}
// Start an internal "socket session server".
// 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) {
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.
// 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
}
// 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