From: Marcin Siodelski Date: Mon, 2 Jul 2018 15:27:46 +0000 (+0200) Subject: [5664] Implemented tests for callout handle store memory leak. X-Git-Tag: Kea-1.4.0-P1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81e3dfff3e01c327ef7e70919dbb310b2a0a6ac7;p=thirdparty%2Fkea.git [5664] Implemented tests for callout handle store memory leak. --- diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index 1e0898776c..f14af29397 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -207,6 +207,21 @@ public: return (dis); } + /// @brief Checks if the state of the callout handle associated with a query + /// was reset after the callout invocation. + /// + /// The check includes verification if the status was set to 'continue' and + /// that all arguments were deleted. + /// + /// @param query pointer to the query which callout handle is associated + /// with. + void checkCalloutHandleReset(const Pkt4Ptr& query) { + CalloutHandlePtr callout_handle = query->getCalloutHandle(); + ASSERT_TRUE(callout_handle); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus()); + EXPECT_TRUE(callout_handle->getArgumentNames().empty()); + } + /// Test callback that stores received callout name and pkt4 value /// @param callout_handle handle passed by the hooks framework /// @return always 0 @@ -909,6 +924,9 @@ TEST_F(HooksDhcpv4SrvTest, Buffer4ReceiveSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(dis); } // Checks if callouts installed on buffer4_receive is able to change @@ -948,6 +966,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveValueChange) { // ... and check if it is the modified value ASSERT_FALSE(hwaddr->hwaddr_.empty()); // there must be a MAC address EXPECT_EQ(0xff, hwaddr->hwaddr_[0]); // check that its first byte was modified + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on buffer4_receive is able to set skip flag that @@ -976,6 +997,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveSkip) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on buffer4_receive is able to set drop flag that @@ -1002,6 +1026,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4ReceiveDrop) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on pkt4_receive are indeed called and the @@ -1043,6 +1070,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_received is able to change @@ -1080,6 +1110,9 @@ TEST_F(HooksDhcpv4SrvTest, valueChange_pkt4_receive) { // ... and check if it is the modified value OptionPtr expected = createOption(DHO_DHCP_CLIENT_IDENTIFIER); EXPECT_TRUE(clientid->equals(expected)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_received is able to delete @@ -1107,6 +1140,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDeleteClientId) { // Check that the server dropped the packet and did not send a response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_received is able to set skip flag that @@ -1133,6 +1169,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveSkip) { // check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_received is able to set drop flag that @@ -1159,6 +1198,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4ReceiveDrop) { // check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } @@ -1210,6 +1252,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); EXPECT_TRUE(callback_resp_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_send is able to change @@ -1247,6 +1292,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendValueChange) { // ... and check if it is the modified value OptionPtr expected = createOption(DHO_DHCP_SERVER_IDENTIFIER); EXPECT_TRUE(clientid->equals(expected)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_send is able to delete @@ -1282,6 +1330,9 @@ TEST_F(HooksDhcpv4SrvTest, pkt4SendDeleteServerId) { // Make sure that it does not have server-id EXPECT_FALSE(adv->getOption(DHO_DHCP_SERVER_IDENTIFIER)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_skip is able to set skip flag that @@ -1313,6 +1364,9 @@ TEST_F(HooksDhcpv4SrvTest, skip_pkt4_send) { // did not do packing on its own) Pkt4Ptr sent = srv_->fake_sent_.front(); EXPECT_EQ(0, sent->getBuffer().getLength()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt4_drop is able to set drop flag that @@ -1344,6 +1398,9 @@ TEST_F(HooksDhcpv4SrvTest, drop_pkt4_send) { // did not do packing on its own) Pkt4Ptr sent = srv_->fake_sent_.front(); EXPECT_EQ(0, sent->getBuffer().getLength()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer4_send are indeed called and the @@ -1385,6 +1442,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4SendSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_resp_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on buffer4_send are indeed called and that @@ -1416,6 +1476,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4Send) { // The callout is supposed to fill the output buffer with dummyFile content ASSERT_EQ(sizeof(dummyFile), adv->getBuffer().getLength()); EXPECT_EQ(0, memcmp(adv->getBuffer().getData(), dummyFile, sizeof(dummyFile))); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on buffer4_send can set skip flag and that flag @@ -1442,6 +1505,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4SendSkip) { // Check that there is no packet sent. ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } // Checks if callouts installed on buffer4_send can set drop flag and that flag @@ -1468,6 +1534,9 @@ TEST_F(HooksDhcpv4SrvTest, buffer4SendDrop) { // Check that there is no packet sent. ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(discover); } @@ -1548,6 +1617,9 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // This test checks if callout installed on subnet4_select hook point can pick @@ -1615,6 +1687,9 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) { // in dynamic pool) EXPECT_TRUE((*subnets)[1]->inRange(addr)); EXPECT_TRUE((*subnets)[1]->inPool(Lease::TYPE_V4, addr)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // This test verifies that the leases4_committed hook point is not triggered @@ -1636,6 +1711,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedDiscover) { // Make sure that the callout wasn't called. EXPECT_TRUE(callback_name_.empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases4_committed hook point is not triggered @@ -1657,6 +1735,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedInform) { // Make sure that the callout wasn't called. EXPECT_TRUE(callback_name_.empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that incoming (positive) REQUEST/Renewing can be handled @@ -1755,6 +1836,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that a callout installed on lease4_renew can trigger @@ -1825,6 +1909,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) { EXPECT_EQ(temp_timestamp, l->cltt_); EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that the callout installed on the leases4_committed hook @@ -1867,6 +1954,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Renew the lease and make sure that the callout has been executed. @@ -1889,6 +1979,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to renew again but force the client to request a different @@ -1914,6 +2007,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Now request an address that can't be allocated. The client should receive @@ -1930,6 +2026,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { EXPECT_FALSE(callback_lease4_); EXPECT_FALSE(callback_deleted_lease4_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that it is possible to park a packet as a result of @@ -1975,6 +2074,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client1.getContext().query_); + // Reset all indicators because we'll be now creating a second client. resetCalloutBuffers(); @@ -2008,6 +2110,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { rsp = client2.getContext().response_; EXPECT_EQ(DHCPACK, rsp->getType()); EXPECT_EQ("192.0.2.101", rsp->getYiaddr().toText()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client2.getContext().query_); } // This test verifies that valid RELEASE triggers lease4_release callouts @@ -2097,6 +2202,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(rel); } // This test verifies that skip flag returned by a callout installed on the @@ -2162,6 +2270,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) { // Try by client-id, should be successful as well. leases = LeaseMgrFactory::instance().getLease4(*client_id_); EXPECT_EQ(leases.size(), 1); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(rel); } // This test verifies that the leases4_committed callout is executed @@ -2206,6 +2317,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRelease) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that drop flag returned by a callout installed on the @@ -2271,6 +2385,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseDrop) { // Try by client-id, should be successful as well. leases = LeaseMgrFactory::instance().getLease4(*client_id_); EXPECT_EQ(leases.size(), 1); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(rel); } // Checks that decline4 hooks (lease4_decline) are triggered properly. @@ -2320,6 +2437,9 @@ TEST_F(HooksDhcpv4SrvTest, HooksDecline) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Checks that decline4 hook is able to skip the packet. @@ -2368,6 +2488,9 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineSkip) { // lease returned and lease from the lease manager) all match. EXPECT_EQ(addr, from_mgr->addr_); EXPECT_EQ(addr, callback_lease4_->addr_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Checks that decline4 hook is able to drop the packet. @@ -2416,6 +2539,9 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineDrop) { // lease returned and lease from the lease manager) all match. EXPECT_EQ(addr, from_mgr->addr_); EXPECT_EQ(addr, callback_lease4_->addr_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases4_committed callout is executed @@ -2461,6 +2587,9 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedDecline) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Checks if callout installed on host4_identifier can generate an @@ -2529,6 +2658,9 @@ TEST_F(HooksDhcpv4SrvTest, host4_identifier) { // Make sure the address offered is the one that was reserved. EXPECT_EQ("192.0.2.201", adv->getYiaddr().toText()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callout installed on host4_identifier can generate identifier of @@ -2597,6 +2729,9 @@ TEST_F(HooksDhcpv4SrvTest, host4_identifier_hwaddr) { // Make sure the address offered is the one that was reserved. EXPECT_EQ("192.0.2.201", adv->getYiaddr().toText()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index b36b97d680..67e88fa597 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/src/bin/dhcp6/tests/hooks_unittest.cc @@ -159,6 +159,21 @@ public: return OptionPtr(new Option(Option::V6, option_code, tmp)); } + /// @brief Checks if the state of the callout handle associated with a query + /// was reset after the callout invocation. + /// + /// The check includes verification if the status was set to 'continue' and + /// that all arguments were deleted. + /// + /// @param query pointer to the query which callout handle is associated + /// with. + void checkCalloutHandleReset(const Pkt6Ptr& query) { + CalloutHandlePtr callout_handle = query->getCalloutHandle(); + ASSERT_TRUE(callout_handle); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus()); + EXPECT_TRUE(callout_handle->getArgumentNames().empty()); + } + /// test callback that stores received callout name and pkt6 value /// @param callout_handle handle passed by the hooks framework /// @return always 0 @@ -1027,6 +1042,9 @@ TEST_F(HooksDhcpv6SrvTest, simpleBuffer6Receive) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_receive is able to change @@ -1063,6 +1081,9 @@ TEST_F(HooksDhcpv6SrvTest, valueChangeBuffer6Receive) { // ... and check if it is the modified value EXPECT_EQ(0xff, clientid->getData()[0]); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_receive is able to delete @@ -1088,6 +1109,9 @@ TEST_F(HooksDhcpv6SrvTest, deleteClientIdBuffer6Receive) { // Check that the server dropped the packet and did not send a response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_received is able to set skip flag that @@ -1112,6 +1136,9 @@ TEST_F(HooksDhcpv6SrvTest, skipBuffer6Receive) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_received is able to set drop flag that @@ -1136,6 +1163,9 @@ TEST_F(HooksDhcpv6SrvTest, dropBuffer6Receive) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_receive are indeed called and the @@ -1175,6 +1205,9 @@ TEST_F(HooksDhcpv6SrvTest, simplePkt6Receive) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_received is able to change @@ -1210,6 +1243,9 @@ TEST_F(HooksDhcpv6SrvTest, valueChangePkt6Receive) { // ... and check if it is the modified value OptionPtr expected = createOption(D6O_CLIENTID); EXPECT_TRUE(clientid->equals(expected)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_received is able to delete @@ -1235,6 +1271,9 @@ TEST_F(HooksDhcpv6SrvTest, deleteClientIdPkt6Receive) { // Check that the server dropped the packet and did not send a response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_received is able to set skip flag that @@ -1259,6 +1298,9 @@ TEST_F(HooksDhcpv6SrvTest, skipPkt6Receive) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_received is able to set drop flag that @@ -1283,6 +1325,9 @@ TEST_F(HooksDhcpv6SrvTest, dropPkt6Receive) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } @@ -1327,6 +1372,9 @@ TEST_F(HooksDhcpv6SrvTest, simplePkt6Send) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); EXPECT_TRUE(callback_resp_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_send is able to change @@ -1362,6 +1410,9 @@ TEST_F(HooksDhcpv6SrvTest, valueChangePkt6Send) { // ... and check if it is the modified value OptionPtr expected = createOption(D6O_SERVERID); EXPECT_TRUE(clientid->equals(expected)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_send is able to delete @@ -1395,6 +1446,9 @@ TEST_F(HooksDhcpv6SrvTest, deleteServerIdPkt6Send) { // Make sure that it does not have server-id EXPECT_FALSE(adv->getOption(D6O_SERVERID)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_skip is able to set skip flag that @@ -1426,6 +1480,9 @@ TEST_F(HooksDhcpv6SrvTest, skipPkt6Send) { // The actual size of sent packet should be 0 EXPECT_EQ(0, sent->getBuffer().getLength()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on pkt6_drop is able to set drop flag that @@ -1450,6 +1507,9 @@ TEST_F(HooksDhcpv6SrvTest, dropPkt6Send) { // Check that the server does not send the packet EXPECT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_send are indeed called and the @@ -1490,6 +1550,9 @@ TEST_F(HooksDhcpv6SrvTest, simpleBuffer6Send) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_resp_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_send can set skip flag and that flag @@ -1517,6 +1580,9 @@ TEST_F(HooksDhcpv6SrvTest, buffer6SendSkip) { // Check that there is no packet sent EXPECT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callouts installed on buffer6_send can set drop flag and that flag @@ -1544,6 +1610,9 @@ TEST_F(HooksDhcpv6SrvTest, buffer6SendDrop) { // Check that there is no packet sent EXPECT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // This test checks if subnet6_select callout is triggered and reports @@ -1625,6 +1694,9 @@ TEST_F(HooksDhcpv6SrvTest, subnet6Select) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // This test checks if callout installed on subnet6_select hook point can pick @@ -1703,6 +1775,9 @@ TEST_F(HooksDhcpv6SrvTest, subnet6SselectChange) { // in dynamic pool) EXPECT_TRUE((*subnets)[1]->inRange(addr_opt->getAddress())); EXPECT_TRUE((*subnets)[1]->inPool(Lease::TYPE_NA, addr_opt->getAddress())); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks that subnet6_select is able to drop the packet. @@ -1726,6 +1801,9 @@ TEST_F(HooksDhcpv6SrvTest, subnet6SelectDrop) { // Check that the server dropped the packet and did not produce any response ASSERT_EQ(0, srv_->fake_sent_.size()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // This test verifies that the leases6_committed hook point is not triggered @@ -1762,6 +1840,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedSolicit) { // Make sure that the callout wasn't called. EXPECT_TRUE(callback_name_.empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed hook point is not triggered @@ -1802,6 +1883,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedConfirm) { // Make sure that the callout wasn't called. EXPECT_TRUE(callback_name_.empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed hook point is not triggered @@ -1837,6 +1921,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedInfRequest) { // Make sure that the callout wasn't called. EXPECT_TRUE(callback_name_.empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the callout installed on the leases6_committed hook @@ -1899,6 +1986,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRapidCommit) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that it is possible to park a SOLICIT packet including @@ -1971,6 +2061,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRapidCommitPrefixes) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client1.getContext().query_); + // Reset all indicators because we'll be now creating a second client. resetCalloutBuffers(); @@ -2006,6 +2099,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRapidCommitPrefixes) { rsp = client2.getContext().response_; EXPECT_EQ(DHCPV6_REPLY, rsp->getType()); EXPECT_TRUE(client2.hasLeaseForPrefix(IOAddress("2001:db8:1:29::"), 64)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client2.getContext().query_); } // This test verifies that the callout installed on the leases6_committed hook @@ -2067,6 +2163,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Request the lease and make sure that the callout has been executed. @@ -2092,6 +2191,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to request again but force the client to request a different @@ -2120,6 +2222,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The requested address is just a hint. @@ -2144,6 +2249,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequest) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Request a prefix: this should lead to an error as no prefix pool @@ -2165,6 +2273,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequest) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the callout installed on the leases6_committed hook @@ -2230,6 +2341,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequestPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Request the lease and make sure that the callout has been executed. @@ -2256,6 +2370,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequestPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to request again but force the client to request a different @@ -2285,6 +2402,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequestPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The requested prefix is just a hint. @@ -2310,6 +2430,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequestPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Request an address: this should lead to an error as no address pool @@ -2331,6 +2454,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRequestPrefix) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that it is possible to park a packet as a result of @@ -2396,6 +2522,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRequests) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client1.getContext().query_); + // Reset all indicators because we'll be now creating a second client. resetCalloutBuffers(); @@ -2430,6 +2559,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRequests) { rsp = client2.getContext().response_; EXPECT_EQ(DHCPV6_REPLY, rsp->getType()); EXPECT_TRUE(client2.hasLeaseForAddress(IOAddress("2001:db8:1::29"))); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client2.getContext().query_); } // This test verifies that it is possible to park a packet as a result of @@ -2499,6 +2631,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRequestsPrefixes) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client1.getContext().query_); + // Reset all indicators because we'll be now creating a second client. resetCalloutBuffers(); @@ -2533,6 +2668,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedParkRequestsPrefixes) { rsp = client2.getContext().response_; EXPECT_EQ(DHCPV6_REPLY, rsp->getType()); EXPECT_TRUE(client2.hasLeaseForPrefix(IOAddress("2001:db8:1:29::"), 64)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client2.getContext().query_); } // This test verifies that incoming (positive) RENEW can be handled properly, @@ -2634,6 +2772,9 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Renew) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that incoming (positive) RENEW can be handled properly, @@ -2726,6 +2867,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Renew) { EXPECT_GE(1, abs(cltt - expected)); EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress())); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that incoming (positive) RENEW can be handled properly, @@ -2798,6 +2942,9 @@ TEST_F(HooksDhcpv6SrvTest, skipLease6Renew) { EXPECT_NE(l->preferred_lft_, subnet_->getPreferred()); EXPECT_NE(l->valid_lft_, subnet_->getValid()); EXPECT_NE(l->cltt_, time(NULL)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that the callout installed on the leases6_committed hook @@ -2859,6 +3006,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenew) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Renew the lease and make sure that the callout has been executed. @@ -2912,6 +3062,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenew) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The renewed address is just a hint. @@ -2936,6 +3089,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenew) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Renew a prefix: this should lead to an error as no prefix pool @@ -2957,6 +3113,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenew) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the callout installed on the leases6_committed hook @@ -3048,6 +3207,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenewPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to renew again but force the client to renew a different @@ -3077,6 +3239,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenewPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The renewed prefix is just a hint. @@ -3102,6 +3267,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenewPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Renew an address: this should lead to an error as no address pool @@ -3123,6 +3291,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRenewPrefix) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that incoming (positive) RELEASE can be handled properly, @@ -3208,6 +3379,9 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Release) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This is a variant of the previous test that tests that callouts are @@ -3287,6 +3461,9 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6ReleasePD) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that skip flag returned by a callout installed on the @@ -3351,6 +3528,9 @@ TEST_F(HooksDhcpv6SrvTest, skipLease6Release) { l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, *duid_, iaid, subnet_->getID()); ASSERT_TRUE(l); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that drop flag returned by a callout installed on the @@ -3415,6 +3595,9 @@ TEST_F(HooksDhcpv6SrvTest, dropLease6Release) { l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, *duid_, iaid, subnet_->getID()); ASSERT_TRUE(l); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that the leases6_committed callout is executed @@ -3475,6 +3658,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRelease) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed callout is executed @@ -3539,6 +3725,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedReleasePrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed callout is executed @@ -3606,6 +3795,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedReleaseMultiple) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that incoming (positive) REBIND can be handled properly, @@ -3702,6 +3894,9 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Rebind) { // Check that the returned lease6 in callout is the same as the one in the // database EXPECT_TRUE(*callback_lease6_ == *l); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that incoming (positive) REBIND can be handled properly, @@ -3791,6 +3986,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Rebind) { EXPECT_GE(1, abs(cltt - expected)); EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress())); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that incoming (positive) REBIND can be handled properly, @@ -3860,6 +4058,9 @@ TEST_F(HooksDhcpv6SrvTest, skipLease6Rebind) { EXPECT_NE(l->preferred_lft_, subnet_->getPreferred()); EXPECT_NE(l->valid_lft_, subnet_->getValid()); EXPECT_NE(l->cltt_, time(NULL)); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(req); } // This test verifies that the callout installed on the leases6_committed hook @@ -3921,6 +4122,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebind) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Rebind the lease and make sure that the callout has been executed. @@ -3946,6 +4150,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebind) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to rebind again but force the client to rebind a different @@ -3974,6 +4181,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebind) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The rebound address is just a hint. @@ -3998,6 +4208,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebind) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Rebind a prefix: this should lead to an error as no prefix pool @@ -4019,6 +4232,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebind) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the callout installed on the leases6_committed hook @@ -4084,6 +4300,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebindPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Rebind the lease and make sure that the callout has been executed. @@ -4110,6 +4329,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebindPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Let's try to rebind again but force the client to rebind a different @@ -4139,6 +4361,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebindPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // The rebound prefix is just a hint. @@ -4164,6 +4389,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebindPrefix) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); + resetCalloutBuffers(); // Rebind an address: this should lead to an error as no address pool @@ -4185,6 +4413,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedRebindPrefix) { EXPECT_EQ(3, callback_new_leases6_->size()); ASSERT_TRUE(callback_deleted_leases6_); EXPECT_TRUE(callback_deleted_leases6_->empty()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test checks that the basic decline hook (lease6_decline) is @@ -4236,6 +4467,9 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Decline) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Test that the lease6_decline hook point can handle SKIP status. @@ -4283,6 +4517,9 @@ TEST_F(HooksDhcpv6SrvTest, lease6DeclineSkip) { // And that the parameters passed to callout are consistent with the database EXPECT_EQ(addr, from_mgr->addr_); EXPECT_EQ(addr, callback_lease6_->addr_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Test that the lease6_decline hook point can handle DROP status. @@ -4328,6 +4565,9 @@ TEST_F(HooksDhcpv6SrvTest, lease6DeclineDrop) { ASSERT_TRUE(from_mgr); // Now check that it's NOT declined. EXPECT_EQ(Lease::STATE_DEFAULT, from_mgr->state_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed callout is executed @@ -4389,6 +4629,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedDecline) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // This test verifies that the leases6_committed callout is executed @@ -4453,6 +4696,9 @@ TEST_F(HooksDhcpv6SrvTest, leases6CommittedDeclineTwoNAs) { // Pkt passed to a callout must be configured to copy retrieved options. EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(client.getContext().query_); } // Should test with one NA and two addresses but need an example first... @@ -4532,6 +4778,9 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier) { ASSERT_TRUE(addr_opt); ASSERT_EQ("2001:db8::f00", addr_opt->getAddress().toText()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } // Checks if callout installed on host6_identifier can generate an identifier @@ -4609,6 +4858,9 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier_hwaddr) { ASSERT_TRUE(addr_opt); ASSERT_EQ("2001:db8::f00", addr_opt->getAddress().toText()); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(sol); } diff --git a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc index 933f31fb27..7d4bb39212 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc @@ -49,6 +49,21 @@ public: callback_skip_ = 0; } + /// @brief Checks if the state of the callout handle associated with a query + /// was reset after the callout invocation. + /// + /// The check includes verification if the status was set to 'continue' and + /// that all arguments were deleted. + /// + /// @param query pointer to the query which callout handle is associated + /// with. + void checkCalloutHandleReset(const Pkt6Ptr& query) { + CalloutHandlePtr callout_handle = query->getCalloutHandle(); + ASSERT_TRUE(callout_handle); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus()); + EXPECT_TRUE(callout_handle->getArgumentNames().empty()); + } + /// callback that stores received callout name and received values static int lease6_select_callout(CalloutHandle& callout_handle) { @@ -227,6 +242,9 @@ TEST_F(HookAllocEngine6Test, lease6_select) { EXPECT_TRUE(callback_argument_names_ == expected_argument_names); EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } // This test checks if lease6_select callout is able to override the values @@ -282,6 +300,9 @@ TEST_F(HookAllocEngine6Test, change_lease6_select) { EXPECT_EQ(t2_override_, from_mgr->t2_); EXPECT_EQ(pref_override_, from_mgr->preferred_lft_); EXPECT_EQ(valid_override_, from_mgr->valid_lft_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } // This test checks if lease6_select callout can set the status to next @@ -313,6 +334,9 @@ TEST_F(HookAllocEngine6Test, skip_lease6_select) { // Check no retry was attempted EXPECT_EQ(1, callback_skip_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } /// @brief helper class used in Hooks testing in AllocEngine4 @@ -348,6 +372,21 @@ public: callback_skip_ = 0; } + /// @brief Checks if the state of the callout handle associated with a query + /// was reset after the callout invocation. + /// + /// The check includes verification if the status was set to 'continue' and + /// that all arguments were deleted. + /// + /// @param query pointer to the query which callout handle is associated + /// with. + void checkCalloutHandleReset(const Pkt4Ptr& query) { + CalloutHandlePtr callout_handle = query->getCalloutHandle(); + ASSERT_TRUE(callout_handle); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus()); + EXPECT_TRUE(callout_handle->getArgumentNames().empty()); + } + /// callback that stores received callout name and received values static int lease4_select_callout(CalloutHandle& callout_handle) { @@ -522,6 +561,9 @@ TEST_F(HookAllocEngine4Test, lease4_select) { EXPECT_TRUE(callback_argument_names_ == expected_argument_names); EXPECT_TRUE(callback_qry_options_copy_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } // This test checks if lease4_select callout is able to override the values @@ -580,6 +622,9 @@ TEST_F(HookAllocEngine4Test, change_lease4_select) { EXPECT_EQ(t1_override_, from_mgr->t1_); EXPECT_EQ(t2_override_, from_mgr->t2_); EXPECT_EQ(valid_override_, from_mgr->valid_lft_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } // This test checks if lease4_select callout can set the status to next @@ -615,6 +660,9 @@ TEST_F(HookAllocEngine4Test, skip_lease4_select) { // Check no retry was attempted EXPECT_EQ(1, callback_skip_); + + // Check if the callout handle state was reset after the callout. + checkCalloutHandleReset(ctx.query_); } }; // namespace test diff --git a/src/lib/hooks/tests/callout_handle_unittest.cc b/src/lib/hooks/tests/callout_handle_unittest.cc index 3e3dcba181..319b9392b5 100644 --- a/src/lib/hooks/tests/callout_handle_unittest.cc +++ b/src/lib/hooks/tests/callout_handle_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -318,6 +318,65 @@ TEST_F(CalloutHandleTest, StatusField) { EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, handle.getStatus()); } +// Tests that ScopedCalloutHandleState object resets CalloutHandle state +// during construction and destruction. +TEST_F(CalloutHandleTest, scopedState) { + // Create pointer to the handle to be wrapped. + CalloutHandlePtr handle(new CalloutHandle(getCalloutManager())); + + // Set two arguments and the non-default status. + int one = 1; + int two = 2; + int three = 3; + handle->setArgument("one", one); + handle->setArgument("two", two); + handle->setContext("three", three); + handle->setStatus(CalloutHandle::NEXT_STEP_DROP); + + + int value = 0; + EXPECT_NO_THROW(handle->getArgument("one", value)); + EXPECT_NO_THROW(handle->getArgument("two", value)); + EXPECT_NO_THROW(handle->getContext("three", value)); + EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, handle->getStatus()); + + { + // Wrap the callout handle with the scoped state object, which should + // reset the state of the handle. + ScopedCalloutHandleState scoped_state(handle); + + // When state is reset, all arguments should be removed and the + // default status should be set. + EXPECT_THROW(handle->getArgument("one", value), NoSuchArgument); + EXPECT_THROW(handle->getArgument("two", value), NoSuchArgument); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, handle->getStatus()); + + // Context should be intact. + ASSERT_NO_THROW(handle->getContext("three", value)); + EXPECT_EQ(three, value); + + // Set the arguments and status again prior to the destruction of + // the wrapper. + handle->setArgument("one", one); + handle->setArgument("two", two); + handle->setStatus(CalloutHandle::NEXT_STEP_DROP); + + EXPECT_NO_THROW(handle->getArgument("one", value)); + EXPECT_NO_THROW(handle->getArgument("two", value)); + EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, handle->getStatus()); + } + + // Arguments should be gone again and the status should be set to + // a default value. + EXPECT_THROW(handle->getArgument("one", value), NoSuchArgument); + EXPECT_THROW(handle->getArgument("two", value), NoSuchArgument); + EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, handle->getStatus()); + + // Context should be intact. + ASSERT_NO_THROW(handle->getContext("three", value)); + EXPECT_EQ(three, value); +} + // Further tests of the "skip" flag and tests of getting the name of the // hook to which the current callout is attached is in the "handles_unittest" // module.