Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b30e87ac authored by William Escande's avatar William Escande
Browse files

Mock static initialization order 20

cpp static order initialization is not guarantee.
In order to avoid the mess, we need to have a lazy init schema.
Replacing all mock incrementation and getter in system/stack/test
```
's|mock_function_count_map\[__func__\]++|inc_func_call_count(__func__)|'
's|mock_function_count_map.count(\("[A-Za-z_]*"\))|get_func_call_count(\1)|'
```

Bug: 265217208
Test: atest --host
Change-Id: Ic6ac8ad96dcbbed8bc43ab9ebfb28cc7953ce72a
parent e46a9fe5
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -138,8 +138,7 @@ TEST_F(StackBtmTest, InformClientOnConnectionSuccess) {
  RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});

  btm_acl_connected(bda, 2, HCI_SUCCESS, false);
  ASSERT_EQ(static_cast<size_t>(1),
            mock_function_count_map.count("BTA_dm_acl_up"));
  ASSERT_EQ(1, get_func_call_count("BTA_dm_acl_up"));

  get_btm_client_interface().lifecycle.btm_free();
}
@@ -150,8 +149,7 @@ TEST_F(StackBtmTest, NoInformClientOnConnectionFail) {
  RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});

  btm_acl_connected(bda, 2, HCI_ERR_NO_CONNECTION, false);
  ASSERT_EQ(static_cast<size_t>(0),
            mock_function_count_map.count("BTA_dm_acl_up"));
  ASSERT_EQ(0, get_func_call_count("BTA_dm_acl_up"));

  get_btm_client_interface().lifecycle.btm_free();
}
+8 −8
Original line number Diff line number Diff line
@@ -33,34 +33,34 @@
#endif

bool bluetooth::shim::is_gd_l2cap_enabled() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return false;
}
bool bluetooth::shim::is_gd_security_enabled() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return false;
}
bool bluetooth::shim::is_gd_shim_enabled() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return false;
}
bool bluetooth::shim::is_gd_stack_started_up() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return false;
}
bool bluetooth::shim::is_gd_link_policy_enabled() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return false;
}
future_t* GeneralShutDown() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return nullptr;
}
future_t* IdleModuleStartUp() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return nullptr;
}
future_t* ShimModuleStartUp() {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return nullptr;
}
+5 −5
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
static std::vector<uint8_t> _rsp_sig_ids{};

void avdt_msg_send_rsp(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  _rsp_sig_ids.push_back(sig_id);
}

@@ -47,18 +47,18 @@ uint8_t mock_avdt_msg_send_rsp_get_sig_id_at(size_t nth) {
}

void avdt_msg_ind(AvdtpCcb* p_ccb, BT_HDR* p_buf) {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
}

void avdt_msg_send_rej(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
}

static std::vector<uint8_t> _cmd_sig_ids{};

void avdt_msg_send_cmd(AvdtpCcb* p_ccb, void* p_scb, uint8_t sig_id,
                       tAVDT_MSG* p_params) {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  _cmd_sig_ids.push_back(sig_id);
}

@@ -75,7 +75,7 @@ uint8_t mock_avdt_msg_send_cmd_get_sig_id_at(size_t nth) {
}

bool avdt_msg_send(AvdtpCcb* p_ccb, BT_HDR* p_msg) {
  mock_function_count_map[__func__]++;
  inc_func_call_count(__func__);
  return true;
}

+3 −3
Original line number Diff line number Diff line
@@ -45,20 +45,20 @@ class StackAvdtpTest : public ::testing::Test {
  static void AvdtConnCallback(uint8_t handle, const RawAddress& bd_addr,
                               uint8_t event, tAVDT_CTRL* p_data,
                               uint8_t scb_index) {
    mock_function_count_map[__func__]++;
    inc_func_call_count(__func__);
    callback_event_ = event;
  }

  static void StreamCtrlCallback(uint8_t handle, const RawAddress& bd_addr,
                                 uint8_t event, tAVDT_CTRL* p_data,
                                 uint8_t scb_index) {
    mock_function_count_map[__func__]++;
    inc_func_call_count(__func__);
    callback_event_ = event;
  }

  static void AvdtReportCallback(uint8_t handle, AVDT_REPORT_TYPE type,
                                 tAVDT_REPORT_DATA* p_data) {
    mock_function_count_map[__func__]++;
    inc_func_call_count(__func__);
  }

  static void SetUpTestCase() {