From d85d34e2d5321da717fbc42372bf577afbd05215 Mon Sep 17 00:00:00 2001
From: Hui Peng <phui@google.com>
Date: Fri, 17 Nov 2023 22:37:38 +0000
Subject: [PATCH] Fix flakiness in net_test_btif_hh

The flakiness is caused by usage of fakeosi
and mock timer implementation. This change
replaces fakeosi and mock timer with real
implementation.

Bug: 311769946
Test: atest net_test_btif_hh
Change-Id: I81434dca67a34a4fc209abb551d5ab3f9842eadc
---
 system/btif/Android.bp           |  5 +++--
 system/btif/test/btif_hh_test.cc | 22 ++--------------------
 2 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/system/btif/Android.bp b/system/btif/Android.bp
index 38a005777f6..92c9455af9c 100644
--- a/system/btif/Android.bp
+++ b/system/btif/Android.bp
@@ -578,7 +578,6 @@ cc_test {
         ":TestCommonCoreInterface",
         ":TestCommonMainHandler",
         ":TestCommonMockFunctions",
-        ":TestFakeOsi",
         ":TestMockAndroidHardware",
         ":TestMockBtaAg",
         ":TestMockBtaAr",
@@ -601,7 +600,6 @@ cc_test {
         ":TestMockBtaVc",
         ":TestMockBtcore",
         ":TestMockBtu",
-        ":TestMockCommon",
         ":TestMockFrameworks",
         ":TestMockHci",
         ":TestMockMainShim",
@@ -636,6 +634,7 @@ cc_test {
         "libbluetooth_crypto_toolbox",
         "libbluetooth_gd",
         "libbt-audio-hal-interface",
+        "libbt-common",
         "libbt-platform-protos-lite",
         "libbt-sbc-decoder",
         "libbt-sbc-encoder",
@@ -651,6 +650,8 @@ cc_test {
         "libcom.android.sysprop.bluetooth.wrapped",
         "libevent",
         "libgmock",
+        "libosi",
+        "libprotobuf-cpp-lite",
         "libstatslog_bt",
     ],
     cflags: [
diff --git a/system/btif/test/btif_hh_test.cc b/system/btif/test/btif_hh_test.cc
index 9650f9df97f..9e47ee3b3e6 100644
--- a/system/btif/test/btif_hh_test.cc
+++ b/system/btif/test/btif_hh_test.cc
@@ -153,27 +153,9 @@ bthh_callbacks_t bthh_callbacks = {
 
 class BtifHhWithMockTest : 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 SetUp() override { reset_mock_function_count_map(); }
 
-  void TearDown() override {
-    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 = {};
-  }
+  void TearDown() override {}
 };
 
 class BtifHhWithHalCallbacksTest : public BtifHhWithMockTest {
-- 
GitLab