From 369e9406e5bc92ef133a1861fc9a37c362d39867 Mon Sep 17 00:00:00 2001 From: wangyikai Date: Mon, 28 Oct 2024 16:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90hdf=5Fcore=E3=80=91HDF=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E6=A1=86=E6=9E=B6=E4=BD=BF=E7=94=A8XCollie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- adapter/BUILD.gn | 1 + adapter/uhdf2/ipc/BUILD.gn | 6 ++ adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 16 ++++- adapter/uhdf2/pub_utils/BUILD.gn | 13 ++-- adapter/uhdf2/utils/test/BUILD.gn | 21 ++++++ adapter/uhdf2/utils/test/fuzztest/BUILD.gn | 20 ++++++ adapter/uhdf2/utils/test/unittest/BUILD.gn | 21 ++++++ .../test/unittest/hdf_xcollie_test/BUILD.gn | 48 ++++++++++++++ .../include/hdf_xcollie_test.h | 29 ++++++++ .../hdf_xcollie_test/src/hdf_xcollie_test.cpp | 66 +++++++++++++++++++ 10 files changed, 234 insertions(+), 7 deletions(-) create mode 100644 adapter/uhdf2/utils/test/BUILD.gn create mode 100644 adapter/uhdf2/utils/test/fuzztest/BUILD.gn create mode 100644 adapter/uhdf2/utils/test/unittest/BUILD.gn create mode 100644 adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/BUILD.gn create mode 100644 adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/include/hdf_xcollie_test.h create mode 100644 adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/src/hdf_xcollie_test.cpp diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 0422193e1..8f9970fb5 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -69,6 +69,7 @@ if (defined(ohos_lite)) { "$hdf_adapter_path/uhdf2/osal/test:unittest", "$hdf_adapter_path/uhdf2/shared/test:unittest", "$hdf_adapter_path/uhdf2/test:hdf_test_uhdf", + "$hdf_adapter_path/uhdf2/utils/test:test", ] } } diff --git a/adapter/uhdf2/ipc/BUILD.gn b/adapter/uhdf2/ipc/BUILD.gn index 1bef89f42..2b55544a2 100644 --- a/adapter/uhdf2/ipc/BUILD.gn +++ b/adapter/uhdf2/ipc/BUILD.gn @@ -55,6 +55,7 @@ if (defined(ohos_lite)) { "hilog:libhilog", "ipc:ipc_single", "samgr:samgr_proxy", +# "hicollie:libhicollie", ] } else { external_deps = [ @@ -64,6 +65,11 @@ if (defined(ohos_lite)) { ] } +# defines = [] +# if (hicollie_enabled) { +# defines += [ "HDFHICOLLIE_ENABLE" ] +# } + if (build_selinux) { cflags = [ "-DWITH_SELINUX" ] } diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 4b7afe7d1..c2404f8bd 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -25,7 +25,7 @@ #include "hdf_object_manager.h" #include "hdf_sbuf_ipc.h" #include "hdf_remote_adapter.h" -#include "hdf_xcollie.h" +// #include "xcollie/xcollie.h" #define HDF_LOG_TAG hdf_remote_adapter @@ -303,8 +303,13 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) const int32_t waitTimes = 50; const int32_t sleepInterval = 20000; + // const unsigned int timeout = 0x7FFFFFFF; //unit: second OHOS::sptr saManager; { + // // required nothrow loop + // int id = OHOS::HiviewDFX::XCollie::GetInstance().SetTimer(std::string(__func__) + + // "_" + OHOS::ToString(saId), timeout, nullptr, nullptr, OHOS::HiviewDFX::XCOLLIE_FLAG_NOOP); + for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -315,6 +320,8 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) HDF_LOGI("GetSystemAbilityManager failed, retry"); usleep(sleepInterval); } + // OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id); + if (saManager == nullptr) { HDF_LOGE("failed to get sa manager, waiting timeout"); return HDF_FAILURE; @@ -328,6 +335,11 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) stub->SetRequestSidFlag(true); #endif int ret = HDF_FAILURE; + + // // required nothrow loop + // int id = OHOS::HiviewDFX::XCollie::GetInstance().SetTimer(std::string(__func__) + + // "_" + OHOS::ToString(saId), timeout, nullptr, nullptr, OHOS::HiviewDFX::XCOLLIE_FLAG_NOOP); + for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for addSa... %{public}d", cnt); ret = saManager->AddSystemAbility(saId, holder->remote_); @@ -338,6 +350,8 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) HDF_LOGI("AddSystemAbility failed, retry"); usleep(sleepInterval); } + // OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id); + if (ret != HDF_SUCCESS) { HDF_LOGE("failed to addSa, waiting timeout"); return ret; diff --git a/adapter/uhdf2/pub_utils/BUILD.gn b/adapter/uhdf2/pub_utils/BUILD.gn index 173d86786..dca27362c 100644 --- a/adapter/uhdf2/pub_utils/BUILD.gn +++ b/adapter/uhdf2/pub_utils/BUILD.gn @@ -45,18 +45,19 @@ if (defined(ohos_lite)) { "$hdf_framework_path/utils/src/hdf_cstring.c", "$hdf_framework_path/utils/src/hdf_sbuf.c", "$hdf_framework_path/utils/src/hdf_sbuf_impl_raw.c", - "$hdf_uhdf_path/utils/src/hdf_xcollie.cpp", +# "$hdf_uhdf_path/utils/src/hdf_xcollie.cpp", ] external_deps = [ "c_utils:utils", "hilog:libhilog", ] - defines = [] - if (hicollie_enabled) { - public_external_deps = [ "hicollie:libhicollie" ] - defines += [ "HDFHICOLLIE_ENABLE" ] - } + +# defines = [] +# if (hicollie_enabled) { +# external_deps += [ "hicollie:libhicollie" ] +# defines += [ "HDFHICOLLIE_ENABLE" ] +# } install_images = [ system_base_dir, diff --git a/adapter/uhdf2/utils/test/BUILD.gn b/adapter/uhdf2/utils/test/BUILD.gn new file mode 100644 index 000000000..2cb77ea09 --- /dev/null +++ b/adapter/uhdf2/utils/test/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +group("test") { + testonly = true + deps = [ + "fuzztest:fuzztest", + "unittest:unittest", + ] +} diff --git a/adapter/uhdf2/utils/test/fuzztest/BUILD.gn b/adapter/uhdf2/utils/test/fuzztest/BUILD.gn new file mode 100644 index 000000000..d85b7818a --- /dev/null +++ b/adapter/uhdf2/utils/test/fuzztest/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +group("fuzztest") { + testonly = true + deps = [ + ] +} diff --git a/adapter/uhdf2/utils/test/unittest/BUILD.gn b/adapter/uhdf2/utils/test/unittest/BUILD.gn new file mode 100644 index 000000000..0d6a29e42 --- /dev/null +++ b/adapter/uhdf2/utils/test/unittest/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +group("unittest") { + testonly = true + deps = [ + "hdf_xcollie_test:hdf_xcollie_test", + ] +} diff --git a/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/BUILD.gn b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/BUILD.gn new file mode 100644 index 000000000..e8b941c15 --- /dev/null +++ b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +hdf_framework_path = "//drivers/hdf_core/framework" +hdf_uhdf_path = "//drivers/hdf_core/adapter/uhdf2" + +module_output_path = "hdf_core/adapter/uhdf2/utils" +ohos_unittest("hdf_xcollie_test") { + module_out_path = module_output_path + + include_dirs = [ + "include", + "$hdf_uhdf_path/utils/include", + ] + + sources = [ + "src/hdf_xcollie_test.cpp", + ] + + if (build_selinux) { + cflags = [ "-DWITH_SELINUX" ] + } + defines = [ "__USER__" ] + external_deps = [ + "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + ] + + if (hicollie_enabled) { + defines += [ "HDFHICOLLIE_ENABLE" ] + external_deps += [ "hicollie:libhicollie" ] + } +} diff --git a/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/include/hdf_xcollie_test.h b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/include/hdf_xcollie_test.h new file mode 100644 index 000000000..bf23d8bcc --- /dev/null +++ b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/include/hdf_xcollie_test.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HDF_XCOLLIE_TEST_H +#define HDF_XCOLLIE_TEST_H + +#include +namespace OHOS { +class HdfUtilsTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + void SetUp(); + void TearDown(); +}; +} +#endif diff --git a/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/src/hdf_xcollie_test.cpp b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/src/hdf_xcollie_test.cpp new file mode 100644 index 000000000..67165a2fa --- /dev/null +++ b/adapter/uhdf2/utils/test/unittest/hdf_xcollie_test/src/hdf_xcollie_test.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "hdf_xcollie_test.h" +#include "xcollie/xcollie.h" + +using namespace testing::ext; + +namespace OHOS { + +void HdfUtilsTest::SetUpTestCase() +{} + +void HdfUtilsTest::TearDownTestCase() +{} + +void HdfUtilsTest::SetUp() +{} + +void HdfUtilsTest::TearDown() +{} + +using namespace std; +using namespace OHOS::HiviewDFX; + +// allocate illegal buffer +HWTEST_F(HdfUtilsTest, HdfUtilsTest001, TestSize.Level1) +{ + HDF_LOGI("Hello: %s", __func__); + cout << "Hello" << endl; + + XCollieCallback callback = [](void *){ + cout << "callback invoke" << endl; + // std::abort(); + }; + + XCollie& inst = XCollie::GetInstance(); + int id = inst.SetTimer(string(__func__), 1, callback, nullptr, XCOLLIE_FLAG_LOG); + + std::this_thread::sleep_for(std::chrono::seconds(2)); + inst.CancelTimer(id); + + + int id2 = inst.SetTimer(string(__func__), 1, callback, nullptr, XCOLLIE_FLAG_DEFAULT); + + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + inst.CancelTimer(id2); +} +} \ No newline at end of file -- Gitee