From 8c6c72b53e2a0b344f0bc1ef4a43b42bed4943d5 Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 12 Oct 2024 11:06:11 +0800 Subject: [PATCH 1/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/BUILD.gn | 10 ++- adapter/khdf/linux/model/usb/host/Kconfig | 8 -- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 12 +++ adapter/uhdf2/hdi/src/iservmgr_client.cpp | 20 +++++ .../uhdf2/hdi/src/servstat_listener_stub.cpp | 3 +- adapter/uhdf2/hdi/test/BUILD.gn | 19 +++-- .../object_collector_test.cpp | 11 +++ .../servmgr/service_manager_hdi_c_test.cpp | 45 +++++++++- .../test/servmgr/service_manager_hdi_test.cpp | 16 ++++ adapter/uhdf2/hdi/test/smq_test/BUILD.gn | 8 +- adapter/uhdf2/hdi/test/smq_test/smq_test.cpp | 53 ++++++++++++ adapter/uhdf2/host/devhost.c | 2 + adapter/uhdf2/host/test/BUILD.gn | 21 +++-- .../uhdf2/host/test/unittest/devhost_test.cpp | 41 ++++++++- .../uhdf2/host/test/unittest/devmgr_test.cpp | 39 ++++++++- .../test/unittest/sample1_driver/BUILD.gn | 45 +++++----- .../host/test/unittest/sample_driver/BUILD.gn | 63 +++++++------- adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 26 ++++-- .../uhdf2/manager/src/devsvc_manager_stub.c | 8 +- adapter/uhdf2/osal/test/BUILD.gn | 12 +-- adapter/uhdf2/test/unittest/manager/BUILD.gn | 4 + bundle.json | 3 +- .../adapter/syscall/src/hdf_syscall_adapter.c | 12 +++ .../unittest/common/devmgr_uevent_test.cpp | 6 +- .../common/hdf_remote_adapter_test.cpp | 11 +++ .../unittest/common/hdf_core_shared_test.cpp | 6 ++ .../platform/src/watchdog/watchdog_core.c | 1 + framework/test/fuzztest/BUILD.gn | 1 - .../loaddevice_fuzzer/BUILD.gn | 1 - .../unloaddevice_fuzzer/BUILD.gn | 1 - .../utils_fuzzer/BUILD.gn | 54 ------------ .../utils_fuzzer/corpus/init | 7 -- .../utils_fuzzer/project.xml | 17 ---- .../utils_fuzzer/utils_fuzzer.cpp | 84 ------------------- .../utils_fuzzer/utils_fuzzer.h | 14 ---- .../ioservicebind_fuzzer/BUILD.gn | 1 - .../ioservicegrouplisten_fuzzer/BUILD.gn | 5 +- .../ioservicelisten_fuzzer/BUILD.gn | 5 +- .../ioserviceremove_fuzzer/BUILD.gn | 5 +- .../BUILD.gn | 1 - framework/tools/hdi-gen/hash/hash.cpp | 1 + 41 files changed, 410 insertions(+), 292 deletions(-) delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 6ac98abab..71d223ed6 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") hdf_adapter_path = "." if (defined(ohos_lite)) { @@ -37,8 +38,6 @@ if (defined(ohos_lite)) { "$hdf_adapter_path/uhdf2/hdi:libhdi", "$hdf_adapter_path/uhdf2/host:hdf_devhost", "$hdf_adapter_path/uhdf2/host:libhdf_host", - "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", - "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", "$hdf_adapter_path/uhdf2/ipc:libhdf_ipc_adapter", "$hdf_adapter_path/uhdf2/manager:hdf_devmgr", "$hdf_adapter_path/uhdf2/manager:hdf_devmgr.cfg", @@ -49,7 +48,12 @@ if (defined(ohos_lite)) { "$hdf_adapter_path/uhdf2/utils:libhdf_utils", "$hdf_framework_path/tools/hdf_dbg:hdf_dbg", "$hdf_peripheral_path:hdf_peripheral.cfg", - ] + if (with_sample) { + deps += [ + "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", + "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", + ] + } } group("uhdf_test_entry") { testonly = true diff --git a/adapter/khdf/linux/model/usb/host/Kconfig b/adapter/khdf/linux/model/usb/host/Kconfig index 2378468c7..710f80dba 100755 --- a/adapter/khdf/linux/model/usb/host/Kconfig +++ b/adapter/khdf/linux/model/usb/host/Kconfig @@ -15,11 +15,3 @@ config DRIVERS_HDF_USB_PNP_NOTIFY depends on DRIVERS_HDF help Answer Y to choice HDF USB PNP Notify driver. - -config DRIVERS_HDF_USB_NET_ADAPTER - bool "Enable HDF USB NET ADAPTER driver" - default n - depends on DRIVERS_HDF - depends on DRIVERS_HDF_USB_PNP_NOTIFY - help - Answer Y to choice HDF NET ADAPTER driver. diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index 57a07348e..a339d7243 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -68,6 +68,10 @@ int32_t DeviceManagerProxy::LoadDevice(const std::string &serviceName) } std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest(DEVMGR_SERVICE_LOAD_DEVICE, data, reply, option); lock.unlock(); if (status != HDF_SUCCESS) { @@ -90,6 +94,10 @@ int32_t DeviceManagerProxy::UnloadDevice(const std::string &serviceName) } std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest(DEVMGR_SERVICE_UNLOAD_DEVICE, data, reply, option); lock.unlock(); if (status != HDF_SUCCESS) { @@ -157,6 +165,10 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf MessageOption option; std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest(DEVMGR_SERVICE_LIST_ALL_DEVICE, data, reply, option); lock.unlock(); if (status != HDF_SUCCESS) { diff --git a/adapter/uhdf2/hdi/src/iservmgr_client.cpp b/adapter/uhdf2/hdi/src/iservmgr_client.cpp index 66e7d3e27..d058a5793 100644 --- a/adapter/uhdf2/hdi/src/iservmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/iservmgr_client.cpp @@ -83,6 +83,10 @@ int32_t ServiceManagerProxy::RegisterServiceStatusListener( } std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest( static_cast(HdfDeviceManagerInterfaceCode::DEVSVC_MANAGER_REGISTER_SVCLISTENER), data, reply, option); lock.unlock(); @@ -103,6 +107,10 @@ int32_t ServiceManagerProxy::UnregisterServiceStatusListener(::OHOS::sptr lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest( static_cast(HdfDeviceManagerInterfaceCode::DEVSVC_MANAGER_UNREGISTER_SVCLISTENER), data, reply, option); @@ -123,6 +131,10 @@ sptr ServiceManagerProxy::GetService(const char *serviceName) MessageOption option; std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return nullptr; + } int status = Remote()->SendRequest( static_cast(HdfDeviceManagerInterfaceCode::DEVSVC_MANAGER_GET_SERVICE), data, reply, option); lock.unlock(); @@ -160,6 +172,10 @@ int32_t ServiceManagerProxy::ListAllService(std::vector &service MessageOption option; std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest( static_cast(HdfDeviceManagerInterfaceCode::DEVSVC_MANAGER_LIST_ALL_SERVICE), data, reply, option); lock.unlock(); @@ -188,6 +204,10 @@ int32_t ServiceManagerProxy::ListServiceByInterfaceDesc( MessageOption option; std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } int status = Remote()->SendRequest( static_cast(HdfDeviceManagerInterfaceCode::DEVSVC_MANAGER_LIST_SERVICE_BY_INTERFACEDESC), data, reply, option); diff --git a/adapter/uhdf2/hdi/src/servstat_listener_stub.cpp b/adapter/uhdf2/hdi/src/servstat_listener_stub.cpp index 9eafc8a07..ab4781f01 100644 --- a/adapter/uhdf2/hdi/src/servstat_listener_stub.cpp +++ b/adapter/uhdf2/hdi/src/servstat_listener_stub.cpp @@ -57,8 +57,7 @@ int32_t ServStatListenerStub::ServStatListenerStubOnReceive( const char *info = data.ReadCString(); status.info = (info == nullptr) ? "" : info; - HDF_LOGI("%{public}s call func OnReceive, serviceName: %{public}s, status: %{public}d", - __func__, status.serviceName.c_str(), status.status); + HDF_LOGI("call OnReceive, %{public}s, %{public}d", status.serviceName.c_str(), status.status); OnReceive(status); return HDF_SUCCESS; } diff --git a/adapter/uhdf2/hdi/test/BUILD.gn b/adapter/uhdf2/hdi/test/BUILD.gn index 0335d56a1..90c7514e8 100644 --- a/adapter/uhdf2/hdi/test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/BUILD.gn @@ -12,7 +12,7 @@ # limitations under the License. import("//build/test.gni") -import("./../../../../adapter/uhdf2/uhdf.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") module_output_path = "hdf_core/srvmgr" @@ -26,17 +26,22 @@ ohos_unittest("HdiServiceManagerTest") { "$hdf_uhdf_path/hdi:libhdi", "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] include_dirs = [ "$hdf_uhdf_path/host/test/unittest/sample_driver", "$hdf_uhdf_path/utils/include", + "$hdf_framework_path/core/shared/include", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + external_deps = [ "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_single", ] @@ -50,15 +55,19 @@ ohos_unittest("HdiServiceManagerTestCC") { ] sources = [ "servmgr/service_manager_hdi_test.cpp" ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + deps = [ "$hdf_uhdf_path/hdi:libhdi", "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_single", "samgr:samgr_proxy", diff --git a/adapter/uhdf2/hdi/test/object_collector/object_collector_test.cpp b/adapter/uhdf2/hdi/test/object_collector/object_collector_test.cpp index f95c85567..a632492e5 100644 --- a/adapter/uhdf2/hdi/test/object_collector/object_collector_test.cpp +++ b/adapter/uhdf2/hdi/test/object_collector/object_collector_test.cpp @@ -38,10 +38,21 @@ public: void SetUp() {}; void TearDown() {}; }; +static bool TestRemove() +{ + return HDI::ObjectCollector::GetInstance().RemoveObject(nullptr); +} HWTEST_F(ObjectCollectorTest, ObjectCollectorTest001, TestSize.Level1) { sptr object = HDI::ObjectCollector::GetInstance().NewObject(nullptr, INTERFACE_NAME); ASSERT_EQ(object, nullptr); + object = HDI::ObjectCollector::GetInstance().GetOrNewObject(nullptr, INTERFACE_NAME); + ASSERT_EQ(object, nullptr); + bool remove = false; + if (!TestRemove()) { + remove = true; + } + ASSERT_EQ(remove, true); } } // namespace OHOS \ No newline at end of file diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index dc732f6d7..fee9c7e27 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -28,36 +29,46 @@ #include "sample_hdi.h" #include "hdi_support.h" +#include +#include #define HDF_LOG_TAG service_manager_test namespace OHOS { using namespace testing::ext; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; static constexpr const char *TEST1_SERVICE_NAME = "sample1_driver_service"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC = "hdf.test.sampele_service"; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "____"; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; static constexpr int PAYLOAD_NUM = 1234; static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; static constexpr int INVALID_DISPATCH_CODE = -1; +#endif + +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "____"; +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; + class HdfServiceMangerHdiCTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); if (devmgr != nullptr) { devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); } +#endif } static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); if (devmgr != nullptr) { devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); } +#endif } void SetUp() {}; void TearDown() {}; @@ -70,6 +81,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest001, TestSize.Level1) HDIServiceManagerRelease(servmgr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest002, TestSize.Level1) { struct HDIServiceManager *servmgr = HDIServiceManagerGet(); @@ -544,6 +556,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest010, TestSize.Level1) OsalMSleep(WAIT_COUNT); ASSERT_FALSE(ssd.callbacked); } +#endif /* * Test shared mem interface @@ -575,6 +588,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest011, TestSize.Level1) close(memFd); } +#ifdef SAMPLE_DRIVER /* * Test get service set by interfacedesc */ @@ -605,6 +619,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest001, TestSize.L ret = HdiServiceSetRelease(serviceSet); ASSERT_TRUE(ret == HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest002, TestSize.Level1) { @@ -637,6 +652,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest004, TestSize.L ASSERT_TRUE(serviceSet == nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest005, TestSize.Level1) { struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); @@ -678,6 +694,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest005, TestSize.L ASSERT_TRUE(ret == HDF_SUCCESS); HDIDeviceManagerRelease(devmgr); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, DevMgrQueryUsableDeviceTest, TestSize.Level1) { @@ -726,6 +743,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest018, TestSize.Level1) HDIServiceManagerRelease(NULL); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, RemoteServiceTest001, TestSize.Level1) { struct HDIServiceManager *servmgr = HDIServiceManagerGet(); ASSERT_TRUE(servmgr != nullptr); @@ -761,6 +779,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, RemoteServiceTest003, TestSize.Level1) { int status = HdfRemoteServiceDefaultDispatch(sampleService, INVALID_DISPATCH_CODE, dataSbuf, replySbuf); ASSERT_TRUE(status != HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, DevMgrTest, TestSize.Level1) { @@ -789,4 +808,24 @@ HWTEST_F(HdfServiceMangerHdiCTest, HdiSupportTest, TestSize.Level1) ASSERT_EQ(LoadHdiImpl(NULL, NULL), nullptr); UnloadHdiImpl(NULL, NULL, NULL); } + +HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest019, TestSize.Level1) +{ + struct ServiceStatusListener *listener = HdiServiceStatusListenerNewInstance(); + HdiServiceStatusListenerFree(nullptr); + struct HDIServiceManager *servmgr = HDIServiceManagerGet(); + int ret = servmgr->RegisterServiceStatusListener(servmgr, listener, DEVICE_CLASS_DEFAULT); + ASSERT_TRUE(ret == HDF_SUCCESS); + ret = servmgr->UnregisterServiceStatusListener(servmgr, listener); + ASSERT_TRUE(ret == HDF_SUCCESS); + struct HdiServiceSet *serviceSet = (struct HdiServiceSet *)OsalMemAlloc(sizeof(struct HdiServiceSet)); + serviceSet->count = 20; + ret = HdiServiceSetRelease(serviceSet); + ASSERT_TRUE(ret != HDF_SUCCESS); + HdiServiceStatusListenerFree(listener); + ret = HdfRemoteServiceRegister(-1, NULL); + ASSERT_TRUE(ret != HDF_SUCCESS); + int status = HdfRemoteServiceDefaultDispatch(NULL, 0, NULL, NULL); + ASSERT_TRUE(status != HDF_SUCCESS); +} } // namespace OHOS \ No newline at end of file diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 49dd3fedf..e3fb386aa 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -46,17 +46,21 @@ using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; using OHOS::HDI::DeviceManager::V1_0::HdiDevHostInfo; using OHOS::HDI::ServiceManager::V1_0::HdiServiceInfo; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; static constexpr const char *TEST1_SERVICE_NAME = "sample1_driver_service"; static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_N = "hdf.test.sampele_service"; +#endif static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "___"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; +#ifdef SAMPLE_DRIVER static constexpr int PAYLOAD_NUM = 1234; static constexpr int SMQ_TEST_QUEUE_SIZE = 10; static constexpr int SMQ_TEST_WAIT_TIME = 100; static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; +#endif static constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; static constexpr int INVALID_CODE = 100; static constexpr int ERROR_CODE_WITH_INVALID_CODE = 305; @@ -65,19 +69,23 @@ class HdfServiceMangerHdiTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->LoadDevice(TEST_SERVICE_NAME); } +#endif } static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->UnloadDevice(TEST_SERVICE_NAME); } +#endif } void TestServiceListenerStop(const sptr& devmgr, const sptr& servmgr); void TestSampleService(sptr& sampleService, const sptr& devmgr, @@ -92,6 +100,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest001, TestSize.Level1) ASSERT_TRUE(servmgr != nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest002, TestSize.Level1) { auto servmgr = IServiceManager::Get(); @@ -278,6 +287,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) sampleService = servmgr->GetService(TEST_SERVICE_NAME); ASSERT_TRUE(sampleService == nullptr); } +#endif class ServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { public: @@ -293,6 +303,7 @@ private: StatusCallback callback_; }; +#ifdef SAMPLE_DRIVER /* * Test service start status listener */ @@ -676,6 +687,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest001, TestSize.Le ASSERT_FALSE(serviceNames.empty()); ASSERT_TRUE(serviceNames.front().compare(TEST_SERVICE_NAME) == 0); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest002, TestSize.Level1) { @@ -707,6 +719,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest004, TestSize.Le ASSERT_TRUE(serviceNames.empty()); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest005, TestSize.Level1) { auto devmgr = IDeviceManager::Get(); @@ -731,6 +744,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest005, TestSize.Le ret = devmgr->UnloadDevice(TEST1_SERVICE_NAME); ASSERT_EQ(ret, HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListAllServiceTest, TestSize.Level1) { @@ -754,6 +768,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListAllDeviceTest, TestSize.Level1) ASSERT_TRUE(deviceInfos.size() != 0); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) { auto servmgr = IServiceManager::Get(); @@ -859,6 +874,7 @@ HWTEST_F(HdfServiceMangerHdiTest, InjectPmTest, TestSize.Level1) ret = devmgr->UnloadDevice(TEST_SERVICE_NAME); ASSERT_TRUE(ret == HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListenerTest001, TestSize.Level1) { diff --git a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn index cb44ac55e..09a2bc7df 100644 --- a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn @@ -24,8 +24,6 @@ ohos_unittest("HdiSmqTest") { "$hdf_uhdf_path/hdi:libhdi", "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] include_dirs = [ @@ -33,8 +31,14 @@ ohos_unittest("HdiSmqTest") { "$hdf_uhdf_path/utils/include", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + external_deps = [ "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_single", ] diff --git a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp index 1f624f42d..1fed1af9b 100644 --- a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp +++ b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp @@ -14,6 +14,10 @@ */ #include +#include +#include +#include "osal_mem.h" +#include #include #include #include @@ -37,14 +41,19 @@ using OHOS::HDI::Base::SharedMemQueueMeta; using OHOS::HDI::Base::SmqType; using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; using OHOS::HDI::ServiceManager::V1_0::IServiceManager; + +static constexpr const uint32_t TEST_NUM = 300; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_HOST_NAME = "sample_host"; static constexpr const char *SERVICE_NAME = "sample_driver_service"; static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; static constexpr int SMQ_TEST_QUEUE_SIZE = 10; static constexpr uint32_t HOST_PID_BUFF_SIZE = 20; static constexpr uint32_t CMD_RESULT_BUFF_SIZE = 1024; +#endif } // namespace +#ifdef SAMPLE_DRIVER static std::vector Split(const std::string &src, const std::string &limit) { std::vector result; @@ -169,31 +178,37 @@ static void PrintFds(const std::string &info, const std::set &fds) } std::cout << std::endl; } +#endif class SmqTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->LoadDevice(SERVICE_NAME); } +#endif } static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->UnloadDevice(SERVICE_NAME); } +#endif } void SetUp() {}; void TearDown() {}; }; +#ifdef SAMPLE_DRIVER HWTEST_F(SmqTest, SmqTest001, TestSize.Level1) { std::set fds1; @@ -295,4 +310,42 @@ HWTEST_F(SmqTest, SmqTest002, TestSize.Level1) if (!servHostUnclosedFds.empty()) { PrintFds("sample_host unclosed fds:", servHostUnclosedFds); } +} +#endif + +static uintptr_t MapMemZone(uint32_t zoneType) +{ + std::shared_ptr> meta_ = + std::make_shared>(TEST_NUM, SmqType::SYNCED_SMQ); + auto memzone = meta_->GetMemZone(zoneType); + if (memzone == nullptr) { + HDF_LOGE("invalid smq mem zone type %{public}u", zoneType); + return reinterpret_cast(nullptr); + } + + int offset = (static_cast(memzone->offset) / PAGE_SIZE) * PAGE_SIZE; + int length = static_cast(memzone->offset) - offset + static_cast(memzone->size); + + void *ptr = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, meta_->GetFd(), offset); + if (ptr == MAP_FAILED) { + HDF_LOGE( + "failed to map memzone %{public}u, size %{public}u, offset %{public}u , fd %{public}d, errnor=%{public}d", + zoneType, length, offset, meta_->GetFd(), errno); + unsigned int num = 20; + unsigned int *uptr = # + return reinterpret_cast(uptr); + } + return (reinterpret_cast(ptr) + (static_cast(memzone->offset) - offset)); +} + +HWTEST_F(SmqTest, SmqTest003, TestSize.Level1) +{ + std::atomic *syncerPtr_ = + reinterpret_cast *>(MapMemZone(SharedMemQueueMeta::MEMZONE_SYNCER)); + std::unique_ptr syncer_ = + std::make_unique(syncerPtr_); + syncer_->Wake(OHOS::HDI::Base::SharedMemQueueSyncer::SYNC_WORD_WRITE); + syncer_->Wait(OHOS::HDI::Base::SharedMemQueueSyncer::SYNC_WORD_WRITE, 0); + syncer_->Wake(OHOS::HDI::Base::SharedMemQueueSyncer::SYNC_WORD_WRITE); + syncer_->Wait(OHOS::HDI::Base::SharedMemQueueSyncer::SYNC_WORD_WRITE, 5); } \ No newline at end of file diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 0e782eda6..8f0d3652f 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -194,6 +194,8 @@ int main(int argc, char **argv) HDF_LOGI("%{public}s start loop", hostName); looper->Start(looper); } + + DevHostServiceFreeInstance(instance); HdfPowerManagerExit(); DevHostDumpDeInit(); HDF_LOGI("hdf device host %{public}s %{public}d %{public}d exit", hostName, hostId, status); diff --git a/adapter/uhdf2/host/test/BUILD.gn b/adapter/uhdf2/host/test/BUILD.gn index 7b949f61b..279a46b8f 100644 --- a/adapter/uhdf2/host/test/BUILD.gn +++ b/adapter/uhdf2/host/test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("DevMgrTest") { ] include_dirs = [ - "//commonlibrary/c_utils/base/include", "$hdf_framework_path/include/osal", "$hdf_framework_path/include/utils", "$hdf_framework_path/utils/include", @@ -40,12 +39,14 @@ ohos_unittest("DevMgrTest") { deps = [ "$hdf_uhdf_path/hdi:libhdi", - "$hdf_uhdf_path/host/test/unittest/sample_driver:sample_driver", "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + deps += [ "$hdf_uhdf_path/host/test/unittest/sample_driver:sample_driver" ] + } + if (is_standard_system) { external_deps = [ "c_utils:utils", @@ -54,6 +55,11 @@ ohos_unittest("DevMgrTest") { } else { external_deps = [ "hilog:libhilog" ] } + + external_deps += [ + "googletest:gmock_main", + "googletest:gtest_main", + ] } ohos_unittest("DevHostTest") { @@ -76,8 +82,6 @@ ohos_unittest("DevHostTest") { "$hdf_uhdf_path/host:libhdf_host", "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] if (is_standard_system) { @@ -88,6 +92,11 @@ ohos_unittest("DevHostTest") { } else { external_deps = [ "hilog:libhilog" ] } + + external_deps += [ + "googletest:gmock_main", + "googletest:gtest_main", + ] } ###########################end########################### diff --git a/adapter/uhdf2/host/test/unittest/devhost_test.cpp b/adapter/uhdf2/host/test/unittest/devhost_test.cpp index 69d1286f1..81384ea01 100644 --- a/adapter/uhdf2/host/test/unittest/devhost_test.cpp +++ b/adapter/uhdf2/host/test/unittest/devhost_test.cpp @@ -32,6 +32,8 @@ #include "hdf_log.h" #include "hdf_sbuf.h" #include "osal_mem.h" +#include "hdf_device_object.h" + #define HDF_LOG_TAG host_test @@ -74,6 +76,9 @@ HWTEST_F(DevHostTest, DevHostDevMgrServiceProxyTest, TestSize.Level1) ASSERT_TRUE(ret != HDF_SUCCESS); ret = instance->LoadDevice(instance, nullptr); ASSERT_TRUE(ret != HDF_SUCCESS); + const char *name = "test_svcName"; + ret = instance->LoadDevice(instance, name); + ASSERT_TRUE(ret == HDF_SUCCESS); struct DevmgrServiceProxy *proxy = reinterpret_cast(object); HdfRemoteServiceRecycle(proxy->remote); @@ -140,6 +145,7 @@ HWTEST_F(DevHostTest, DevHostDevSvcMgrProxyTest, TestSize.Level1) instance->RemoveService(instance, "test", nullptr); DevSvcManagerProxyRelease(object); DevSvcManagerProxyRelease(nullptr); + HdfDeviceObjectCheckInterfaceDesc(nullptr, nullptr); } HWTEST_F(DevHostTest, DevHostServiceTest, TestSize.Level1) @@ -275,27 +281,33 @@ HWTEST_F(DevHostTest, DevHostDeviceNodeTest2, TestSize.Level1) struct HdfDeviceNode *devNode = HdfDeviceNodeNewInstance(&deviceInfo, &driver); ASSERT_TRUE(devNode != nullptr); HdfDeviceNodeConstruct(devNode); + devNode->hostService = nullptr; struct IDeviceNode *nodeIf = &devNode->super; int32_t ret = nodeIf->LaunchNode(devNode); + devNode->devStatus = DEVNODE_NONE; + nodeIf->UnlaunchNode(devNode); entry.Bind = HdfTestFailBind; entry.Init = HdfTestInit; devNode = HdfDeviceNodeNewInstance(&deviceInfo, &driver); ASSERT_TRUE(devNode != nullptr); HdfDeviceNodeConstruct(devNode); - nodeIf = &devNode->super; + nodeIf = &devNode->super;\ + devNode->hostService = nullptr; ret = nodeIf->LaunchNode(devNode); entry.Init = nullptr; devNode = HdfDeviceNodeNewInstance(&deviceInfo, &driver); ASSERT_TRUE(devNode != nullptr); HdfDeviceNodeConstruct(devNode); + devNode->hostService = nullptr; nodeIf = &devNode->super; ret = nodeIf->LaunchNode(devNode); ASSERT_TRUE(ret != HDF_SUCCESS); devNode->devStatus = DEVNODE_NONE; nodeIf->UnlaunchNode(devNode); + DevmgrServiceClntDetachDevice(devNode->devId); } HWTEST_F(DevHostTest, DevHostDeviceNodeTest3, TestSize.Level1) @@ -312,8 +324,10 @@ HWTEST_F(DevHostTest, DevHostDeviceNodeTest3, TestSize.Level1) deviceInfo.deviceName = "test_module"; struct HdfDeviceNode *devNode = HdfDeviceNodeNewInstance(&deviceInfo, &driver); ASSERT_TRUE(devNode != nullptr); + int32_t ret = HdfDeviceNodePublishPublicService(devNode); + ASSERT_TRUE(ret != HDF_SUCCESS); struct IDeviceNode *nodeIf = &devNode->super; - int32_t ret = HdfDeviceNodeAddPowerStateListener(devNode, nullptr); + ret = HdfDeviceNodeAddPowerStateListener(devNode, nullptr); ASSERT_TRUE(ret == HDF_SUCCESS); ret = HdfDeviceNodeAddPowerStateListener(devNode, nullptr); ASSERT_TRUE(ret != HDF_SUCCESS); @@ -340,10 +354,30 @@ HWTEST_F(DevHostTest, DevHostDeviceNodeTest3, TestSize.Level1) HWTEST_F(DevHostTest, DevHostDeviceTest, TestSize.Level1) { + struct HdfDriverEntry entry; + entry.Bind = nullptr; + struct HdfDriver driver; + driver.entry = &entry; + struct HdfDeviceInfo deviceInfo; + deviceInfo.deviceId = 0; + deviceInfo.permission = 0; + deviceInfo.preload = 0; + deviceInfo.deviceType = 0; + deviceInfo.svcName = "driver_service"; + deviceInfo.deviceName = "driver_module"; + + deviceInfo.policy = SERVICE_POLICY_PUBLIC; + entry.Bind = HdfTestSuccBind; + entry.Init = HdfTestInit; + struct HdfDeviceNode *devNode = HdfDeviceNodeNewInstance(&deviceInfo, &driver); + ASSERT_TRUE(devNode != nullptr); + HdfDeviceNodeConstruct(devNode); struct HdfObject *object = HdfDeviceCreate(); ASSERT_TRUE(object != nullptr); struct IHdfDevice *device = reinterpret_cast(object); + devNode->devId = 0; + device->Attach(device, devNode); int32_t ret = device->Attach(device, nullptr); ASSERT_TRUE(ret != HDF_SUCCESS); ret = device->Attach(nullptr, nullptr); @@ -356,6 +390,9 @@ HWTEST_F(DevHostTest, DevHostDeviceTest, TestSize.Level1) ASSERT_TRUE(ret != HDF_SUCCESS); ret = HdfDeviceDetach(device, nullptr); ASSERT_TRUE(ret != HDF_SUCCESS); + devNode->servStatus = true; + struct IDeviceNode *deviceIf = reinterpret_cast(object); + ret = deviceIf->RemoveService(devNode); HdfDeviceRelease(nullptr); HdfDeviceFreeInstance(nullptr); } diff --git a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp index 0b5562e16..7678e47bc 100644 --- a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp +++ b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp @@ -21,6 +21,8 @@ #include #include "hdf_dump.h" #include "hdf_dump_reg.h" +#include "hcs_tree_if.h" +#include "hcs_dm_parser.h" #define HDF_LOG_TAG driver_manager @@ -62,6 +64,7 @@ void DevMgrTest::TearDown() { } +#ifdef SAMPLE_DRIVER /* * @tc.name: DriverLoaderTest * @tc.desc: driver load test @@ -86,6 +89,8 @@ HWTEST_F(DevMgrTest, DriverLoaderTest, TestSize.Level1) ASSERT_TRUE(sampleService != nullptr); } +#endif + /* * @tc.name: DriverUnLoaderTest * @tc.desc: driver unload test @@ -111,6 +116,7 @@ HWTEST_F(DevMgrTest, DriverUnLoaderTest, TestSize.Level1) ASSERT_TRUE(sampleService == nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(DevMgrTest, DriverTest, TestSize.Level1) { ASSERT_TRUE(servmgr != nullptr); @@ -142,16 +148,47 @@ HWTEST_F(DevMgrTest, DriverTest, TestSize.Level1) ASSERT_TRUE(sampleService == nullptr); } } +#endif + +static int TestDump(struct HdfSBuf *, struct HdfSBuf *) +{ + return HDF_SUCCESS; +} HWTEST_F(DevMgrTest, DevMgrDumpErrorTest, TestSize.Level1) { ASSERT_TRUE(servmgr != nullptr); ASSERT_TRUE(devmgr != nullptr); HdfRegisterDumpFunc(nullptr); + int32_t fd = 0; + HdfRegisterDumpFunc(TestDump); + const std::vector vcr = {u"123", u"456"}; + const std::vector vcr1 = { + u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10", + u"11", u"12", u"13", u"14", u"15", u"16", u"17", u"18", u"19", u"20", + u"21", u"22", u"23", u"24" + }; + int ret = HdfDump(fd, vcr); + ASSERT_TRUE(ret != HDF_SUCCESS); + fd = 1; + ret = HdfDump(fd, vcr1); + ASSERT_TRUE(ret != HDF_SUCCESS); int32_t illegalFd = -1; std::vector illegalArgs = {}; - int ret = HdfDump(illegalFd, illegalArgs); + ret = HdfDump(illegalFd, illegalArgs); ASSERT_TRUE(ret != HDF_SUCCESS); } + +HWTEST_F(DevMgrTest, HdfUtilsTest, TestSize.Level1) +{ + std::string CONFIGPATH = "/system/etc/hdfconfig/default"; + std::string CONFIGPATH1 = "/system/etc/hdfconfig/default.hcb"; + SetHcsBlobPath(CONFIGPATH.c_str()); + const struct DeviceResourceNode *node = HcsGetRootNode(); + ASSERT_TRUE(node == nullptr); + SetHcsBlobPath(CONFIGPATH1.c_str()); + const struct DeviceResourceNode *node1 = HcsGetRootNode(); + ASSERT_TRUE(node1 == nullptr); +} } // namespace OHOS diff --git a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn index 385c5194c..4fe7fc389 100755 --- a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn @@ -13,29 +13,32 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") -group("sample1_driver") { - deps = [ ":libsample1_driver" ] -} -ohos_shared_library("libsample1_driver") { - include_dirs = [ - "$hdf_framework_path/core/host/include", - "$hdf_framework_path/core/shared/include", - ] - sources = [ "sample1_driver.c" ] +if (with_sample) { + group("sample1_driver") { + deps = [ ":libsample1_driver" ] + } + + ohos_shared_library("libsample1_driver") { + include_dirs = [ + "$hdf_framework_path/core/host/include", + "$hdf_framework_path/core/shared/include", + ] + sources = [ "sample1_driver.c" ] - deps = [ - "./../../../../host:libhdf_host", - "./../../../../utils:libhdf_utils", - ] + deps = [ + "./../../../../host:libhdf_host", + "./../../../../utils:libhdf_utils", + ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] - shlib_type = "hdi" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "hdf_core" + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "hdf_core" + } } diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn index c576e2bc1..9bdbc5433 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn @@ -13,36 +13,39 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") -group("sample_driver") { - deps = [ ":libsample_driver" ] -} -ohos_shared_library("libsample_driver") { - sources = [ - "sample_driver.cpp", - "sample_hdi_service.cpp", - "sample_hdi_service_stub.cpp", - ] - include_dirs = [ - "$hdf_uhdf_path/host/include", - "$hdf_framework_path/core/shared/include", - "$hdf_framework_path/core/host/include", - "$hdf_framework_path/utils/include", - ] - deps = [ - "./../../../../hdi:libhdi", - "./../../../../host:libhdf_host", - "./../../../../ipc:libhdf_ipc_adapter", - "./../../../../utils:libhdf_utils", - ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - ] +if (with_sample) { + group("sample_driver") { + deps = [ ":libsample_driver" ] + } + + ohos_shared_library("libsample_driver") { + sources = [ + "sample_driver.cpp", + "sample_hdi_service.cpp", + "sample_hdi_service_stub.cpp", + ] + include_dirs = [ + "$hdf_uhdf_path/host/include", + "$hdf_framework_path/core/shared/include", + "$hdf_framework_path/core/host/include", + "$hdf_framework_path/utils/include", + ] + deps = [ + "./../../../../hdi:libhdi", + "./../../../../host:libhdf_host", + "./../../../../ipc:libhdf_ipc_adapter", + "./../../../../utils:libhdf_utils", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] - shlib_type = "hdi" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "hdf_core" + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "hdf_core" + } } diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index e6eb78e70..84066fbdd 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -296,12 +296,12 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) if (service == nullptr) { return HDF_ERR_INVALID_PARAM; } + + const int32_t waitTimes = 50; + const int32_t sleepInterval = 20000; OHOS::sptr saManager; { - saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - const int32_t waitTimes = 50; - const int32_t sleepInterval = 20000; - for (uint32_t cnt = 1; cnt <= waitTimes; ++cnt) { + for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saManager != nullptr) { @@ -323,9 +323,23 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) OHOS::IPCObjectStub *stub = reinterpret_cast(remote.GetRefPtr()); stub->SetRequestSidFlag(true); #endif - int ret = saManager->AddSystemAbility(saId, holder->remote_); + int ret = HDF_FAILURE; + for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { + HDF_LOGI("waiting for addSa... %{public}d", cnt); + ret = saManager->AddSystemAbility(saId, holder->remote_); + if (ret == HDF_SUCCESS) { + HDF_LOGI("addsa %{public}d, success", saId); + break; + } + HDF_LOGI("AddSystemAbility failed, retry"); + usleep(sleepInterval); + } + if (ret != HDF_SUCCESS) { + HDF_LOGE("failed to addSa, waiting timeout"); + return ret; + } + (void)OHOS::IPCSkeleton::GetInstance().SetMaxWorkThreadNum(g_remoteThreadMax++); - HDF_LOGI("add sa %{public}d, ret = %{public}s", saId, (ret == 0) ? "succ" : "fail"); } return HDF_SUCCESS; } diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index 9ed2cd7d9..48f7d5125 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -93,6 +93,7 @@ static int32_t ListServicePermCheck(void) return HDF_SUCCESS; } +// LCOV_EXCL_START static bool CheckServiceObjectValidNoLock(const struct DevSvcManagerStub *stub, const struct HdfDeviceObject *service) { if (service == NULL) { @@ -214,6 +215,7 @@ static void ReleaseServiceObject(struct DevSvcManagerStub *stub, struct HdfDevic OsalMutexUnlock(&stub->devSvcStubMutex); } +// LCOV_EXCL_STOP static int32_t DevSvcMgrStubGetPara( struct HdfSBuf *data, struct HdfServiceInfo *info, struct HdfRemoteService **service) @@ -353,7 +355,7 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct if (remoteService != NULL) { HdfSbufWriteRemoteService(reply, remoteService); ret = HDF_SUCCESS; - HDF_LOGD("StubGetService service %{public}s found", name); + HDF_LOGD("StubGetService service %{public}s found!", name); } else { HDF_LOGE("StubGetService %{public}s remoteService is null", name); ret = HDF_FAILURE; @@ -554,6 +556,7 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct return ret; } +// LCOV_EXCL_START void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfRemoteService *remote) { struct DevSvcManagerStub *stub = @@ -593,6 +596,7 @@ void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfR ReleaseServiceObject(stub, serviceObject); OsalMemFree(serviceName); } +// LCOV_EXCL_STOP int DevSvcManagerStubStart(struct IDevSvcManager *svcmgr) { @@ -665,6 +669,7 @@ struct HdfObject *DevSvcManagerStubCreate(void) return (struct HdfObject *)instance; } +// LCOV_EXCL_START static void DevObjHolderListReleaseNoLock(struct DevSvcManagerStub *stub) { struct HdfSListIterator it; @@ -693,3 +698,4 @@ void DevSvcManagerStubRelease(struct HdfObject *object) OsalMutexDestroy(&instance->devSvcStubMutex); } } +// LCOV_EXCL_STOP diff --git a/adapter/uhdf2/osal/test/BUILD.gn b/adapter/uhdf2/osal/test/BUILD.gn index ea8f5e3f7..bb2bbb0c6 100644 --- a/adapter/uhdf2/osal/test/BUILD.gn +++ b/adapter/uhdf2/osal/test/BUILD.gn @@ -24,18 +24,13 @@ ohos_unittest("OsalTest") { sources = [ "unittest/common/osal_slist_test.cpp" ] include_dirs = [ - "//commonlibrary/c_utils/base/include", "$hdf_framework_path/include/osal", "$hdf_framework_path/include/utils", "$hdf_framework_path/utils/include", "unittest/common/", ] - deps = [ - "$hdf_uhdf_path/utils:libhdf_utils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] + deps = [ "$hdf_uhdf_path/utils:libhdf_utils" ] if (is_standard_system) { external_deps = [ @@ -45,6 +40,11 @@ ohos_unittest("OsalTest") { } else { external_deps = [ "hilog:libhilog" ] } + + external_deps += [ + "googletest:gmock_main", + "googletest:gtest_main", + ] } ###########################end########################### diff --git a/adapter/uhdf2/test/unittest/manager/BUILD.gn b/adapter/uhdf2/test/unittest/manager/BUILD.gn index 1e5b77551..6365a0f72 100644 --- a/adapter/uhdf2/test/unittest/manager/BUILD.gn +++ b/adapter/uhdf2/test/unittest/manager/BUILD.gn @@ -194,6 +194,10 @@ ohos_unittest("hdf_adapter_uhdf_test_uevent") { defines = [ "__USER__" ] sources = [ "$hdf_framework_path/core/manager/test/unittest/common/devmgr_uevent_test.cpp" ] + if (with_sample) { + defines += [ "SAMPLE_DRIVER" ] + } + if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/bundle.json b/bundle.json index f8ef5f16e..1e83bfccf 100644 --- a/bundle.json +++ b/bundle.json @@ -15,8 +15,7 @@ "features": [ "hdf_core_khdf_test_support", "hdf_core_platform_test_support", - "hdf_core_platform_rtc_test_support", - "hdf_core_feature_config" + "hdf_core_platform_rtc_test_support" ], "adapted_system_type": ["standard", "small", "mini"], "rom": "735KB", diff --git a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c index 53feb92c1..acc5c7ee9 100644 --- a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -48,6 +48,7 @@ static bool HaveOnlyOneElement(const struct DListHead *head) return false; } +// LCOV_EXCL_START static int32_t HdfDevEventGrowReadBuffer(struct HdfWriteReadBuf *buffer) { size_t newSize = buffer->readSize; @@ -290,6 +291,7 @@ EXIT: return HDF_SUCCESS; } +// LCOV_EXCL_STOP static int32_t HdfAdapterStartListenIoctl(int fd) { @@ -513,6 +515,7 @@ static int32_t HdfIoServiceGroupThreadInit(struct HdfSyscallAdapterGroup *group) return HdfDevListenerThreadInit(group->thread); } +// LCOV_EXCL_START static int32_t HdfIoServiceGroupThreadStart(struct HdfSyscallAdapterGroup *group, int policy) { OsalMutexLock(&group->mutex); @@ -525,6 +528,7 @@ static int32_t HdfIoServiceGroupThreadStart(struct HdfSyscallAdapterGroup *group OsalMutexUnlock(&group->mutex); return ret; } +// LCOV_EXCL_STOP static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter) { @@ -582,6 +586,7 @@ static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struc return ret; } +// LCOV_EXCL_START static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter) { if (thread == NULL) { @@ -608,6 +613,7 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct H thread->pollChanged = true; OsalMutexUnlock(&thread->mutex); } +// LCOV_EXCL_STOP static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread) { @@ -670,6 +676,7 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) } } +// LCOV_EXCL_START static int32_t HdfSyscallAdapterDispatch( struct HdfObject *object, int32_t code, struct HdfSBuf *data, struct HdfSBuf *reply) { @@ -707,6 +714,7 @@ static int32_t HdfSyscallAdapterDispatch( } return ret; } +// LCOV_EXCL_STOP static int TrytoLoadIoService(const char *serviceName, char *devNodePath, char *realPath) { @@ -886,6 +894,7 @@ int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDe return HdfDeviceRegisterEventListenerWithSchedPolicy(target, listener, SCHED_OTHER); } +// LCOV_EXCL_START int32_t HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener) { if (target == NULL || listener == NULL) { @@ -910,6 +919,7 @@ int32_t HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct Hdf return HDF_SUCCESS; } +// LCOV_EXCL_STOP struct HdfIoServiceGroup *HdfIoServiceGroupObtain(void) { @@ -1034,6 +1044,7 @@ static int32_t GetListenerCount(struct HdfDevListenerThread *thread) return count; } +// LCOV_EXCL_START int32_t HdfIoServiceGroupUnregisterListener(struct HdfIoServiceGroup *group, struct HdfDevEventlistener *listener) { if (group == NULL || listener == NULL) { @@ -1060,6 +1071,7 @@ int32_t HdfIoServiceGroupUnregisterListener(struct HdfIoServiceGroup *group, str return HDF_SUCCESS; } +// LCOV_EXCL_STOP int32_t HdfIoServiceGroupAddService(struct HdfIoServiceGroup *group, struct HdfIoService *service) { diff --git a/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp b/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp index 71b3abb4f..8ce84cfc8 100644 --- a/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp +++ b/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp @@ -15,10 +15,12 @@ #include using namespace testing::ext; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; -static constexpr const char *TEST_DEV_NODE = "/sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; static constexpr const char *ADD_EVENT_CMD = "echo \"add\" > /sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; static constexpr const char *REMOVE_EVENT_CMD = "echo \"remove\" > /sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; +#endif +static constexpr const char *TEST_DEV_NODE = "/sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; class DevmgrUeventTest : public testing::Test { public: @@ -55,6 +57,7 @@ void DevmgrUeventTest::SetUp() {} void DevmgrUeventTest::TearDown() {} +#ifdef SAMPLE_DRIVER /** * @tc.name: DevmgrUeventTestAdd * @tc.desc: trigger add uevent @@ -207,6 +210,7 @@ HWTEST_F(DevmgrUeventTest, DevmgrUeventStressTest, TestSize.Level3) ASSERT_TRUE(sampleService == nullptr); } } +#endif HWTEST_F(DevmgrUeventTest, HdiProxyBrokerTest001, TestSize.Level1) { diff --git a/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp b/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp index f744bdc60..8fa4436c5 100644 --- a/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp @@ -21,6 +21,7 @@ #include "hdf_remote_adapter.h" #include "hdf_remote_adapter_if.h" #include "hdf_sbuf_ipc.h" +#include "hdf_dump.h" namespace OHOS { using namespace testing::ext; @@ -61,6 +62,13 @@ HWTEST_F(HdfRemoteAdapterTest, HdfRemoteAdapterTest002, TestSize.Level1) ret = HdfRemoteAdapterAddService(name, NULL); ASSERT_EQ(ret, HDF_ERR_INVALID_PARAM); + const char *serviceName = "test_service"; + HdfRemoteService *remoteService = HdfRemoteAdapterObtain(); + ret = HdfRemoteAdapterAddService(serviceName, remoteService); + ASSERT_TRUE(ret != HDF_SUCCESS); + ret = HdfRemoteAdapterAddSa(-1, remoteService); + ASSERT_TRUE(ret != HDF_SUCCESS); + HdfRemoteService *remote = HdfRemoteAdapterGetService(NULL); ASSERT_EQ(remote, nullptr); remote = HdfRemoteAdapterGetService(name); @@ -164,6 +172,9 @@ HWTEST_F(HdfRemoteAdapterTest, HdfRemoteAdapterTest007, TestSize.Level1) ASSERT_TRUE(status); status = HdfRemoteServiceCheckInterfaceToken(service, sBuf); ASSERT_FALSE(status); + HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + HdfRemoteAdapterDefaultDispatch(service, 0, data, reply); HdfRemoteServiceRecycle(service); } } // namespace OHOS diff --git a/framework/core/shared/test/unittest/common/hdf_core_shared_test.cpp b/framework/core/shared/test/unittest/common/hdf_core_shared_test.cpp index 7589bf87b..3380d3ec2 100644 --- a/framework/core/shared/test/unittest/common/hdf_core_shared_test.cpp +++ b/framework/core/shared/test/unittest/common/hdf_core_shared_test.cpp @@ -70,7 +70,13 @@ HWTEST_F(HdfCoreSharedTest, ServiceStatusMarshallingTest, TestSize.Level1) ASSERT_NE(status, nullptr); ret = ServiceStatusMarshalling(status, nullptr); ASSERT_EQ(ret, HDF_ERR_INVALID_PARAM); + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + const char *serviceName = "testServiceName"; + HdfSbufWriteString(sBuf, serviceName); + ret = ServiceStatusMarshalling(status, sBuf); + ASSERT_TRUE(ret !=HDF_FAILURE); OsalMemFree(status); + HdfSbufRecycle(sBuf); } HWTEST_F(HdfCoreSharedTest, ServiceStatusUnMarshallingTest, TestSize.Level1) diff --git a/framework/support/platform/src/watchdog/watchdog_core.c b/framework/support/platform/src/watchdog/watchdog_core.c index eb2d4c887..757fc5361 100644 --- a/framework/support/platform/src/watchdog/watchdog_core.c +++ b/framework/support/platform/src/watchdog/watchdog_core.c @@ -111,6 +111,7 @@ int32_t WatchdogCntlrGetStatus(struct WatchdogCntlr *cntlr, int32_t *status) ret = cntlr->ops->getStatus(cntlr, status); if (ret != HDF_SUCCESS) { HDF_LOGE("WatchdogCntlrGetStatus: getStatus fail!"); + (void)OsalSpinUnlockIrqRestore(&cntlr->lock, &flags); return ret; } (void)OsalSpinUnlockIrqRestore(&cntlr->lock, &flags); diff --git a/framework/test/fuzztest/BUILD.gn b/framework/test/fuzztest/BUILD.gn index 00a9ab9fa..5abca4bb8 100644 --- a/framework/test/fuzztest/BUILD.gn +++ b/framework/test/fuzztest/BUILD.gn @@ -17,7 +17,6 @@ group("hdf_framework_fuzztest") { "devsvcmanagerstub_fuzzer:DevSvcManagerStubFuzzTest", "framework_fuzzer/hcs_fuzzer:HdfHcsFuzzTest", "framework_fuzzer/support/posix_fuzzer:HdfPosixFuzzTest", - "framework_utils_fuzzer/utils_fuzzer:HdfUtilsFuzzTest", "ioservice_fuzzer/ioserviceadapterobtain_fuzzer:IoserviceAdapterObtainFuzzTest", "ioservice_fuzzer/ioservicebind_fuzzer:IoserviceBindFuzzTest", "ioservice_fuzzer/ioservicegrouplisten_fuzzer:IoserviceGroupListenFuzzTest", diff --git a/framework/test/fuzztest/devmgr_cpp_fuzzer/loaddevice_fuzzer/BUILD.gn b/framework/test/fuzztest/devmgr_cpp_fuzzer/loaddevice_fuzzer/BUILD.gn index be553cff9..783482a06 100644 --- a/framework/test/fuzztest/devmgr_cpp_fuzzer/loaddevice_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/devmgr_cpp_fuzzer/loaddevice_fuzzer/BUILD.gn @@ -22,7 +22,6 @@ ohos_fuzztest("LoadDeviceFuzzTest") { "$hdf_adapter_path/uhdf2/include/hdi", "$hdf_adapter_path/uhdf2/osal/include", "$hdf_framework_path/include/utils", - "//commonlibrary/c_utils/base/include", ] sources = [ "loaddevice_fuzzer.cpp" ] diff --git a/framework/test/fuzztest/devmgr_cpp_fuzzer/unloaddevice_fuzzer/BUILD.gn b/framework/test/fuzztest/devmgr_cpp_fuzzer/unloaddevice_fuzzer/BUILD.gn index e57cfae64..db59e986a 100644 --- a/framework/test/fuzztest/devmgr_cpp_fuzzer/unloaddevice_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/devmgr_cpp_fuzzer/unloaddevice_fuzzer/BUILD.gn @@ -22,7 +22,6 @@ ohos_fuzztest("UnloadDeviceFuzzTest") { "$hdf_adapter_path/uhdf2/include/hdi", "$hdf_adapter_path/uhdf2/osal/include", "$hdf_framework_path/include/utils", - "//commonlibrary/c_utils/base/include", ] sources = [ "unloaddevice_fuzzer.cpp" ] diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn deleted file mode 100644 index 1760762dd..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# -# HDF is dual licensed: you can use it either under the terms of -# the GPL, or the BSD license, at your option. -# See the LICENSE file in the root of this repository for complete details. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "hdf_core/hdf_core/framework_utils_fuzzer" - -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" -hdf_interfaces_path = "../../../../interfaces" - -ohos_fuzztest("HdfUtilsFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/framework_utils_fuzzer/utils_fuzzer" - - include_dirs = [ - "$hdf_uhdf_path/utils/include", - "$hdf_uhdf_path/hdi/include", - "$hdf_framework_path/include", - "$hdf_framework_path/utils/include", - "$hdf_interfaces_path/inner_api/hdi", - "$hdf_interfaces_path/inner_api/utils", - ] - - sources = [ - "$hdf_framework_path/utils/src/hdf_sbuf.c", - "$hdf_framework_path/utils/src/hdf_sbuf_impl_raw.c", - "$hdf_framework_path/utils/src/hdf_cstring.c", - "utils_fuzzer.cpp", - ] - - deps = [ - "../../../../../adapter/uhdf2/hdi:libhdi", - "../../../../../adapter/uhdf2/utils:libhdf_utils", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfUtilsFuzzTest" ] -} diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# -# HDF is dual licensed: you can use it either under the terms of -# the GPL, or the BSD license, at your option. -# See the LICENSE file in the root of this repository for complete details. - -FUZZ \ No newline at end of file diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml deleted file mode 100644 index e47b18640..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp deleted file mode 100644 index 81a77affa..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ -#include "utils_fuzzer.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "parcel.h" -#include -#include "osal_mem.h" -#include "hdi_support.h" -#include -#include "hdf_map.h" -#include "hdf_sbuf.h" -#include "hdf_sbuf_impl.h" -#include "hdf_cstring.h" -#include "hdf_thread_ex.h" -#include "osal_message.h" - -namespace OHOS { -static void HdfUtilsFuzzTest(const uint8_t *data, size_t size) -{ - if (data == nullptr) { - HDF_LOGE("%{public}s: data is nullptr!", __func__); - } - Map testMap; - Map testMap1; - MapInit(&testMap); - MapInit(&testMap1); - MapDelete(&testMap); - int num = 0; - int num1 = 1; - const char *name = "i2c"; - const char *name1 = "rtc"; - MapSet(&testMap1, name, &num, sizeof(int *)); - MapSet(&testMap1, name1, &num1, sizeof(int *)); - MapGet(&testMap1, ""); - MapGet(&testMap1, name); - MapErase(&testMap1, ""); - MapErase(&testMap1, name); - MapDelete(&testMap1); - - struct HdfMessage *message = HdfMessageObtain(size); - HdfMessageDelete(reinterpret_cast(message)); - - const char *str = "123"; - struct HdfCString *cstr = HdfCStringObtain(str); - HdfCStringRecycle(cstr); - struct HdfThread *thread = HdfThreadNewInstance(); - HdfThreadFreeInstance(thread); - - struct HdfSBuf *sbuf = HdfSbufObtainDefaultSize(); - struct HdfSBuf *copy = HdfSbufCopy(sbuf); - HdfSbufSetDataSize(copy, size); - HdfSbufGetDataSize(copy); - HdfSbufGetData(copy); - struct HdfSBufImpl *impl = HdfSbufGetImpl(copy); - if (impl == nullptr) { - impl = (struct HdfSBufImpl *)OsalMemCalloc(sizeof(struct HdfSBufImpl)); - } - struct HdfSBuf *newCopy = HdfSbufMove(copy); - HdfSbufTransDataOwnership(copy); - HdfSbufTypedObtainInplace(static_cast(size), impl); - impl->recycle(impl); - HdfSbufFlush(copy); - HdfSbufGetCapacity(copy); - HdfSbufRecycle(sbuf); - HdfSbufRecycle(copy); - HdfSbufRecycle(newCopy); - sbuf = nullptr; - copy = nullptr; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::HdfUtilsFuzzTest(data, size); - return HDF_SUCCESS; -} \ No newline at end of file diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h deleted file mode 100644 index 9b26247a8..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef HDI_COLLECTION_FUZZER_H -#define HDI_COLLECTION_FUZZER_H - -#define FUZZ_PROJECT_NAME "collector_fuzzer" - -#endif // HDI_COLLECTION_FUZZER_H \ No newline at end of file diff --git a/framework/test/fuzztest/ioservice_fuzzer/ioservicebind_fuzzer/BUILD.gn b/framework/test/fuzztest/ioservice_fuzzer/ioservicebind_fuzzer/BUILD.gn index b3c9bdb59..93d2b9c2d 100644 --- a/framework/test/fuzztest/ioservice_fuzzer/ioservicebind_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/ioservice_fuzzer/ioservicebind_fuzzer/BUILD.gn @@ -18,7 +18,6 @@ ohos_fuzztest("IoserviceBindFuzzTest") { include_dirs = [ "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicebind_fuzzer.h", - "//commonlibrary/c_utils/base/include", ] sources = [ "ioservicebind_fuzzer.cpp" ] deps = [ "../../../../../adapter/uhdf2/utils:libhdf_utils" ] diff --git a/framework/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer/BUILD.gn b/framework/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer/BUILD.gn index 1e741368d..afcf1bde0 100644 --- a/framework/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer/BUILD.gn @@ -15,10 +15,7 @@ ohos_fuzztest("IoserviceGroupListenFuzzTest") { fuzz_config_file = "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer" - include_dirs = [ - "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer.h", - "//commonlibrary/c_utils/base/include", - ] + include_dirs = [ "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicegrouplisten_fuzzer.h" ] if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/framework/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer/BUILD.gn b/framework/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer/BUILD.gn index 0ab7cdccc..d4705a188 100644 --- a/framework/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer/BUILD.gn @@ -15,10 +15,7 @@ ohos_fuzztest("IoserviceListenFuzzTest") { fuzz_config_file = "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer" - include_dirs = [ - "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer.h", - "//commonlibrary/c_utils/base/include", - ] + include_dirs = [ "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioservicelisten_fuzzer.h" ] if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/framework/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer/BUILD.gn b/framework/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer/BUILD.gn index 6698c9823..3d732c3bc 100644 --- a/framework/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer/BUILD.gn @@ -15,10 +15,7 @@ ohos_fuzztest("IoserviceRemoveFuzzTest") { fuzz_config_file = "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer" - include_dirs = [ - "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer.h", - "//commonlibrary/c_utils/base/include", - ] + include_dirs = [ "$hdf_framework_path/test/fuzztest/ioservice_fuzzer/ioserviceremove_fuzzer.h" ] if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/BUILD.gn b/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/BUILD.gn index 049d18276..007088e3b 100644 --- a/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/BUILD.gn +++ b/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/BUILD.gn @@ -21,7 +21,6 @@ ohos_fuzztest("UnregisterServiceStatusListenerFuzzTest") { "$hdf_adapter_path/uhdf2/include/hdi", "$hdf_adapter_path/uhdf2/osal/include", "$hdf_framework_path/include/utils", - "//commonlibrary/c_utils/base/include", ] sources = [ "unregisterservicestatuslistener_fuzzer.cpp" ] diff --git a/framework/tools/hdi-gen/hash/hash.cpp b/framework/tools/hdi-gen/hash/hash.cpp index ddfe3bd8c..160167bb2 100644 --- a/framework/tools/hdi-gen/hash/hash.cpp +++ b/framework/tools/hdi-gen/hash/hash.cpp @@ -90,6 +90,7 @@ bool Hash::GenFileHashKey(const std::string &path, size_t &hashKey) buffer << fs.rdbuf(); hashKey = std::hash()(buffer.str()); + fs.close(); return true; } } // namespace HDI -- Gitee From d8bdadc82cb89d682ecd65e4fa62d96301fcec8d Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 12 Oct 2024 11:14:27 +0800 Subject: [PATCH 2/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- framework/model/sensor/driver/include/sensor_platform_if.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/model/sensor/driver/include/sensor_platform_if.h b/framework/model/sensor/driver/include/sensor_platform_if.h index 85ee52221..3ac92b5d8 100755 --- a/framework/model/sensor/driver/include/sensor_platform_if.h +++ b/framework/model/sensor/driver/include/sensor_platform_if.h @@ -85,13 +85,13 @@ struct SensorBusCfg { }; }; -enum SENSORConfigValueIndex { +enum SensorConfigValueIndex { SENSOR_ADDR_INDEX, SENSOR_VALUE_INDEX, SENSOR_VALUE_BUTT, }; -enum SENSORConfigShortValueIndex { +enum SensorConfigShortValueIndex { SENSOR_SHORT_VALUE_INDEX0, SENSOR_SHORT_VALUE_INDEX1, SENSOR_SHORT_VALUE_INDEX2, -- Gitee From 28b63e2340eb5eb39c4e247ec4ee3c4c5a35721c Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 12 Oct 2024 14:15:11 +0800 Subject: [PATCH 3/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 71d223ed6..72aa7c730 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -48,6 +48,8 @@ if (defined(ohos_lite)) { "$hdf_adapter_path/uhdf2/utils:libhdf_utils", "$hdf_framework_path/tools/hdf_dbg:hdf_dbg", "$hdf_peripheral_path:hdf_peripheral.cfg", + ] + if (with_sample) { deps += [ "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", -- Gitee From 2fa8b0a044386efee4205c0fdd33bb889d55933b Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 14 Oct 2024 09:47:46 +0800 Subject: [PATCH 4/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/test/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/uhdf2/host/test/BUILD.gn b/adapter/uhdf2/host/test/BUILD.gn index 279a46b8f..b3941d83c 100644 --- a/adapter/uhdf2/host/test/BUILD.gn +++ b/adapter/uhdf2/host/test/BUILD.gn @@ -78,6 +78,8 @@ ohos_unittest("DevHostTest") { "$hdf_uhdf_path/ipc/include", ] + defines = [ "__USER__" ] + deps = [ "$hdf_uhdf_path/host:libhdf_host", "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", -- Gitee From af67b9716fee85553e36dd60a508cd4fcfc34713 Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 14 Oct 2024 09:51:33 +0800 Subject: [PATCH 5/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/test/BUILD.gn b/adapter/uhdf2/host/test/BUILD.gn index b3941d83c..d9d8e9fe6 100644 --- a/adapter/uhdf2/host/test/BUILD.gn +++ b/adapter/uhdf2/host/test/BUILD.gn @@ -79,7 +79,7 @@ ohos_unittest("DevHostTest") { ] defines = [ "__USER__" ] - + deps = [ "$hdf_uhdf_path/host:libhdf_host", "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", -- Gitee From 5f3a0eb915d22c527a6fa134c9ccd6b382a0337e Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 14 Oct 2024 15:11:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- framework/test/unittest/platform/virtual/adc_virtual.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/test/unittest/platform/virtual/adc_virtual.c b/framework/test/unittest/platform/virtual/adc_virtual.c index eed330b17..c76d9bb2e 100644 --- a/framework/test/unittest/platform/virtual/adc_virtual.c +++ b/framework/test/unittest/platform/virtual/adc_virtual.c @@ -6,7 +6,7 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include +#include #include "adc/adc_core.h" #include "device_resource_if.h" #include "hdf_device_desc.h" -- Gitee From aa417b7cbdf7dc19db1cf705faf87ce0746fc859 Mon Sep 17 00:00:00 2001 From: huyx Date: Mon, 14 Oct 2024 17:00:39 +0800 Subject: [PATCH 7/7] =?UTF-8?q?release=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- interfaces/inner_api/hdi/hdi_base.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/inner_api/hdi/hdi_base.h b/interfaces/inner_api/hdi/hdi_base.h index 7d61947be..df36c1fc9 100644 --- a/interfaces/inner_api/hdi/hdi_base.h +++ b/interfaces/inner_api/hdi/hdi_base.h @@ -65,6 +65,7 @@ public: * @param DESCRIPTOR Indicates the interface descriptor. */ #define DECLARE_HDI_DESCRIPTOR(DESCRIPTOR) \ + __attribute__((visibility("hidden"))) \ const static inline std::u16string metaDescriptor_ = {DESCRIPTOR}; \ const static inline std::u16string &GetDescriptor() \ { \ -- Gitee