diff --git a/services/BUILD.gn b/services/BUILD.gn index 133b20fef71145191159cf445c2ce87f1ce9fa17..a03c71276bbb0bf4664a80965f838a8942c5a4f7 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -81,8 +81,6 @@ ohos_shared_library("thermalservice") { "${utils_path}:coverage_flags", ] - defines = [] - if (use_libfuzzer) { defines += [ "FUZZ_TEST" ] } @@ -110,7 +108,6 @@ ohos_shared_library("thermalservice") { "hdf_core:libpub_utils", "hicollie:libhicollie", "hilog:libhilog", - "hisysevent:libhisysevent", "image_framework:image_native", "init:libbegetutil", "ipc:ipc_core", @@ -155,6 +152,10 @@ ohos_shared_library("thermalservice") { defines += [ "THERMAL_USER_VERSION" ] } + if (has_hiviewdfx_hisysevent_part) { + external_deps += [ "hisysevent:libhisysevent" ] + } + subsystem_name = "powermgr" part_name = "thermal_manager" } diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 0e3164448266ad9c622e4cef5d9ee8906f8a50cd..5edcbafb5c87dbc55701b8aa14c2e2b6d6f74cac 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -182,7 +182,6 @@ ohos_systemtest("ThermalLevelEventSystemTest") { ] external_deps = deps_ex - defines = [] if (defined(global_parts_info) && defined(global_parts_info.powermgr_battery_manager)) { defines += [ "BATTERY_MANAGER_ENABLE" ] diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 3fdea02b9876f2b7d6564392f1e89db6cf944887..45686056f6f68b3a3c7b166d111a312891908aa6 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -71,7 +71,7 @@ ohos_unittest("ThermalMockActionTest") { "${utils_path}:coverage_flags", ] - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -219,11 +219,9 @@ ohos_unittest("ThermalActionReportTest") { "//third_party/googletest:gtest_main", ] - defines = [] - if (defined(global_parts_info) && defined(global_parts_info.powermgr_battery_statistics)) { - defines = [ "BATTERY_STATS_ENABLE" ] + defines += [ "BATTERY_STATS_ENABLE" ] deps += [ "${batterystats_utils_path}:batterystats_utils" ] external_deps = [ "battery_statistics:batterystats_client" ] external_deps += deps_ex @@ -307,7 +305,7 @@ ohos_unittest("ThermalMockProxyWriteinterfacetokenTest") { "${utils_path}:coverage_flags", ] - defines = [ "MOCK_WRITE_INTERFACE_TOKEN_RETURN_FALSE" ] + defines += [ "MOCK_WRITE_INTERFACE_TOKEN_RETURN_FALSE" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -337,7 +335,7 @@ ohos_unittest("ThermalMockProxyWriteremoteobjectTest") { "${utils_path}:coverage_flags", ] - defines = [ "MOCK_WRITE_REMOTE_OBJECT_RETURN_FALSE" ] + defines += [ "MOCK_WRITE_REMOTE_OBJECT_RETURN_FALSE" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -367,7 +365,7 @@ ohos_unittest("ThermalMockProxyWritevectorTest") { "${utils_path}:coverage_flags", ] - defines = [ "MOCK_WRITEVECTOR_RETURN_FALSE" ] + defines += [ "MOCK_WRITEVECTOR_RETURN_FALSE" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -396,7 +394,7 @@ ohos_unittest("ThermalMockProxySendrequestTest") { "${utils_path}:coverage_flags", ] - defines = [ "MOCK_SEND_REQUEST_RETURN_ONE" ] + defines += [ "MOCK_SEND_REQUEST_RETURN_ONE" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -447,7 +445,7 @@ ohos_unittest("ThermalServiceDeathTest") { "${utils_path}:coverage_flags", ] - defines = [ "THERMAL_SERVICE_DEATH_UT" ] + defines += [ "THERMAL_SERVICE_DEATH_UT" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -522,7 +520,6 @@ ohos_unittest("ThermalClientTest") { "hdf_core:libhdi", "hdf_core:libpub_utils", "hilog:libhilog", - "hisysevent:libhisysevent", "ipc:ipc_core", "libxml2:libxml2", "power_manager:powermgr_client", @@ -530,12 +527,16 @@ ohos_unittest("ThermalClientTest") { "samgr:samgr_proxy", "window_manager:libwm", ] + + if (has_hiviewdfx_hisysevent_part) { + external_deps += [ "hisysevent:libhisysevent" ] + } } # thermal mock stub test ohos_unittest("ThermalMockStubTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_mock_stub_test.cpp" ] configs = [ @@ -593,7 +594,7 @@ ohos_unittest("ThermalActionTest") { "${utils_path}:coverage_flags", ] - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -621,7 +622,7 @@ ohos_unittest("ThermalObserverTest") { "${utils_path}:coverage_flags", ] - defines = [ "THERMAL_OBSERVER_UT_TEST" ] + defines += [ "THERMAL_OBSERVER_UT_TEST" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -643,7 +644,7 @@ ohos_unittest("ThermalObserverTest") { # thermal service test ohos_unittest("ThermalServiceTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_service_test.cpp" ] configs = [ @@ -667,7 +668,7 @@ ohos_unittest("ThermalServiceTest") { # thermal config sensor cluster test ohos_unittest("ThermalConfigSensorClusterTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_config_sensor_cluster_test.cpp" ] configs = [ @@ -691,7 +692,7 @@ ohos_unittest("ThermalConfigSensorClusterTest") { # thermal mgr dump test ohos_unittest("ThermalMgrDumpTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_mgr_dump_test.cpp" ] configs = [ @@ -715,7 +716,7 @@ ohos_unittest("ThermalMgrDumpTest") { # thermal policy test ohos_unittest("ThermalPolicyTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_policy_test.cpp" ] configs = [ @@ -739,7 +740,7 @@ ohos_unittest("ThermalPolicyTest") { # fan fault detect test ohos_unittest("FanFaultDetectTest") { module_out_path = module_output_path - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] sources = [ "src/fan_fault_detect_test.cpp" ] configs = [ @@ -757,10 +758,13 @@ ohos_unittest("FanFaultDetectTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "hisysevent:libhisysevent", - "hisysevent:libhisyseventmanager", - ] + external_deps = [] + if (has_hiviewdfx_hisysevent_part) { + external_deps = [ + "hisysevent:libhisysevent", + "hisysevent:libhisyseventmanager", + ] + } external_deps += deps_ex } diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index a9744eda87f6d54b3ca53761691c8a7081f3fcdd..49fa7a3919006f2961b317ffca348c17a52af3e3 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -19,14 +19,17 @@ #include #include +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include "hisysevent.h" #include "hisysevent_listener.h" #include "hisysevent_manager.h" #include "hisysevent_record.h" +#endif #include "thermal_log.h" - using namespace testing::ext; +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART using namespace OHOS::HiviewDFX; +#endif using namespace OHOS::PowerMgr; namespace { @@ -44,11 +47,15 @@ const int32_t FAN_SLOW_SPEED = 400; const int32_t FAN_FAST_SPEED = 1600; const int32_t TEMP_HIGH = 60000; const int32_t TEMP_LOW = 20000; + +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART const int64_t TIME_OUT = 2; -std::mutex g_mutex; -std::condition_variable g_callbackCV; std::atomic_bool g_eventTriggered = false; +#endif +std::mutex g_mutex; +std::condition_variable g_callbackCV; +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART class Watcher : public HiSysEventListener { public: explicit Watcher(std::function)> func) : func_(func) {} @@ -67,6 +74,7 @@ public: private: std::function)> func_; }; +#endif } // namespace void FanFaultDetectTest::SetUpTestCase() {} @@ -101,7 +109,7 @@ void FanFaultDetectTest::GetFaultId(int64_t& faultId, const FanSensorInfo& repor std::shared_ptr fanFaultDetect = std::make_shared(); EXPECT_NE(fanFaultDetect, nullptr); InitFanFaultInfoMap(fanFaultDetect); - +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART auto watcher = std::make_shared([&faultId] (std::shared_ptr sysEvent) { if (sysEvent == nullptr) { return; @@ -126,6 +134,7 @@ void FanFaultDetectTest::GetFaultId(int64_t& faultId, const FanSensorInfo& repor ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher); EXPECT_TRUE(ret == SUCCESS); +#endif } namespace { diff --git a/test/unittest/src/thermal_config_file_parser.cpp b/test/unittest/src/thermal_config_file_parser.cpp index 2189db957e9beb1efbeee7239166780e48961277..4eb8ded92aeaca6b8691b38431b5d82ec4b0e405 100644 --- a/test/unittest/src/thermal_config_file_parser.cpp +++ b/test/unittest/src/thermal_config_file_parser.cpp @@ -39,12 +39,14 @@ bool ThermalConfigFileParser::Init() bool ThermalConfigFileParser::GetActionEnableEvent(const std::string& actionName) { +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART for (auto iter : actionItem_) { if (iter.name.compare(actionName) == 0 || actionName.find(iter.name) != std::string::npos) { return iter.enableEvent; } } +#endif return false; } diff --git a/thermalmgr.gni b/thermalmgr.gni index 09c0f19571a61a932ba094ba0667a3010a1ce90e..1995f6b6dd1d09de0c70e9db5a8908b5baa6fef6 100644 --- a/thermalmgr.gni +++ b/thermalmgr.gni @@ -13,6 +13,15 @@ import("//build/ohos.gni") +defines = [] +if (!defined(global_parts_info) || + defined(global_parts_info.hiviewdfx_hisysevent)) { + has_hiviewdfx_hisysevent_part = true + defines += [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] +} else { + has_hiviewdfx_hisysevent_part = false +} + if (!defined(global_parts_info) || defined(global_parts_info.communication_netmanager_base)) { has_thermal_airplane_manager_part = true @@ -30,7 +39,7 @@ if (!defined(global_parts_info) || if (!defined(global_parts_info) || defined(global_parts_info.powermgr_display_manager)) { has_thermal_display_manager_part = true - cflags_cc = [ "-DHAS_THERMAL_DISPLAY_MANAGER_PART" ] + defines += [ "HAS_THERMAL_DISPLAY_MANAGER_PART" ] } else { has_thermal_display_manager_part = false } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index d0841e783bd25833d7d04674e8a8161ba3e82e1b..fb96978b478c97f8e6a9917ecff7d777968195c6 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -44,10 +44,13 @@ ohos_source_set("thermal_utils") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "hisysevent:libhisysevent", "init:libbegetutil", ] + if (has_hiviewdfx_hisysevent_part) { + external_deps += [ "hisysevent:libhisysevent" ] + } + subsystem_name = "powermgr" part_name = "thermal_manager" } diff --git a/utils/native/src/thermal_hisysevent.cpp b/utils/native/src/thermal_hisysevent.cpp index e59f05b193f8677b2dcbc29571948d7250386b00..bb08ceeeded688c5931fea09f84dae8cd0f50825 100644 --- a/utils/native/src/thermal_hisysevent.cpp +++ b/utils/native/src/thermal_hisysevent.cpp @@ -17,7 +17,9 @@ #define HISYSEVENT_PERIOD 5 #define HISYSEVENT_THRESHOLD 200 +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include "hisysevent.h" +#endif #include "thermal_log.h" namespace OHOS { @@ -25,11 +27,13 @@ namespace PowerMgr { template static void WriteEvent(const std::string& eventType, Types... args) { +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType, HiviewDFX::HiSysEvent::EventType::STATISTIC, args...); if (ret != 0) { THERMAL_HILOGE(COMP_SVC, "Write event fail: %{public}s", eventType.c_str()); } +#endif } void WriteLevelChangedHiSysEvent(bool enableEvent, int32_t level) @@ -56,11 +60,13 @@ void WriteActionTriggeredHiSysEventWithRatio(bool enableEvent, const std::string template static void WriteFaultEvent(const std::string& eventType, Types... args) { +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType, HiviewDFX::HiSysEvent::EventType::FAULT, args...); if (ret != 0) { THERMAL_HILOGE(COMP_SVC, "Write fault event fail: %{public}s", eventType.c_str()); } +#endif } void WriteFanFaultEvent(int32_t faultId, std::string msg)