diff options
Diffstat (limited to 'src/lib/dhcpsrv/tests')
19 files changed, 16 insertions, 256 deletions
diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index 8aad886da0..c7d8bf2aa4 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -131,7 +131,6 @@ libdhcpsrv_unittests_SOURCES += srv_config_unittest.cc libdhcpsrv_unittests_SOURCES += subnet_unittest.cc libdhcpsrv_unittests_SOURCES += test_get_callout_handle.cc test_get_callout_handle.h libdhcpsrv_unittests_SOURCES += triplet_unittest.cc -libdhcpsrv_unittests_SOURCES += test_utils.cc test_utils.h libdhcpsrv_unittests_SOURCES += timer_mgr_unittest.cc libdhcpsrv_unittests_SOURCES += network_state_unittest.cc libdhcpsrv_unittests_SOURCES += network_unittest.cc diff --git a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc index 6ffd1d54ec..ffb2696f62 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc @@ -11,7 +11,7 @@ #include <dhcpsrv/shared_network.h> #include <dhcpsrv/host_mgr.h> #include <dhcpsrv/tests/alloc_engine_utils.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <testutils/gtest_utils.h> #include <hooks/hooks_manager.h> #include <hooks/callout_handle.h> diff --git a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc index ff2ab7c656..b1c9f855af 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc @@ -9,7 +9,7 @@ #include <dhcp/pkt6.h> #include <dhcpsrv/host_mgr.h> #include <dhcpsrv/tests/alloc_engine_utils.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <stats/stats_mgr.h> #include <testutils/gtest_utils.h> diff --git a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc index be89802b7a..c758e476c0 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc @@ -9,7 +9,7 @@ #include <dhcp/option_data_types.h> #include <dhcp_ddns/ncr_msg.h> #include <dhcpsrv/tests/alloc_engine_utils.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <hooks/hooks_manager.h> #include <stats/stats_mgr.h> #include <gtest/gtest.h> diff --git a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc index 682e64aa4c..935296dcba 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc @@ -6,7 +6,7 @@ #include <config.h> #include <dhcpsrv/tests/alloc_engine_utils.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <hooks/server_hooks.h> #include <hooks/callout_manager.h> diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc index 9de1ea6990..03d224bfcb 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc @@ -18,7 +18,7 @@ #include <hooks/callout_handle.h> #include <stats/stats_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/alloc_engine_utils.h> #include <hooks/hooks_manager.h> diff --git a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc index ec2b80b2ef..17b084c748 100644 --- a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc @@ -18,7 +18,7 @@ #include <config.h> #include <asiolink/io_address.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <exceptions/exceptions.h> #include <dhcpsrv/host.h> #include <dhcpsrv/cql_host_data_source.h> diff --git a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc index d79dd8bb69..38f4455e43 100644 --- a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc @@ -23,7 +23,7 @@ #include <cql/testutils/cql_schema.h> #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/cql_lease_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <exceptions/exceptions.h> diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index cc8966fdf8..1d3524819c 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -13,7 +13,7 @@ #include <dhcpsrv/dhcpsrv_exceptions.h> #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <exceptions/exceptions.h> #include <stats/stats_mgr.h> diff --git a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc index 014a1b8b18..564f863407 100644 --- a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc @@ -11,7 +11,7 @@ #include <dhcpsrv/host.h> #include <dhcpsrv/host_data_source_factory.h> #include <dhcpsrv/host_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <testutils/multi_threading_utils.h> #include <util/multi_threading_mgr.h> diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc index a430c789c0..01dadd931a 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc @@ -9,7 +9,7 @@ #include <asiolink/io_address.h> #include <dhcpsrv/lease_mgr.h> #include <dhcpsrv/memfile_lease_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <gtest/gtest.h> diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 25d4a5541b..937f8a3b4e 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -16,7 +16,7 @@ #include <dhcpsrv/memfile_lease_mgr.h> #include <dhcpsrv/timer_mgr.h> #include <dhcpsrv/testutils/lease_file_io.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <util/multi_threading_mgr.h> #include <util/pid_file.h> diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index c28417e708..677a0679bd 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -7,7 +7,7 @@ #include <config.h> #include <asiolink/io_address.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <exceptions/exceptions.h> #include <dhcpsrv/host.h> #include <dhcpsrv/mysql_host_data_source.h> diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 82f2185a55..d740b64430 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -9,7 +9,7 @@ #include <asiolink/io_address.h> #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/mysql_lease_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <exceptions/exceptions.h> #include <mysql/mysql_connection.h> diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index c7e5546831..6f6985037b 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -7,7 +7,7 @@ #include <config.h> #include <asiolink/io_address.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <exceptions/exceptions.h> #include <dhcpsrv/host.h> #include <dhcpsrv/pgsql_host_data_source.h> diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index f5433d01ba..393c0d36e3 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -9,7 +9,7 @@ #include <asiolink/io_address.h> #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/pgsql_lease_mgr.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <exceptions/exceptions.h> #include <pgsql/pgsql_connection.h> diff --git a/src/lib/dhcpsrv/tests/sanity_checks_unittest.cc b/src/lib/dhcpsrv/tests/sanity_checks_unittest.cc index a7231e1baa..6831d308a2 100644 --- a/src/lib/dhcpsrv/tests/sanity_checks_unittest.cc +++ b/src/lib/dhcpsrv/tests/sanity_checks_unittest.cc @@ -13,7 +13,7 @@ #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/subnet.h> #include <dhcpsrv/sanity_checker.h> -#include <dhcpsrv/tests/test_utils.h> +#include <dhcpsrv/testutils/test_utils.h> #include <util/range_utilities.h> #include <cc/data.h> #include <gtest/gtest.h> diff --git a/src/lib/dhcpsrv/tests/test_utils.cc b/src/lib/dhcpsrv/tests/test_utils.cc deleted file mode 100644 index 4fe7d86d93..0000000000 --- a/src/lib/dhcpsrv/tests/test_utils.cc +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include <config.h> -#include "test_utils.h" -#include <asiolink/io_address.h> -#include <gtest/gtest.h> -#include <sstream> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -using namespace std; -using namespace isc::asiolink; - -namespace isc { -namespace dhcp { -namespace test { - -void -detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second) { - // Compare address strings. Comparison of address objects is not used, as - // odd things happen when they are different: the EXPECT_EQ macro appears to - // call the operator uint32_t() function, which causes an exception to be - // thrown for IPv6 addresses. - ASSERT_TRUE(first); - ASSERT_TRUE(second); - EXPECT_EQ(first->addr_, second->addr_); - - // We need to compare the actual HWAddr objects, not pointers - EXPECT_TRUE(*first->hwaddr_ == *second->hwaddr_); - - if (first->client_id_ && second->client_id_) { - EXPECT_TRUE(*first->client_id_ == *second->client_id_); - } else { - if (first->client_id_ && !second->client_id_) { - - ADD_FAILURE() << "Client-id present in first lease (" - << first->client_id_->getClientId().size() - << " bytes), but missing in second."; - } - if (!first->client_id_ && second->client_id_) { - ADD_FAILURE() << "Client-id missing in first lease, but present in second (" - << second->client_id_->getClientId().size() - << " bytes)."; - } - // else here would mean that both leases do not have client_id_ - // which makes them equal in that regard. It is ok. - } - EXPECT_EQ(first->valid_lft_, second->valid_lft_); - EXPECT_EQ(first->cltt_, second->cltt_); - EXPECT_EQ(first->subnet_id_, second->subnet_id_); - EXPECT_EQ(first->fqdn_fwd_, second->fqdn_fwd_); - EXPECT_EQ(first->fqdn_rev_, second->fqdn_rev_); - EXPECT_EQ(first->hostname_, second->hostname_); - if (first->getContext()) { - EXPECT_TRUE(second->getContext()); - if (second->getContext()) { - EXPECT_EQ(first->getContext()->str(), second->getContext()->str()); - } - } else { - EXPECT_FALSE(second->getContext()); - } -} - -void -detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second) { - ASSERT_TRUE(first); - ASSERT_TRUE(second); - EXPECT_EQ(first->type_, second->type_); - - // Compare address strings. Comparison of address objects is not used, as - // odd things happen when they are different: the EXPECT_EQ macro appears to - // call the operator uint32_t() function, which causes an exception to be - // thrown for IPv6 addresses. - EXPECT_EQ(first->addr_, second->addr_); - EXPECT_EQ(first->prefixlen_, second->prefixlen_); - EXPECT_EQ(first->iaid_, second->iaid_); - ASSERT_TRUE(first->duid_); - ASSERT_TRUE(second->duid_); - EXPECT_TRUE(*first->duid_ == *second->duid_); - EXPECT_EQ(first->preferred_lft_, second->preferred_lft_); - EXPECT_EQ(first->valid_lft_, second->valid_lft_); - EXPECT_EQ(first->cltt_, second->cltt_); - EXPECT_EQ(first->subnet_id_, second->subnet_id_); - EXPECT_EQ(first->fqdn_fwd_, second->fqdn_fwd_); - EXPECT_EQ(first->fqdn_rev_, second->fqdn_rev_); - EXPECT_EQ(first->hostname_, second->hostname_); - if (first->getContext()) { - EXPECT_TRUE(second->getContext()); - if (second->getContext()) { - EXPECT_EQ(first->getContext()->str(), second->getContext()->str()); - } - } else { - EXPECT_FALSE(second->getContext()); - } -} - -int findLastSocketFd() { - int max_fd_number = getdtablesize(); - int last_socket = -1; - struct stat stats; - - // Iterate over the open fds - for (int fd = 0; fd <= max_fd_number; fd++ ) { - errno = 0; - fstat(fd, &stats); - - if (errno == EBADF ) { - // Skip any that aren't open - continue; - } - - // it's a socket, remember it - if (S_ISSOCK(stats.st_mode)) { - last_socket = fd; - } - } - - return (last_socket); -} - -FillFdHoles::FillFdHoles(int limit) : fds_() { - if (limit <= 0) { - return; - } - for (;;) { - int fd = open("/dev/null", O_RDWR, 0); - if (fd == -1) { - return; - } - if (fd < limit) { - fds_.push_front(fd); - } else { - static_cast<void>(close(fd)); - return; - } - } -} - -FillFdHoles::~FillFdHoles() { - while (!fds_.empty()) { - static_cast<void>(close(fds_.back())); - fds_.pop_back(); - } -} - -} // namespace test -} // namespace dhcp -} // namespace isc diff --git a/src/lib/dhcpsrv/tests/test_utils.h b/src/lib/dhcpsrv/tests/test_utils.h deleted file mode 100644 index 02af9ba467..0000000000 --- a/src/lib/dhcpsrv/tests/test_utils.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef LIBDHCPSRV_TEST_UTILS_H -#define LIBDHCPSRV_TEST_UTILS_H - -#include <dhcpsrv/lease_mgr.h> -#include <list> -#include <vector> - -namespace isc { -namespace dhcp { -namespace test { - -// @brief performs details comparison between two IPv6 leases -// -// @param first first lease to compare -// @param second second lease to compare -// -// This method is intended to be run from gtest tests as it -// uses gtest macros and possibly reports gtest failures. -void -detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second); - -// @brief performs details comparison between two IPv4 leases -// -// @param first first lease to compare -// @param second second lease to compare -// -// This method is intended to be run from gtest tests as it -// uses gtest macros and possibly reports gtest failures. -void -detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second); - -/// @brief Function that finds the last open socket descriptor -/// -/// This function is used to attempt lost connectivity -/// with backends, notably MySQL and Postgresql. -/// -/// The theory being, that in a confined test environment the last -/// such descriptor is the SQL client socket descriptor. This allows -/// us to the close that descriptor and simulate a loss of server -/// connectivity. -/// -/// @return the descriptor of the last open socket or -1 if there -/// are none. -int findLastSocketFd(); - -/// @brief RAII tool which fills holes in the file descriptor sequence -/// -/// The @ref findLastSocketFd requires new socket descriptors are allocated -/// after the last open socket descriptor so there is no hole i.e. a free -/// file descriptor in the sequence. -/// This tool detects and fills such holes. It uses the RAII idiom to avoid -/// file descriptor leaks: the destructor called when the object goes out -/// of scope closes all file descriptors which were opened by the constructor. -class FillFdHoles { -public: - /// @brief Constructor - /// - /// Holes between 0 and the specified limit will be filled by opening - /// the null device. Typically the limit argument is the result of - /// a previous call to @ref findLastSocketFd. Note if the limit is - /// 0 or negative the constructor returns doing nothing. - /// - /// @param limit Holes will be filled up to this limit - FillFdHoles(int limit); - - /// @brief Destructor - /// - /// The destructor closes members of the list - ~FillFdHoles(); - -private: - /// @brief The list of holes - std::list<int> fds_; -}; - -} // namespace test -} // namespace dhcp -} // namespace isc - -#endif |