Bug Summary

File:usr/include/boost/smart_ptr/detail/shared_count.hpp
Warning:line 559, column 22
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name flq_allocator_unittest.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests -resource-dir /usr/lib64/clang/16 -D HAVE_CONFIG_H -I . -I ../../../.. -I ../../../../src/lib -I ../../../../src/lib -D TEST_DATA_BUILDDIR="/home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests" -D DHCP_DATA_DIR="/home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests" -D KEA_LFC_BUILD_DIR="/home/fedora/workspace/kea-dev/clang-static-analyzer/src/bin/lfc" -D INSTALL_PROG="/home/fedora/workspace/kea-dev/clang-static-analyzer/install-sh" -I /usr/src/googletest/googletest -I /usr/src/googletest/googletest/include -I /usr/include/mysql -I /usr/include/mysql/mysql -D _GNU_SOURCE -I /usr/include/libxml2 -I /usr/include -I /usr/include/pgsql/server -D OS_LINUX -I ../../../.. -I ../../../.. -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/backward -internal-isystem /usr/lib64/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wwrite-strings -Wno-sign-compare -Wno-missing-field-initializers -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/fedora/workspace/kea-dev/clang-static-analyzer/report/2024-05-17-164749-18469-1 -x c++ flq_allocator_unittest.cc

flq_allocator_unittest.cc

