summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2023-01-11 21:59:00 -0800
committer William Escande <wescande@google.com> 2023-01-12 00:47:28 -0800
commitab3f84bb5c5445732dea90bbc3eabf1770a0c7f7 (patch)
tree483b128171530044d493562ed46e433e9a19f5f3
parentded3d038547e20f83249f27e3ae122b749c5ea7c (diff)
Mock static initialization order 02
cpp static order initialization is not guarantee. In order to avoid the mess, we need to have a lazy init schema. Remove extra declaration of map to the common mock declaration Bug: 265217208 Test: atest --host Change-Id: Ic95c034968fa3699f169ce92d727df1012e01789
-rw-r--r--system/bta/Android.bp12
-rw-r--r--system/bta/csis/csis_client_test.cc3
-rw-r--r--system/bta/groups/groups_test.cc3
-rw-r--r--system/bta/le_audio/broadcaster/broadcaster_test.cc3
-rw-r--r--system/bta/le_audio/broadcaster/state_machine_test.cc3
-rw-r--r--system/bta/le_audio/le_audio_client_test.cc2
-rw-r--r--system/bta/le_audio/state_machine_test.cc2
-rw-r--r--system/bta/test/bta_dm_test.cc3
-rw-r--r--system/bta/vc/vc_test.cc3
-rw-r--r--system/stack/Android.bp8
-rw-r--r--system/stack/test/gatt/gatt_sr_test.cc3
-rw-r--r--system/stack/test/gatt/stack_gatt_test.cc3
-rw-r--r--system/stack/test/hci/stack_hci_test.cc4
-rw-r--r--system/stack/test/hid/stack_hid_test.cc4
-rw-r--r--system/stack/test/stack_avdtp_test.cc4
-rw-r--r--system/stack/test/stack_btu_test.cc3
-rw-r--r--system/stack/test/stack_gatt_sr_hash_test.cc3
-rw-r--r--system/stack/test/stack_smp_test.cc2
-rw-r--r--system/test/common/mock_functions.cc3
19 files changed, 38 insertions, 33 deletions
diff --git a/system/bta/Android.bp b/system/bta/Android.bp
index 508aa47b63..d314aa2176 100644
--- a/system/bta/Android.bp
+++ b/system/bta/Android.bp
@@ -244,6 +244,7 @@ cc_test {
":OsiCompatSources",
":TestCommonLogMsg",
":TestCommonMainHandler",
+ ":TestCommonMockFunctions",
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
@@ -362,6 +363,7 @@ cc_test {
"packages/modules/Bluetooth/system/osi/include",
],
srcs : [
+ ":TestCommonMockFunctions",
":TestMockBtif",
":TestMockMainShimLeScanning",
"csis/csis_client.cc",
@@ -412,6 +414,7 @@ cc_test {
"packages/modules/Bluetooth/system/bta/include",
],
srcs : [
+ ":TestCommonMockFunctions",
":TestMockBtif",
"groups/groups_test.cc",
"groups/groups.cc",
@@ -457,6 +460,7 @@ cc_test {
"packages/modules/Bluetooth/system/stack/include",
],
srcs : [
+ ":TestCommonMockFunctions",
":TestMockOsi",
"gatt/database.cc",
"gatt/database_builder.cc",
@@ -590,8 +594,9 @@ cc_test {
"packages/modules/Bluetooth/system/stack/include",
],
srcs : [
- ":TestStubOsi",
+ ":TestCommonMockFunctions",
":TestMockBtaLeAudioHalVerifier",
+ ":TestStubOsi",
"test/common/bta_gatt_api_mock.cc",
"test/common/bta_gatt_queue_mock.cc",
"test/common/btm_api_mock.cc",
@@ -664,8 +669,9 @@ cc_test {
"packages/modules/Bluetooth/system/stack/include",
],
srcs : [
- ":TestStubOsi",
+ ":TestCommonMockFunctions",
":TestMockBtaLeAudioHalVerifier",
+ ":TestStubOsi",
"gatt/database.cc",
"gatt/database_builder.cc",
"le_audio/client.cc",
@@ -766,6 +772,7 @@ cc_test {
"le_audio/le_audio_types.cc",
"le_audio/mock_iso_manager.cc",
"le_audio/mock_codec_manager.cc",
+ ":TestCommonMockFunctions",
":TestCommonStackConfig",
],
shared_libs: [
@@ -822,6 +829,7 @@ cc_test {
"le_audio/mock_iso_manager.cc",
"test/common/mock_controller.cc",
"le_audio/mock_codec_manager.cc",
+ ":TestCommonMockFunctions",
":TestCommonStackConfig",
],
shared_libs: [
diff --git a/system/bta/csis/csis_client_test.cc b/system/bta/csis/csis_client_test.cc
index 129c99fd41..43579e286b 100644
--- a/system/bta/csis/csis_client_test.cc
+++ b/system/bta/csis/csis_client_test.cc
@@ -29,8 +29,7 @@
#include "csis_types.h"
#include "gatt/database_builder.h"
#include "hardware/bt_gatt_types.h"
-
-std::map<std::string, int> mock_function_count_map;
+#include "test/common/mock_functions.h"
namespace bluetooth {
namespace csis {
diff --git a/system/bta/groups/groups_test.cc b/system/bta/groups/groups_test.cc
index 2299c573e3..9fd768f71b 100644
--- a/system/bta/groups/groups_test.cc
+++ b/system/bta/groups/groups_test.cc
@@ -20,11 +20,10 @@
#include <gtest/gtest.h>
#include "bta_groups.h"
+#include "test/common/mock_functions.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
-std::map<std::string, int> mock_function_count_map;
-
namespace bluetooth {
namespace groups {
diff --git a/system/bta/le_audio/broadcaster/broadcaster_test.cc b/system/bta/le_audio/broadcaster/broadcaster_test.cc
index bfb5f3fe17..a08eff59ff 100644
--- a/system/bta/le_audio/broadcaster/broadcaster_test.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster_test.cc
@@ -30,6 +30,7 @@
#include "bta/test/common/mock_controller.h"
#include "device/include/controller.h"
#include "stack/include/btm_iso_api.h"
+#include "test/common/mock_functions.h"
using namespace std::chrono_literals;
@@ -54,8 +55,6 @@ using le_audio::LeAudioSourceAudioHalClient;
using le_audio::broadcaster::BigConfig;
using le_audio::broadcaster::BroadcastCodecWrapper;
-std::map<std::string, int> mock_function_count_map;
-
// Disables most likely false-positives from base::SplitString()
extern "C" const char* __asan_default_options() {
return "detect_container_overflow=0";
diff --git a/system/bta/le_audio/broadcaster/state_machine_test.cc b/system/bta/le_audio/broadcaster/state_machine_test.cc
index c634a8fdea..f0998c9c81 100644
--- a/system/bta/le_audio/broadcaster/state_machine_test.cc
+++ b/system/bta/le_audio/broadcaster/state_machine_test.cc
@@ -27,6 +27,7 @@
#include "mock_iso_manager.h"
#include "stack/include/ble_advertiser.h"
#include "state_machine.h"
+#include "test/common/mock_functions.h"
using namespace bluetooth::hci::iso_manager;
@@ -37,8 +38,6 @@ using testing::Mock;
using testing::SaveArg;
using testing::Test;
-std::map<std::string, int> mock_function_count_map;
-
// Disables most likely false-positives from base::SplitString()
extern "C" const char* __asan_default_options() {
return "detect_container_overflow=0";
diff --git a/system/bta/le_audio/le_audio_client_test.cc b/system/bta/le_audio/le_audio_client_test.cc
index 54fe8f76a4..39728c42d1 100644
--- a/system/bta/le_audio/le_audio_client_test.cc
+++ b/system/bta/le_audio/le_audio_client_test.cc
@@ -42,6 +42,7 @@
#include "mock_iso_manager.h"
#include "mock_state_machine.h"
#include "osi/include/log.h"
+#include "test/common/mock_functions.h"
using testing::_;
using testing::AnyNumber;
@@ -70,7 +71,6 @@ using le_audio::LeAudioSourceAudioHalClient;
extern struct fake_osi_alarm_set_on_mloop fake_osi_alarm_set_on_mloop_;
-std::map<std::string, int> mock_function_count_map;
constexpr int max_num_of_ases = 5;
static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
diff --git a/system/bta/le_audio/state_machine_test.cc b/system/bta/le_audio/state_machine_test.cc
index ba55ed900f..4e51f1bd2a 100644
--- a/system/bta/le_audio/state_machine_test.cc
+++ b/system/bta/le_audio/state_machine_test.cc
@@ -34,6 +34,7 @@
#include "mock_controller.h"
#include "mock_csis_client.h"
#include "mock_iso_manager.h"
+#include "test/common/mock_functions.h"
#include "types/bt_transport.h"
using ::le_audio::DeviceConnectState;
@@ -50,7 +51,6 @@ using ::testing::Return;
using ::testing::SaveArg;
using ::testing::Test;
-std::map<std::string, int> mock_function_count_map;
extern struct fake_osi_alarm_set_on_mloop fake_osi_alarm_set_on_mloop_;
void osi_property_set_bool(const char* key, bool value);
diff --git a/system/bta/test/bta_dm_test.cc b/system/bta/test/bta_dm_test.cc
index 232a038a25..e12153f3dd 100644
--- a/system/bta/test/bta_dm_test.cc
+++ b/system/bta/test/bta_dm_test.cc
@@ -30,6 +30,7 @@
#include "osi/include/compat.h"
#include "stack/include/btm_status.h"
#include "test/common/main_handler.h"
+#include "test/common/mock_functions.h"
#include "test/mock/mock_osi_alarm.h"
#include "test/mock/mock_osi_allocator.h"
#include "test/mock/mock_stack_acl.h"
@@ -37,8 +38,6 @@
using namespace std::chrono_literals;
-std::map<std::string, int> mock_function_count_map;
-
extern struct btm_client_interface_t btm_client_interface;
namespace base {
diff --git a/system/bta/vc/vc_test.cc b/system/bta/vc/vc_test.cc
index 159eb80d19..58cabfb45d 100644
--- a/system/bta/vc/vc_test.cc
+++ b/system/bta/vc/vc_test.cc
@@ -27,11 +27,10 @@
#include "gatt/database_builder.h"
#include "hardware/bt_gatt_types.h"
#include "mock_csis_client.h"
+#include "test/common/mock_functions.h"
#include "types.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
-
-std::map<std::string, int> mock_function_count_map;
void btif_storage_add_volume_control(const RawAddress& addr, bool auto_conn) {}
namespace bluetooth {
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index 13cde3dcd1..78e273d57b 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -430,6 +430,7 @@ cc_test {
srcs: crypto_toolbox_srcs + [
":TestCommonLogMsg",
":TestCommonMainHandler",
+ ":TestCommonMockFunctions",
":TestMockBtif",
":TestMockCommon",
":TestMockDevice",
@@ -601,6 +602,7 @@ cc_test {
"packages/modules/Bluetooth/system/utils/include",
],
srcs: [
+ ":TestCommonMockFunctions",
":TestMockStackBtm",
"gatt/gatt_utils.cc",
"test/common/mock_eatt.cc",
@@ -658,6 +660,7 @@ cc_test {
"test/common/mock_btu_layer.cc",
"test/common/mock_stack_avdt_msg.cc",
":TestCommonLogMsg",
+ ":TestCommonMockFunctions",
":TestMockStackL2cap",
":TestMockStackAcl",
":TestMockStackA2dp",
@@ -743,6 +746,7 @@ cc_test {
],
srcs: crypto_toolbox_srcs + [
":TestCommonMainHandler",
+ ":TestCommonMockFunctions",
":TestMockStackBtm",
"gatt/gatt_db.cc",
"gatt/gatt_sr_hash.cc",
@@ -994,6 +998,7 @@ cc_test {
"packages/modules/Bluetooth/system/vnd/ble",
],
srcs: crypto_toolbox_srcs + [
+ ":TestCommonMockFunctions",
"test/hci/stack_hci_test.cc",
],
static_libs: [
@@ -1039,6 +1044,7 @@ cc_test {
"packages/modules/Bluetooth/system/stack/btm",
],
srcs: crypto_toolbox_srcs + [
+ ":TestCommonMockFunctions",
":TestMockStackL2cap",
":TestMockStackSdp",
":TestMockStackBtm",
@@ -1098,6 +1104,7 @@ cc_test {
],
srcs: [
":TestCommonLogMsg",
+ ":TestCommonMockFunctions",
":TestMockBta",
":TestMockBtif",
":TestMockHci",
@@ -1164,6 +1171,7 @@ cc_test {
srcs: [
":OsiCompatSources",
":TestCommonMainHandler",
+ ":TestCommonMockFunctions",
":TestCommonStackConfig",
":TestMockBta",
":TestMockBtif",
diff --git a/system/stack/test/gatt/gatt_sr_test.cc b/system/stack/test/gatt/gatt_sr_test.cc
index 7e6ab3119d..7915ad9ea6 100644
--- a/system/stack/test/gatt/gatt_sr_test.cc
+++ b/system/stack/test/gatt/gatt_sr_test.cc
@@ -26,13 +26,12 @@
#include "stack/test/common/mock_eatt.h"
#undef LOG_TAG
#include "stack/gatt/gatt_sr.cc"
+#include "test/common/mock_functions.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
#define MAX_UINT16 ((uint16_t)0xffff)
-std::map<std::string, int> mock_function_count_map;
-
tGATT_CB gatt_cb;
namespace {
diff --git a/system/stack/test/gatt/stack_gatt_test.cc b/system/stack/test/gatt/stack_gatt_test.cc
index fd58899a12..8f57abfcac 100644
--- a/system/stack/test/gatt/stack_gatt_test.cc
+++ b/system/stack/test/gatt/stack_gatt_test.cc
@@ -26,11 +26,10 @@
#include "common/strings.h"
#include "stack/gatt/gatt_int.h"
#include "stack/include/gatt_api.h"
+#include "test/common/mock_functions.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
-std::map<std::string, int> mock_function_count_map;
-
class StackGattTest : public ::testing::Test {};
namespace {
diff --git a/system/stack/test/hci/stack_hci_test.cc b/system/stack/test/hci/stack_hci_test.cc
index 8ef98a3df3..bee6e1214a 100644
--- a/system/stack/test/hci/stack_hci_test.cc
+++ b/system/stack/test/hci/stack_hci_test.cc
@@ -16,16 +16,16 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+
#include <cstring>
#include <map>
#include "osi/include/log.h"
#include "stack/include/hcidefs.h"
#include "stack/include/l2cdefs.h"
+#include "test/common/mock_functions.h"
#include "test/mock/mock_hcic_hcicmds.h"
-std::map<std::string, int> mock_function_count_map;
-
namespace mock = test::mock::hcic_hcicmds;
namespace {
diff --git a/system/stack/test/hid/stack_hid_test.cc b/system/stack/test/hid/stack_hid_test.cc
index 3a955d3480..bdd351450a 100644
--- a/system/stack/test/hid/stack_hid_test.cc
+++ b/system/stack/test/hid/stack_hid_test.cc
@@ -16,6 +16,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+
#include <cstring>
#include <map>
@@ -23,12 +24,11 @@
#include "osi/include/log.h"
#include "stack/hid/hidh_int.h"
#include "stack/include/hci_error_code.h"
+#include "test/common/mock_functions.h"
#include "test/mock/mock_stack_l2cap_api.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"
-std::map<std::string, int> mock_function_count_map;
-
bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
tHCI_REASON btm_get_acl_disc_reason_code(void) { return HCI_SUCCESS; }
diff --git a/system/stack/test/stack_avdtp_test.cc b/system/stack/test/stack_avdtp_test.cc
index b3660632ec..49642560f5 100644
--- a/system/stack/test/stack_avdtp_test.cc
+++ b/system/stack/test/stack_avdtp_test.cc
@@ -21,6 +21,7 @@
#include "stack/avdt/avdt_int.h"
#include "stack/include/avdt_api.h"
#include "stack/test/common/mock_stack_avdt_msg.h"
+#include "test/common/mock_functions.h"
#include "types/raw_address.h"
#ifndef UNUSED_ATTR
@@ -30,9 +31,6 @@
// Global trace level referred in the code under test
uint8_t appl_trace_level = BT_TRACE_LEVEL_VERBOSE;
-// All mock requires this symbol to count calling times
-std::map<std::string, int> mock_function_count_map;
-
class StackAvdtpTest : public ::testing::Test {
protected:
StackAvdtpTest() = default;
diff --git a/system/stack/test/stack_btu_test.cc b/system/stack/test/stack_btu_test.cc
index c8f7280886..797ab64050 100644
--- a/system/stack/test/stack_btu_test.cc
+++ b/system/stack/test/stack_btu_test.cc
@@ -23,8 +23,7 @@
#include "stack/include/btu.h"
#include "stack/include/hci_error_code.h"
#include "stack/include/hcidefs.h"
-
-std::map<std::string, int> mock_function_count_map;
+#include "test/common/mock_functions.h"
/* Function for test provided by btu_hcif.cc */
void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status,
diff --git a/system/stack/test/stack_gatt_sr_hash_test.cc b/system/stack/test/stack_gatt_sr_hash_test.cc
index b831859c40..d60fc46f5f 100644
--- a/system/stack/test/stack_gatt_sr_hash_test.cc
+++ b/system/stack/test/stack_gatt_sr_hash_test.cc
@@ -21,14 +21,13 @@
#include "crypto_toolbox/crypto_toolbox.h"
#include "stack/gatt/gatt_int.h"
#include "stack/test/common/mock_eatt.h"
+#include "test/common/mock_functions.h"
#include "types/bluetooth/uuid.h"
using bluetooth::Uuid;
tGATT_CB gatt_cb;
-std::map<std::string, int> mock_function_count_map;
-
static void add_item_to_list(std::list<tGATT_SRV_LIST_ELEM>& srv_list_info,
tGATT_SVC_DB* db, bool is_primary) {
srv_list_info.emplace_back();
diff --git a/system/stack/test/stack_smp_test.cc b/system/stack/test/stack_smp_test.cc
index 167539bb73..d516248ad8 100644
--- a/system/stack/test/stack_smp_test.cc
+++ b/system/stack/test/stack_smp_test.cc
@@ -30,12 +30,12 @@
#include "stack/include/smp_api.h"
#include "stack/smp/p_256_ecc_pp.h"
#include "stack/smp/smp_int.h"
+#include "test/common/mock_functions.h"
#include "test/mock/mock_stack_acl.h"
#include "types/hci_role.h"
#include "types/raw_address.h"
tBTM_CB btm_cb;
-std::map<std::string, int> mock_function_count_map;
const std::string kSmpOptions("mock smp options");
const std::string kBroadcastAudioConfigOptions(
diff --git a/system/test/common/mock_functions.cc b/system/test/common/mock_functions.cc
index 85a7c646d4..2c910da66c 100644
--- a/system/test/common/mock_functions.cc
+++ b/system/test/common/mock_functions.cc
@@ -14,10 +14,11 @@
* limitations under the License.
*/
+#include "test/common/mock_functions.h"
+
#include <map>
#include "osi/include/log.h"
-#include "test/common/mock_functions.h"
std::map<std::string, int> mock_function_count_map;