diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 4b7afe7d1e3a610431b412f7bfe5c218d9490981..e3b4cac1bf679fd63d02502f6b9ed3b2d180659b 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -83,7 +83,7 @@ HdfRemoteServiceHolder::~HdfRemoteServiceHolder() { HDF_LOGD("~HdfRemoteServiceHolder"); } - +// LCOV_EXCL_START int32_t HdfRemoteServiceStub::Dump(int32_t fd, const std::vector &args) { return HdfDump(fd, args); @@ -104,7 +104,7 @@ void HdfDeathNotifier::OnRemoteDied(const OHOS::wptr &objec recipient_->OnRemoteDied(recipient_, service_); } } - +// LCOV_EXCL_STop static int HdfRemoteAdapterOptionalDispatch(struct HdfRemoteService *service, int code, HdfSBuf *data, HdfSBuf *reply, bool sync) { @@ -120,14 +120,17 @@ static int HdfRemoteAdapterOptionalDispatch(struct HdfRemoteService *service, in dummyReply.FlushBuffer(); replyParcel = &dummyReply; } else if (SbufToParcel(reply, &replyParcel)) { +// LCOV_EXCL_START HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } - +// LCOV_EXCL_STOP if (SbufToParcel(data, &dataParcel)) { +// LCOV_EXCL_START HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } +// LCOV_EXCL_STOP int flag = sync ? OHOS::MessageOption::TF_SYNC : OHOS::MessageOption::TF_ASYNC; OHOS::MessageOption option(flag); struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); @@ -145,13 +148,13 @@ static int HdfRemoteAdapterDispatch(struct HdfRemoteService *service, { return HdfRemoteAdapterOptionalDispatch(service, code, data, reply, true); } - +// LCOV_EXCL_START static int HdfRemoteAdapterDispatchAsync(struct HdfRemoteService *service, int code, HdfSBuf *data, HdfSBuf *reply) { return HdfRemoteAdapterOptionalDispatch(service, code, data, reply, false); } - +// LCOV_EXCL_STOP HdfRemoteServiceHolder::HdfRemoteServiceHolder() : remote_(nullptr), deathRecipient_(nullptr) { service_.object.objectId = HDF_OBJECT_ID_REMOTE_SERVICE; @@ -166,11 +169,12 @@ bool HdfRemoteServiceHolder::SetInterfaceDescriptor(const char *desc) return false; } std::u16string newDesc = OHOS::Str8ToStr16(std::string(desc)); +// LCOV_EXCL_START if (newDesc.empty()) { HDF_LOGE("failed to set interface des, error on cover str8 to str16, %{public}s", desc); return false; } - +// LCOV_EXCL_STOP descriptor_.assign(newDesc); return true; } @@ -182,6 +186,7 @@ void HdfRemoteAdapterAddDeathRecipient( if (holder == nullptr) { return; } +// LCOV_EXCL_START OHOS::sptr remote = holder->remote_; if (remote == nullptr) { return; @@ -191,6 +196,7 @@ void HdfRemoteAdapterAddDeathRecipient( } holder->deathRecipient_ = new HdfDeathNotifier(service, recipient); remote->AddDeathRecipient(holder->deathRecipient_); +// LCOV_EXCL_STOP } // LCOV_EXCL_START @@ -257,7 +263,7 @@ void HdfRemoteAdapterRecycle(struct HdfRemoteService *object) delete holder; } } - +// LCOV_EXCL_START int HdfRemoteAdapterAddService(const char *name, struct HdfRemoteService *service) { if (name == nullptr || service == nullptr) { @@ -294,7 +300,7 @@ struct HdfRemoteService *HdfRemoteAdapterGetService(const char *name) } return nullptr; } - +// LCOV_EXCL_STOP int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) { if (service == nullptr) { @@ -360,10 +366,12 @@ struct HdfRemoteService *HdfRemoteAdapterGetSa(int32_t saId) constexpr int32_t sleepInterval = 20000; int32_t timeout = waitTimes; while (remote == nullptr && (timeout > 0)) { +// LCOV_EXCL_START HDF_LOGD("waiting for saId %{public}d", saId); usleep(sleepInterval); remote = saManager->GetSystemAbility(saId); timeout--; +// LCOV_EXCL_STOP } if (remote != nullptr) { return HdfRemoteAdapterBind(remote); diff --git a/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp b/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp index c8966f6b2192316f51228574583736e3692a7093..6decc88b5baaac9379d8017b8119b714d645f817 100644 --- a/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp +++ b/adapter/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp @@ -209,7 +209,7 @@ static bool SbufMParcelImplReadUint16(struct HdfSBufImpl *sbuf, uint16_t *value) *value = v; return ret; } - +// LCOV_EXCL_START static bool SbufMParcelImplReadUint8(struct HdfSBufImpl *sbuf, uint8_t *value) { if (value == nullptr) { @@ -231,7 +231,7 @@ static bool SbufMParcelImplReadInt64(struct HdfSBufImpl *sbuf, int64_t *value) *value = v; return ret; } - +// LCOV_EXCL_STOP static bool SbufMParcelImplReadInt32(struct HdfSBufImpl *sbuf, int32_t *value) { if (value == nullptr) { @@ -242,7 +242,7 @@ static bool SbufMParcelImplReadInt32(struct HdfSBufImpl *sbuf, int32_t *value) *value = v; return ret; } - +// LCOV_EXCL_START static bool SbufMParcelImplReadInt16(struct HdfSBufImpl *sbuf, int16_t *value) { if (value == nullptr) { @@ -264,7 +264,7 @@ static bool SbufMParcelImplReadInt8(struct HdfSBufImpl *sbuf, int8_t *value) *value = v; return ret; } - +// LCOV_EXCL_STOP static const char *SbufMParcelImplReadString(struct HdfSBufImpl *sbuf) { return MParcelCast(sbuf)->ReadCString(); @@ -298,7 +298,7 @@ static struct HdfRemoteService *SbufMParcelImplReadRemoteService(struct HdfSBufI } return HdfRemoteAdapterBind(remote); } - +// LCOV_EXCL_START static const uint8_t *SbufMParcelImplGetData(const struct HdfSBufImpl *sbuf) { return reinterpret_cast(MParcelCast(const_cast(sbuf))->GetData()); @@ -323,7 +323,7 @@ static void SbufMParcelImplSetDataSize(struct HdfSBufImpl *sbuf, size_t size) { MParcelCast(sbuf)->SetDataSize(size); } - +// LCOV_EXCL_STOP static void SbufMParcelImplRecycle(struct HdfSBufImpl *sbuf) { SBufMParcelImpl *sbufImpl = reinterpret_cast(sbuf); @@ -381,7 +381,7 @@ extern "C" struct HdfSBufImpl *SbufObtainIpc(size_t capacity) struct SBufMParcelImpl *sbuf = new SBufMParcelImpl(new MessageParcel()); return &sbuf->infImpl; } - +// LCOV_EXCL_START class SbufAllocator : public Allocator { public: void *Realloc(void *data, size_t newSize) override @@ -415,7 +415,7 @@ struct HdfSBuf *ParcelToSbuf(OHOS::MessageParcel *parcel) struct SBufMParcelImpl *sbuf = new SBufMParcelImpl(parcel, false); return HdfSbufTypedObtainInplace(SBUF_IPC, &sbuf->infImpl); } - +// LCOV_EXCL_STOP int32_t SbufToParcel(struct HdfSBuf *sbuf, OHOS::MessageParcel **parcel) { if (sbuf == nullptr || parcel == nullptr) { diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index fc8db513584872805c6bbaac16ad0404ceb627b2..26bb65d8cc0ef58ed68422204ca1ff9d941d86fc 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -132,7 +132,7 @@ static int32_t DevMgrUeventParseKeyValue(char *str, struct DevMgrMatchKey *match char *subPtr = strstr(str, sep); if (subPtr == NULL) { if (strstr(str, "@/") == NULL) { - HDF_LOGE("parse Key value failed:[%{public}s]", str); + HDF_LOGD("parse Key value failed:[%{public}s]", str); } return HDF_FAILURE; } diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index ca14c9da7de51208226722515fcaafacdc201f66..1096e8e711bbe85b69786cd272105ec841a5941d 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -32,6 +32,7 @@ #define HDF_LOG_TAG devsvc_manager_stub +// LCOV_EXCL_START static int32_t AddServicePermCheck(const char *servName) { #ifdef WITH_SELINUX @@ -93,7 +94,6 @@ 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,8 +214,8 @@ static void ReleaseServiceObject(struct DevSvcManagerStub *stub, struct HdfDevic ReleaseServiceObjectHolder(stub, serviceObjectHolder); OsalMutexUnlock(&stub->devSvcStubMutex); -} // LCOV_EXCL_STOP +} static int32_t DevSvcMgrStubGetPara( struct HdfSBuf *data, struct HdfServiceInfo *info, struct HdfRemoteService **service) @@ -266,6 +266,7 @@ static int32_t DevSvcManagerStubAddService(struct IDevSvcManager *super, struct return ret; } +// LCOV_EXCL_START struct HdfDeviceObject *serviceObject = ObtainServiceObject(stub, info.servName, service); if (serviceObject == NULL) { return HDF_ERR_MALLOC_FAIL; @@ -280,6 +281,7 @@ static int32_t DevSvcManagerStubAddService(struct IDevSvcManager *super, struct } HDF_LOGI("add service %{public}s, %{public}d", info.servName, ret); return ret; +// LCOV_EXCL_STOP } static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, struct HdfSBuf *data) @@ -298,6 +300,7 @@ static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, stru return ret; } +// LCOV_EXCL_START struct HdfDeviceObject *oldServiceObject = super->GetObject(super, info.servName); if (oldServiceObject == NULL) { HDF_LOGE("update service %{public}s not exist", info.servName); @@ -317,6 +320,7 @@ static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, stru } HDF_LOGI("update service %{public}s, %{public}d", info.servName, ret); return ret; + // LCOV_EXCL_STOP } static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -342,6 +346,7 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct return HDF_FAILURE; } +// LCOV_EXCL_START const char *svcMgrName = "hdf_device_manager"; if (strcmp(name, svcMgrName) != 0) { OsalMutexLock(&stub->devSvcStubMutex); @@ -366,6 +371,7 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct } return ret; +// LCOV_EXCL_STOP } static int32_t DevSvcManagerStubListAllService( @@ -429,7 +435,7 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru HDF_LOGE("remove service %{public}s not exist", name); return HDF_DEV_ERR_NO_DEVICE_SERVICE; } - +// LCOV_EXCL_START OsalMutexLock(&stub->devSvcStubMutex); if (!CheckServiceObjectValidNoLock(stub, serviceObject)) { OsalMutexUnlock(&stub->devSvcStubMutex); @@ -455,6 +461,7 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru ReleaseServiceObject(stub, serviceObject); return HDF_SUCCESS; +// LCOV_EXCL_STOP } static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *super, struct HdfSBuf *data) { @@ -471,7 +478,7 @@ static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *supe if (listenerRemote == NULL) { return HDF_ERR_INVALID_PARAM; } - +// LCOV_EXCL_START struct ServStatListenerHolder *listenerHolder = ServStatListenerHolderCreate((uintptr_t)listenerRemote, listenClass); if (listenerHolder == NULL) { @@ -487,6 +494,7 @@ static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *supe } return HDF_SUCCESS; +// LCOV_EXCL_STOP } static int32_t DevSvcManagerStubUnregisterServListener(struct IDevSvcManager *super, struct HdfSBuf *data) @@ -500,6 +508,7 @@ static int32_t DevSvcManagerStubUnregisterServListener(struct IDevSvcManager *su if (listenerRemote == NULL) { return HDF_ERR_INVALID_PARAM; } +// LCOV_EXCL_START struct ServStatListenerHolder *listenerHolder = ServStatListenerHolderGet(listenerRemote->index); if (listenerHolder == NULL) { HDF_LOGE("failed to unregister svcstat listener, unknown listener"); @@ -511,6 +520,7 @@ static int32_t DevSvcManagerStubUnregisterServListener(struct IDevSvcManager *su HdfRemoteServiceRecycle(listenerRemote); HDF_LOGI("unregister servstat listener success"); return HDF_SUCCESS; +// LCOV_EXCL_STOP } int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -524,6 +534,10 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct struct IDevSvcManager *super = (struct IDevSvcManager *)&stub->super; HDF_LOGD("DevSvcManagerStubDispatch called: code=%{public}d, calling pid=%{public}d", code, HdfRemoteGetCallingPid()); + HDF_LOGD("DevSvcManagerStubDispatch called: code=%{public}d, calling uid=%{public}d", + code, HdfRemoteGetCallingUid()); + HDF_LOGD("DevSvcManagerStubDispatch called: code=%{public}d, calling sid=%{public}s", + code, HdfRemoteGetCallingSid()); switch (code) { case DEVSVC_MANAGER_ADD_SERVICE: ret = DevSvcManagerStubAddService(super, data); @@ -661,11 +675,12 @@ struct HdfObject *DevSvcManagerStubCreate(void) } instance = OsalMemCalloc(sizeof(struct DevSvcManagerStub)); +// LCOV_EXCL_START if (!DevSvcManagerStubConstruct(instance)) { OsalMemFree(instance); instance = NULL; } - +// LCOV_EXCL_STOP return (struct HdfObject *)instance; } diff --git a/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp b/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp index 7386a62c8853e06e1a4314d2bf7497daed601e1c..395184474a3862fea2f919be8557a2ccade861d5 100644 --- a/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp +++ b/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp @@ -39,6 +39,10 @@ static int DeviceManagerStartServiceFuzzTest() if (instance->StartService != NULL) { status = instance->StartService(instance); HDF_LOGI("device manager fuzzer start service success"); + status = instance->StartService(nullptr); + if (status == HDF_ERR_INVALID_PARAM) { + HDF_LOGI("device manager fuzzer start service FAILED"); + } } (void)DevMgrUeventReceiveStart(); diff --git a/framework/test/fuzztest/devsvcmanagerstub_fuzzer/devsvcmanagerstub_fuzzer.cpp b/framework/test/fuzztest/devsvcmanagerstub_fuzzer/devsvcmanagerstub_fuzzer.cpp index af59cc9f6d02c3ff64e9ff4952575f5cf27e780e..78f0665b06238203cacfe0d011d1d432e5c15f56 100644 --- a/framework/test/fuzztest/devsvcmanagerstub_fuzzer/devsvcmanagerstub_fuzzer.cpp +++ b/framework/test/fuzztest/devsvcmanagerstub_fuzzer/devsvcmanagerstub_fuzzer.cpp @@ -99,6 +99,10 @@ static bool DevsvcManagerFuzzTest(int32_t code, const uint8_t *data, size_t size (void)instance->remote->dispatcher->Dispatch( reinterpret_cast(instance->remote->target), code, dataBuf, replyBuf); + int ret = instance->remote->dispatcher->Dispatch(nullptr, code, dataBuf, replyBuf); + if (ret == HDF_FAILURE) { + HDF_LOGE("%{public}s:%{public}d: Dispatch FAILED", __func__, __LINE__); + } HdfSbufRecycle(dataBuf); HdfSbufRecycle(replyBuf); return true; diff --git a/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/unregisterservicestatuslistener_fuzzer.cpp b/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/unregisterservicestatuslistener_fuzzer.cpp index b689d8c0999d5319c09c569ff178ce9eb828aa57..6089417d360d8402741a8cbf734dd43a2a1b8d3d 100644 --- a/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/unregisterservicestatuslistener_fuzzer.cpp +++ b/framework/test/fuzztest/servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer/unregisterservicestatuslistener_fuzzer.cpp @@ -58,6 +58,11 @@ bool UnregisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size) result = true; } OsalMSleep(WAIT_THRESHOLD); + OsalUSleep(WAIT_THRESHOLD); + OsalUDelay(THRESHOLD); + OsalMDelay(THRESHOLD); + uint64_t time = OsalGetSysTimeMs(); + HDF_LOGD("%{public}s: time is %{public}llu!", __func__, time); return result; }