1// Copyright (C) 2023-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8#include <asiolink/io_address.h>
9#include <dhcp/hwaddr.h>
10#include <dhcpsrv/flq_allocator.h>
11#include <dhcpsrv/tests/alloc_engine_utils.h>
12#include <boost/make_shared.hpp>
13#include <gtest/gtest.h>
14
15using namespace isc::asiolink;
16using namespace std;
17
18namespace isc {
19namespace dhcp {
20namespace test {
21
22/// @brief Test fixture class for the DHCPv4 Free Lease Queue allocator.
23class FreeLeaseQueueAllocatorTest4 : public AllocEngine4Test {
24public:
25
26 /// @brief Creates a DHCPv4 lease for an address and MAC address.
27 ///
28 /// @param address Lease address.
29 /// @param hw_address_seed a seed from which the hardware address is generated.
30 /// @return Created lease pointer.
31 Lease4Ptr
32 createLease4(const IOAddress& address, uint64_t hw_address_seed) const {
33 vector<uint8_t> hw_address_vec(sizeof(hw_address_seed));
34 for (auto i = 0; i < sizeof(hw_address_seed); ++i) {
35 hw_address_vec[i] = (hw_address_seed >> i) & 0xFF;
36 }
37 auto hw_address = boost::make_shared<HWAddr>(hw_address_vec, HTYPE_ETHER);
38 auto lease = boost::make_shared<Lease4>(address, hw_address, ClientIdPtr(),
39 3600, time(0), subnet_->getID());
40 return (lease);
41 }
42};
43
44// Test that the allocator returns the correct type.
45TEST_F(FreeLeaseQueueAllocatorTest4, getType)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getType") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_getType_Test : public FreeLeaseQueueAllocatorTest4
{ public: FreeLeaseQueueAllocatorTest4_getType_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_getType_Test
(FreeLeaseQueueAllocatorTest4_getType_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest4_getType_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_getType_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "getType", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 45), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest4>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest4>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 45), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest4>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 45), new ::testing::internal::TestFactoryImpl
<FreeLeaseQueueAllocatorTest4_getType_Test>); void FreeLeaseQueueAllocatorTest4_getType_Test
::TestBody()
{
46 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
47 EXPECT_EQ("flq", alloc.getType())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"flq\""
, "alloc.getType()", "flq", alloc.getType()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 47, gtest_ar.failure_message()
) = ::testing::Message()
;
48}
49
50// Test populating free DHCPv4 leases to the queue.
51TEST_F(FreeLeaseQueueAllocatorTest4, populateFreeAddressLeases)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("populateFreeAddressLeases") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
: public FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
(FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "populateFreeAddressLeases", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 51), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest4>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 51), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 51)
, new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
>); void FreeLeaseQueueAllocatorTest4_populateFreeAddressLeases_Test
::TestBody()
{
52 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
53
54 auto& lease_mgr = LeaseMgrFactory::instance();
55
56 EXPECT_TRUE(lease_mgr.addLease((createLease4(IOAddress("192.0.2.100"), 0))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease4
(IOAddress("192.0.2.100"), 0))))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 56, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease((createLease4(IOAddress(\"192.0.2.100\"), 0)))"
, "false", "true").c_str()) = ::testing::Message()
;
57 EXPECT_TRUE(lease_mgr.addLease((createLease4(IOAddress("192.0.2.102"), 1))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease4
(IOAddress("192.0.2.102"), 1))))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 57, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease((createLease4(IOAddress(\"192.0.2.102\"), 1)))"
, "false", "true").c_str()) = ::testing::Message()
;
58 EXPECT_TRUE(lease_mgr.addLease((createLease4(IOAddress("192.0.2.104"), 2))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease4
(IOAddress("192.0.2.104"), 2))))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 58, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease((createLease4(IOAddress(\"192.0.2.104\"), 2)))"
, "false", "true").c_str()) = ::testing::Message()
;
59 EXPECT_TRUE(lease_mgr.addLease((createLease4(IOAddress("192.0.2.106"), 3))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease4
(IOAddress("192.0.2.106"), 3))))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 59, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease((createLease4(IOAddress(\"192.0.2.106\"), 3)))"
, "false", "true").c_str()) = ::testing::Message()
;
60 EXPECT_TRUE(lease_mgr.addLease((createLease4(IOAddress("192.0.2.108"), 4))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease4
(IOAddress("192.0.2.108"), 4))))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 60, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease((createLease4(IOAddress(\"192.0.2.108\"), 4)))"
, "false", "true").c_str()) = ::testing::Message()
;
61
62 EXPECT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_62; } } else
gtest_label_testnothrow_62: ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 62, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
63
64 auto pool_state = boost::dynamic_pointer_cast<PoolFreeLeaseQueueAllocationState>(pool_->getAllocationState());
65 ASSERT_TRUE(pool_state)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool_state)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "flq_allocator_unittest.cc", 65, ::testing::internal
::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state", "false"
, "true").c_str()) = ::testing::Message()
;
66 EXPECT_FALSE(pool_state->exhausted())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pool_state->exhausted
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 66, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state->exhausted()"
, "true", "false").c_str()) = ::testing::Message()
;
67
68 std::set<IOAddress> addresses;
69 for (auto i = 0; i < 5; ++i) {
70 auto lease = pool_state->offerFreeLease();
71 ASSERT_FALSE(lease.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease.isV4Zero())))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "flq_allocator_unittest.cc", 71, ::testing::
internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease.isV4Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
72 addresses.insert(lease);
73 }
74 ASSERT_EQ(5, addresses.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("5", "addresses.size()"
, 5, addresses.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 74, gtest_ar.failure_message()) = ::testing::Message()
;
75 EXPECT_EQ(1, addresses.count(IOAddress("192.0.2.101")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"192.0.2.101\"))"
, 1, addresses.count(IOAddress("192.0.2.101"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 75, gtest_ar.failure_message()
) = ::testing::Message()
;
76 EXPECT_EQ(1, addresses.count(IOAddress("192.0.2.103")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"192.0.2.103\"))"
, 1, addresses.count(IOAddress("192.0.2.103"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 76, gtest_ar.failure_message()
) = ::testing::Message()
;
77 EXPECT_EQ(1, addresses.count(IOAddress("192.0.2.105")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"192.0.2.105\"))"
, 1, addresses.count(IOAddress("192.0.2.105"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 77, gtest_ar.failure_message()
) = ::testing::Message()
;
78 EXPECT_EQ(1, addresses.count(IOAddress("192.0.2.107")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"192.0.2.107\"))"
, 1, addresses.count(IOAddress("192.0.2.107"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 78, gtest_ar.failure_message()
) = ::testing::Message()
;
79 EXPECT_EQ(1, addresses.count(IOAddress("192.0.2.109")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"192.0.2.109\"))"
, 1, addresses.count(IOAddress("192.0.2.109"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 79, gtest_ar.failure_message()
) = ::testing::Message()
;
80}
81
82// Test allocating IPv4 addresses when a subnet has a single pool.
83TEST_F(FreeLeaseQueueAllocatorTest4, singlePool)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePool") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_singlePool_Test : public
FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_singlePool_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_singlePool_Test
(FreeLeaseQueueAllocatorTest4_singlePool_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest4_singlePool_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_singlePool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "singlePool", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 83), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest4>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest4>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 83), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest4>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 83), new ::testing::internal::TestFactoryImpl
<FreeLeaseQueueAllocatorTest4_singlePool_Test>); void FreeLeaseQueueAllocatorTest4_singlePool_Test
::TestBody()
{
84 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
85
86 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_86; } } else
gtest_label_testnothrow_86: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 86, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
87
88 // Remember returned addresses, so we can verify that unique addresses
89 // are returned.
90 std::set<IOAddress> addresses;
91 for (auto i = 0; i < 1000; ++i) {
92 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
93 addresses.insert(candidate);
94 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
95 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 95, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
96 }
97 // The pool comprises 10 addresses. All should be returned.
98 EXPECT_EQ(10, addresses.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10", "addresses.size()"
, 10, addresses.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 98, gtest_ar.failure_message()) = ::testing::Message()
;
99}
100
101// Test allocating IPv4 addresses and re-allocating these that are
102// deleted (released).
103TEST_F(FreeLeaseQueueAllocatorTest4, singlePoolWithAllocations)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePoolWithAllocations") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
: public FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
(FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "singlePoolWithAllocations", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 103), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest4>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 103), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 103
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
>); void FreeLeaseQueueAllocatorTest4_singlePoolWithAllocations_Test
::TestBody()
{
104 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
105
106 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_106; } } else
gtest_label_testnothrow_106: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 106, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
107
108 auto& lease_mgr = LeaseMgrFactory::instance();
109
110 // Remember returned addresses, so we can verify that unique addresses
111 // are returned.
112 std::map<IOAddress, Lease4Ptr> leases;
113 for (auto i = 0; i < 10; ++i) {
114 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
115 auto lease = createLease4(candidate, i);
116 leases[candidate] = lease;
117 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 117, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
118 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 118, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
119 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 119, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
120 }
121 // The pool comprises 10 addresses. All should be returned.
122 EXPECT_EQ(10, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10", "leases.size()"
, 10, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 122, gtest_ar.failure_message()) = ::testing::Message()
;
123
124 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
125 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 125, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
126
127 auto i = 0;
128 for (auto const& address_lease : leases) {
129 if (i % 2) {
130 EXPECT_TRUE(lease_mgr.deleteLease(address_lease.second))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.deleteLease
(address_lease.second))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 130, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.deleteLease(address_lease.second)", "false", "true"
).c_str()) = ::testing::Message()
;
131 }
132 ++i;
133 }
134
135 for (auto i = 0; i < 5; ++i) {
136 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
137 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 137, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
138 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
139 auto lease = createLease4(candidate, i);
140 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 140, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
141 }
142
143 candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
144 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 144, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
145}
146
147// Test allocating IPv4 addresses and re-allocating these that are
148// reclaimed.
149TEST_F(FreeLeaseQueueAllocatorTest4, singlePoolWithReclamations)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePoolWithReclamations") > 1,
"test_name must not be empty"); class FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
: public FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
(FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
const &) = delete; void operator=(FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "singlePoolWithReclamations", nullptr, nullptr, ::testing::
internal::CodeLocation("flq_allocator_unittest.cc", 149), (::
testing::internal::GetTypeId<FreeLeaseQueueAllocatorTest4>
()), ::testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 149), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest4
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 149
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
>); void FreeLeaseQueueAllocatorTest4_singlePoolWithReclamations_Test
::TestBody()
{
150 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
151
152 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_152; } } else
gtest_label_testnothrow_152: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 152, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
153
154 auto& lease_mgr = LeaseMgrFactory::instance();
155
156 // Remember returned addresses, so we can verify that unique addresses
157 // are returned.
158 std::map<IOAddress, Lease4Ptr> leases;
159 for (auto i = 0; i < 10; ++i) {
160 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
161 auto lease = createLease4(candidate, i);
162 leases[candidate] = lease;
163 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 163, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
164 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 164, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
165 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 165, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
166 }
167 // The pool comprises 10 addresses. All should be returned.
168 EXPECT_EQ(10, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10", "leases.size()"
, 10, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 168, gtest_ar.failure_message()) = ::testing::Message()
;
169
170 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
171 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 171, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
172
173 auto i = 0;
174 for (auto const& address_lease : leases) {
175 if (i % 2) {
176 auto lease = address_lease.second;
177 lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
178 EXPECT_NO_THROW(lease_mgr.updateLease4(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease4(lease); }; } catch (...) { goto gtest_label_testnothrow_178
; } } else gtest_label_testnothrow_178: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 178, "Expected: " "lease_mgr.updateLease4(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
179 }
180 ++i;
181 }
182 for (auto i = 0; i < 5; ++i) {
183 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
184 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 184, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
185 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 185, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
186 auto lease = lease_mgr.getLease4(candidate);
187 lease->state_ = Lease::STATE_DEFAULT;
188 EXPECT_NO_THROW(lease_mgr.updateLease4(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease4(lease); }; } catch (...) { goto gtest_label_testnothrow_188
; } } else gtest_label_testnothrow_188: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 188, "Expected: " "lease_mgr.updateLease4(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
189 }
190
191 candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
192 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 192, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
193}
194
195// Test allocating DHCPv4 leases for many pools in a subnet.
196TEST_F(FreeLeaseQueueAllocatorTest4, manyPools)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPools") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_manyPools_Test : public
FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_manyPools_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_manyPools_Test
(FreeLeaseQueueAllocatorTest4_manyPools_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest4_manyPools_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_manyPools_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "manyPools", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 196), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest4>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest4>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 196), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest4>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 196), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest4_manyPools_Test
>); void FreeLeaseQueueAllocatorTest4_manyPools_Test::TestBody
()
{
197 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
198
199 // Add several more pools.
200 for (int i = 1; i < 10; ++i) {
201 stringstream min, max;
202 min << "192.0.2." << i * 10;
203 max << "192.0.2." << i * 10 + 9;
204 auto pool = boost::make_shared<Pool4>(IOAddress(min.str()),
205 IOAddress(max.str()));
206 subnet_->addPool(pool);
207 }
208
209 // There are ten pools with 10 addresses each.
210 int total = 100;
211
212 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_212; } } else
gtest_label_testnothrow_212: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 212, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
213
214 auto& lease_mgr = LeaseMgrFactory::instance();
215
216 std::set<IOAddress> addresses_set;
217 std::vector<IOAddress> addresses_vector;
218 std::vector<PoolPtr> pools_vector;
219
220 // Pick random addresses the number of times equal to the
221 // subnet capacity to ensure that all addresses are returned.
222 for (auto i = 0; i < total; ++i) {
223 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
224 addresses_set.insert(candidate);
225 addresses_vector.push_back(candidate);
226 auto lease = createLease4(candidate, i);
227 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 227, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
228 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 228, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
229 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 229, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
230 pools_vector.push_back(subnet_->getPool(Lease::TYPE_V4, candidate));
231 }
232 // Make sure that unique addresses have been returned.
233 EXPECT_EQ(total, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "addresses_set.size()"
, total, addresses_set.size()))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 233, gtest_ar.failure_message()) = ::testing::Message()
;
234
235 // Verify that the addresses are returned in the random order.
236 // Count how many times we found consecutive addresses. It should
237 // be 0 or close to 0.
238 int consecutive_addresses = 0;
239 for (auto k = 0; k < addresses_vector.size()-1; ++k) {
240 if (addresses_vector[k].toUint32() == addresses_vector[k+1].toUint32()-1) {
241 ++consecutive_addresses;
242 }
243 }
244 // Ideally, the number of consecutive occurrences should be 0 but we
245 // allow some to make sure the test doesn't fall over sporadically.
246 EXPECT_LT(consecutive_addresses, addresses_vector.size()/4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("consecutive_addresses"
, "addresses_vector.size()/4", consecutive_addresses, addresses_vector
.size()/4))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 246, gtest_ar.failure_message()) = ::testing::Message()
;
247
248 // Repeat similar check for pools. The pools should be picked in the
249 // random order too.
250 int consecutive_pools = 0;
251 for (auto k = 0; k < pools_vector.size()-1; ++k) {
252 // Check if the pools are adjacent (i.e., last address of the
253 // previous pool is a neighbor of the first address of the next
254 // pool).
255 if (pools_vector[k]->getLastAddress().toUint32()+1 ==
256 pools_vector[k+1]->getFirstAddress().toUint32()) {
257 ++consecutive_pools;
258 }
259 }
260 EXPECT_LT(consecutive_pools, pools_vector.size()/2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("consecutive_pools"
, "pools_vector.size()/2", consecutive_pools, pools_vector.size
()/2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 260, gtest_ar
.failure_message()) = ::testing::Message()
;
261}
262
263// Test that the allocator returns a zero address when there are no pools
264// in a subnet.
265TEST_F(FreeLeaseQueueAllocatorTest4, noPools)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("noPools") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_noPools_Test : public FreeLeaseQueueAllocatorTest4
{ public: FreeLeaseQueueAllocatorTest4_noPools_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_noPools_Test
(FreeLeaseQueueAllocatorTest4_noPools_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest4_noPools_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_noPools_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "noPools", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 265), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest4>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest4>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 265), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest4>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 265), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest4_noPools_Test>
); void FreeLeaseQueueAllocatorTest4_noPools_Test::TestBody()
{
266 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
267
268 subnet_->delPools(Lease::TYPE_V4);
269
270 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
271 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 271, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
272}
273
274// Test that the allocator respects client class guards.
275TEST_F(FreeLeaseQueueAllocatorTest4, clientClasses)static_assert(sizeof("FreeLeaseQueueAllocatorTest4") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("clientClasses") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest4_clientClasses_Test : public
FreeLeaseQueueAllocatorTest4 { public: FreeLeaseQueueAllocatorTest4_clientClasses_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest4_clientClasses_Test
(FreeLeaseQueueAllocatorTest4_clientClasses_Test const &)
= delete; void operator=(FreeLeaseQueueAllocatorTest4_clientClasses_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest4_clientClasses_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest4"
, "clientClasses", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 275), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest4>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest4>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 275), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest4>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 275), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest4_clientClasses_Test
>); void FreeLeaseQueueAllocatorTest4_clientClasses_Test::
TestBody()
{
276 FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
277
278 // First pool only allows the client class foo.
279 pool_->allowClientClass("foo");
280
281 // Second pool. It only allows client class bar.
282 auto pool1 = boost::make_shared<Pool4>(IOAddress("192.0.2.120"),
283 IOAddress("192.0.2.129"));
284 pool1->allowClientClass("bar");
285 subnet_->addPool(pool1);
286
287 // Third pool. It only allows client class foo.
288 auto pool2 = boost::make_shared<Pool4>(IOAddress("192.0.2.140"),
289 IOAddress("192.0.2.149"));
290 pool2->allowClientClass("foo");
291 subnet_->addPool(pool2);
292
293 // Forth pool. It only allows client class bar.
294 auto pool3 = boost::make_shared<Pool4>(IOAddress("192.0.2.160"),
295 IOAddress("192.0.2.169"));
296 pool3->allowClientClass("bar");
297 subnet_->addPool(pool3);
298
299 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_299; } } else
gtest_label_testnothrow_299: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 299, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
300 auto& lease_mgr = LeaseMgrFactory::instance();
301
302 // Remember offered addresses.
303 std::set<IOAddress> addresses_set;
304
305 // Simulate client's request belonging to the class bar.
306 cc_.insert("bar");
307 for (auto i = 0; i < 20; ++i) {
308 // Allocate random addresses and make sure they belong to the
309 // pools associated with the class bar.
310 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
311 EXPECT_FALSE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV4Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 311, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
312 EXPECT_TRUE(lease_mgr.addLease(createLease4(candidate, i+50)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease4
(candidate, i+50)))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 312, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease4(candidate, i+50))", "false"
, "true").c_str()) = ::testing::Message()
;
313 addresses_set.insert(candidate);
314 EXPECT_TRUE(pool1->inRange(candidate) || pool3->inRange(candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool1->inRange(candidate
) || pool3->inRange(candidate))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pool1->inRange(candidate) || pool3->inRange(candidate)"
, "false", "true").c_str()) = ::testing::Message()
;
315 }
316 EXPECT_EQ(20, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("20", "addresses_set.size()"
, 20, addresses_set.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 316, gtest_ar.failure_message()) = ::testing::Message()
;
317
318 addresses_set.clear();
319
320 // Simulate the case that the client also belongs to the class foo.
321 // All pools should now be available.
322 cc_.insert("foo");
323 for (auto i = 0; i < 20; ++i) {
324 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
325 addresses_set.insert(candidate);
326 EXPECT_TRUE(lease_mgr.addLease(createLease4(candidate, i+100)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease4
(candidate, i+100)))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 326, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease4(candidate, i+100))", "false"
, "true").c_str()) = ::testing::Message()
;
327 EXPECT_TRUE(subnet_->inRange(candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(candidate
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 327, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "subnet_->inRange(candidate)"
, "false", "true").c_str()) = ::testing::Message()
;
328 }
329 EXPECT_EQ(20, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("20", "addresses_set.size()"
, 20, addresses_set.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 329, gtest_ar.failure_message()) = ::testing::Message()
;
330
331 // When the client does not belong to any client class the allocator
332 // can't offer any address to the client.
333 cc_.clear();
334 IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
335 EXPECT_TRUE(candidate.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV4Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 335, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV4Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
336}
337
338/// @brief Test fixture class for the DHCPv6 Free Lease Queue allocator.
339class FreeLeaseQueueAllocatorTest6 : public AllocEngine6Test {
340public:
341
342 /// @brief Creates a DHCPv6 lease for an address and DUID.
343 ///
344 /// @param type lease type.
345 /// @param address Lease address.
346 /// @param duid_seed a seed from which the DUID is generated.
347 /// @return Created lease pointer.
348 Lease6Ptr
349 createLease6(Lease::Type type, const IOAddress& address, uint64_t duid_seed) const {
350 vector<uint8_t> duid_vec(sizeof(duid_seed));
351 for (auto i = 0; i < sizeof(duid_seed); ++i) {
352 duid_vec[i] = (duid_seed >> i) & 0xFF;
353 }
354 auto duid = boost::make_shared<DUID>(duid_vec);
355 auto lease = boost::make_shared<Lease6>(type, address, duid, 1, 1800,
356 3600, subnet_->getID());
357 return (lease);
358 }
359
360};
361
362// Test that the allocator returns the correct type.
363TEST_F(FreeLeaseQueueAllocatorTest6, getType)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getType") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_getType_Test : public FreeLeaseQueueAllocatorTest6
{ public: FreeLeaseQueueAllocatorTest6_getType_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_getType_Test
(FreeLeaseQueueAllocatorTest6_getType_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest6_getType_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_getType_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "getType", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 363), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 363), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 363), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_getType_Test>
); void FreeLeaseQueueAllocatorTest6_getType_Test::TestBody()
{
364 FreeLeaseQueueAllocator allocNA(Lease::TYPE_NA, subnet_);
1
Calling implicit destructor for 'weak_ptr<isc::dhcp::Subnet>'
2
Calling '~weak_count'
11
Returning from '~weak_count'
12
Returning from destructor for 'weak_ptr<isc::dhcp::Subnet>'
365 EXPECT_EQ("flq", allocNA.getType())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"flq\""
, "allocNA.getType()", "flq", allocNA.getType()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 365, gtest_ar.failure_message(
)) = ::testing::Message()
;
13
Control jumps to 'case 0:' at line 365
14
Assuming the condition is true
15
Taking true branch
366
367 FreeLeaseQueueAllocator allocPD(Lease::TYPE_PD, subnet_);
16
Calling constructor for 'weak_ptr<isc::dhcp::Subnet>'
368 EXPECT_EQ("flq", allocPD.getType())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"flq\""
, "allocPD.getType()", "flq", allocPD.getType()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 368, gtest_ar.failure_message(
)) = ::testing::Message()
;
369}
370
371// Test populating free DHCPv6 address leases to the queue.
372TEST_F(FreeLeaseQueueAllocatorTest6, populateFreeAddressLeases)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("populateFreeAddressLeases") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
(FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "populateFreeAddressLeases", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 372), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 372), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 372
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
>); void FreeLeaseQueueAllocatorTest6_populateFreeAddressLeases_Test
::TestBody()
{
373 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
374
375 auto& lease_mgr = LeaseMgrFactory::instance();
376
377 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::10"), 0))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_NA, IOAddress("2001:db8:1::10"), 0))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 377, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress(\"2001:db8:1::10\"), 0)))"
, "false", "true").c_str()) = ::testing::Message()
;
378 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::12"), 1))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_NA, IOAddress("2001:db8:1::12"), 1))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 378, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress(\"2001:db8:1::12\"), 1)))"
, "false", "true").c_str()) = ::testing::Message()
;
379 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::14"), 2))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_NA, IOAddress("2001:db8:1::14"), 2))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 379, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress(\"2001:db8:1::14\"), 2)))"
, "false", "true").c_str()) = ::testing::Message()
;
380 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::16"), 3))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_NA, IOAddress("2001:db8:1::16"), 3))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 380, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress(\"2001:db8:1::16\"), 3)))"
, "false", "true").c_str()) = ::testing::Message()
;
381 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::18"), 4))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_NA, IOAddress("2001:db8:1::18"), 4))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 381, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_NA, IOAddress(\"2001:db8:1::18\"), 4)))"
, "false", "true").c_str()) = ::testing::Message()
;
382
383 EXPECT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_383; } } else
gtest_label_testnothrow_383: ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 383, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
384
385 auto pool_state = boost::dynamic_pointer_cast<PoolFreeLeaseQueueAllocationState>(pool_->getAllocationState());
386 ASSERT_TRUE(pool_state)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool_state)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "flq_allocator_unittest.cc", 386, ::testing::internal
::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state", "false"
, "true").c_str()) = ::testing::Message()
;
387 EXPECT_FALSE(pool_state->exhausted())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pool_state->exhausted
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 387, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state->exhausted()"
, "true", "false").c_str()) = ::testing::Message()
;
388
389 std::set<IOAddress> addresses;
390 for (auto i = 0; i < 12; ++i) {
391 auto lease = pool_state->offerFreeLease();
392 ASSERT_FALSE(lease.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease.isV6Zero())))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "flq_allocator_unittest.cc", 392, ::testing::
internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
393 addresses.insert(lease);
394 }
395 ASSERT_EQ(12, addresses.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("12", "addresses.size()"
, 12, addresses.size()))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 395, gtest_ar.failure_message()) = ::testing::Message()
;
396 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::11")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::11\"))"
, 1, addresses.count(IOAddress("2001:db8:1::11"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 396, gtest_ar.failure_message(
)) = ::testing::Message()
;
397 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::13")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::13\"))"
, 1, addresses.count(IOAddress("2001:db8:1::13"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 397, gtest_ar.failure_message(
)) = ::testing::Message()
;
398 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::15")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::15\"))"
, 1, addresses.count(IOAddress("2001:db8:1::15"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 398, gtest_ar.failure_message(
)) = ::testing::Message()
;
399 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::17")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::17\"))"
, 1, addresses.count(IOAddress("2001:db8:1::17"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 399, gtest_ar.failure_message(
)) = ::testing::Message()
;
400 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::19")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::19\"))"
, 1, addresses.count(IOAddress("2001:db8:1::19"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 400, gtest_ar.failure_message(
)) = ::testing::Message()
;
401 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1a")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1a\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1a"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 401, gtest_ar.failure_message(
)) = ::testing::Message()
;
402 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1b")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1b\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1b"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 402, gtest_ar.failure_message(
)) = ::testing::Message()
;
403 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1c")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1c\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1c"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 403, gtest_ar.failure_message(
)) = ::testing::Message()
;
404 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1d")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1d\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1d"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 404, gtest_ar.failure_message(
)) = ::testing::Message()
;
405 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1e")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1e\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1e"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 405, gtest_ar.failure_message(
)) = ::testing::Message()
;
406 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::1f")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::1f\"))"
, 1, addresses.count(IOAddress("2001:db8:1::1f"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 406, gtest_ar.failure_message(
)) = ::testing::Message()
;
407 EXPECT_EQ(1, addresses.count(IOAddress("2001:db8:1::20")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "addresses.count(IOAddress(\"2001:db8:1::20\"))"
, 1, addresses.count(IOAddress("2001:db8:1::20"))))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 407, gtest_ar.failure_message(
)) = ::testing::Message()
;
408}
409
410// Test allocating IPv6 addresses when a subnet has a single pool.
411TEST_F(FreeLeaseQueueAllocatorTest6, singlePool)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePool") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_singlePool_Test : public
FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePool_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePool_Test
(FreeLeaseQueueAllocatorTest6_singlePool_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest6_singlePool_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePool", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 411), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 411), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 411), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePool_Test
>); void FreeLeaseQueueAllocatorTest6_singlePool_Test::TestBody
()
{
412 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
413 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_413; } } else
gtest_label_testnothrow_413: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 413, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
414
415 // Remember returned addresses, so we can verify that unique addresses
416 // are returned.
417 std::set<IOAddress> addresses;
418 for (auto i = 0; i < 1000; ++i) {
419 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
420 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 420, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
421 addresses.insert(candidate);
422 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 422, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
423 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 423, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
424 }
425 // The pool comprises 17 addresses. All should be returned.
426 EXPECT_EQ(17, addresses.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("17", "addresses.size()"
, 17, addresses.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 426, gtest_ar.failure_message()) = ::testing::Message()
;
427}
428
429// Test allocating IPv6 addresses and re-allocating these that are
430// deleted (released).
431TEST_F(FreeLeaseQueueAllocatorTest6, singlePoolWithAllocations)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePoolWithAllocations") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
(FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePoolWithAllocations", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 431), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 431), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 431
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
>); void FreeLeaseQueueAllocatorTest6_singlePoolWithAllocations_Test
::TestBody()
{
432 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
433 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_433; } } else
gtest_label_testnothrow_433: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 433, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
434
435 auto& lease_mgr = LeaseMgrFactory::instance();
436
437 // Remember returned addresses, so we can verify that unique addresses
438 // are returned.
439 std::map<IOAddress, Lease6Ptr> leases;
440 for (auto i = 0; i < 17; ++i) {
441 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
442 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 442, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
443 auto lease = createLease6(Lease::TYPE_NA, candidate, i);
444 leases[candidate] = lease;
445 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 445, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
446 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 446, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
447 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 447, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
448 }
449 // The pool comprises 17 addresses. All should be returned.
450 EXPECT_EQ(17, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("17", "leases.size()"
, 17, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 450, gtest_ar.failure_message()) = ::testing::Message()
;
451
452 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
453 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 453, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
454
455 auto i = 0;
456 for (auto const& address_lease : leases) {
457 if (i % 2) {
458 EXPECT_TRUE(lease_mgr.deleteLease(address_lease.second))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.deleteLease
(address_lease.second))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 458, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.deleteLease(address_lease.second)", "false", "true"
).c_str()) = ::testing::Message()
;
459 }
460 ++i;
461 }
462
463 for (auto i = 0; i < 8; ++i) {
464 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
465 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 465, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
466 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
467 auto lease = createLease6(Lease::TYPE_NA, candidate, i);
468 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 468, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
469 }
470
471 candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
472 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 472, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
473}
474
475// Test allocating IPv6 addresses and re-allocating these that are
476// reclaimed.
477TEST_F(FreeLeaseQueueAllocatorTest6, singlePoolWithReclamations)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePoolWithReclamations") > 1,
"test_name must not be empty"); class FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
(FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
const &) = delete; void operator=(FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePoolWithReclamations", nullptr, nullptr, ::testing::
internal::CodeLocation("flq_allocator_unittest.cc", 477), (::
testing::internal::GetTypeId<FreeLeaseQueueAllocatorTest6>
()), ::testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 477), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 477
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
>); void FreeLeaseQueueAllocatorTest6_singlePoolWithReclamations_Test
::TestBody()
{
478 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
479 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_479; } } else
gtest_label_testnothrow_479: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 479, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
480
481 auto& lease_mgr = LeaseMgrFactory::instance();
482
483 // Remember returned addresses, so we can verify that unique addresses
484 // are returned.
485 std::map<IOAddress, Lease6Ptr> leases;
486 for (auto i = 0; i < 17; ++i) {
487 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
488 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 488, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
489 auto lease = createLease6(Lease::TYPE_NA, candidate, i);
490 leases[candidate] = lease;
491 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 491, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
492 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 492, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
493 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 493, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
494 }
495 // The pool comprises 17 addresses. All should be returned.
496 EXPECT_EQ(17, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("17", "leases.size()"
, 17, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 496, gtest_ar.failure_message()) = ::testing::Message()
;
497
498 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
499 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 499, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
500
501 auto i = 0;
502 for (auto const& address_lease : leases) {
503 if (i % 2) {
504 auto lease = address_lease.second;
505 lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
506 EXPECT_NO_THROW(lease_mgr.updateLease6(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease6(lease); }; } catch (...) { goto gtest_label_testnothrow_506
; } } else gtest_label_testnothrow_506: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 506, "Expected: " "lease_mgr.updateLease6(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
507 }
508 ++i;
509 }
510
511 for (auto i = 0; i < 8; ++i) {
512 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
513 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
514 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
515 auto lease = lease_mgr.getLease6(Lease::TYPE_NA, candidate);
516 lease->state_ = Lease::STATE_DEFAULT;
517 EXPECT_NO_THROW(lease_mgr.updateLease6(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease6(lease); }; } catch (...) { goto gtest_label_testnothrow_517
; } } else gtest_label_testnothrow_517: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 517, "Expected: " "lease_mgr.updateLease6(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
518 }
519
520 candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
521 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 521, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
522}
523
524// Test allocating DHCPv6 leases for many pools in a subnet.
525TEST_F(FreeLeaseQueueAllocatorTest6, manyPools)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPools") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_manyPools_Test : public
FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_manyPools_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_manyPools_Test
(FreeLeaseQueueAllocatorTest6_manyPools_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest6_manyPools_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_manyPools_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "manyPools", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 525), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 525), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 525), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_manyPools_Test
>); void FreeLeaseQueueAllocatorTest6_manyPools_Test::TestBody
()
{
526 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
527
528 // Add several more pools.
529 for (int i = 2; i < 10; ++i) {
530 stringstream min, max;
531 min << "2001:db8:1::" << hex << i * 16 + 1;
532 max << "2001:db8:1::" << hex << i * 16 + 16;
533 auto pool = boost::make_shared<Pool6>(Lease::TYPE_NA,
534 IOAddress(min.str()),
535 IOAddress(max.str()));
536 subnet_->addPool(pool);
537 }
538
539 // First pool (::10 - ::20) has 17 addresses.
540 // There are 8 extra pools with 16 addresses in each.
541 int total = 17 + 8 * 16;
542
543 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_543; } } else
gtest_label_testnothrow_543: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 543, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
544
545 auto& lease_mgr = LeaseMgrFactory::instance();
546
547 std::set<IOAddress> addresses_set;
548 std::vector<IOAddress> addresses_vector;
549 std::vector<PoolPtr> pools_vector;
550
551 // Pick random addresses the number of times equal to the
552 // subnet capacity to ensure that all addresses are returned.
553 for (auto i = 0; i < total; ++i) {
554 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
555 addresses_set.insert(candidate);
556 addresses_vector.push_back(candidate);
557 auto lease = createLease6(Lease::TYPE_NA, candidate, i);
558 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 558, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
559 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 559, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
560 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_NA, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 560, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_NA, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
561 pools_vector.push_back(subnet_->getPool(Lease::TYPE_NA, candidate));
562 }
563 // Make sure that unique addresses have been returned.
564 EXPECT_EQ(total, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "addresses_set.size()"
, total, addresses_set.size()))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 564, gtest_ar.failure_message()) = ::testing::Message()
;
565
566 // Verify that the addresses are returned in the random order.
567 // Count how many times we found consecutive addresses. It should
568 // be 0 or close to 0.
569 int consecutive_addresses = 0;
570 for (auto k = 0; k < addresses_vector.size()-1; ++k) {
571 if (IOAddress::increase(addresses_vector[k]) == addresses_vector[k+1]) {
572 ++consecutive_addresses;
573 }
574 }
575 // Ideally, the number of consecutive occurrences should be 0 but we
576 // allow some to make sure the test doesn't fall over sporadically.
577 EXPECT_LT(consecutive_addresses, addresses_vector.size()/4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("consecutive_addresses"
, "addresses_vector.size()/4", consecutive_addresses, addresses_vector
.size()/4))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 577, gtest_ar.failure_message()) = ::testing::Message()
;
578
579 // Repeat similar check for pools. The pools should be picked in the
580 // random order too.
581 int consecutive_pools = 0;
582 for (auto k = 0; k < pools_vector.size()-1; ++k) {
583 if (IOAddress::increase(pools_vector[k]->getLastAddress()) ==
584 pools_vector[k]->getFirstAddress()) {
585 ++consecutive_pools;
586 }
587 }
588 EXPECT_LT(consecutive_pools, pools_vector.size()/2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("consecutive_pools"
, "pools_vector.size()/2", consecutive_pools, pools_vector.size
()/2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 588, gtest_ar
.failure_message()) = ::testing::Message()
;
589}
590
591// Test that the allocator returns a zero address when there are no pools
592// in a subnet.
593TEST_F(FreeLeaseQueueAllocatorTest6, noPools)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("noPools") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_noPools_Test : public FreeLeaseQueueAllocatorTest6
{ public: FreeLeaseQueueAllocatorTest6_noPools_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_noPools_Test
(FreeLeaseQueueAllocatorTest6_noPools_Test const &) = delete
; void operator=(FreeLeaseQueueAllocatorTest6_noPools_Test const
&) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_noPools_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "noPools", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 593), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 593), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 593), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_noPools_Test>
); void FreeLeaseQueueAllocatorTest6_noPools_Test::TestBody()
{
594 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
595
596 subnet_->delPools(Lease::TYPE_NA);
597
598 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
599 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 599, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
600}
601
602// Test that the allocator respects client class guards.
603TEST_F(FreeLeaseQueueAllocatorTest6, clientClasses)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("clientClasses") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_clientClasses_Test : public
FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_clientClasses_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_clientClasses_Test
(FreeLeaseQueueAllocatorTest6_clientClasses_Test const &)
= delete; void operator=(FreeLeaseQueueAllocatorTest6_clientClasses_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_clientClasses_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "clientClasses", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 603), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 603), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 603), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_clientClasses_Test
>); void FreeLeaseQueueAllocatorTest6_clientClasses_Test::
TestBody()
{
604 FreeLeaseQueueAllocator alloc(Lease::TYPE_NA, subnet_);
605
606 // First pool only allows the client class foo.
607 pool_->allowClientClass("foo");
608
609 // Second pool. It only allows client class bar.
610 auto pool1 = boost::make_shared<Pool6>(Lease::TYPE_NA,
611 IOAddress("2001:db8:1::120"),
612 IOAddress("2001:db8:1::129"));
613 pool1->allowClientClass("bar");
614 subnet_->addPool(pool1);
615
616 // Third pool. It only allows client class foo.
617 auto pool2 = boost::make_shared<Pool6>(Lease::TYPE_NA,
618 IOAddress("2001:db8:1::140"),
619 IOAddress("2001:db8:1::149"));
620 pool2->allowClientClass("foo");
621 subnet_->addPool(pool2);
622
623 // Forth pool. It only allows client class bar.
624 auto pool3 = boost::make_shared<Pool6>(Lease::TYPE_NA,
625 IOAddress("2001:db8:1::160"),
626 IOAddress("2001:db8:1::169"));
627 pool3->allowClientClass("bar");
628 subnet_->addPool(pool3);
629
630 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_630; } } else
gtest_label_testnothrow_630: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 630, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
631 auto& lease_mgr = LeaseMgrFactory::instance();
632
633 // When the client does not belong to any client class the allocator
634 // can't offer any address to the client.
635 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
636 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 636, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
637
638 // Remember offered addresses.
639 std::set<IOAddress> addresses_set;
640
641 // Simulate client's request belonging to the class bar.
642 cc_.insert("bar");
643 for (auto i = 0; i < 20; ++i) {
644 // Allocate random addresses and make sure they belong to the
645 // pools associated with the class bar.
646 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
647 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 647, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
648 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_NA, candidate, i+50)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_NA, candidate, i+50)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_NA, candidate, i+50))"
, "false", "true").c_str()) = ::testing::Message()
;
649 addresses_set.insert(candidate);
650 EXPECT_TRUE(pool1->inRange(candidate) || pool3->inRange(candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool1->inRange(candidate
) || pool3->inRange(candidate))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 650, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pool1->inRange(candidate) || pool3->inRange(candidate)"
, "false", "true").c_str()) = ::testing::Message()
;
651 }
652 EXPECT_EQ(20, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("20", "addresses_set.size()"
, 20, addresses_set.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 652, gtest_ar.failure_message()) = ::testing::Message()
;
653
654 // Simulate the case that the client also belongs to the class foo.
655 // All pools should now be available.
656 cc_.insert("foo");
657 for (auto i = 0; i < 27; ++i) {
658 IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
659 addresses_set.insert(candidate);
660 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_NA, candidate, i+100)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_NA, candidate, i+100)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 660, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_NA, candidate, i+100))"
, "false", "true").c_str()) = ::testing::Message()
;
661 EXPECT_TRUE(subnet_->inRange(candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(candidate
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 661, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "subnet_->inRange(candidate)"
, "false", "true").c_str()) = ::testing::Message()
;
662 }
663 EXPECT_EQ(47, addresses_set.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("47", "addresses_set.size()"
, 47, addresses_set.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 663, gtest_ar.failure_message()) = ::testing::Message()
;
664}
665
666// Test populating free DHCPv6 prefix leases to the queue.
667TEST_F(FreeLeaseQueueAllocatorTest6, populateFreePrefixDelegationLeases)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("populateFreePrefixDelegationLeases")
> 1, "test_name must not be empty"); class FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
(FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
const &) = delete; void operator=(FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "populateFreePrefixDelegationLeases", nullptr, nullptr, ::testing
::internal::CodeLocation("flq_allocator_unittest.cc", 667), (
::testing::internal::GetTypeId<FreeLeaseQueueAllocatorTest6
>()), ::testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 667), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 667
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
>); void FreeLeaseQueueAllocatorTest6_populateFreePrefixDelegationLeases_Test
::TestBody()
{
668 subnet_->delPools(Lease::TYPE_PD);
669
670 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
671
672 auto pool = Pool6::create(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 112, 120);
673 subnet_->addPool(pool);
674
675 auto& lease_mgr = LeaseMgrFactory::instance();
676
677 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 0))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 0))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 677, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress(\"2001:db8:2::\"), 0)))"
, "false", "true").c_str()) = ::testing::Message()
;
678 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress("2001:db8:2::1000"), 1))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_PD, IOAddress("2001:db8:2::1000"), 1))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 678, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress(\"2001:db8:2::1000\"), 1)))"
, "false", "true").c_str()) = ::testing::Message()
;
679 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress("2001:db8:2::2000"), 2))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_PD, IOAddress("2001:db8:2::2000"), 2))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 679, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress(\"2001:db8:2::2000\"), 2)))"
, "false", "true").c_str()) = ::testing::Message()
;
680 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress("2001:db8:2::3000"), 3))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_PD, IOAddress("2001:db8:2::3000"), 3))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 680, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress(\"2001:db8:2::3000\"), 3)))"
, "false", "true").c_str()) = ::testing::Message()
;
681 EXPECT_TRUE(lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress("2001:db8:2::4000"), 4))))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease((createLease6
(Lease::TYPE_PD, IOAddress("2001:db8:2::4000"), 4))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 681, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease((createLease6(Lease::TYPE_PD, IOAddress(\"2001:db8:2::4000\"), 4)))"
, "false", "true").c_str()) = ::testing::Message()
;
682
683 EXPECT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_683; } } else
gtest_label_testnothrow_683: ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 683, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
684
685 auto pool_state = boost::dynamic_pointer_cast<PoolFreeLeaseQueueAllocationState>(pool->getAllocationState());
686 ASSERT_TRUE(pool_state)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool_state)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "flq_allocator_unittest.cc", 686, ::testing::internal
::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state", "false"
, "true").c_str()) = ::testing::Message()
;
687 EXPECT_FALSE(pool_state->exhausted())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pool_state->exhausted
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 687, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "pool_state->exhausted()"
, "true", "false").c_str()) = ::testing::Message()
;
688
689 std::set<IOAddress> addresses;
690 for (auto i = 0; i < 256; ++i) {
691 auto lease = pool_state->offerFreeLease();
692 ASSERT_FALSE(lease.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease.isV6Zero())))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "flq_allocator_unittest.cc", 692, ::testing::
internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
693 addresses.insert(lease);
694 }
695 ASSERT_EQ(251, addresses.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("251", "addresses.size()"
, 251, addresses.size()))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 695, gtest_ar.failure_message()) = ::testing::Message()
;
696 EXPECT_EQ(0, addresses.count(IOAddress("2001:db8:2::")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "addresses.count(IOAddress(\"2001:db8:2::\"))"
, 0, addresses.count(IOAddress("2001:db8:2::"))))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 696, gtest_ar.failure_message(
)) = ::testing::Message()
;
697 EXPECT_EQ(0, addresses.count(IOAddress("2001:db8:2::1000")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "addresses.count(IOAddress(\"2001:db8:2::1000\"))"
, 0, addresses.count(IOAddress("2001:db8:2::1000"))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 697, gtest_ar.
failure_message()) = ::testing::Message()
;
698 EXPECT_EQ(0, addresses.count(IOAddress("2001:db8:2::2000")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "addresses.count(IOAddress(\"2001:db8:2::2000\"))"
, 0, addresses.count(IOAddress("2001:db8:2::2000"))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 698, gtest_ar.
failure_message()) = ::testing::Message()
;
699 EXPECT_EQ(0, addresses.count(IOAddress("2001:db8:2::3000")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "addresses.count(IOAddress(\"2001:db8:2::3000\"))"
, 0, addresses.count(IOAddress("2001:db8:2::3000"))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 699, gtest_ar.
failure_message()) = ::testing::Message()
;
700 EXPECT_EQ(0, addresses.count(IOAddress("2001:db8:2::4000")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "addresses.count(IOAddress(\"2001:db8:2::4000\"))"
, 0, addresses.count(IOAddress("2001:db8:2::4000"))))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "flq_allocator_unittest.cc", 700, gtest_ar.
failure_message()) = ::testing::Message()
;
701}
702
703// Test allocating delegated prefixes when a subnet has a single pool.
704TEST_F(FreeLeaseQueueAllocatorTest6, singlePdPool)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePdPool") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_singlePdPool_Test : public
FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePdPool_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePdPool_Test
(FreeLeaseQueueAllocatorTest6_singlePdPool_Test const &) =
delete; void operator=(FreeLeaseQueueAllocatorTest6_singlePdPool_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePdPool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePdPool", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 704), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 704), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 704), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePdPool_Test
>); void FreeLeaseQueueAllocatorTest6_singlePdPool_Test::TestBody
()
{
705 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
706 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_706; } } else
gtest_label_testnothrow_706: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 706, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
707 auto& lease_mgr = LeaseMgrFactory::instance();
708
709 Pool6Ptr pool;
710
711 // Remember returned prefixes, so we can verify that unique addresses
712 // are returned.
713 std::set<IOAddress> prefixes;
714 for (auto i = 0; i < 65536; ++i) {
715 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
716 EXPECT_EQ(pd_pool_, pool)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("pd_pool_"
, "pool", pd_pool_, pool))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 716, gtest_ar.failure_message()) = ::testing::Message()
;
717 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 717, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
718 prefixes.insert(candidate);
719 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
720 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 720, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
721 }
722 // The pool comprises 65536 prefixes. All should be returned.
723 EXPECT_EQ(65536, prefixes.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("65536", "prefixes.size()"
, 65536, prefixes.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 723, gtest_ar.failure_message()) = ::testing::Message()
;
724}
725
726// Test allocating IPv6 addresses and re-allocating these that are
727// deleted (released).
728TEST_F(FreeLeaseQueueAllocatorTest6, singlePdPoolWithAllocations)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePdPoolWithAllocations") > 1
, "test_name must not be empty"); class FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
(FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
const &) = delete; void operator=(FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePdPoolWithAllocations", nullptr, nullptr, ::testing::
internal::CodeLocation("flq_allocator_unittest.cc", 728), (::
testing::internal::GetTypeId<FreeLeaseQueueAllocatorTest6>
()), ::testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 728), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 728
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
>); void FreeLeaseQueueAllocatorTest6_singlePdPoolWithAllocations_Test
::TestBody()
{
729 // Remove the default pool because it is too large for this test case.
730 subnet_->delPools(Lease::TYPE_PD);
731 // Add a smaller pool.
732 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
733 IOAddress("3000::"),
734 120,
735 128);
736 subnet_->addPool(pool);
737
738 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
739 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_739; } } else
gtest_label_testnothrow_739: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 739, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
740
741 auto& lease_mgr = LeaseMgrFactory::instance();
742
743 // Remember returned addresses, so we can verify that unique addresses
744 // are returned.
745 std::map<IOAddress, Lease6Ptr> leases;
746 for (auto i = 0; i < 256; ++i) {
747 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
748 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 748, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
749 auto lease = createLease6(Lease::TYPE_PD, candidate, i);
750 leases[candidate] = lease;
751 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 751, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
752 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 752, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
753 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 753, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
754 }
755 // The pool comprises 256 delegated prefixes. All should be returned.
756 EXPECT_EQ(256, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256", "leases.size()"
, 256, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 756, gtest_ar.failure_message()) = ::testing::Message()
;
757
758 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
759 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 759, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
760
761 auto i = 0;
762 for (auto const& address_lease : leases) {
763 if (i % 2) {
764 EXPECT_TRUE(lease_mgr.deleteLease(address_lease.second))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.deleteLease
(address_lease.second))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 764, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.deleteLease(address_lease.second)", "false", "true"
).c_str()) = ::testing::Message()
;
765 }
766 ++i;
767 }
768
769 for (auto i = 0; i < 128; ++i) {
770 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
771 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 771, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
772 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 772, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
773 auto lease = createLease6(Lease::TYPE_PD, candidate, i);
774 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 774, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
775 }
776
777 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
778 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 778, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
779}
780
781// Test allocating IPv6 addresses and re-allocating these that are
782// reclaimed.
783TEST_F(FreeLeaseQueueAllocatorTest6, singlePdPoolWithReclamations)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("singlePdPoolWithReclamations") > 1
, "test_name must not be empty"); class FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
(FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
const &) = delete; void operator=(FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "singlePdPoolWithReclamations", nullptr, nullptr, ::testing
::internal::CodeLocation("flq_allocator_unittest.cc", 783), (
::testing::internal::GetTypeId<FreeLeaseQueueAllocatorTest6
>()), ::testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 783), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 783
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
>); void FreeLeaseQueueAllocatorTest6_singlePdPoolWithReclamations_Test
::TestBody()
{
784 // Remove the default pool because it is too large for this test case.
785 subnet_->delPools(Lease::TYPE_PD);
786 // Add a smaller pool.
787 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
788 IOAddress("3000::"),
789 120,
790 128);
791 subnet_->addPool(pool);
792
793 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
794 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_794; } } else
gtest_label_testnothrow_794: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 794, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
795
796 auto& lease_mgr = LeaseMgrFactory::instance();
797
798 // Remember returned addresses, so we can verify that unique addresses
799 // are returned.
800 std::map<IOAddress, Lease6Ptr> leases;
801 for (auto i = 0; i < 256; ++i) {
802 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
803 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 803, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
804 auto lease = createLease6(Lease::TYPE_PD, candidate, i);
805 leases[candidate] = lease;
806 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 806, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
807 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
808 EXPECT_TRUE(lease_mgr.addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(lease
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 808, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease_mgr.addLease(lease)"
, "false", "true").c_str()) = ::testing::Message()
;
809 }
810 // The pool comprises 256 delegated prefixes. All should be returned.
811 EXPECT_EQ(256, leases.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256", "leases.size()"
, 256, leases.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 811, gtest_ar.failure_message()) = ::testing::Message()
;
812
813 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
814 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 814, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
815
816 auto i = 0;
817 for (auto const& address_lease : leases) {
818 if (i % 2) {
819 auto lease = address_lease.second;
820 lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
821 EXPECT_NO_THROW(lease_mgr.updateLease6(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease6(lease); }; } catch (...) { goto gtest_label_testnothrow_821
; } } else gtest_label_testnothrow_821: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 821, "Expected: " "lease_mgr.updateLease6(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
822 }
823 ++i;
824 }
825
826 for (auto i = 0; i < 128; ++i) {
827 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
828 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
829 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 829, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
830 auto lease = lease_mgr.getLease6(Lease::TYPE_PD, candidate);
831 lease->state_ = Lease::STATE_DEFAULT;
832 EXPECT_NO_THROW(lease_mgr.updateLease6(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { lease_mgr
.updateLease6(lease); }; } catch (...) { goto gtest_label_testnothrow_832
; } } else gtest_label_testnothrow_832: ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 832, "Expected: " "lease_mgr.updateLease6(lease)" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
833 }
834
835 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
836 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 836, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
837}
838
839
840// Test allocating delegated prefixes from multiple pools.
841TEST_F(FreeLeaseQueueAllocatorTest6, manyPdPools)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPdPools") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_manyPdPools_Test : public
FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_manyPdPools_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_manyPdPools_Test
(FreeLeaseQueueAllocatorTest6_manyPdPools_Test const &) =
delete; void operator=(FreeLeaseQueueAllocatorTest6_manyPdPools_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_manyPdPools_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "manyPdPools", nullptr, nullptr, ::testing::internal::CodeLocation
("flq_allocator_unittest.cc", 841), (::testing::internal::GetTypeId
<FreeLeaseQueueAllocatorTest6>()), ::testing::internal::
SuiteApiResolver< FreeLeaseQueueAllocatorTest6>::GetSetUpCaseOrSuite
("flq_allocator_unittest.cc", 841), ::testing::internal::SuiteApiResolver
< FreeLeaseQueueAllocatorTest6>::GetTearDownCaseOrSuite
("flq_allocator_unittest.cc", 841), new ::testing::internal::
TestFactoryImpl<FreeLeaseQueueAllocatorTest6_manyPdPools_Test
>); void FreeLeaseQueueAllocatorTest6_manyPdPools_Test::TestBody
()
{
842 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
843
844 for (auto i = 0; i < 10; ++i) {
845 ostringstream s;
846 s << "300" << hex << i + 1 << "::";
847 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
848 IOAddress(s.str()),
849 120,
850 128);
851 subnet_->addPool(pool);
852 }
853 size_t total = 65536 + 10 * 256;
854
855 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_855; } } else
gtest_label_testnothrow_855: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 855, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
856 auto& lease_mgr = LeaseMgrFactory::instance();
857
858 Pool6Ptr pool;
859
860 std::set<IOAddress> prefixes;
861 for (auto i = 0; i < total; ++i) {
862 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
863 EXPECT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pool)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "flq_allocator_unittest.cc", 863, ::testing::internal::GetBoolAssertionFailureMessage
( gtest_ar_, "pool", "false", "true").c_str()) = ::testing::Message
()
;
864 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 864, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
865 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 865, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
866 prefixes.insert(candidate);
867 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
868 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
869 }
870 // Make sure that unique prefixes have been returned.
871 EXPECT_EQ(total, prefixes.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "prefixes.size()"
, total, prefixes.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 871, gtest_ar.failure_message()) = ::testing::Message()
;
872}
873
874// Test allocating delegated prefixes from multiple pools.
875TEST_F(FreeLeaseQueueAllocatorTest6, manyPdPoolsPreferLower)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPdPoolsPreferLower") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "manyPdPoolsPreferLower", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 875), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 875), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 875
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
>); void FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferLower_Test
::TestBody()
{
876 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
877
878 for (auto i = 0; i < 10; ++i) {
879 ostringstream s;
880 s << "300" << hex << i + 1 << "::";
881 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
882 IOAddress(s.str()),
883 120,
884 128);
885 subnet_->addPool(pool);
886 }
887
888 size_t total = 65536;
889
890 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_890; } } else
gtest_label_testnothrow_890: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 890, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
891 auto& lease_mgr = LeaseMgrFactory::instance();
892
893
894 Pool6Ptr pool;
895
896 std::set<IOAddress> prefixes;
897 for (auto i = 0; i < total; ++i) {
898 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_LOWER, IOAddress("::"), 120);
899 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 899, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
900 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 900, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
901 prefixes.insert(candidate);
902 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 902, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
903 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 903, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
904 }
905 // Make sure that unique prefixes have been returned.
906 EXPECT_EQ(total, prefixes.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "prefixes.size()"
, total, prefixes.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 906, gtest_ar.failure_message()) = ::testing::Message()
;
907}
908
909// Test allocating delegated prefixes from multiple pools.
910TEST_F(FreeLeaseQueueAllocatorTest6, manyPdPoolsPreferEqual)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPdPoolsPreferEqual") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "manyPdPoolsPreferEqual", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 910), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 910), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 910
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
>); void FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferEqual_Test
::TestBody()
{
911 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
912
913 for (auto i = 0; i < 10; ++i) {
914 ostringstream s;
915 s << "300" << hex << i + 1 << "::";
916 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
917 IOAddress(s.str()),
918 120,
919 128);
920 subnet_->addPool(pool);
921 }
922
923 size_t total = 10 * 256;
924
925 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_925; } } else
gtest_label_testnothrow_925: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 925, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
926 auto& lease_mgr = LeaseMgrFactory::instance();
927
928 Pool6Ptr pool;
929
930 std::set<IOAddress> prefixes;
931 for (auto i = 0; i < total; ++i) {
932 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_EQUAL, IOAddress("::"), 128);
933 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 933, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
934 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 934, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
935 prefixes.insert(candidate);
936 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 936, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
937 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 937, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
938 }
939 // Make sure that unique prefixes have been returned.
940 EXPECT_EQ(total, prefixes.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "prefixes.size()"
, total, prefixes.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 940, gtest_ar.failure_message()) = ::testing::Message()
;
941}
942
943// Test allocating delegated prefixes from multiple pools.
944TEST_F(FreeLeaseQueueAllocatorTest6, manyPdPoolsPreferHigher)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("manyPdPoolsPreferHigher") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "manyPdPoolsPreferHigher", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 944), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 944), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 944
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
>); void FreeLeaseQueueAllocatorTest6_manyPdPoolsPreferHigher_Test
::TestBody()
{
945 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
946
947 for (auto i = 0; i < 10; ++i) {
948 ostringstream s;
949 s << "300" << hex << i + 1 << "::";
950 auto pool = boost::make_shared<Pool6>(Lease::TYPE_PD,
951 IOAddress(s.str()),
952 120,
953 128);
954 subnet_->addPool(pool);
955 }
956
957 size_t total = 10 * 256;
958
959 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_959; } } else
gtest_label_testnothrow_959: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 959, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
960 auto& lease_mgr = LeaseMgrFactory::instance();
961
962 Pool6Ptr pool;
963
964 std::set<IOAddress> prefixes;
965 for (auto i = 0; i < total; ++i) {
966 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
967 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 967, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
968 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
969 prefixes.insert(candidate);
970 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 970, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
971 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 971, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
972 }
973 // Make sure that unique prefixes have been returned.
974 EXPECT_EQ(total, prefixes.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("total", "prefixes.size()"
, total, prefixes.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 974, gtest_ar.failure_message()) = ::testing::Message()
;
975}
976
977// Test that the allocator respects client class guards.
978TEST_F(FreeLeaseQueueAllocatorTest6, pdPoolsClientClasses)static_assert(sizeof("FreeLeaseQueueAllocatorTest6") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("pdPoolsClientClasses") > 1, "test_name must not be empty"
); class FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
: public FreeLeaseQueueAllocatorTest6 { public: FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
(FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test const
&) = delete; void operator=(FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
const &) = delete; }; ::testing::TestInfo* const FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FreeLeaseQueueAllocatorTest6"
, "pdPoolsClientClasses", nullptr, nullptr, ::testing::internal
::CodeLocation("flq_allocator_unittest.cc", 978), (::testing::
internal::GetTypeId<FreeLeaseQueueAllocatorTest6>()), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetSetUpCaseOrSuite("flq_allocator_unittest.cc", 978), ::
testing::internal::SuiteApiResolver< FreeLeaseQueueAllocatorTest6
>::GetTearDownCaseOrSuite("flq_allocator_unittest.cc", 978
), new ::testing::internal::TestFactoryImpl<FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
>); void FreeLeaseQueueAllocatorTest6_pdPoolsClientClasses_Test
::TestBody()
{
979 FreeLeaseQueueAllocator alloc(Lease::TYPE_PD, subnet_);
980
981 // First pool only allows the client class foo.
982 pd_pool_->allowClientClass("foo");
983
984 auto pool2 = boost::make_shared<Pool6>(Lease::TYPE_PD,
985 IOAddress("3000:1::"),
986 120,
987 128);
988 // Second pool only allows the client class bar.
989 pool2->allowClientClass("bar");
990 subnet_->addPool(pool2);
991
992 ASSERT_NO_THROW(alloc.initAfterConfigure())switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { try { if (::testing::internal::AlwaysTrue()) { alloc.initAfterConfigure
(); }; } catch (...) { goto gtest_label_testnothrow_992; } } else
gtest_label_testnothrow_992: return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "flq_allocator_unittest.cc"
, 992, "Expected: " "alloc.initAfterConfigure()" " doesn't throw an exception.\n"
" Actual: it throws.") = ::testing::Message()
;
993 auto& lease_mgr = LeaseMgrFactory::instance();
994
995 Pool6Ptr pool;
996
997 IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
998 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 998, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
999
1000 cc_.insert("bar");
1001 for (auto i = 0; i < 256; ++i) {
1002 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
1003 EXPECT_FALSE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(candidate.isV6Zero(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 1003, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "true", "false").c_str()) = ::testing::Message()
;
1004 EXPECT_TRUE(lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease_mgr.addLease(createLease6
(Lease::TYPE_PD, candidate, i)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 1004, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease_mgr.addLease(createLease6(Lease::TYPE_PD, candidate, i))"
, "false", "true").c_str()) = ::testing::Message()
;
1005 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 1005, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate)", "false", "true"
).c_str()) = ::testing::Message()
;
1006 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_PD, candidate, cc_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "flq_allocator_unittest.cc"
, 1006, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_PD, candidate, cc_)", "false"
, "true").c_str()) = ::testing::Message()
;
1007 }
1008
1009 candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
1010 EXPECT_TRUE(candidate.isV6Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(candidate.isV6Zero())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "flq_allocator_unittest.cc", 1010, ::testing
::internal::GetBoolAssertionFailureMessage( gtest_ar_, "candidate.isV6Zero()"
, "false", "true").c_str()) = ::testing::Message()
;
1011}
1012
1013
1014} // end of isc::dhcp::test namespace
1015} // end of isc::dhcp namespace
1016} // end of isc namespace

