From e8e9665313ddf4f7f8b773743ffd4d9529cd4885 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Wed, 28 Aug 2024 13:08:30 +0800 Subject: [PATCH 1/9] build: decouple hisysevent Signed-off-by: lulu1023 --- services/BUILD.gn | 6 +++++- test/unittest/BUILD.gn | 18 +++++++++++++----- test/unittest/src/fan_fault_detect_test.cpp | 16 ++++++++++------ thermalmgr.gni | 7 +++++++ utils/BUILD.gn | 5 ++++- utils/native/src/thermal_hisysevent.cpp | 6 ++++++ 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 133b20f..be9b03e 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -110,7 +110,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 +154,11 @@ ohos_shared_library("thermalservice") { defines += [ "THERMAL_USER_VERSION" ] } + if (has_hiviewdfx_hisysevent_part) { + defines += [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] + external_deps += [ "hisysevent:libhisysevent" ] + } + subsystem_name = "powermgr" part_name = "thermal_manager" } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 3fdea02..1e6bebb 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -522,7 +522,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,6 +529,11 @@ ohos_unittest("ThermalClientTest") { "samgr:samgr_proxy", "window_manager:libwm", ] + + if (has_hiviewdfx_hisysevent_part) { + defines = [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] + external_deps += [ "hisysevent:libhisysevent" ] + } } # thermal mock stub test @@ -757,10 +761,14 @@ ohos_unittest("FanFaultDetectTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "hisysevent:libhisysevent", - "hisysevent:libhisyseventmanager", - ] + external_deps = [] + if (has_hiviewdfx_hisysevent_part) { + defines += [ "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 a9744ed..aed3601 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -18,15 +18,17 @@ #include #include #include - +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include "hisysevent.h" #include "hisysevent_listener.h" #include "hisysevent_manager.h" #include "hisysevent_record.h" #include "thermal_log.h" - +#endif using namespace testing::ext; +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART using namespace OHOS::HiviewDFX; +#endif using namespace OHOS::PowerMgr; namespace { @@ -48,7 +50,7 @@ const int64_t TIME_OUT = 2; std::mutex g_mutex; std::condition_variable g_callbackCV; std::atomic_bool g_eventTriggered = false; - +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART class Watcher : public HiSysEventListener { public: explicit Watcher(std::function)> func) : func_(func) {} @@ -67,6 +69,7 @@ public: private: std::function)> func_; }; +#endif } // namespace void FanFaultDetectTest::SetUpTestCase() {} @@ -101,7 +104,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; @@ -116,16 +119,17 @@ void FanFaultDetectTest::GetFaultId(int64_t& faultId, const FanSensorInfo& repor sysRules.emplace_back(listenerRule); auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules); EXPECT_TRUE(ret == SUCCESS); - + #endif fanFaultDetect->OnFanSensorInfoChanged(report); std::unique_lock lock(g_mutex); g_callbackCV.wait_for(lock, std::chrono::seconds(TIME_OUT), [] { return g_eventTriggered.load(); }); g_eventTriggered = false; - + #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher); EXPECT_TRUE(ret == SUCCESS); + #endif } namespace { diff --git a/thermalmgr.gni b/thermalmgr.gni index 09c0f19..81f2f02 100644 --- a/thermalmgr.gni +++ b/thermalmgr.gni @@ -13,6 +13,13 @@ import("//build/ohos.gni") +if (!defined(global_parts_info) || + defined(global_parts_info.hiviewdfx_hisysevent)) { + has_hiviewdfx_hisysevent_part = true +} else { + has_hiviewdfx_hisysevent_part = false +} + if (!defined(global_parts_info) || defined(global_parts_info.communication_netmanager_base)) { has_thermal_airplane_manager_part = true diff --git a/utils/BUILD.gn b/utils/BUILD.gn index d0841e7..1a407cd 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) { + defines = [ "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 e59f05b..d187a7e 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) -- Gitee From e972f473fb19acd3c8049d07471729aecdd84a78 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Wed, 28 Aug 2024 15:20:37 +0800 Subject: [PATCH 2/9] build: handle gn format Signed-off-by: lulu1023 --- services/BUILD.gn | 4 ++-- test/unittest/BUILD.gn | 2 +- utils/BUILD.gn | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index be9b03e..8e41c2e 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -156,9 +156,9 @@ ohos_shared_library("thermalservice") { if (has_hiviewdfx_hisysevent_part) { defines += [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] - external_deps += [ "hisysevent:libhisysevent" ] + external_deps += [ "hisysevent:libhisysevent" ] } - + subsystem_name = "powermgr" part_name = "thermal_manager" } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 1e6bebb..7787737 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -532,7 +532,7 @@ ohos_unittest("ThermalClientTest") { if (has_hiviewdfx_hisysevent_part) { defines = [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] - external_deps += [ "hisysevent:libhisysevent" ] + external_deps += [ "hisysevent:libhisysevent" ] } } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 1a407cd..0f82c3d 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -49,7 +49,7 @@ ohos_source_set("thermal_utils") { if (has_hiviewdfx_hisysevent_part) { defines = [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] - external_deps += [ "hisysevent:libhisysevent" ] + external_deps += [ "hisysevent:libhisysevent" ] } subsystem_name = "powermgr" part_name = "thermal_manager" -- Gitee From eba6703a26726563b3ec4847c5b1ed9a84443a97 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Mon, 2 Sep 2024 18:27:01 +0800 Subject: [PATCH 3/9] build: handle error Signed-off-by: lulu1023 --- test/unittest/src/fan_fault_detect_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index aed3601..1eddddd 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -23,8 +23,8 @@ #include "hisysevent_listener.h" #include "hisysevent_manager.h" #include "hisysevent_record.h" -#include "thermal_log.h" #endif +#include "thermal_log.h" using namespace testing::ext; #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART using namespace OHOS::HiviewDFX; -- Gitee From 1498cbf5f9e8a06c3d6515e9196189cdab70e670 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Mon, 2 Sep 2024 18:31:02 +0800 Subject: [PATCH 4/9] build: handle code format Signed-off-by: lulu1023 --- test/unittest/src/fan_fault_detect_test.cpp | 8 ++++---- utils/native/src/thermal_hisysevent.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index 1eddddd..8ec36f8 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -104,7 +104,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 +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART auto watcher = std::make_shared([&faultId] (std::shared_ptr sysEvent) { if (sysEvent == nullptr) { return; @@ -119,17 +119,17 @@ void FanFaultDetectTest::GetFaultId(int64_t& faultId, const FanSensorInfo& repor sysRules.emplace_back(listenerRule); auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules); EXPECT_TRUE(ret == SUCCESS); - #endif +#endif fanFaultDetect->OnFanSensorInfoChanged(report); std::unique_lock lock(g_mutex); g_callbackCV.wait_for(lock, std::chrono::seconds(TIME_OUT), [] { return g_eventTriggered.load(); }); g_eventTriggered = false; - #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART +#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher); EXPECT_TRUE(ret == SUCCESS); - #endif +#endif } namespace { diff --git a/utils/native/src/thermal_hisysevent.cpp b/utils/native/src/thermal_hisysevent.cpp index d187a7e..bb08cee 100644 --- a/utils/native/src/thermal_hisysevent.cpp +++ b/utils/native/src/thermal_hisysevent.cpp @@ -27,13 +27,13 @@ namespace PowerMgr { template static void WriteEvent(const std::string& eventType, Types... args) { - #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART +#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 +#endif } void WriteLevelChangedHiSysEvent(bool enableEvent, int32_t level) @@ -60,13 +60,13 @@ void WriteActionTriggeredHiSysEventWithRatio(bool enableEvent, const std::string template static void WriteFaultEvent(const std::string& eventType, Types... args) { - #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART +#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 +#endif } void WriteFanFaultEvent(int32_t faultId, std::string msg) -- Gitee From dc692968d0f7e8dec79b8845732cfd571a9cacb4 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Mon, 2 Sep 2024 19:23:02 +0800 Subject: [PATCH 5/9] build: handle gn format4 Signed-off-by: lulu1023 --- services/BUILD.gn | 3 --- test/systemtest/BUILD.gn | 1 - test/unittest/BUILD.gn | 34 +++++++++++++++------------------- thermalmgr.gni | 4 +++- utils/BUILD.gn | 1 - 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 8e41c2e..a03c712 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" ] } @@ -155,7 +153,6 @@ ohos_shared_library("thermalservice") { } if (has_hiviewdfx_hisysevent_part) { - defines += [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] external_deps += [ "hisysevent:libhisysevent" ] } diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 0e31644..5edcbaf 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 7787737..4568605 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", @@ -531,7 +529,6 @@ ohos_unittest("ThermalClientTest") { ] if (has_hiviewdfx_hisysevent_part) { - defines = [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] external_deps += [ "hisysevent:libhisysevent" ] } } @@ -539,7 +536,7 @@ ohos_unittest("ThermalClientTest") { # 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 = [ @@ -597,7 +594,7 @@ ohos_unittest("ThermalActionTest") { "${utils_path}:coverage_flags", ] - defines = [ "THERMAL_GTEST" ] + defines += [ "THERMAL_GTEST" ] deps = [ "${thermal_inner_api}:thermalsrv_client", @@ -625,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", @@ -647,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 = [ @@ -671,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 = [ @@ -695,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 = [ @@ -719,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 = [ @@ -743,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 = [ @@ -763,7 +760,6 @@ ohos_unittest("FanFaultDetectTest") { external_deps = [] if (has_hiviewdfx_hisysevent_part) { - defines += [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] external_deps = [ "hisysevent:libhisysevent", "hisysevent:libhisyseventmanager", diff --git a/thermalmgr.gni b/thermalmgr.gni index 81f2f02..c642b07 100644 --- a/thermalmgr.gni +++ b/thermalmgr.gni @@ -13,9 +13,11 @@ 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 } @@ -37,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 += [ "-DHAS_THERMAL_DISPLAY_MANAGER_PART" ] } else { has_thermal_display_manager_part = false } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 0f82c3d..e83b891 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -48,7 +48,6 @@ ohos_source_set("thermal_utils") { ] if (has_hiviewdfx_hisysevent_part) { - defines = [ "HAS_HIVIEWDFX_HISYSEVENT_PART" ] external_deps += [ "hisysevent:libhisysevent" ] } subsystem_name = "powermgr" -- Gitee From 404769010f7dd3d4ed493e27f2945230bb010d3d Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Mon, 2 Sep 2024 19:49:09 +0800 Subject: [PATCH 6/9] build: handle gn format5 Signed-off-by: lulu1023 --- thermalmgr.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thermalmgr.gni b/thermalmgr.gni index c642b07..1995f6b 100644 --- a/thermalmgr.gni +++ b/thermalmgr.gni @@ -39,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 - defines += [ "-DHAS_THERMAL_DISPLAY_MANAGER_PART" ] + defines += [ "HAS_THERMAL_DISPLAY_MANAGER_PART" ] } else { has_thermal_display_manager_part = false } -- Gitee From faedbe19896030933de4ee68b2355725b21a92f9 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Tue, 10 Sep 2024 14:52:50 +0800 Subject: [PATCH 7/9] build: code modify Signed-off-by: lulu1023 --- test/unittest/src/fan_fault_detect_test.cpp | 7 ++++++- test/unittest/src/thermal_config_file_parser.cpp | 2 ++ utils/BUILD.gn | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index 8ec36f8..569f35e 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -18,6 +18,7 @@ #include #include #include + #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include "hisysevent.h" #include "hisysevent_listener.h" @@ -46,10 +47,14 @@ 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::atomic_bool g_eventTriggered = false; +#endif + std::mutex g_mutex; std::condition_variable g_callbackCV; -std::atomic_bool g_eventTriggered = false; #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART class Watcher : public HiSysEventListener { public: diff --git a/test/unittest/src/thermal_config_file_parser.cpp b/test/unittest/src/thermal_config_file_parser.cpp index 2189db9..4eb8ded 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/utils/BUILD.gn b/utils/BUILD.gn index e83b891..fb96978 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -50,6 +50,7 @@ ohos_source_set("thermal_utils") { if (has_hiviewdfx_hisysevent_part) { external_deps += [ "hisysevent:libhisysevent" ] } + subsystem_name = "powermgr" part_name = "thermal_manager" } -- Gitee From 73bdb1cb1eec0400b730be0e17c86b23c807f1ae Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Tue, 10 Sep 2024 15:07:38 +0800 Subject: [PATCH 8/9] build: code modify Signed-off-by: lulu1023 --- test/unittest/src/fan_fault_detect_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index 569f35e..225c380 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -51,7 +51,7 @@ const int32_t TEMP_LOW = 20000; #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART const int64_t TIME_OUT = 2; std::atomic_bool g_eventTriggered = false; -#endif +#endif std::mutex g_mutex; std::condition_variable g_callbackCV; -- Gitee From 1d733853f954bb7f29259c5d5c6276e971c2bf08 Mon Sep 17 00:00:00 2001 From: lulu1023 Date: Tue, 10 Sep 2024 15:59:39 +0800 Subject: [PATCH 9/9] build: code modify Signed-off-by: lulu1023 --- test/unittest/src/fan_fault_detect_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/src/fan_fault_detect_test.cpp b/test/unittest/src/fan_fault_detect_test.cpp index 225c380..49fa7a3 100644 --- a/test/unittest/src/fan_fault_detect_test.cpp +++ b/test/unittest/src/fan_fault_detect_test.cpp @@ -124,14 +124,14 @@ void FanFaultDetectTest::GetFaultId(int64_t& faultId, const FanSensorInfo& repor sysRules.emplace_back(listenerRule); auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules); EXPECT_TRUE(ret == SUCCESS); -#endif + fanFaultDetect->OnFanSensorInfoChanged(report); std::unique_lock lock(g_mutex); g_callbackCV.wait_for(lock, std::chrono::seconds(TIME_OUT), [] { return g_eventTriggered.load(); }); g_eventTriggered = false; -#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART + ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher); EXPECT_TRUE(ret == SUCCESS); #endif -- Gitee