diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 6ac98ababa48820025e96c9a2b80dc9f13643d84..72aa7c7302b3b14d78115406dd4261dd6733f8ae 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", @@ -50,6 +49,13 @@ if (defined(ohos_lite)) { "$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 2378468c75c00ec18a82f650fbd26a2267165042..710f80dba66d0389e3365586b5bba6e96b9791ab 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 57a07348ebb9d3299c495836f923484d24fe0f8b..a339d72439da5f8fb1797a5612f305d0b1564679 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 66e7d3e278f40d2d34393c77af41d607cba2dfd1..d058a5793e10257b9c1b52faec17127d776c5e60 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 9eafc8a07d23d85fd2ef78e2878ff381cb7d4b57..ab4781f01d5bd45916c22b14260bddd40f8ae480 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 0335d56a17c38f7c0a69fbfef74ea335e09ad945..90c7514e87c3d274f152457e02083c9dd8073c7e 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 f95c85567f9b655cf4717abadb4689acabb336d1..a632492e5265a0cb98d6a6fd463331b6f1468cb8 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 dc732f6d72467e248653444fd49d45fd5e4e296f..fee9c7e278a1051a5f2962091f64c7b4c3ee8f1f 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 49dd3fedf69574e5e0440baa567fbadd3c94de79..e3fb386aa60e6beebfda6a27996f956714fbb973 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 cb44ac55e21c65cf0157c8b0f1cae25a063feac6..09a2bc7df921ba4f6b1be8245c75c5a6240dcd2f 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 1f624f42d5c330a6a1e493c7a05945c514940cb4..1fed1af9b5699882185d284c1af41f934544e83e 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 0e782eda62c1743ba80dc90af9abd9a31bdbc879..8f0d3652f856c114899b86feead5b0a36d192360 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 7b949f61b5065b6006c29f549c68e6136a348bc1..d9d8e9fe6bad3db939668ce7dd7d4d22affadf60 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") { @@ -72,12 +78,12 @@ ohos_unittest("DevHostTest") { "$hdf_uhdf_path/ipc/include", ] + defines = [ "__USER__" ] + deps = [ "$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 +94,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 69d1286f14a978cf69ae0dd0bc67d97a42f857aa..81384ea0165fb04518d81382d4fd8e479b4e9b5a 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 0b5562e164f2f4e159aee24b552fcf7dac87defe..7678e47bceacbb49d8758f4722c2f13b1545591a 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 385c5194ce8e0999ea789f7676db7fc522472f7d..4fe7fc389076c408de3a11cdc6ca66c09fea7b53 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 c576e2bc1791951312b852a3994b02a3d84d8823..9bdbc543302d2827352bc301da199972e60371e1 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 e6eb78e703904c89c2593e266ac02308f91eba8b..84066fbddd5effb7accf3a80140486ad6aa47d78 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 9ed2cd7d94ab40b157de2b10218042bdaac518b4..48f7d51254e19f52f992002bb288484761fce715 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 ea8f5e3f74843b652d177f736de59c98120950b9..bb2bbb0c602dad73af4236bad75142b8c0abefe6 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 1e5b7755165fcaa2421ff162d04c6a8a7cb746a2..6365a0f726d5501271d57de32a42d05441972a6e 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 f8ef5f16e709d7c5c038360b572accb6db9ccd02..1e83bfccfe0ec0f3208ec975bb1e17c035a354fc 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 53feb92c1fbf6cda0802977e19f030a101dcb209..acc5c7ee9c51e4929a955f292f91bc1234dfee26 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 71b3abb4fd5bb619ab64c07f4de686ee2fbf7c75..8ce84cfc8070630ab0fb8cfae0e2dd951f3d0d34 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 f744bdc60d64489ee10b7be23852e2ea611a5568..8fa4436c57910c316c34fbfdc3bd50e2518996e9 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 7589bf87b4f33f27306bb9b0174b1ecd7fcc8114..3380d3ec2876e4f6ed7b2757b8a126e6c07933ef 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/model/sensor/driver/include/sensor_platform_if.h b/framework/model/sensor/driver/include/sensor_platform_if.h index 85ee522213b524730c4ffc35e40a25c7d6beef91..3ac92b5d82a227f4ccaf049f31cf6eb8e0ceac02 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, diff --git a/framework/support/platform/src/watchdog/watchdog_core.c b/framework/support/platform/src/watchdog/watchdog_core.c index eb2d4c8876b1f1c8728c18aa194a09284ee1ff3a..757fc536197ed71c2ba4faef0407598b6bd9f64e 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 00a9ab9faed08665fe4ef5a1e8f21ad56f8ea183..5abca4bb8240a729ce700b8deefc81830fc45caa 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 be553cff9844fa2cca6b5adf0281946b955104a3..783482a06e48386a51e67b74a1ea2255d1e24c65 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 e57cfae64c07ea763e0365cd9125d12ac33c2bca..db59e986a0940dd30d0feaa4a263b0c1c36a457f 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 1760762dd3beb7f29dc2ee6b9577c14e2f64c0aa..0000000000000000000000000000000000000000 --- 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 f707fb4e4acfe262dfeb05dbbae64043e18526fb..0000000000000000000000000000000000000000 --- 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 e47b18640e151ce8f11a708c2e2a7f209b166fb9..0000000000000000000000000000000000000000 --- 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 81a77affa7b955ee5f483516e418a52c0040343d..0000000000000000000000000000000000000000 --- 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 9b26247a83c7f6dcfa98eca1ca16ff8f0d13ed51..0000000000000000000000000000000000000000 --- 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 b3c9bdb597f66af4a8867939ef40a3333eb3e551..93d2b9c2dc987ac0c520d1593c6c6ac8c9c3470a 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 1e741368da5f8c198c928ca98c46d5de54dac1b7..afcf1bde0628b30a7b1b6f7b04ebd05a786e5cad 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 0ab7cdccc8d488fbfcff3c3d16592a554e8ecff3..d4705a1886f09919d4428d60a58ccf2dfeefaddb 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 6698c9823523cbab79de3a921bd07164f17696f7..3d732c3bc955b191f96ed2a8a2444dab6c560e4a 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 049d1827631b275e50e17d4a2ac5a6bf27aebfbd..007088e3bef86745abdeec9d761b6060deee02ed 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/test/unittest/platform/virtual/adc_virtual.c b/framework/test/unittest/platform/virtual/adc_virtual.c index eed330b17460755bbf9dc476c612dd50db315047..c76d9bb2eb5049b69070ab6efbc1792b1612cf96 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" diff --git a/framework/tools/hdi-gen/hash/hash.cpp b/framework/tools/hdi-gen/hash/hash.cpp index ddfe3bd8c439e4aed046fb449f2eef57160f13d3..160167bb2f2332b5a3a5ac6bdd7babd2c7db780b 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 diff --git a/interfaces/inner_api/hdi/hdi_base.h b/interfaces/inner_api/hdi/hdi_base.h index 7d61947be570c35f3dcbad3a4dc6d9070aa04598..df36c1fc950722f251ffa791956b8c886cb7a464 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() \ { \