/usr/include/boost/smart_ptr/weak_ptr.hpp

1#ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
2#define BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
3
4//
5// weak_ptr.hpp
6//
7// Copyright (c) 2001, 2002, 2003 Peter Dimov
8//
9// Distributed under the Boost Software License, Version 1.0. (See
10// accompanying file LICENSE_1_0.txt or copy at
11// http://www.boost.org/LICENSE_1_0.txt)
12//
13// See http://www.boost.org/libs/smart_ptr/ for documentation.
14//
15
16#include <boost/smart_ptr/detail/shared_count.hpp>
17#include <boost/smart_ptr/shared_ptr.hpp>
18#include <boost/smart_ptr/detail/sp_noexcept.hpp>
19#include <memory>
20#include <cstddef>
21
22namespace boost
23{
24
25template<class T> class weak_ptr
26{
27private:
28
29 // Borland 5.5.1 specific workarounds
30 typedef weak_ptr<T> this_type;
31
32public:
33
34 typedef typename boost::detail::sp_element< T >::type element_type;
35
36 BOOST_CONSTEXPRconstexpr weak_ptr() BOOST_SP_NOEXCEPTnoexcept : px(0), pn()
37 {
38 }
39
40// generated copy constructor, assignment, destructor are fine...
41
42#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
43
44// ... except in C++0x, move disables the implicit copy
45
46 weak_ptr( weak_ptr const & r ) BOOST_SP_NOEXCEPTnoexcept : px( r.px ), pn( r.pn )
47 {
48 }
49
50 weak_ptr & operator=( weak_ptr const & r ) BOOST_SP_NOEXCEPTnoexcept
51 {
52 px = r.px;
53 pn = r.pn;
54 return *this;
55 }
56
57#endif
58
59//
60// The "obvious" converting constructor implementation:
61//
62// template<class Y>
63// weak_ptr(weak_ptr<Y> const & r): px(r.px), pn(r.pn)
64// {
65// }
66//
67// has a serious problem.
68//
69// r.px may already have been invalidated. The px(r.px)
70// conversion may require access to *r.px (virtual inheritance).
71//
72// It is not possible to avoid spurious access violations since
73// in multithreaded programs r.px may be invalidated at any point.
74//
75
76 template<class Y>
77#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
78
79 weak_ptr( weak_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
80
81#else
82
83 weak_ptr( weak_ptr<Y> const & r )
84
85#endif
86 BOOST_SP_NOEXCEPTnoexcept : px(r.lock().get()), pn(r.pn)
87 {
88 boost::detail::sp_assert_convertible< Y, T >();
89 }
90
91#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
92
93 template<class Y>
94#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
95
96 weak_ptr( weak_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
97
98#else
99
100 weak_ptr( weak_ptr<Y> && r )
101
102#endif
103 BOOST_SP_NOEXCEPTnoexcept : px( r.lock().get() ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
104 {
105 boost::detail::sp_assert_convertible< Y, T >();
106 r.px = 0;
107 }
108
109 // for better efficiency in the T == Y case
110 weak_ptr( weak_ptr && r )
111 BOOST_SP_NOEXCEPTnoexcept : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
112 {
113 r.px = 0;
114 }
115
116 // for better efficiency in the T == Y case
117 weak_ptr & operator=( weak_ptr && r ) BOOST_SP_NOEXCEPTnoexcept
118 {
119 this_type( static_cast< weak_ptr && >( r ) ).swap( *this );
120 return *this;
121 }
122
123
124#endif
125
126 template<class Y>
127#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
128
129 weak_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
130
131#else
132
133 weak_ptr( shared_ptr<Y> const & r )
134
135#endif
136 BOOST_SP_NOEXCEPTnoexcept : px( r.px ), pn( r.pn )
17
Calling constructor for 'weak_count'
137 {
138 boost::detail::sp_assert_convertible< Y, T >();
139 }
140
141 // aliasing
142 template<class Y> weak_ptr(shared_ptr<Y> const & r, element_type * p) BOOST_SP_NOEXCEPTnoexcept: px( p ), pn( r.pn )
143 {
144 }
145
146 template<class Y> weak_ptr(weak_ptr<Y> const & r, element_type * p) BOOST_SP_NOEXCEPTnoexcept: px( p ), pn( r.pn )
147 {
148 }
149
150#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
151
152 template<class Y> weak_ptr(weak_ptr<Y> && r, element_type * p) BOOST_SP_NOEXCEPTnoexcept: px( p ), pn( std::move( r.pn ) )
153 {
154 }
155
156#endif
157
158#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
159
160 template<class Y>
161 weak_ptr & operator=( weak_ptr<Y> const & r ) BOOST_SP_NOEXCEPTnoexcept
162 {
163 boost::detail::sp_assert_convertible< Y, T >();
164
165 px = r.lock().get();
166 pn = r.pn;
167
168 return *this;
169 }
170
171#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
172
173 template<class Y>
174 weak_ptr & operator=( weak_ptr<Y> && r ) BOOST_SP_NOEXCEPTnoexcept
175 {
176 this_type( static_cast< weak_ptr<Y> && >( r ) ).swap( *this );
177 return *this;
178 }
179
180#endif
181
182 template<class Y>
183 weak_ptr & operator=( shared_ptr<Y> const & r ) BOOST_SP_NOEXCEPTnoexcept
184 {
185 boost::detail::sp_assert_convertible< Y, T >();
186
187 px = r.px;
188 pn = r.pn;
189
190 return *this;
191 }
192
193#endif
194
195 shared_ptr<T> lock() const BOOST_SP_NOEXCEPTnoexcept
196 {
197 return shared_ptr<T>( *this, boost::detail::sp_nothrow_tag() );
198 }
199
200 long use_count() const BOOST_SP_NOEXCEPTnoexcept
201 {
202 return pn.use_count();
203 }
204
205 bool expired() const BOOST_SP_NOEXCEPTnoexcept
206 {
207 return pn.use_count() == 0;
208 }
209
210 bool _empty() const BOOST_SP_NOEXCEPTnoexcept // extension, not in std::weak_ptr
211 {
212 return pn.empty();
213 }
214
215 bool empty() const BOOST_SP_NOEXCEPTnoexcept // extension, not in std::weak_ptr
216 {
217 return pn.empty();
218 }
219
220 void reset() BOOST_SP_NOEXCEPTnoexcept
221 {
222 this_type().swap(*this);
223 }
224
225 void swap(this_type & other) BOOST_SP_NOEXCEPTnoexcept
226 {
227 std::swap(px, other.px);
228 pn.swap(other.pn);
229 }
230
231 template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPTnoexcept
232 {
233 return pn < rhs.pn;
234 }
235
236 template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPTnoexcept
237 {
238 return pn < rhs.pn;
239 }
240
241 template<class Y> bool owner_equals( weak_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPTnoexcept
242 {
243 return pn == rhs.pn;
244 }
245
246 template<class Y> bool owner_equals( shared_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPTnoexcept
247 {
248 return pn == rhs.pn;
249 }
250
251 std::size_t owner_hash_value() const BOOST_SP_NOEXCEPTnoexcept
252 {
253 return pn.hash_value();
254 }
255
256// Tasteless as this may seem, making all members public allows member templates
257// to work in the absence of member template friends. (Matthew Langston)
258
259#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
260
261private:
262
263 template<class Y> friend class weak_ptr;
264 template<class Y> friend class shared_ptr;
265
266#endif
267
268 element_type * px; // contained pointer
269 boost::detail::weak_count pn; // reference counter
270
271}; // weak_ptr
272
273template<class T, class U> inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b) BOOST_SP_NOEXCEPTnoexcept
274{
275 return a.owner_before( b );
276}
277
278template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b) BOOST_SP_NOEXCEPTnoexcept
279{
280 a.swap(b);
281}
282
283#if defined(__cpp_deduction_guides201703L)
284
285template<class T> weak_ptr( shared_ptr<T> ) -> weak_ptr<T>;
286
287#endif
288
289// hash_value
290
291template< class T > std::size_t hash_value( boost::weak_ptr<T> const & p ) BOOST_SP_NOEXCEPTnoexcept
292{
293 return p.owner_hash_value();
294}
295
296} // namespace boost
297
298// std::hash, std::equal_to
299
300namespace std
301{
302
303#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
304
305template<class T> struct hash< ::boost::weak_ptr<T> >
306{
307 std::size_t operator()( ::boost::weak_ptr<T> const & p ) const BOOST_SP_NOEXCEPTnoexcept
308 {
309 return p.owner_hash_value();
310 }
311};
312
313#endif // #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
314
315template<class T> struct equal_to< ::boost::weak_ptr<T> >
316{
317 bool operator()( ::boost::weak_ptr<T> const & a, ::boost::weak_ptr<T> const & b ) const BOOST_SP_NOEXCEPTnoexcept
318 {
319 return a.owner_equals( b );
320 }
321};
322
323} // namespace std
324
325#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED

/usr/include/boost/smart_ptr/detail/shared_count.hpp

1#ifndef BOOST_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED
2#define BOOST_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED
3
4// MS compatible compilers support #pragma once
5
6#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7# pragma once
8#endif
9
10//
11// detail/shared_count.hpp
12//
13// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14// Copyright 2004-2005 Peter Dimov
15//
16// Distributed under the Boost Software License, Version 1.0. (See
17// accompanying file LICENSE_1_0.txt or copy at
18// http://www.boost.org/LICENSE_1_0.txt)
19//
20
21#if defined(__BORLANDC__) && !defined(__clang__1)
22# pragma warn -8027 // Functions containing try are not expanded inline
23#endif
24
25#include <boost/smart_ptr/bad_weak_ptr.hpp>
26#include <boost/smart_ptr/detail/sp_counted_base.hpp>
27#include <boost/smart_ptr/detail/sp_counted_impl.hpp>
28#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
29#include <boost/smart_ptr/detail/sp_noexcept.hpp>
30#include <boost/checked_delete.hpp>
31#include <boost/throw_exception.hpp>
32#include <boost/core/addressof.hpp>
33#include <boost/config.hpp>
34#include <boost/config/workaround.hpp>
35#include <boost/cstdint.hpp>
36#include <memory> // std::auto_ptr
37#include <functional> // std::less
38#include <cstddef> // std::size_t
39
40#ifdef BOOST_NO_EXCEPTIONS
41# include <new> // std::bad_alloc
42#endif
43
44#if defined( BOOST_SP_DISABLE_DEPRECATED )
45#pragma GCC diagnostic push
46#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
47#endif
48
49namespace boost
50{
51
52namespace movelib
53{
54
55template< class T, class D > class unique_ptr;
56
57} // namespace movelib
58
59namespace detail
60{
61
62#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
63
64int const shared_count_id = 0x2C35F101;
65int const weak_count_id = 0x298C38A4;
66
67#endif
68
69struct sp_nothrow_tag {};
70
71template< class D > struct sp_inplace_tag
72{
73};
74
75template< class T > class sp_reference_wrapper
76{
77public:
78
79 explicit sp_reference_wrapper( T & t): t_( boost::addressof( t ) )
80 {
81 }
82
83 template< class Y > void operator()( Y * p ) const
84 {
85 (*t_)( p );
86 }
87
88private:
89
90 T * t_;
91};
92
93template< class D > struct sp_convert_reference
94{
95 typedef D type;
96};
97
98template< class D > struct sp_convert_reference< D& >
99{
100 typedef sp_reference_wrapper< D > type;
101};
102
103template<class T> std::size_t sp_hash_pointer( T* p ) BOOST_NOEXCEPTnoexcept
104{
105 boost::uintptr_t v = reinterpret_cast<boost::uintptr_t>( p );
106
107 // match boost::hash<T*>
108 return static_cast<std::size_t>( v + ( v >> 3 ) );
109}
110
111class weak_count;
112
113class shared_count
114{
115private:
116
117 sp_counted_base * pi_;
118
119#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
120 int id_;
121#endif
122
123 friend class weak_count;
124
125public:
126
127 BOOST_CONSTEXPRconstexpr shared_count() BOOST_SP_NOEXCEPTnoexcept: pi_(0)
128#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
129 , id_(shared_count_id)
130#endif
131 {
132 }
133
134 BOOST_CONSTEXPRconstexpr explicit shared_count( sp_counted_base * pi ) BOOST_SP_NOEXCEPTnoexcept: pi_( pi )
135#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
136 , id_(shared_count_id)
137#endif
138 {
139 }
140
141 template<class Y> explicit shared_count( Y * p ): pi_( 0 )
142#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
143 , id_(shared_count_id)
144#endif
145 {
146#ifndef BOOST_NO_EXCEPTIONS
147
148 try
149 {
150 pi_ = new sp_counted_impl_p<Y>( p );
151 }
152 catch(...)
153 {
154 boost::checked_delete( p );
155 throw;
156 }
157
158#else
159
160 pi_ = new sp_counted_impl_p<Y>( p );
161
162 if( pi_ == 0 )
163 {
164 boost::checked_delete( p );
165 boost::throw_exception( std::bad_alloc() );
166 }
167
168#endif
169 }
170
171#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1200 )((1 + 0 == 0) && (BOOST_MSVC != 0) && (1 % ((
(BOOST_MSVC <= 1200) ) + 1)))
172 template<class Y, class D> shared_count( Y * p, D d ): pi_(0)
173#else
174 template<class P, class D> shared_count( P p, D d ): pi_(0)
175#endif
176#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
177 , id_(shared_count_id)
178#endif
179 {
180#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1200 )((1 + 0 == 0) && (BOOST_MSVC != 0) && (1 % ((
(BOOST_MSVC <= 1200) ) + 1)))
181 typedef Y* P;
182#endif
183#ifndef BOOST_NO_EXCEPTIONS
184
185 try
186 {
187 pi_ = new sp_counted_impl_pd<P, D>(p, d);
188 }
189 catch(...)
190 {
191 d(p); // delete p
192 throw;
193 }
194
195#else
196
197 pi_ = new sp_counted_impl_pd<P, D>(p, d);
198
199 if(pi_ == 0)
200 {
201 d(p); // delete p
202 boost::throw_exception(std::bad_alloc());
203 }
204
205#endif
206 }
207
208#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
209
210 template< class P, class D > shared_count( P p, sp_inplace_tag<D> ): pi_( 0 )
211#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
212 , id_(shared_count_id)
213#endif
214 {
215#ifndef BOOST_NO_EXCEPTIONS
216
217 try
218 {
219 pi_ = new sp_counted_impl_pd< P, D >( p );
220 }
221 catch( ... )
222 {
223 D::operator_fn( p ); // delete p
224 throw;
225 }
226
227#else
228
229 pi_ = new sp_counted_impl_pd< P, D >( p );
230
231 if( pi_ == 0 )
232 {
233 D::operator_fn( p ); // delete p
234 boost::throw_exception( std::bad_alloc() );
235 }
236
237#endif // #ifndef BOOST_NO_EXCEPTIONS
238 }
239
240#endif // !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
241
242 template<class P, class D, class A> shared_count( P p, D d, A a ): pi_( 0 )
243#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
244 , id_(shared_count_id)
245#endif
246 {
247 typedef sp_counted_impl_pda<P, D, A> impl_type;
248
249#if !defined( BOOST_NO_CXX11_ALLOCATOR )
250
251 typedef typename std::allocator_traits<A>::template rebind_alloc< impl_type > A2;
252
253#else
254
255 typedef typename A::template rebind< impl_type >::other A2;
256
257#endif
258
259 A2 a2( a );
260
261#ifndef BOOST_NO_EXCEPTIONS
262
263 try
264 {
265 pi_ = a2.allocate( 1 );
266 ::new( static_cast< void* >( pi_ ) ) impl_type( p, d, a );
267 }
268 catch(...)
269 {
270 d( p );
271
272 if( pi_ != 0 )
273 {
274 a2.deallocate( static_cast< impl_type* >( pi_ ), 1 );
275 }
276
277 throw;
278 }
279
280#else
281
282 pi_ = a2.allocate( 1 );
283
284 if( pi_ != 0 )
285 {
286 ::new( static_cast< void* >( pi_ ) ) impl_type( p, d, a );
287 }
288 else
289 {
290 d( p );
291 boost::throw_exception( std::bad_alloc() );
292 }
293
294#endif
295 }
296
297#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
298
299 template< class P, class D, class A > shared_count( P p, sp_inplace_tag< D >, A a ): pi_( 0 )
300#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
301 , id_(shared_count_id)
302#endif
303 {
304 typedef sp_counted_impl_pda< P, D, A > impl_type;
305
306#if !defined( BOOST_NO_CXX11_ALLOCATOR )
307
308 typedef typename std::allocator_traits<A>::template rebind_alloc< impl_type > A2;
309
310#else
311
312 typedef typename A::template rebind< impl_type >::other A2;
313
314#endif
315
316 A2 a2( a );
317
318#ifndef BOOST_NO_EXCEPTIONS
319
320 try
321 {
322 pi_ = a2.allocate( 1 );
323 ::new( static_cast< void* >( pi_ ) ) impl_type( p, a );
324 }
325 catch(...)
326 {
327 D::operator_fn( p );
328
329 if( pi_ != 0 )
330 {
331 a2.deallocate( static_cast< impl_type* >( pi_ ), 1 );
332 }
333
334 throw;
335 }
336
337#else
338
339 pi_ = a2.allocate( 1 );
340
341 if( pi_ != 0 )
342 {
343 ::new( static_cast< void* >( pi_ ) ) impl_type( p, a );
344 }
345 else
346 {
347 D::operator_fn( p );
348 boost::throw_exception( std::bad_alloc() );
349 }
350
351#endif // #ifndef BOOST_NO_EXCEPTIONS
352 }
353
354#endif // !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
355
356#ifndef BOOST_NO_AUTO_PTR
357
358 // auto_ptr<Y> is special cased to provide the strong guarantee
359
360 template<class Y>
361 explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_impl_p<Y>( r.get() ) )
362#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
363 , id_(shared_count_id)
364#endif
365 {
366#ifdef BOOST_NO_EXCEPTIONS
367
368 if( pi_ == 0 )
369 {
370 boost::throw_exception(std::bad_alloc());
371 }
372
373#endif
374
375 r.release();
376 }
377
378#endif
379
380#if !defined( BOOST_NO_CXX11_SMART_PTR )
381
382 template<class Y, class D>
383 explicit shared_count( std::unique_ptr<Y, D> & r ): pi_( 0 )
384#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
385 , id_(shared_count_id)
386#endif
387 {
388 typedef typename sp_convert_reference<D>::type D2;
389
390 D2 d2( static_cast<D&&>( r.get_deleter() ) );
391 pi_ = new sp_counted_impl_pd< typename std::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
392
393#ifdef BOOST_NO_EXCEPTIONS
394
395 if( pi_ == 0 )
396 {
397 boost::throw_exception( std::bad_alloc() );
398 }
399
400#endif
401
402 r.release();
403 }
404
405#endif
406
407 template<class Y, class D>
408 explicit shared_count( boost::movelib::unique_ptr<Y, D> & r ): pi_( 0 )
409#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
410 , id_(shared_count_id)
411#endif
412 {
413 typedef typename sp_convert_reference<D>::type D2;
414
415 D2 d2( r.get_deleter() );
416 pi_ = new sp_counted_impl_pd< typename boost::movelib::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
417
418#ifdef BOOST_NO_EXCEPTIONS
419
420 if( pi_ == 0 )
421 {
422 boost::throw_exception( std::bad_alloc() );
423 }
424
425#endif
426
427 r.release();
428 }
429
430 ~shared_count() /*BOOST_SP_NOEXCEPT*/
431 {
432 if( pi_ != 0 ) pi_->release();
433#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
434 id_ = 0;
435#endif
436 }
437
438 shared_count(shared_count const & r) BOOST_SP_NOEXCEPTnoexcept: pi_(r.pi_)
439#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
440 , id_(shared_count_id)
441#endif
442 {
443 if( pi_ != 0 ) pi_->add_ref_copy();
444 }
445
446#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
447
448 shared_count(shared_count && r) BOOST_SP_NOEXCEPTnoexcept: pi_(r.pi_)
449#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
450 , id_(shared_count_id)
451#endif
452 {
453 r.pi_ = 0;
454 }
455
456#endif
457
458 explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0
459 shared_count( weak_count const & r, sp_nothrow_tag ) BOOST_SP_NOEXCEPTnoexcept; // constructs an empty *this when r.use_count() == 0
460
461 shared_count & operator= (shared_count const & r) BOOST_SP_NOEXCEPTnoexcept
462 {
463 sp_counted_base * tmp = r.pi_;
464
465 if( tmp != pi_ )
466 {
467 if( tmp != 0 ) tmp->add_ref_copy();
468 if( pi_ != 0 ) pi_->release();
469 pi_ = tmp;
470 }
471
472 return *this;
473 }
474
475 void swap(shared_count & r) BOOST_SP_NOEXCEPTnoexcept
476 {
477 sp_counted_base * tmp = r.pi_;
478 r.pi_ = pi_;
479 pi_ = tmp;
480 }
481
482 long use_count() const BOOST_SP_NOEXCEPTnoexcept
483 {
484 return pi_ != 0? pi_->use_count(): 0;
485 }
486
487 bool unique() const BOOST_SP_NOEXCEPTnoexcept
488 {
489 return use_count() == 1;
490 }
491
492 bool empty() const BOOST_SP_NOEXCEPTnoexcept
493 {
494 return pi_ == 0;
495 }
496
497 bool operator==( shared_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
498 {
499 return pi_ == r.pi_;
500 }
501
502 bool operator==( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept;
503
504 bool operator<( shared_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
505 {
506 return std::less<sp_counted_base *>()( pi_, r.pi_ );
507 }
508
509 bool operator<( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept;
510
511 void * get_deleter( sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPTnoexcept
512 {
513 return pi_? pi_->get_deleter( ti ): 0;
514 }
515
516 void * get_local_deleter( sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPTnoexcept
517 {
518 return pi_? pi_->get_local_deleter( ti ): 0;
519 }
520
521 void * get_untyped_deleter() const BOOST_SP_NOEXCEPTnoexcept
522 {
523 return pi_? pi_->get_untyped_deleter(): 0;
524 }
525
526 std::size_t hash_value() const BOOST_SP_NOEXCEPTnoexcept
527 {
528 return sp_hash_pointer( pi_ );
529 }
530};
531
532
533class weak_count
534{
535private:
536
537 sp_counted_base * pi_;
538
539#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
540 int id_;
541#endif
542
543 friend class shared_count;
544
545public:
546
547 BOOST_CONSTEXPRconstexpr weak_count() BOOST_SP_NOEXCEPTnoexcept: pi_(0)
548#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
549 , id_(weak_count_id)
550#endif
551 {
552 }
553
554 weak_count(shared_count const & r) BOOST_SP_NOEXCEPTnoexcept: pi_(r.pi_)
555#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
556 , id_(weak_count_id)
557#endif
558 {
559 if(pi_
17.1
Field 'pi_' is not equal to null
17.1
Field 'pi_' is not equal to null
17.1
Field 'pi_' is not equal to null
17.1
Field 'pi_' is not equal to null
!= 0) pi_->weak_add_ref();
18
Taking true branch
19
Use of memory after it is freed
560 }
561
562 weak_count(weak_count const & r) BOOST_SP_NOEXCEPTnoexcept: pi_(r.pi_)
563#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
564 , id_(weak_count_id)
565#endif
566 {
567 if(pi_ != 0) pi_->weak_add_ref();
568 }
569
570// Move support
571
572#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
573
574 weak_count(weak_count && r) BOOST_SP_NOEXCEPTnoexcept: pi_(r.pi_)
575#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
576 , id_(weak_count_id)
577#endif
578 {
579 r.pi_ = 0;
580 }
581
582#endif
583
584 ~weak_count() /*BOOST_SP_NOEXCEPT*/
585 {
586 if(pi_
2.1
Field 'pi_' is not equal to null
2.1
Field 'pi_' is not equal to null
2.1
Field 'pi_' is not equal to null
2.1
Field 'pi_' is not equal to null
!= 0) pi_->weak_release();
3
Taking true branch
4
Calling 'sp_counted_base::weak_release'
10
Returning; memory was released
587#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
588 id_ = 0;
589#endif
590 }
591
592 weak_count & operator= (shared_count const & r) BOOST_SP_NOEXCEPTnoexcept
593 {
594 sp_counted_base * tmp = r.pi_;
595
596 if( tmp != pi_ )
597 {
598 if(tmp != 0) tmp->weak_add_ref();
599 if(pi_ != 0) pi_->weak_release();
600 pi_ = tmp;
601 }
602
603 return *this;
604 }
605
606 weak_count & operator= (weak_count const & r) BOOST_SP_NOEXCEPTnoexcept
607 {
608 sp_counted_base * tmp = r.pi_;
609
610 if( tmp != pi_ )
611 {
612 if(tmp != 0) tmp->weak_add_ref();
613 if(pi_ != 0) pi_->weak_release();
614 pi_ = tmp;
615 }
616
617 return *this;
618 }
619
620 void swap(weak_count & r) BOOST_SP_NOEXCEPTnoexcept
621 {
622 sp_counted_base * tmp = r.pi_;
623 r.pi_ = pi_;
624 pi_ = tmp;
625 }
626
627 long use_count() const BOOST_SP_NOEXCEPTnoexcept
628 {
629 return pi_ != 0? pi_->use_count(): 0;
630 }
631
632 bool empty() const BOOST_SP_NOEXCEPTnoexcept
633 {
634 return pi_ == 0;
635 }
636
637 bool operator==( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
638 {
639 return pi_ == r.pi_;
640 }
641
642 bool operator==( shared_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
643 {
644 return pi_ == r.pi_;
645 }
646
647 bool operator<( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
648 {
649 return std::less<sp_counted_base *>()( pi_, r.pi_ );
650 }
651
652 bool operator<( shared_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
653 {
654 return std::less<sp_counted_base *>()( pi_, r.pi_ );
655 }
656
657 std::size_t hash_value() const BOOST_SP_NOEXCEPTnoexcept
658 {
659 return sp_hash_pointer( pi_ );
660 }
661};
662
663inline shared_count::shared_count( weak_count const & r ): pi_( r.pi_ )
664#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
665 , id_(shared_count_id)
666#endif
667{
668 if( pi_ == 0 || !pi_->add_ref_lock() )
669 {
670 boost::throw_exception( boost::bad_weak_ptr() );
671 }
672}
673
674inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ) BOOST_SP_NOEXCEPTnoexcept: pi_( r.pi_ )
675#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
676 , id_(shared_count_id)
677#endif
678{
679 if( pi_ != 0 && !pi_->add_ref_lock() )
680 {
681 pi_ = 0;
682 }
683}
684
685inline bool shared_count::operator==( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
686{
687 return pi_ == r.pi_;
688}
689
690inline bool shared_count::operator<( weak_count const & r ) const BOOST_SP_NOEXCEPTnoexcept
691{
692 return std::less<sp_counted_base *>()( pi_, r.pi_ );
693}
694
695} // namespace detail
696
697} // namespace boost
698
699#if defined( BOOST_SP_DISABLE_DEPRECATED )
700#pragma GCC diagnostic pop
701#endif
702
703#if defined(__BORLANDC__) && !defined(__clang__1)
704# pragma warn .8027 // Functions containing try are not expanded inline
705#endif
706
707#endif // #ifndef BOOST_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED

/usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp

1#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_ATOMIC_HPP_INCLUDED
2#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_ATOMIC_HPP_INCLUDED
3
4// MS compatible compilers support #pragma once
5
6#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7# pragma once
8#endif
9
10// detail/sp_counted_base_gcc_atomic.hpp - g++ 4.7+ __atomic intrinsics
11//
12// Copyright 2007, 2020 Peter Dimov
13// Distributed under the Boost Software License, Version 1.0.
14// https://www.boost.org/LICENSE_1_0.txt
15
16#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
17#include <boost/config.hpp>
18#include <boost/cstdint.hpp>
19
20#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
21
22#include <boost/config/pragma_message.hpp>
23BOOST_PRAGMA_MESSAGE("Using __atomic sp_counted_base")message("Using __atomic sp_counted_base")
24
25#endif
26
27namespace boost
28{
29
30namespace detail
31{
32
33inline void atomic_increment( boost::uint_least32_t * pw )
34{
35 __atomic_fetch_add( pw, 1, __ATOMIC_RELAXED0 );
36}
37
38inline boost::uint_least32_t atomic_decrement( boost::uint_least32_t * pw )
39{
40 return __atomic_fetch_sub( pw, 1, __ATOMIC_ACQ_REL4 );
41}
42
43inline boost::uint_least32_t atomic_conditional_increment( boost::uint_least32_t * pw )
44{
45 // long r = *pw;
46 // if( r != 0 ) ++*pw;
47 // return r;
48
49 boost::uint_least32_t r = __atomic_load_n( pw, __ATOMIC_RELAXED0 );
50
51 for( ;; )
52 {
53 if( r == 0 )
54 {
55 return r;
56 }
57
58 if( __atomic_compare_exchange_n( pw, &r, r + 1, true, __ATOMIC_RELAXED0, __ATOMIC_RELAXED0 ) )
59 {
60 return r;
61 }
62 }
63}
64
65inline boost::uint_least32_t atomic_load( boost::uint_least32_t const * pw )
66{
67 return __atomic_load_n( pw, __ATOMIC_ACQUIRE2 );
68}
69
70class BOOST_SYMBOL_VISIBLE__attribute__((__visibility__("default"))) sp_counted_base
71{
72private:
73
74 sp_counted_base( sp_counted_base const & );
75 sp_counted_base & operator= ( sp_counted_base const & );
76
77 boost::uint_least32_t use_count_; // #shared
78 boost::uint_least32_t weak_count_; // #weak + (#shared != 0)
79
80public:
81
82 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
83 {
84 }
85
86 virtual ~sp_counted_base() // nothrow
87 {
88 }
89
90 // dispose() is called when use_count_ drops to zero, to release
91 // the resources managed by *this.
92
93 virtual void dispose() = 0; // nothrow
94
95 // destroy() is called when weak_count_ drops to zero.
96
97 virtual void destroy() // nothrow
98 {
99 delete this;
8
Memory is released
100 }
101
102 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
103 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
104 virtual void * get_untyped_deleter() = 0;
105
106 void add_ref_copy()
107 {
108 atomic_increment( &use_count_ );
109 }
110
111 bool add_ref_lock() // true on success
112 {
113 return atomic_conditional_increment( &use_count_ ) != 0;
114 }
115
116 void release() // nothrow
117 {
118 if( atomic_decrement( &use_count_ ) == 1 )
119 {
120 dispose();
121 weak_release();
122 }
123 }
124
125 void weak_add_ref() // nothrow
126 {
127 atomic_increment( &weak_count_ );
128 }
129
130 void weak_release() // nothrow
131 {
132 if( atomic_decrement( &weak_count_ ) == 1 )
5
Assuming the condition is true
6
Taking true branch
133 {
134 destroy();
7
Calling 'sp_counted_base::destroy'
9
Returning; memory was released
135 }
136 }
137
138 long use_count() const // nothrow
139 {
140 return atomic_load( &use_count_ );
141 }
142};
143
144} // namespace detail
145
146} // namespace boost
147
148#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SYNC_HPP_INCLUDED