OSDN Git Service

Introduce net_test_stack_btm
authorChris Manton <cmanton@google.com>
Thu, 26 Nov 2020 00:38:18 +0000 (16:38 -0800)
committerChris Manton <cmanton@google.com>
Tue, 1 Dec 2020 16:15:15 +0000 (16:15 +0000)
Towards testable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host
Change-Id: Ifcd3424bf95794037d8d87d68857feef137190e7

stack/Android.bp
stack/test/btm/stack_btm_test.cc [new file with mode: 0644]

index bc3c27b..315bb1a 100644 (file)
@@ -609,3 +609,89 @@ cc_test {
         cfi: false,
     },
 }
+
+cc_test {
+    name: "net_test_stack_btm",
+    test_suites: ["device-tests"],
+    host_supported: true,
+    defaults: ["fluoride_defaults"],
+    local_include_dirs: [
+        "include",
+        "btm",
+        "test/common",
+    ],
+    include_dirs: [
+        "system/bt",
+        "system/bt/vnd/ble",
+    ],
+    srcs: crypto_toolbox_srcs + [
+        "acl/ble_acl.cc",
+        "acl/btm_acl.cc",
+        "acl/btm_ble_connection_establishment.cc",
+        "acl/btm_pm.cc",
+        "btm/ble_advertiser_hci_interface.cc",
+        "btm/btm_ble.cc",
+        "btm/btm_ble_addr.cc",
+        "btm/btm_ble_adv_filter.cc",
+        "btm/btm_ble_batchscan.cc",
+        "btm/btm_ble_bgconn.cc",
+        "btm/btm_ble_gap.cc",
+        "btm/btm_ble_multi_adv.cc",
+        "btm/btm_ble_privacy.cc",
+        "btm/btm_dev.cc",
+        "btm/btm_devctl.cc",
+        "btm/btm_inq.cc",
+        "btm/btm_iso.cc",
+        "btm/btm_main.cc",
+        "btm/btm_sco.cc",
+        "btm/btm_sec.cc",
+        "test/btm/stack_btm_test.cc",
+        "test/common/mock_bta_dm_act.cc",
+        "test/common/mock_bta_sys_conn.cc",
+        "test/common/mock_btif_dm.cc",
+        "test/common/mock_btif_storage.cc",
+        "test/common/mock_btu_hcif.cc",
+        "test/common/mock_gap_gap_ble.cc",
+        "test/common/mock_gatt_connection_manager.cc",
+        "test/common/mock_gatt_gatt_auth.cc",
+        "test/common/mock_gatt_main.cc",
+        "test/common/mock_hci_packet_parser.cc",
+        "test/common/mock_hcic_hciblecmds.cc",
+        "test/common/mock_hcic_hcicmds.cc",
+        "test/common/mock_l2cap_l2c_api.cc",
+        "test/common/mock_l2cap_l2c_ble.cc",
+        "test/common/mock_l2cap_l2c_link.cc",
+        "test/common/mock_l2cap_l2c_main.cc",
+        "test/common/mock_l2cap_l2c_utils.cc",
+        "test/common/mock_main_bte_main.cc",
+        "test/common/mock_main_shim.cc",
+        "test/common/mock_main_shim_acl_api.cc",
+        "test/common/mock_main_shim_l2c_api.cc",
+        "test/common/mock_main_shim_btm_api.cc",
+        "test/common/mock_main_shim_controller.cc",
+        "test/common/mock_smp_smp_act.cc",
+        "test/common/mock_smp_smp_api.cc",
+    ],
+    static_libs: [
+        "libbt-common",
+        "libbt-protos-lite",
+        "libgmock",
+        "liblog",
+        "libosi",
+        "libbtdevice",
+    ],
+    shared_libs: [
+        "libprotobuf-cpp-lite",
+        "libcrypto",
+    ],
+    sanitize: {
+        address: true,
+        all_undefined: true,
+        cfi: true,
+        integer_overflow: true,
+        scs: true,
+        diag: {
+            undefined : true
+        },
+    },
+}
diff --git a/stack/test/btm/stack_btm_test.cc b/stack/test/btm/stack_btm_test.cc
new file mode 100644 (file)
index 0000000..92fc9b2
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *
+ *  Copyright 2020 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 <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <map>
+
+#include "hci/include/hci_layer.h"
+#include "hci/include/hci_packet_factory.h"
+#include "internal_include/stack_config.h"
+#include "osi/include/osi.h"
+#include "stack/btm/btm_int.h"
+#include "stack/btm/btm_int_types.h"
+
+base::MessageLoop* get_main_message_loop() { return nullptr; }
+
+const hci_packet_factory_t* hci_packet_factory_get_interface() {
+  return nullptr;
+}
+const hci_t* hci_layer_get_interface() { return nullptr; }
+
+bt_status_t do_in_main_thread(const base::Location& from_here,
+                              base::OnceClosure task) {
+  return BT_STATUS_SUCCESS;
+}
+void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {}
+
+const std::string kSmpOptions("mock smp options");
+
+bool get_trace_config_enabled(void) { return false; }
+bool get_pts_avrcp_test(void) { return false; }
+bool get_pts_secure_only_mode(void) { return false; }
+bool get_pts_conn_updates_disabled(void) { return false; }
+bool get_pts_crosskey_sdp_disable(void) { return false; }
+const std::string* get_pts_smp_options(void) { return &kSmpOptions; }
+int get_pts_smp_failure_case(void) { return 123; }
+config_t* get_all(void) { return nullptr; }
+
+stack_config_t mock_stack_config{
+    .get_trace_config_enabled = get_trace_config_enabled,
+    .get_pts_avrcp_test = get_pts_avrcp_test,
+    .get_pts_secure_only_mode = get_pts_secure_only_mode,
+    .get_pts_conn_updates_disabled = get_pts_conn_updates_disabled,
+    .get_pts_crosskey_sdp_disable = get_pts_crosskey_sdp_disable,
+    .get_pts_smp_options = get_pts_smp_options,
+    .get_pts_smp_failure_case = get_pts_smp_failure_case,
+    .get_all = get_all,
+};
+const stack_config_t* stack_config_get_interface(void) {
+  return &mock_stack_config;
+}
+
+std::map<std::string, int> mock_function_count_map;
+
+namespace {
+
+using testing::_;
+using testing::DoAll;
+using testing::NotNull;
+using testing::Pointee;
+using testing::Return;
+using testing::SaveArg;
+using testing::SaveArgPointee;
+using testing::StrEq;
+using testing::StrictMock;
+using testing::Test;
+
+class StackBtmTest : public Test {
+ public:
+ protected:
+  void SetUp() override {}
+  void TearDown() override {}
+};
+
+TEST_F(StackBtmTest, GlobalLifecycle) {
+  btm_init();
+  btm_free();
+}
+
+TEST_F(StackBtmTest, DynamicLifecycle) {
+  auto* btm = new tBTM_CB();
+  delete btm;
+}
+
+}  // namespace