From 1b9c2af1fcadae4ccf623099bef750160a093423 Mon Sep 17 00:00:00 2001 From: Jack He Date: Sat, 20 Apr 2019 17:01:53 -0700 Subject: [PATCH] TEST: Fix net_test_stock_rfcomm unit test * Properly mock updated L2CAP registeration method by including the filtered btsnoop option * Properly mock btsnoop module by creating a separate file to link with the test executable Fixes: 123361801 Test: atest net_test_stack_rfcomm Change-Id: I89ca875cbcc941feddd7c501fa1b7e14f8d14794 --- stack/Android.bp | 1 + stack/test/common/mock_btsnoop_module.cc | 42 ++++++++++++++++++++++++++++++++ stack/test/common/mock_l2cap_layer.cc | 8 +++--- stack/test/common/mock_l2cap_layer.h | 6 +++-- stack/test/rfcomm/stack_rfcomm_test.cc | 22 +---------------- 5 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 stack/test/common/mock_btsnoop_module.cc diff --git a/stack/Android.bp b/stack/Android.bp index 53076bbb1..f7f5a4532 100644 --- a/stack/Android.bp +++ b/stack/Android.bp @@ -257,6 +257,7 @@ cc_test { "rfcomm/rfc_ts_frames.cc", "rfcomm/rfc_utils.cc", "test/common/mock_btm_layer.cc", + "test/common/mock_btsnoop_module.cc", "test/common/mock_btu_layer.cc", "test/common/mock_l2cap_layer.cc", "test/common/stack_test_packet_utils.cc", diff --git a/stack/test/common/mock_btsnoop_module.cc b/stack/test/common/mock_btsnoop_module.cc new file mode 100644 index 000000000..7a5c5ae88 --- /dev/null +++ b/stack/test/common/mock_btsnoop_module.cc @@ -0,0 +1,42 @@ +/****************************************************************************** + * + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#include "hci/include/btsnoop.h" + +static void capture(const BT_HDR*, bool) { /* do nothing */ +} + +static void whitelist_l2c_channel(uint16_t, uint16_t, + uint16_t) { /* do nothing */ +} + +static void whitelist_rfc_dlci(uint16_t, uint8_t) { /* do nothing */ +} + +static void add_rfc_l2c_channel(uint16_t, uint16_t, uint16_t) { /* do nothing */ +} + +static void clear_l2cap_whitelist(uint16_t, uint16_t, + uint16_t) { /* do nothing */ +} + +static const btsnoop_t fake_snoop = {capture, whitelist_l2c_channel, + whitelist_rfc_dlci, add_rfc_l2c_channel, + clear_l2cap_whitelist}; + +const btsnoop_t* btsnoop_get_interface() { return &fake_snoop; } diff --git a/stack/test/common/mock_l2cap_layer.cc b/stack/test/common/mock_l2cap_layer.cc index 9f08d5673..4756f170e 100644 --- a/stack/test/common/mock_l2cap_layer.cc +++ b/stack/test/common/mock_l2cap_layer.cc @@ -24,9 +24,11 @@ void bluetooth::l2cap::SetMockInterface( l2cap_interface = mock_l2cap_interface; } -uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info) { - VLOG(1) << __func__ << ": psm=" << psm << ", p_cb_info=" << p_cb_info; - return l2cap_interface->Register(psm, p_cb_info); +uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, + bool enable_snoop) { + VLOG(1) << __func__ << ": psm=" << psm << ", p_cb_info=" << p_cb_info + << ", enable_snoop=" << enable_snoop; + return l2cap_interface->Register(psm, p_cb_info, enable_snoop); } uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& bd_addr) { diff --git a/stack/test/common/mock_l2cap_layer.h b/stack/test/common/mock_l2cap_layer.h index 78c8a9c6d..ade758546 100644 --- a/stack/test/common/mock_l2cap_layer.h +++ b/stack/test/common/mock_l2cap_layer.h @@ -26,7 +26,8 @@ namespace l2cap { class L2capInterface { public: - virtual uint16_t Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info) = 0; + virtual uint16_t Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, + bool enable_snoop) = 0; virtual uint16_t ConnectRequest(uint16_t psm, const RawAddress& bd_addr) = 0; virtual bool ConnectResponse(const RawAddress& bd_addr, uint8_t id, uint16_t lcid, uint16_t result, @@ -41,7 +42,8 @@ class L2capInterface { class MockL2capInterface : public L2capInterface { public: - MOCK_METHOD2(Register, uint16_t(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info)); + MOCK_METHOD3(Register, uint16_t(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, + bool enable_snoop)); MOCK_METHOD2(ConnectRequest, uint16_t(uint16_t psm, const RawAddress& bd_addr)); MOCK_METHOD5(ConnectResponse, diff --git a/stack/test/rfcomm/stack_rfcomm_test.cc b/stack/test/rfcomm/stack_rfcomm_test.cc index 0d27e5dec..52e1170c8 100644 --- a/stack/test/rfcomm/stack_rfcomm_test.cc +++ b/stack/test/rfcomm/stack_rfcomm_test.cc @@ -27,7 +27,6 @@ #include "port_api.h" #include "btm_int.h" -#include "hci/include/btsnoop.h" #include "rfc_int.h" #include "mock_btm_layer.h" @@ -35,23 +34,6 @@ #include "stack_rfcomm_test_utils.h" #include "stack_test_packet_utils.h" -static void capture(const BT_HDR*, bool) { /* do nothing */ -} -static void whitelist_l2c_channel(uint16_t, uint16_t, - uint16_t) { /* do nothing */ -} -static void whitelist_rfc_dlci(uint16_t, uint8_t) { /* do nothing */ -} -static void add_rfc_l2c_channel(uint16_t, uint16_t, uint16_t) { /* do nothing */ -} -static void clear_l2cap_whitelist(uint16_t, uint16_t, - uint16_t) { /* do nothing */ -} -static const btsnoop_t fake_snoop = {capture, whitelist_l2c_channel, - whitelist_rfc_dlci, add_rfc_l2c_channel, - clear_l2cap_whitelist}; -const btsnoop_t* btsnoop_get_interface() { return &fake_snoop; } - std::string DumpByteBufferToString(uint8_t* p_data, size_t len) { std::stringstream str; str.setf(std::ios_base::hex, std::ios::basefield); @@ -64,8 +46,6 @@ std::string DumpByteBufferToString(uint8_t* p_data, size_t len) { return str.str(); } -uint16_t L2CA_Register(unsigned short, tL2CAP_APPL_INFO*, bool) { return 0; } - std::string DumpBtHdrToString(BT_HDR* p_hdr) { uint8_t* p_hdr_data = p_hdr->data + p_hdr->offset; return DumpByteBufferToString(p_hdr_data, p_hdr->len); @@ -473,7 +453,7 @@ class StackRfcommTest : public Test { &btm_security_internal_interface_); bluetooth::l2cap::SetMockInterface(&l2cap_interface_); rfcomm_callback = &rfcomm_callback_; - EXPECT_CALL(l2cap_interface_, Register(BT_PSM_RFCOMM, _)) + EXPECT_CALL(l2cap_interface_, Register(BT_PSM_RFCOMM, _, _)) .WillOnce( DoAll(SaveArgPointee<1>(&l2cap_appl_info_), Return(BT_PSM_RFCOMM))); RFCOMM_Init(); -- 2.11.0