diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 0422193e1c4f551c47ada1644a0358c3799a1f9a..8f9970fb5a65fb33de8fb48825c99b39211531fe 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 1bef89f422aa7ee2896fc8afdacc4fcf1b94b30e..2b55544a21cd358d1541950455fcbcde48dfc107 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 4b7afe7d1e3a610431b412f7bfe5c218d9490981..c2404f8bd851b18b4b6c4ca1f3bc16c95ab6f8c1 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 173d86786aa4f54685dae55d779df7965f7f4e45..dca27362c26a55a521b5083d81eadbf316ccec4e 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 0000000000000000000000000000000000000000..2cb77ea096819df95ab8cac4f8738aef0d406531 --- /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 0000000000000000000000000000000000000000..d85b7818acea6d008b144627294f5e6afe41232b --- /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 0000000000000000000000000000000000000000..0d6a29e4245f0654ef4da13bb8810cbd63f208e1 --- /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 0000000000000000000000000000000000000000..e8b941c15162e3c1339d20ab232828725d2db9aa --- /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 0000000000000000000000000000000000000000..bf23d8bccde1f374e6c299b81d31072908a155b6 --- /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 0000000000000000000000000000000000000000..67165a2fa25bb5e9f7808cf5119bcb17ed36d9af --- /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