OSDN Git Service

TEST: Fix net_test_stock_rfcomm unit test
authorJack He <siyuanh@google.com>
Sun, 21 Apr 2019 00:01:53 +0000 (17:01 -0700)
committerJack He <siyuanh@google.com>
Sun, 21 Apr 2019 10:32:54 +0000 (10:32 +0000)
* 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
stack/test/common/mock_btsnoop_module.cc [new file with mode: 0644]
stack/test/common/mock_l2cap_layer.cc
stack/test/common/mock_l2cap_layer.h
stack/test/rfcomm/stack_rfcomm_test.cc

index 53076bb..f7f5a45 100644 (file)
@@ -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 (file)
index 0000000..7a5c5ae
--- /dev/null
@@ -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; }
index 9f08d56..4756f17 100644 (file)
@@ -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) {
index 78c8a9c..ade7585 100644 (file)
@@ -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,
index 0d27e5d..52e1170 100644 (file)
@@ -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"
 #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();