From 4e85c099593a7d337bb277afc178eda3f7e7a818 Mon Sep 17 00:00:00 2001 From: "xiaoshun.xu" Date: Tue, 11 Jul 2023 17:30:04 +0800 Subject: [PATCH] Fix vts sco test fail for usb interface [Description] If bt controller device is usb interface, sco loopback single pkt and bandwidth test can not pass because pkt size is limited accroding to core spec [Root Cause] USB sco packet size is limited in spec [Solution] If is bt usb chip, continuous receive sco packets from controller until size is enough [Test Report] Test Pass Bug: 286355871 Change-Id: Idb150d8a72149f7e1dfaccfd7bc82a91710da59c --- .../aidl/vts/VtsHalBluetoothTargetTest.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp index e5222a764d..24eb4d0871 100644 --- a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp +++ b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp @@ -222,6 +222,8 @@ class BluetoothAidlTest : public ::testing::TestWithParam { int wait_for_completed_packets_event(uint16_t handle); void send_and_wait_for_cmd_complete(std::unique_ptr cmd, std::vector& cmd_complete); + void reassemble_sco_loopback_pkt(std::vector& scoPackets, + size_t size); // A simple test implementation of BluetoothHciCallbacks. class BluetoothHciCallbacks @@ -569,6 +571,11 @@ void BluetoothAidlTest::sendAndCheckSco(int num_packets, size_t size, ASSERT_TRUE( sco_queue.tryPopWithTimeout(sco_loopback, kWaitForScoDataTimeout)); + if (sco_loopback.size() < size) { + // The packets may have been split for USB. Reassemble before checking. + reassemble_sco_loopback_pkt(sco_loopback, size); + } + ASSERT_EQ(sco_packet, sco_loopback); } logger.setTotalBytes(num_packets * size * 2); @@ -703,6 +710,22 @@ void BluetoothAidlTest::send_and_wait_for_cmd_complete( wait_for_command_complete_event(view.GetOpCode(), cmd_complete)); } +// Handle the loopback packet. +void BluetoothAidlTest::reassemble_sco_loopback_pkt(std::vector& scoPackets, + size_t size) { + std::vector sco_packet_whole; + sco_packet_whole.assign(scoPackets.begin(), scoPackets.end()); + while (size + 3 > sco_packet_whole.size()) { + std::vector sco_packets; + ASSERT_TRUE( + sco_queue.tryPopWithTimeout(sco_packets, kWaitForScoDataTimeout)); + sco_packet_whole.insert(sco_packet_whole.end(), sco_packets.begin() + 3, + sco_packets.end()); + } + scoPackets.assign(sco_packet_whole.begin(), sco_packet_whole.end()); + scoPackets[2] = size; +} + // Empty test: Initialize()/Close() are called in SetUp()/TearDown(). TEST_P(BluetoothAidlTest, InitializeAndClose) {}