From 9d01b8fafbc1f2e2135105354445323a30f267e4 Mon Sep 17 00:00:00 2001 From: wangyikai Date: Thu, 18 Jul 2024 11:17:54 +0800 Subject: [PATCH] =?UTF-8?q?HDF=5FCORE=E6=89=93=E5=BC=80xcollie=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 4 -- adapter/uhdf2/pub_utils/BUILD.gn | 4 +- adapter/uhdf2/uhdf.gni | 2 +- adapter/uhdf2/utils/include/hdf_xcollie.h | 34 +++++++++----- adapter/uhdf2/utils/src/hdf_xcollie.cpp | 44 ++++++++----------- .../hdfxcollie_fuzzer/BUILD.gn | 8 ++-- .../hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp | 5 +-- 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 7c976f408..1b3091451 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -296,8 +296,6 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) } OHOS::sptr saManager; { - OHOS::HdfXCollie hdfXCollie("HdfRemoteAdapterAddSa_" + OHOS::ToString(saId) + "_get_samgr", - OHOS::HdfXCollie::DEFAULT_TIMEOUT_SECONDS, nullptr, nullptr, OHOS::HdfXCollie::HDF_XCOLLIE_FLAG_RECOVERY); saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); const int32_t waitTimes = 50; const int32_t sleepInterval = 20000; @@ -317,8 +315,6 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) } } { - OHOS::HdfXCollie hdfXCollie("HdfRemoteAdapterAddSa_" + OHOS::ToString(saId) + "_add_sa", - OHOS::HdfXCollie::DEFAULT_TIMEOUT_SECONDS, nullptr, nullptr, OHOS::HdfXCollie::HDF_XCOLLIE_FLAG_RECOVERY); struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); #ifdef WITH_SELINUX OHOS::sptr remote = holder->remote_; diff --git a/adapter/uhdf2/pub_utils/BUILD.gn b/adapter/uhdf2/pub_utils/BUILD.gn index da7803e2c..22dae89f3 100644 --- a/adapter/uhdf2/pub_utils/BUILD.gn +++ b/adapter/uhdf2/pub_utils/BUILD.gn @@ -53,8 +53,8 @@ if (defined(ohos_lite)) { ] defines = [] if (hicollie_enabled) { - external_deps += [ "hicollie:libhicollie" ] - defines += [ "HICOLLIE_ENABLE" ] + public_external_deps = [ "hicollie:libhicollie" ] + defines += [ "HDFHICOLLIE_ENABLE" ] } install_images = [ diff --git a/adapter/uhdf2/uhdf.gni b/adapter/uhdf2/uhdf.gni index 92db9f3d9..a877b1b01 100644 --- a/adapter/uhdf2/uhdf.gni +++ b/adapter/uhdf2/uhdf.gni @@ -14,7 +14,7 @@ hdf_framework_path = "//drivers/hdf_core/framework" hdf_uhdf_path = "//drivers/hdf_core/adapter/uhdf2" declare_args() { - hicollie_enabled = false + hicollie_enabled = true if (defined(global_parts_info) && !defined(global_parts_info.hiviewdfx_hicollie)) { hicollie_enabled = false diff --git a/adapter/uhdf2/utils/include/hdf_xcollie.h b/adapter/uhdf2/utils/include/hdf_xcollie.h index d6281fae0..32511b961 100644 --- a/adapter/uhdf2/utils/include/hdf_xcollie.h +++ b/adapter/uhdf2/utils/include/hdf_xcollie.h @@ -17,22 +17,32 @@ #define HDF_UHDF_UTILS_INCLUDE_HDF_XCOLLIE_H #include +#ifdef HDFHICOLLIE_ENABLE +#include "xcollie/xcollie.h" +#else +#include "singleton.h" +#endif namespace OHOS { -class HdfXCollie { +#ifdef HDFHICOLLIE_ENABLE +using HdfXCollie = ::OHOS::HiviewDFX::XCollie; +#else +class HdfXCollie : public Singleton { + DECLARE_SINGLETON(HdfXCollie); public: - HdfXCollie(const std::string& tag, uint32_t timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, - std::function func = nullptr, void* arg = nullptr, uint32_t flag = HDF_XCOLLIE_FLAG_LOG); - ~HdfXCollie(); + // NULL impl + int SetTimer(const std::string &name, unsigned int timeout, + std::function func, void *arg, unsigned int flag); - void CancelHdfXCollie(); - static const uint32_t HDF_XCOLLIE_FLAG_LOG = 1; // generate log file - static const uint32_t HDF_XCOLLIE_FLAG_RECOVERY = 2; // die when timeout - static const uint32_t DEFAULT_TIMEOUT_SECONDS = 10; -private: - int32_t id_; - std::string tag_; - bool isCanceled_; + // NULL impl + void CancelTimer(int id); + + // NULL impl + int SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit); + + // NULL impl + void TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message); }; +#endif } #endif // HDF_UHDF_UTILS_INCLUDE_HDF_XCOLLIE_H \ No newline at end of file diff --git a/adapter/uhdf2/utils/src/hdf_xcollie.cpp b/adapter/uhdf2/utils/src/hdf_xcollie.cpp index 5f362ea6c..e6f116caa 100644 --- a/adapter/uhdf2/utils/src/hdf_xcollie.cpp +++ b/adapter/uhdf2/utils/src/hdf_xcollie.cpp @@ -13,42 +13,34 @@ * limitations under the License. */ #include - #include "hdf_xcollie.h" #include "hdf_log.h" -#ifdef HICOLLIE_ENABLE -#include "xcollie/xcollie.h" -#endif - namespace OHOS { -HdfXCollie::HdfXCollie(const std::string& tag, uint32_t timeoutSeconds, - std::function func, void* arg, uint32_t flag) -{ - tag_ = tag; -#ifdef HICOLLIE_ENABLE - id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag_, timeoutSeconds, func, arg, flag); +#ifdef HDFHICOLLIE_ENABLE #else - id_ = -1; -#endif - isCanceled_ = false; - HDF_LOGD("start HdfXCollie, tag:%{public}s,timeout:%{public}u,flag:%{public}u,id:%{public}d", - tag_.c_str(), timeoutSeconds, flag, id_); +#define HDFXCOLLIE_SUCCESS 0 +// NULL impl +int HdfXCollie::SetTimer(const std::string &name, unsigned int timeout, + std::function func, void *arg, unsigned int flag) +{ + return HDFXCOLLIE_SUCCESS; } -HdfXCollie::~HdfXCollie() +// NULL impl +void HdfXCollie::CancelTimer(int id) { - CancelHdfXCollie(); } -void HdfXCollie::CancelHdfXCollie() +// NULL impl +int HdfXCollie::SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit) { - if (!isCanceled_) { -#ifdef HICOLLIE_ENABLE - HiviewDFX::XCollie::GetInstance().CancelTimer(id_); -#endif - isCanceled_ = true; - HDF_LOGD("cancel HdfXCollie, tag:%{public}s,id:%{public}d", tag_.c_str(), id_); - } + return HDFXCOLLIE_SUCCESS; } + +// NULL impl +void HdfXCollie::TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message) +{ } +#endif +} \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn index e967ac9fc..aeb320049 100644 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn @@ -7,12 +7,10 @@ import("//build/config/features.gni") import("//build/ohos.gni") import("//build/test.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") module_output_path = "hdf_core/hdf_core/uhdf2_utils_fuzzer" -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" - ohos_fuzztest("HdfXCollieFuzzTest") { module_out_path = module_output_path @@ -29,6 +27,10 @@ ohos_fuzztest("HdfXCollieFuzzTest") { "c_utils:utils", "hilog:libhilog", ] + + if (hicollie_enabled) { + defines = [ "HDFHICOLLIE_ENABLE" ] + } } group("fuzztest") { diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp index ce18678d1..762c971c0 100644 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp +++ b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp @@ -11,13 +11,12 @@ #include "hdf_xcollie.h" #include "hdf_base.h" #include "hdf_log.h" - #define HDF_LOG_TAG hdfxcollie_fuzzer static int HdfXCollieFuzzTest() { - OHOS::HdfXCollie hdfXCollieObj("hdfxcollie_fuzzer", OHOS::HdfXCollie::DEFAULT_TIMEOUT_SECONDS, - nullptr, nullptr, OHOS::HdfXCollie::HDF_XCOLLIE_FLAG_RECOVERY); + ::OHOS::HdfXCollie& inst = ::OHOS::HdfXCollie::GetInstance(); + (void)inst; return HDF_SUCCESS; } -- Gitee