Loading system/bta/Android.bp +68 −0 Original line number Diff line number Diff line Loading @@ -877,3 +877,71 @@ cc_test { }, }, } cc_test { name: "bluetooth_hh_test", test_suites: ["device-tests"], defaults: [ "fluoride_bta_defaults", "clang_coverage_bin", "mts_defaults", ], host_supported: true, // TODO(b/231993739): Reenable isolated:true by deleting the explicit disable below isolated: false, include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/bta/include", "packages/modules/Bluetooth/system/bta/test/common", "packages/modules/Bluetooth/system/stack/include", ], srcs : [ ":TestMockMainShim", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestMockBtaGatt", ":TestMockBtaSys", ":TestMockBtif", ":TestMockDevice", ":TestMockOsi", ":TestMockStack", "dm/bta_dm_act.cc", "dm/bta_dm_cfg.cc", "dm/bta_dm_ci.cc", "dm/bta_dm_main.cc", "dm/bta_dm_pm.cc", "gatt/bta_gattc_queue.cc", "hh/bta_hh_act.cc", "hh/bta_hh_api.cc", "hh/bta_hh_cfg.cc", "hh/bta_hh_le.cc", "hh/bta_hh_main.cc", "hh/bta_hh_utils.cc", "test/bta_hh_test.cc", ], shared_libs: [ "libprotobuf-cpp-lite", "libcrypto", ], static_libs : [ "crypto_toolbox_for_tests", "libgmock", "libbt-common", "libbt-protos-lite", "libosi", // ADDED ], generated_headers: [ "BluetoothGeneratedDumpsysDataSchema_h", "BluetoothGeneratedPackets_h", ], sanitize: { cfi: true, scs: true, address: true, all_undefined: true, integer_overflow: true, diag: { undefined : true }, }, } system/bta/test/bta_hh_test.cc 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * Copyright 2022 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 <gtest/gtest.h> #include <array> #include "bta/dm/bta_dm_int.h" #include "bta/hh/bta_hh_int.h" #include "bta/include/bta_hh_api.h" #include "osi/include/allocator.h" #include "test/common/mock_functions.h" #include "test/mock/mock_osi_allocator.h" uint8_t appl_trace_level = 0; void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {} uint8_t btif_trace_level = BT_TRACE_LEVEL_DEBUG; namespace { std::array<uint8_t, 32> data32 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, }; } class BtaHhTest : public ::testing::Test { protected: void SetUp() override { reset_mock_function_count_map(); test::mock::osi_allocator::osi_malloc.body = [](size_t size) { return malloc(size); }; test::mock::osi_allocator::osi_calloc.body = [](size_t size) { return calloc(1UL, size); }; test::mock::osi_allocator::osi_free.body = [](void* ptr) { free(ptr); }; test::mock::osi_allocator::osi_free_and_reset.body = [](void** ptr) { free(*ptr); *ptr = nullptr; }; } void TearDown() override { bta_hh_cb.p_cback = nullptr; test::mock::osi_allocator::osi_malloc = {}; test::mock::osi_allocator::osi_calloc = {}; test::mock::osi_allocator::osi_free = {}; test::mock::osi_allocator::osi_free_and_reset = {}; } }; TEST_F(BtaHhTest, simple) {} TEST_F(BtaHhTest, bta_hh_ctrl_dat_act__BTA_HH_GET_RPT_EVT) { tBTA_HH_DEV_CB cb = { .w4_evt = BTA_HH_GET_RPT_EVT, }; tBTA_HH_DATA data = { .hid_cback = { .hdr = { .event = 0, .len = 0, .offset = 0, .layer_specific = 0, }, .addr = RawAddress::kEmpty, .data = 32, .p_data = static_cast<BT_HDR*>(osi_calloc(32 + sizeof(BT_HDR))), }, }; data.hid_cback.p_data->len = static_cast<uint16_t>(data32.size()); uint8_t* p_data = (uint8_t*)(data.hid_cback.p_data + 1); int i = 0; for (const auto& byte : data32) { p_data[i++] = byte; } bta_hh_cb.p_cback = [](tBTA_HH_EVT event, tBTA_HH* p_data) { tBTA_HH_HSDATA& hs_data = p_data->hs_data; uint8_t* data = (uint8_t*)(hs_data.rsp_data.p_rpt_data + 1); ASSERT_EQ(BTA_HH_GET_RPT_EVT, event); int i = 0; for (const auto& byte : data32) { ASSERT_EQ(byte, data[i++]); } }; bta_hh_ctrl_dat_act(&cb, &data); ASSERT_EQ(mock_function_count_map["bta_hh_co_get_rpt_rsp"], 1); } Loading
system/bta/Android.bp +68 −0 Original line number Diff line number Diff line Loading @@ -877,3 +877,71 @@ cc_test { }, }, } cc_test { name: "bluetooth_hh_test", test_suites: ["device-tests"], defaults: [ "fluoride_bta_defaults", "clang_coverage_bin", "mts_defaults", ], host_supported: true, // TODO(b/231993739): Reenable isolated:true by deleting the explicit disable below isolated: false, include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/bta/include", "packages/modules/Bluetooth/system/bta/test/common", "packages/modules/Bluetooth/system/stack/include", ], srcs : [ ":TestMockMainShim", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestMockBtaGatt", ":TestMockBtaSys", ":TestMockBtif", ":TestMockDevice", ":TestMockOsi", ":TestMockStack", "dm/bta_dm_act.cc", "dm/bta_dm_cfg.cc", "dm/bta_dm_ci.cc", "dm/bta_dm_main.cc", "dm/bta_dm_pm.cc", "gatt/bta_gattc_queue.cc", "hh/bta_hh_act.cc", "hh/bta_hh_api.cc", "hh/bta_hh_cfg.cc", "hh/bta_hh_le.cc", "hh/bta_hh_main.cc", "hh/bta_hh_utils.cc", "test/bta_hh_test.cc", ], shared_libs: [ "libprotobuf-cpp-lite", "libcrypto", ], static_libs : [ "crypto_toolbox_for_tests", "libgmock", "libbt-common", "libbt-protos-lite", "libosi", // ADDED ], generated_headers: [ "BluetoothGeneratedDumpsysDataSchema_h", "BluetoothGeneratedPackets_h", ], sanitize: { cfi: true, scs: true, address: true, all_undefined: true, integer_overflow: true, diag: { undefined : true }, }, }
system/bta/test/bta_hh_test.cc 0 → 100644 +110 −0 Original line number Diff line number Diff line /* * Copyright 2022 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 <gtest/gtest.h> #include <array> #include "bta/dm/bta_dm_int.h" #include "bta/hh/bta_hh_int.h" #include "bta/include/bta_hh_api.h" #include "osi/include/allocator.h" #include "test/common/mock_functions.h" #include "test/mock/mock_osi_allocator.h" uint8_t appl_trace_level = 0; void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {} uint8_t btif_trace_level = BT_TRACE_LEVEL_DEBUG; namespace { std::array<uint8_t, 32> data32 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, }; } class BtaHhTest : public ::testing::Test { protected: void SetUp() override { reset_mock_function_count_map(); test::mock::osi_allocator::osi_malloc.body = [](size_t size) { return malloc(size); }; test::mock::osi_allocator::osi_calloc.body = [](size_t size) { return calloc(1UL, size); }; test::mock::osi_allocator::osi_free.body = [](void* ptr) { free(ptr); }; test::mock::osi_allocator::osi_free_and_reset.body = [](void** ptr) { free(*ptr); *ptr = nullptr; }; } void TearDown() override { bta_hh_cb.p_cback = nullptr; test::mock::osi_allocator::osi_malloc = {}; test::mock::osi_allocator::osi_calloc = {}; test::mock::osi_allocator::osi_free = {}; test::mock::osi_allocator::osi_free_and_reset = {}; } }; TEST_F(BtaHhTest, simple) {} TEST_F(BtaHhTest, bta_hh_ctrl_dat_act__BTA_HH_GET_RPT_EVT) { tBTA_HH_DEV_CB cb = { .w4_evt = BTA_HH_GET_RPT_EVT, }; tBTA_HH_DATA data = { .hid_cback = { .hdr = { .event = 0, .len = 0, .offset = 0, .layer_specific = 0, }, .addr = RawAddress::kEmpty, .data = 32, .p_data = static_cast<BT_HDR*>(osi_calloc(32 + sizeof(BT_HDR))), }, }; data.hid_cback.p_data->len = static_cast<uint16_t>(data32.size()); uint8_t* p_data = (uint8_t*)(data.hid_cback.p_data + 1); int i = 0; for (const auto& byte : data32) { p_data[i++] = byte; } bta_hh_cb.p_cback = [](tBTA_HH_EVT event, tBTA_HH* p_data) { tBTA_HH_HSDATA& hs_data = p_data->hs_data; uint8_t* data = (uint8_t*)(hs_data.rsp_data.p_rpt_data + 1); ASSERT_EQ(BTA_HH_GET_RPT_EVT, event); int i = 0; for (const auto& byte : data32) { ASSERT_EQ(byte, data[i++]); } }; bta_hh_ctrl_dat_act(&cb, &data); ASSERT_EQ(mock_function_count_map["bta_hh_co_get_rpt_rsp"], 1); }