Skip to content
Snippets Groups Projects
Commit a4cf58db authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Stabilize hci_layer_test

Currently this test fails around 1 every 10 runs, with null pointer
exception.

Bug: 177907117
Tag: #feature
Test: atest bluetooth_test_gd --gtest_filter=HciTest.receiveMultiple* --gtest_repeat=100
Change-Id: I58de30ae493dc1a2764e36a4451906218632fd47
parent 189a0770
No related branches found
No related tags found
No related merge requests found
......@@ -204,6 +204,7 @@ class DependsOnHci : public Module {
}
EventView GetReceivedEvent() {
std::lock_guard<std::mutex> lock(list_protector_);
EventView packetview = incoming_events_.front();
incoming_events_.pop_front();
return packetview;
......@@ -220,6 +221,7 @@ class DependsOnHci : public Module {
}
AclView GetReceivedAcl() {
std::lock_guard<std::mutex> lock(list_protector_);
AclView packetview = incoming_acl_packets_.front();
incoming_acl_packets_.pop_front();
return packetview;
......@@ -253,8 +255,11 @@ class DependsOnHci : public Module {
std::list<AclView> incoming_acl_packets_;
std::unique_ptr<std::promise<void>> event_promise_;
std::unique_ptr<std::promise<void>> acl_promise_;
/* This mutex is protecting lists above from being pushed/popped from different threads at same time */
std::mutex list_protector_;
void handle_acl() {
std::lock_guard<std::mutex> lock(list_protector_);
auto acl_ptr = hci_->GetAclQueueEnd()->TryDequeue();
incoming_acl_packets_.push_back(*acl_ptr);
if (acl_promise_ != nullptr) {
......@@ -266,6 +271,7 @@ class DependsOnHci : public Module {
template <typename T>
void handle_event(T event) {
std::lock_guard<std::mutex> lock(list_protector_);
incoming_events_.push_back(event);
if (event_promise_ != nullptr) {
auto promise = std::move(event_promise_);
......@@ -688,7 +694,7 @@ TEST_F(HciTest, receiveMultipleAclPackets) {
Address bd_addr;
ASSERT_TRUE(Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr));
uint16_t handle = 0x0001;
uint16_t num_packets = 100;
const uint16_t num_packets = 100;
PacketBoundaryFlag packet_boundary_flag = PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE;
BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT;
for (uint16_t i = 0; i < num_packets; i++) {
......@@ -702,15 +708,15 @@ TEST_F(HciTest, receiveMultipleAclPackets) {
auto incoming_acl_future = upper->GetReceivedAclFuture();
uint16_t received_packets = 0;
while (received_packets < num_packets - 1) {
size_t num_packets = upper->GetNumReceivedAclPackets();
if (num_packets == 0) {
size_t num_rcv_packets = upper->GetNumReceivedAclPackets();
if (num_rcv_packets == 0) {
auto incoming_acl_status = incoming_acl_future.wait_for(kAclTimeout);
// Get the next future.
ASSERT_EQ(incoming_acl_status, std::future_status::ready);
incoming_acl_future = upper->GetReceivedAclFuture();
num_packets = upper->GetNumReceivedAclPackets();
num_rcv_packets = upper->GetNumReceivedAclPackets();
}
for (size_t i = 0; i < num_packets; i++) {
for (size_t i = 0; i < num_rcv_packets; i++) {
auto acl_view = upper->GetReceivedAcl();
ASSERT_TRUE(acl_view.IsValid());
ASSERT_EQ(bd_addr.length() + sizeof(handle) + sizeof(received_packets), acl_view.GetPayload().size());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment