!2039 modify review issue for usb

Merge pull request !2039 from wuzhimin/master
This commit is contained in:
openharmony_ci
2022-08-20 09:54:52 +00:00
committed by Gitee
29 changed files with 306 additions and 307 deletions
+43 -45
View File
@@ -129,25 +129,23 @@ static bool IsDeviceDirExist(const char *deviceName)
static int32_t UsbFnWriteFile(const char *path, const char *str)
{
int32_t ret;
size_t ret;
if (strlen(str) == 0) {
return 0;
}
FILE *fp = fopen(path, "w");
if (fp == NULL) {
HDF_LOGE("%{public}s: UsbFnWriteFile failure!", __func__);
return HDF_ERR_BAD_FD;
}
ret = fwrite(str, strlen(str), 1, fp);
if (ret != 1) {
if (fclose(fp)) {
return HDF_FAILURE;
}
return HDF_FAILURE;
}
if (fclose(fp)) {
(void)fclose(fp);
return HDF_FAILURE;
}
(void)fclose(fp);
return 0;
}
@@ -189,7 +187,7 @@ static int32_t UsbFnWriteConfString(const char *deviceName, int32_t configVal, u
if (!IsDirExist(tmp)) {
ret = mkdir(tmp, S_IREAD | S_IWRITE);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: mkdir failure!", __func__);
return HDF_ERR_IO;
}
@@ -218,7 +216,7 @@ static int32_t UsbFnWriteDesString(
}
if (!IsDirExist(tmp)) {
ret = mkdir(tmp, S_IREAD | S_IWRITE);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: mkdir failure!", __func__);
return HDF_ERR_IO;
}
@@ -239,13 +237,13 @@ static int32_t UsbFnAdapterCreateFunc(const char *configPath, const char *funcPa
int32_t ret;
ret = mkdir(funcPath, S_IREAD | S_IWRITE);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: mkdir failure!", __func__);
return HDF_ERR_IO;
}
ret = symlink(funcPath, configPath);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: symlink failed", __func__);
return HDF_ERR_IO;
}
@@ -288,7 +286,7 @@ static int32_t UsbFnAdapterWriteUDC(const char *deviceName, const char *udcName,
HDF_LOGE("%{public}s: snprintf_s failed", __func__);
return HDF_ERR_IO;
}
if (enable) {
if (enable != 0) {
(void)UsbFnWriteFile(tmp, udcName);
for (i = 0; i < OPEN_CNT; i++) {
(void)UsbFnReadFile(tmp, udcTmp, strlen(udcName));
@@ -369,7 +367,7 @@ static int32_t UsbFnAdapterCreatInterface(const char *interfaceName, int32_t nam
return HDF_ERR_IO;
}
ret = ioctl(fd, FUNCTIONFS_NEWFN, &fnnew);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: FUNCTIONFS_NEWFN failure!", __func__);
return HDF_ERR_IO;
}
@@ -398,7 +396,7 @@ static int32_t UsbFnAdapterDelInterface(const char *interfaceName, int32_t nameL
return HDF_ERR_IO;
}
ret = ioctl(fd, FUNCTIONFS_DELFN, &fnnew);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: FUNCTIONFS_DELFN failure!", __func__);
return HDF_ERR_IO;
}
@@ -516,21 +514,21 @@ ERR:
static int32_t CopyCount(uint8_t **whereDec, uint32_t fsCount, uint32_t hsCount, uint32_t ssCount)
{
int32_t ret;
if (fsCount) {
if (fsCount != 0) {
ret = memcpy_s(*whereDec, sizeof(uint32_t), &fsCount, sizeof(uint32_t));
if (ret != EOK) {
return HDF_FAILURE;
}
*whereDec += sizeof(uint32_t);
}
if (hsCount) {
if (hsCount != 0) {
ret = memcpy_s(*whereDec, sizeof(uint32_t), &hsCount, sizeof(uint32_t));
if (ret != EOK) {
return HDF_FAILURE;
}
*whereDec += sizeof(uint32_t);
}
if (ssCount) {
if (ssCount != 0) {
ret = memcpy_s(*whereDec, sizeof(uint32_t), &ssCount, sizeof(uint32_t));
if (ret != EOK) {
return HDF_FAILURE;
@@ -580,15 +578,15 @@ static void GetCountAndHead(struct UsbFunctionfsDescsHeadV2 *header, uint32_t *f
lenDes += func->ssDescriptors[i]->bLength;
}
if (*fsCount) {
if (*fsCount != 0) {
lenCount += sizeof(uint32_t);
header->flags |= htole32(FUNCTIONFS_HAS_FS_DESC);
}
if (*hsCount) {
if (*hsCount != 0) {
lenCount += sizeof(uint32_t);
header->flags |= htole32(FUNCTIONFS_HAS_HS_DESC);
}
if (*ssCount) {
if (*ssCount != 0) {
lenCount += sizeof(uint32_t);
header->flags |= htole32(FUNCTIONFS_HAS_SS_DESC);
}
@@ -659,35 +657,35 @@ static int32_t WriteDeviceId(const char *devName, const struct UsbDeviceDescript
{
int32_t ret;
ret = UsbFnWriteProp(devName, "idVendor", desc->idVendor);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "idProduct", desc->idProduct);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bcdUSB", desc->bcdUSB);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bcdDevice", desc->bcdDevice);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bDeviceClass", desc->bDeviceClass);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bDeviceSubClass", desc->bDeviceSubClass);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bDeviceProtocol", desc->bDeviceProtocol);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteProp(devName, "bMaxPacketSize0", desc->bMaxPacketSize0);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
return 0;
@@ -698,23 +696,23 @@ static int32_t WriteDeviceDescriptor(
{
int32_t i, ret;
ret = WriteDeviceId(devName, desc);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
for (i = 0; strings[i] != NULL; i++) {
ret = UsbFnWriteDesString(
devName, strings[i]->language, "manufacturer", strings[i]->strings[desc->iManufacturer].s);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteDesString(devName, strings[i]->language, "product", strings[i]->strings[desc->iProduct].s);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
ret = UsbFnWriteDesString(
devName, strings[i]->language, "serialnumber", strings[i]->strings[desc->iSerialNumber].s);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_INVALID_PARAM;
}
}
@@ -732,7 +730,7 @@ static int32_t CreatDeviceDir(const char *devName)
}
if (!IsDirExist(tmp)) {
ret = mkdir(tmp, S_IREAD | S_IWRITE);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: mkdir failure!", __func__);
return HDF_ERR_IO;
}
@@ -752,7 +750,7 @@ static int32_t WriteConfPowerAttributes(const char *devName, struct UsbFnConfigu
}
if (!IsDirExist(configName)) {
ret = mkdir(configName, S_IREAD | S_IWRITE);
if (ret) {
if (ret != 0) {
return HDF_ERR_IO;
}
}
@@ -808,7 +806,7 @@ static int32_t CreatKernelFunc(const char *devName, const struct UsbFnFunction *
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFunc(configPath, funcPath);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnAdapterCreateFunc failure!", __func__);
return HDF_ERR_IO;
}
@@ -832,7 +830,7 @@ static int32_t CreatFunc(const char *devName, const struct UsbFnFunction *functi
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreatInterface(interfaceName, strlen(interfaceName));
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnAdapterCreatInterface failure!", __func__);
CleanConfigFs(devName, interfaceName);
return HDF_ERR_IO;
@@ -845,12 +843,12 @@ static int32_t CreatFunc(const char *devName, const struct UsbFnFunction *functi
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreatPipes(fd, functions);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnAdapterCreatPipes failure!", __func__);
return HDF_ERR_IO;
}
ret = UsbFnAdapterClosePipe(fd);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnAdapterClosePipe failure!", __func__);
return HDF_ERR_IO;
}
@@ -914,7 +912,7 @@ static void CleanFunction(const char *devName, const char *funcName)
{
int32_t ret;
ret = UsbFnAdapterDelInterface(funcName, strlen(funcName));
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnAdapterDelInterface failure!", __func__);
return;
}
@@ -970,7 +968,7 @@ static int32_t UsbFnAdapterDelDevice(const char *deviceName, const char *udcName
}
}
if (strcmp("g1", deviceName)) {
if (strcmp("g1", deviceName) != 0) {
DelConfigDevice(deviceName);
}
return 0;
@@ -1013,7 +1011,7 @@ static int32_t EnableDevice(const char *udcName, const char *devName, struct Usb
}
#endif
ret = UsbFnAdapterWriteUDC(devName, udcName, 1);
if (ret) {
if (ret != HDF_SUCCESS) {
(void)UsbFnAdapterDelDevice(devName, udcName, descriptor);
}
return ret;
@@ -1046,12 +1044,12 @@ static int32_t UsbFnAdapterCreateDevice(const char *udcName, const char *devName
UsbFnAdapterCleanDevice(devName);
ret = CreatDeviceDir(devName);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_IO;
}
ret = WriteDeviceDescriptor(devName, descriptor->deviceDesc, descriptor->deviceStrings);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: WriteDeviceDescriptor failure!", __func__);
return HDF_ERR_IO;
}
@@ -1059,7 +1057,7 @@ static int32_t UsbFnAdapterCreateDevice(const char *udcName, const char *devName
for (i = 0; descriptor->configs[i] != NULL; i++) {
confVal = descriptor->configs[i]->configurationValue;
ret = WriteConfPowerAttributes(devName, descriptor->configs[i], confVal);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: WriteConfPowerAttributes failure!", __func__);
return HDF_ERR_IO;
}
@@ -1098,7 +1096,7 @@ static int32_t UsbFnAdapterGetPipeInfo(int32_t ep, struct UsbFnPipeInfo * const
struct UsbEndpointDescriptor desc;
ret = ioctl(ep, FUNCTIONFS_ENDPOINT_DESC, &desc);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: FUNCTIONFS_ENDPOINT_DESC failure!", __func__);
return HDF_ERR_IO;
}
+34 -34
View File
@@ -68,7 +68,7 @@ static int32_t UsbFnAdapterCreateFconfigString(struct FconfigString * const conf
return HDF_ERR_IO;
}
int32_t strLen = strlen(name);
size_t strLen = strlen(name);
configString->len = (uint32_t)strLen;
configString->s = UsbFnMemCalloc(strLen + 1);
if (configString->s == NULL) {
@@ -96,7 +96,7 @@ static int32_t UsbFnAdapterWriteGadget(int32_t fd, int32_t cmd, struct FconfigSt
return HDF_ERR_IO;
}
ret = handle_ioctl(fd, cmd, gadgetName);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
return HDF_ERR_IO;
}
@@ -122,7 +122,7 @@ static int32_t UsbFnAdapterWriteDevDesc(
}
ret = handle_ioctl(fd, FCONFIG_CMD_WRITE_DEV_DESC, &devDesc);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
@@ -155,14 +155,14 @@ static int32_t UsbFnAdapterWriteDevString(
for (jCount = 0; jCount < (int)devStrings->strCount; jCount++) {
devStrings->strings[jCount].id = usbString[jCount].id;
ret = UsbFnAdapterCreateFconfigString(&devStrings->strings[jCount].str, usbString[jCount].s);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create string failed!", __func__);
UsbFnMemFree(devStrings->strings[jCount].str.s);
goto FAIL;
}
}
ret = handle_ioctl(fd, FCONFIG_CMD_WRITE_STRINGS, devStrings);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
goto FAIL;
}
@@ -491,12 +491,12 @@ static int32_t UsbFnAdapterWriteFunctions(int32_t fd, struct UsbFnConfiguration
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&funcInfo.funcName, tmp);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create config name failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = handle_ioctl(fd, cmd, &funcInfo);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
goto FAIL;
}
@@ -553,23 +553,23 @@ static int32_t UsbFnAdapterWriteConfigs(
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&configDesc.configName, tmp);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create config name failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = UsbFnAdapterFillConfigDesc(&configDesc.cfgDesc, descriptor->configs[iCount]);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = handle_ioctl(fd, FCONFIG_CMD_ADD_CONFIG, &configDesc);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = UsbFnAdapterWriteFunctions(
fd, descriptor->configs[iCount], FCONFIG_CMD_MAKE_FUNCTION, gadgetName, &configDesc.configName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: write func failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
@@ -590,12 +590,12 @@ static int32_t UsbFnAdapterWriteFcofnigUDC(
udcInfo.gadgetName.len = gadgetName->len;
udcInfo.gadgetName.s = gadgetName->s;
ret = UsbFnAdapterCreateFconfigString(&udcInfo.udcName, udcName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create udc_name failed!", __func__);
return HDF_ERR_IO;
}
ret = handle_ioctl(fd, cmd, &udcInfo);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
}
UsbFnMemFree(udcInfo.udcName.s);
@@ -614,32 +614,32 @@ static int32_t UsbFnAdapterCreateDevice(const char *udcName, const char *devName
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&gadgetName, devName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create gadget name failed!", __func__);
goto FAIL;
}
ret = UsbFnAdapterWriteGadget(fd, FCONFIG_CMD_MAKE_GADGET, &gadgetName);
if (ret) {
if (ret != HDF_SUCCESS) {
dprintf("%s: UsbFnAdapterWriteGadget failed!", __func__);
goto EXIT;
}
ret = UsbFnAdapterWriteDevDesc(fd, &gadgetName, descriptor);
if (ret) {
if (ret != HDF_SUCCESS) {
dprintf("%s: UsbFnAdapterWriteDevDesc failed!", __func__);
goto EXIT;
}
ret = UsbFnAdapterWriteDevStrings(fd, &gadgetName, descriptor);
if (ret) {
if (ret != HDF_SUCCESS) {
dprintf("%s: UsbFnAdapterWriteDevStrings failed!", __func__);
goto EXIT;
}
ret = UsbFnAdapterWriteConfigs(fd, &gadgetName, descriptor);
if (ret) {
if (ret != HDF_SUCCESS) {
dprintf("%s: UsbFnAdapterWriteConfigs failed!", __func__);
goto EXIT;
}
ret = UsbFnAdapterWriteFcofnigUDC(fd, FCONFIG_CMD_ENABLE_UDC, &gadgetName, udcName);
if (ret) {
if (ret != HDF_SUCCESS) {
dprintf("%s: UsbFnAdapterWriteFcofnigUDC failed!", __func__);
goto EXIT;
}
@@ -678,7 +678,7 @@ static int32_t UsbFnAdapterDelConfigs(
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&configName, tmp);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create config name failed!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
@@ -686,17 +686,17 @@ static int32_t UsbFnAdapterDelConfigs(
configDesc.configName.s = configName.s;
ret = UsbFnAdapterWriteFunctions(
configFd, descriptor->configs[iCount], FCONFIG_CMD_DROP_FUNCTION, gadgetName, &configName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: write func failed!", __func__);
goto FAIL;
}
ret = UsbFnAdapterFillConfigDesc(&configDesc.cfgDesc, descriptor->configs[iCount]);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
goto FAIL;
}
ret = handle_ioctl(configFd, FCONFIG_CMD_REMOVE_CONFIG, &configDesc);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
goto FAIL;
}
@@ -722,20 +722,20 @@ static int32_t UsbFnAdapterDelDevice(const char *devName, const char *udcName, s
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&gadgetName, devName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create gadget_name failed!", __func__);
return HDF_ERR_IO;
}
ret = UsbFnAdapterWriteFcofnigUDC(configFd, FCONFIG_CMD_DISABLE_UDC, &gadgetName, udcName);
if (ret) {
if (ret != HDF_SUCCESS) {
goto FAIL;
}
ret = UsbFnAdapterDelConfigs(configFd, &gadgetName, descriptor);
if (ret) {
if (ret != HDF_SUCCESS) {
goto FAIL;
}
ret = UsbFnAdapterWriteGadget(configFd, FCONFIG_CMD_DROP_GADGET, &gadgetName);
if (ret) {
if (ret != HDF_SUCCESS) {
goto FAIL;
}
ret = UsbFnAdapterClosefn(configFd);
@@ -760,7 +760,7 @@ static int32_t UsbFnAdapterGetPipeInfo(int32_t ep, struct UsbFnPipeInfo * const
}
ret = handle_ioctl(ep, GENERIC_CMD_GET_PIPE_INFO, &desc);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: FUNCTIONFS_ENDPOINT_DESC failed!", __func__);
return HDF_ERR_IO;
}
@@ -943,13 +943,13 @@ static int32_t UsbFnAdapterWriteUDC(const char *deviceName, const char *udcName,
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&udcInfo.gadgetName, deviceName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create gadget_name failed!", __func__);
return HDF_ERR_IO;
}
cmd = enable ? FCONFIG_CMD_ENABLE_UDC : FCONFIG_CMD_DISABLE_UDC;
ret = UsbFnAdapterWriteFcofnigUDC(configFd, cmd, &udcInfo.gadgetName, udcName);
if (ret) {
if (ret != HDF_SUCCESS) {
return HDF_ERR_IO;
}
configFd = UsbFnAdapterClosefn(configFd);
@@ -969,7 +969,7 @@ static int32_t UsbFnWriteProp(const char *deviceName, const char *propName, uint
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&info.gadgetName, deviceName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create gadget name failed!", __func__);
return HDF_ERR_IO;
}
@@ -981,7 +981,7 @@ static int32_t UsbFnWriteProp(const char *deviceName, const char *propName, uint
goto FAIL;
}
ret = handle_ioctl(configFd, FCONFIG_CMD_CHAGE_DEVINFO, &info);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
goto FAIL;
}
@@ -1006,7 +1006,7 @@ static int32_t UsbFnWriteDesString(
return HDF_ERR_IO;
}
ret = UsbFnAdapterCreateFconfigString(&info.gadgetName, deviceName);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: create gadget name failed!", __func__);
return HDF_ERR_IO;
}
@@ -1020,7 +1020,7 @@ static int32_t UsbFnWriteDesString(
goto FAIL;
}
ret = handle_ioctl(configFd, FCONFIG_CMD_CHAGE_DEVSTRING, &info);
if (ret) {
if (ret != 0) {
HDF_LOGE("%{public}s: ioctl failed!", __func__);
goto FAIL;
}
+1 -1
View File
@@ -126,7 +126,7 @@ static int32_t OsSubmitUrb(
}
err = usb_setup_endpoint(adapterDevice, uhe, 1024);
if (err) {
if (err < 0) {
DPRINTFN(0, "setup failed err:%d\n", err);
return (err);
}
+2 -2
View File
@@ -680,7 +680,7 @@ OUT:
static int32_t UsbSerialWrite(struct UsbSerial *port, struct HdfSBuf *data)
{
uint32_t size;
int32_t size;
const char *tmp = NULL;
OsalMutexLock(&port->lock);
@@ -703,7 +703,7 @@ static int32_t UsbSerialWrite(struct UsbSerial *port, struct HdfSBuf *data)
return HDF_ERR_IO;
}
size = DataFifoWrite(&port->writeFifo, (uint8_t *)buf, strlen(buf));
size = (int32_t)DataFifoWrite(&port->writeFifo, (uint8_t *)buf, strlen(buf));
if (port->acm) {
UsbSerialStartTx(port);
+3 -3
View File
@@ -28,17 +28,17 @@ public:
explicit UsbInfo(const USBDeviceInfo &info) : devInfo_(info) {}
void SetDevInfoStatus(int32_t status)
void SetDevInfoStatus(const int32_t status)
{
devInfo_.status = status;
}
void SetDevInfoBusNum(int32_t busNum)
void SetDevInfoBusNum(const int32_t busNum)
{
devInfo_.busNum = busNum;
}
void SetDevInfoDevNum(int32_t devNum)
void SetDevInfoDevNum(const int32_t devNum)
{
devInfo_.devNum = devNum;
}
+2 -2
View File
@@ -445,7 +445,7 @@ static int32_t EcmWrite(struct EcmDevice *ecm, struct HdfSBuf *data)
wbn = EcmWbAlloc(ecm);
} else {
HDF_LOGE("%s:%d no write buf", __func__, __LINE__);
return size;
return (int32_t)size;
}
if (wbn < ECM_NW && wbn >= 0) {
wb = &ecm->wb[wbn];
@@ -463,7 +463,7 @@ static int32_t EcmWrite(struct EcmDevice *ecm, struct HdfSBuf *data)
if (wb->buf) {
ret = memcpy_s(wb->buf, ecm->writeSize, tmp, len);
if (ret) {
return size;
return (int32_t)size;
}
tmp += len;
wb->len = (int)len;
+8 -8
View File
@@ -47,7 +47,7 @@ static void TestWrite(char *buf)
(void)HdfSbufWriteString(g_data, buf);
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, USB_SERIAL_WRITE, g_data, g_reply);
if (status <= 0) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_WRITE failed status = %d", __func__, status);
}
}
@@ -63,7 +63,7 @@ static void TestRead(void)
}
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, USB_SERIAL_READ, g_data, g_reply);
if (status) {
if (status != HDF_SUCCESS) {
printf("%s: Dispatch USB_SERIAL_READ failed status = %d", __func__, status);
return;
}
@@ -84,7 +84,7 @@ static void TestRead(void)
static int32_t ReadThread(void *arg)
{
(void)arg;
while (running) {
while (running != 0) {
TestRead();
usleep(SLEEP_100MS);
}
@@ -126,9 +126,9 @@ static void SetTermios(void)
static void WriteThread(void)
{
char str[STR_LEN] = {0};
while (running) {
str[0] = getchar();
if (running) {
while (running != 0) {
str[0] = (char)getchar();
if (running != 0) {
TestWrite(str);
}
}
@@ -140,7 +140,7 @@ static void StopAcmTest(int32_t signo)
int32_t status;
running = 0;
status = g_acmService->dispatcher->Dispatch(g_acmService, USB_SERIAL_CLOSE, g_data, g_reply);
if (status) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_CLOSE err", __func__);
}
tcsetattr(STDIN_FILENO, TCSANOW, &g_orgOpts);
@@ -182,7 +182,7 @@ int32_t acm_test(int32_t argc, const char *argv[])
}
status = g_acmService->dispatcher->Dispatch(g_acmService, USB_SERIAL_OPEN, g_data, g_reply);
if (status) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_OPEN err", __func__);
return HDF_FAILURE;
}
+1 -1
View File
@@ -34,7 +34,7 @@ static void TestWrite(char *buf)
HdfSbufFlush(g_data);
(void)HdfSbufWriteString(g_data, buf);
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, USB_SERIAL_WRITE, g_data, g_reply);
if (status <= 0) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_WRITE failed status = %d", __func__, status);
}
}
+11 -11
View File
@@ -13,9 +13,9 @@
* limitations under the License.
*/
#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <pthread.h>
#include <unistd.h>
#include "hdf_io_service_if.h"
#include "hdf_log.h"
@@ -25,7 +25,7 @@
#include "osal_time.h"
#include "securec.h"
#define HDF_LOG_TAG cdc_acm_test
#define HDF_LOG_TAG cdc_acm_test
enum UsbSerialCmd {
USB_SERIAL_OPEN = 0,
@@ -42,14 +42,14 @@ enum UsbSerialCmd {
static struct HdfSBuf *g_data;
static struct HdfSBuf *g_reply;
static struct HdfIoService *g_acmService;
static struct OsalMutex g_lock;
static struct OsalMutex g_lock;
static void TestWrite(const char *buf)
{
HdfSbufFlush(g_data);
(void)HdfSbufWriteString(g_data, buf);
int32_t status = g_acmService->dispatcher->Dispatch(&g_acmService->object, USB_SERIAL_WRITE, g_data, g_reply);
if (status <= 0) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_WRITE failed status = %d", __func__, status);
}
}
@@ -62,7 +62,7 @@ static void TestRead(void)
printf("%s: Dispatch USB_SERIAL_READ failed status = %d", __func__, status);
return;
}
if (HdfSbufGetDataSize(g_reply)) {
if (HdfSbufGetDataSize(g_reply) != 0) {
const char *tmp = HdfSbufReadString(g_reply);
if (tmp && strlen(tmp) > 0) {
printf("%s: read : %s \n", __func__, tmp);
@@ -91,11 +91,11 @@ static void StartPThreadRead(void)
}
}
#define STR_LEN 256
#define STR_LEN 256
#define SLEEP_GETCHAR 100000
static void Test02(void)
{
char c;
char ch;
char str[STR_LEN] = {0};
char *getStr = NULL;
if (OsalMutexInit(&g_lock) != HDF_SUCCESS) {
@@ -104,8 +104,8 @@ static void Test02(void)
}
while (1) {
printf("\ninput: \nr: for read acm\nw: for write acm \nq: for exit \n");
c = getchar();
if (c == 'r') {
ch = (char)getchar();
if (ch == 'r') {
printf("input: 'q' quit reading\n");
g_readRuning = true;
StartPThreadRead();
@@ -114,7 +114,7 @@ static void Test02(void)
usleep(SLEEP_GETCHAR);
}
g_readRuning = false;
} else if (c == 'w') {
} else if (ch == 'w') {
printf("input strings and press enter to send\n");
getchar();
getStr = gets_s(str, STR_LEN - 1);
@@ -122,7 +122,7 @@ static void Test02(void)
HDF_LOGE("%s: gets_s failed", __func__);
}
TestWrite(str);
} else if (c == 'q') {
} else if (ch == 'q') {
return;
}
}
@@ -13,6 +13,9 @@
* limitations under the License.
*/
#ifndef LIB_ACM_TEST_H
#define LIB_ACM_TEST_H
extern "C" {
void acm_open();
void acm_close();
@@ -22,3 +25,4 @@ void acm_prop_regist(const char *propName, const char *propValue);
void acm_prop_write(const char *propName, const char *propValue);
void acm_prop_read(const char *propName, char *propValue);
}
#endif /* LIB_ACM_TEST_H */
@@ -98,7 +98,7 @@ void acm_write(const char *buf)
HdfSbufFlush(g_data);
(void)HdfSbufWriteString(g_data, buf);
int32_t status = g_acmService->dispatcher->Dispatch(&g_acmService->object, USB_SERIAL_WRITE, g_data, g_reply);
if (status <= 0) {
if (status != HDF_SUCCESS) {
HDF_LOGE("%s: Dispatch USB_SERIAL_WRITE failed status = %d", __func__, status);
return;
}
@@ -40,8 +40,8 @@
#define USB_DEV_FS_PATH "/dev/bus/usb"
#define URB_COMPLETE_PROCESS_STACK_SIZE 8196
#define ENDPOINT_IN_OFFSET 7
#define DEFAULT_BUSNUM 1
#define DEFAULT_DEVADDR 2
#define DEFAULT_BUSNUM 1
#define DEFAULT_DEVADDR 2
static int32_t g_speedFlag = 0;
static int32_t g_busNum = DEFAULT_BUSNUM;
static int32_t g_devAddr = DEFAULT_DEVADDR;
@@ -81,9 +81,9 @@ static int32_t OpenDevice(void)
return 0;
}
static int32_t ClaimInterface(unsigned int iface)
static int32_t ClaimInterface(int32_t iface)
{
HDF_LOGI("%{public}s:%{public}d claim success: iface=%u\n", __func__, __LINE__, iface);
HDF_LOGI("%{public}s:%{public}d claim success: iface=%d\n", __func__, __LINE__, iface);
return HDF_SUCCESS;
}
@@ -106,7 +106,7 @@ static int32_t SendProcess(void *argurb)
{
(void)argurb;
int32_t i;
int32_t r;
int32_t err;
while (!g_speedFlag) {
OsalSemWait(&sem, HDF_WAIT_FOREVER);
for (i = 0; i < TEST_CYCLE; i++) {
@@ -120,14 +120,14 @@ static int32_t SendProcess(void *argurb)
i = TEST_CYCLE - 1;
}
sendUrb = urb[i].urb;
r = usb_setup_endpoint(fd, uhe, TEST_BYTE_COUNT_UINT);
if (r) {
DPRINTFN(0, "setup failed ret:%d\n", r);
return r;
err = usb_setup_endpoint(fd, uhe, TEST_BYTE_COUNT_UINT);
if (err < 0) {
DPRINTFN(0, "setup failed err:%d\n", err);
return err;
}
r = usb_submit_urb(sendUrb, 0);
if (r < 0) {
HDF_LOGI("SubmitBulkRequest: ret:%d\n", r);
err = usb_submit_urb(sendUrb, 0);
if (err < 0) {
HDF_LOGI("SubmitBulkRequest: err:%d\n", err);
urb[i].inUse = 0;
continue;
}
@@ -209,7 +209,7 @@ static int32_t BeginProcessHandleFirst(void)
static int32_t BeginProcess(unsigned char endPoint)
{
int32_t r;
int32_t ret;
const int32_t transNum = 0;
int32_t i;
@@ -223,9 +223,9 @@ static int32_t BeginProcess(unsigned char endPoint)
HDF_LOGE("%{public}s:%{public}d usb_find_host_endpoint error\n", __func__, __LINE__);
return -1;
}
r = BeginProcessHandleFirst();
if (r != HDF_SUCCESS) {
return r;
ret = BeginProcessHandleFirst();
if (ret != HDF_SUCCESS) {
return ret;
}
HDF_LOGI("%{public}s:%{public}d test NO SDK endpoint:%u\n", __func__, __LINE__, endPoint);
@@ -235,14 +235,14 @@ static int32_t BeginProcess(unsigned char endPoint)
urb[i].inUse = 1;
urb[i].urbNum = transNum;
sendUrb = urb[i].urb;
r = usb_setup_endpoint(fd, uhe, TEST_BYTE_COUNT_UINT);
if (r) {
DPRINTFN(0, "setup failed ret:%d\n", r);
return r;
ret = usb_setup_endpoint(fd, uhe, TEST_BYTE_COUNT_UINT);
if (ret < 0) {
DPRINTFN(0, "setup failed ret:%d\n", ret);
return ret;
}
r = usb_submit_urb(sendUrb, 0);
if (r < 0) {
HDF_LOGI("%{public}s:%{public}d SubmitBulkRequest: ret:%d\n", __func__, __LINE__, r);
ret = usb_submit_urb(sendUrb, 0);
if (ret < 0) {
HDF_LOGI("%{public}s:%{public}d SubmitBulkRequest: ret:%d\n", __func__, __LINE__, ret);
urb[i].inUse = 0;
continue;
}
@@ -487,7 +487,7 @@ static int32_t AcmDriverInit(struct HdfDeviceObject *device)
return 0;
}
static void AcmDriverRelease(struct HdfDeviceObject *device)
static void AcmDriverRelease(struct HdfDeviceObject *device)
{
(void)device;
return;
@@ -195,7 +195,7 @@ static int32_t SerialBegin(struct AcmDevice * const acm)
int32_t ret;
struct AcmDb *db = NULL;
int32_t dbn;
if (AcmDbIsAvail(acm)) {
if (AcmDbIsAvail(acm) != 0) {
dbn = AcmDbAlloc(acm);
} else {
HDF_LOGE("no buf\n");
@@ -210,7 +210,7 @@ static int32_t UsbGetConfigDescriptor(UsbRawHandle *devHandle, struct UsbRawConf
}
ret = UsbRawGetConfiguration(devHandle, &activeConfig);
if (ret) {
if (ret != HDF_SUCCESS) {
printf("%s:%d UsbRawGetConfiguration failed, ret=%d", __func__, __LINE__, ret);
return HDF_FAILURE;
}
@@ -222,7 +222,7 @@ static int32_t UsbGetConfigDescriptor(UsbRawHandle *devHandle, struct UsbRawConf
}
ret = UsbRawGetConfigDescriptor(dev, activeConfig, config);
if (ret) {
if (ret != HDF_SUCCESS) {
printf("UsbRawGetConfigDescriptor failed, ret=%d\n", ret);
return HDF_FAILURE;
}
@@ -309,7 +309,7 @@ static int32_t UsbParseConfigDescriptor(struct AcmDevice * const acm, struct Usb
if (acm->devHandle) {
ret = UsbRawClaimInterface(acm->devHandle, interfaceIndex);
if (ret) {
if (ret != HDF_SUCCESS) {
printf("%s:%d claim interface %d failed", __func__, __LINE__, i);
return ret;
}
@@ -343,7 +343,7 @@ static int32_t UsbAllocDataRequests(struct AcmDevice * const acm)
reqData.length = acm->dataSize;
ret = UsbRawFillBulkRequest(snd->request, acm->devHandle, &reqData);
if (ret) {
if (ret != HDF_SUCCESS) {
printf("%s: FillInterruptRequest failed, ret=%d", __func__, ret);
return HDF_FAILURE;
}
@@ -478,7 +478,7 @@ static int32_t SerialBegin(struct AcmDevice *acm)
int32_t ret;
struct AcmDb *db = NULL;
int32_t dbn;
if (AcmDbIsAvail(acm)) {
if (AcmDbIsAvail(acm) != 0) {
dbn = AcmDbAlloc(acm);
} else {
printf("no buf\n");
@@ -603,7 +603,7 @@ static int32_t UsbSpeedDdkInit(const struct UsbSession *session)
UsbRawHandle *devHandle = NULL;
ret = UsbRawInit((struct UsbSession **)&session);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbRawInit failed\n", __func__);
return HDF_FAILURE;
}
@@ -615,7 +615,7 @@ static int32_t UsbSpeedDdkInit(const struct UsbSession *session)
}
g_acm->devHandle = devHandle;
ret = UsbGetConfigDescriptor(devHandle, &g_acm->config);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbGetConfigDescriptor failed\n", __func__);
return HDF_FAILURE;
}
@@ -641,7 +641,7 @@ static int32_t UsbSpeedDdkInit(const struct UsbSession *session)
}
ret = UsbStartIo(g_acm);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbAllocReadRequests failed\n", __func__);
return HDF_FAILURE;
}
+19 -20
View File
@@ -52,10 +52,6 @@ struct TestUsbDeviceDescriptor {
#define BUFFER_MAX_LEN 1024
#define SPEED_SLEEP_TIME 300
const char *g_acmServiceName = "usbhost_acm_pnp_service";
const char *g_acmRawServiceName = "usbhost_acm_rawapi_service";
const char *g_ecmServiceName = "usbhost_ecm_pnp_service";
struct HdfSBuf *g_data = NULL;
struct HdfSBuf *g_reply = NULL;
#ifdef __LITEOS_USB_HOST_DDK_TEST__
@@ -88,6 +84,9 @@ int32_t UsbObtainSbuf(void)
int32_t UsbHostDdkTestInit(const char *apiType)
{
const char *acmRawServiceName = "usbhost_acm_rawapi_service";
const char *acmServiceName = "usbhost_acm_pnp_service";
const char *ecmServiceName = "usbhost_ecm_pnp_service";
#ifndef __LITEOS_USB_HOST_DDK_TEST__
struct HDIServiceManager *servmgr = HDIServiceManagerGet();
if (servmgr == NULL) {
@@ -99,28 +98,28 @@ int32_t UsbHostDdkTestInit(const char *apiType)
return HDF_FAILURE;
}
if (!strcmp(apiType, "-SDK")) {
printf("%s:%d test SDK API, service=%s\n", __func__, __LINE__, g_acmServiceName);
HDF_LOGI("%s:%d test SDK API, service=%s", __func__, __LINE__, g_acmServiceName);
printf("%s:%d test SDK API, service=%s\n", __func__, __LINE__, acmServiceName);
HDF_LOGI("%s:%d test SDK API, service=%s", __func__, __LINE__, acmServiceName);
#ifdef __LITEOS_USB_HOST_DDK_TEST__
g_acmService = HdfIoServiceBind(g_acmServiceName);
g_acmService = HdfIoServiceBind(acmServiceName);
#else
g_acmService = servmgr->GetService(servmgr, g_acmServiceName);
g_acmService = servmgr->GetService(servmgr, acmServiceName);
#endif
} else if (!strcmp(apiType, "-RAW")) {
printf("%s:%d test RAW API, service=%s\n", __func__, __LINE__, g_acmRawServiceName);
HDF_LOGI("%s:%d test RAW API, service=%s", __func__, __LINE__, g_acmRawServiceName);
printf("%s:%d test RAW API, service=%s\n", __func__, __LINE__, acmRawServiceName);
HDF_LOGI("%s:%d test RAW API, service=%s", __func__, __LINE__, acmRawServiceName);
#ifdef __LITEOS_USB_HOST_DDK_TEST__
g_acmService = HdfIoServiceBind(g_acmRawServiceName);
g_acmService = HdfIoServiceBind(acmRawServiceName);
#else
g_acmService = servmgr->GetService(servmgr, g_acmRawServiceName);
g_acmService = servmgr->GetService(servmgr, acmRawServiceName);
#endif
} else if (!strcmp(apiType, "-ECM")) {
printf("%s:%d test ECM API, service=%s\n", __func__, __LINE__, g_ecmServiceName);
HDF_LOGI("%s:%d test ECM API, service=%s", __func__, __LINE__, g_ecmServiceName);
printf("%s:%d test ECM API, service=%s\n", __func__, __LINE__, ecmServiceName);
HDF_LOGI("%s:%d test ECM API, service=%s", __func__, __LINE__, ecmServiceName);
#ifdef __LITEOS_USB_HOST_DDK_TEST__
g_acmService = HdfIoServiceBind(g_ecmServiceName);
g_acmService = HdfIoServiceBind(ecmServiceName);
#else
g_acmService = servmgr->GetService(servmgr, g_ecmServiceName);
g_acmService = servmgr->GetService(servmgr, ecmServiceName);
#endif
} else {
printf("%s:%d apiType=%s is not define\n", __func__, __LINE__, apiType);
@@ -274,7 +273,7 @@ void UsbHostDdkTestSyncRead(char *readSbuf)
#else
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, CMD_READ_DATA_SYNC, g_data, g_reply);
#endif
if (status) {
if (status != HDF_SUCCESS) {
g_exitFlag = true;
printf("%s:%d Dispatch CMD_READ_DATA_SYNC failed status = %d\n", __func__, __LINE__, status);
HDF_LOGE("%s:%d Dispatch CMD_READ_DATA_SYNC failed status = %d", __func__, __LINE__, status);
@@ -547,7 +546,7 @@ void UsbHostDdkTestGetBaudrate(char *readSbuf)
return;
}
if (HdfSbufReadUint32(g_reply, &value)) {
if (HdfSbufReadUint32(g_reply, &value) == true) {
if (readSbuf != NULL) {
const char tmp[] = "CMD_GET_BAUDRATE";
errno_t err = memcpy_s(readSbuf, DATA_MAX_LEN, tmp, strlen(tmp));
@@ -629,7 +628,7 @@ int32_t UsbHostDdkTestOpen(int32_t cmdType)
#else
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, CMD_OPEN_PARM, g_data, g_reply);
#endif
if (status) {
if (status != HDF_SUCCESS) {
g_exitFlag = true;
HDF_LOGE("%s:%d Dispatch CMD_OPEN_PARM status=%d err", __func__, __LINE__, status);
}
@@ -655,7 +654,7 @@ int32_t UsbHostDdkTestClose(int32_t cmdType)
#else
int32_t status = g_acmService->dispatcher->Dispatch(g_acmService, CMD_CLOSE_PARM, g_data, g_reply);
#endif
if (status) {
if (status != HDF_SUCCESS) {
g_exitFlag = true;
HDF_LOGE("%s:%d Dispatch CMD_CLOSE_PARM status=%d err", __func__, __LINE__, status);
}
+12 -16
View File
@@ -34,9 +34,6 @@
#endif
#define USB_TEST_INTERFACE_NUM 2
struct HdfSBuf *g_data;
struct HdfSBuf *g_reply;
static int32_t UsbPnpTestEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
{
(void)priv;
@@ -50,6 +47,8 @@ int32_t main(int32_t argc, char *argv[])
{
(void)argc;
(void)argv;
struct HdfSBuf *data;
struct HdfSBuf *reply;
HDF_LOGI("%s:%d usbhost pnp test start", __func__, __LINE__);
int32_t ret;
struct HdfIoService *testService = NULL;
@@ -71,42 +70,39 @@ int32_t main(int32_t argc, char *argv[])
return HDF_FAILURE;
}
g_data = HdfSbufObtainDefaultSize();
g_reply = HdfSbufObtainDefaultSize();
if (g_data == NULL || g_reply == NULL) {
data = HdfSbufObtainDefaultSize();
reply = HdfSbufObtainDefaultSize();
if (data == NULL || reply == NULL) {
HdfIoServiceRecycle(serv);
HDF_LOGE("%s:%d GetService err", __func__, __LINE__);
return HDF_FAILURE;
}
HdfSbufWriteString(g_data, USB_TEST_SAMPLE_MODULE_NAME);
HdfSbufWriteString(g_data, USB_TEST_SAMPLE_SERVICE_NAME);
HdfSbufWriteString(data, USB_TEST_SAMPLE_MODULE_NAME);
HdfSbufWriteString(data, USB_TEST_SAMPLE_SERVICE_NAME);
ret = serv->dispatcher->Dispatch(&serv->object, USB_PNP_DRIVER_REGISTER_DEVICE, g_data, NULL);
ret = serv->dispatcher->Dispatch(&serv->object, USB_PNP_DRIVER_REGISTER_DEVICE, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d Dispatch USB_PNP_DRIVER_REGISTER_DEVICE err", __func__, __LINE__);
goto OUT;
}
HDF_LOGI("%s:%d", __func__, __LINE__);
testService = HdfIoServiceBind(USB_TEST_SAMPLE_SERVICE_NAME);
if (testService == NULL) {
HDF_LOGE("%s:%d testService USB_PNP_DRIVER_REGISTER_DEVICE err", __func__, __LINE__);
goto OUT;
}
HDF_LOGI("%s:%d", __func__, __LINE__);
ret = serv->dispatcher->Dispatch(&serv->object, USB_PNP_DRIVER_UNREGISTER_DEVICE, g_data, NULL);
ret = serv->dispatcher->Dispatch(&serv->object, USB_PNP_DRIVER_UNREGISTER_DEVICE, data, NULL);
if (ret != HDF_SUCCESS) {
HdfIoServiceRecycle(testService);
HDF_LOGE("%s:%d Dispatch USB_PNP_DRIVER_UNREGISTER_DEVICE err", __func__, __LINE__);
goto OUT;
}
HDF_LOGI("%s:%d", __func__, __LINE__);
OUT:
HdfSbufRecycle(g_data);
HdfSbufRecycle(g_reply);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
HdfIoServiceRecycle(serv);
+14 -14
View File
@@ -196,7 +196,7 @@ static int32_t ReapProcess(void * const argurb)
printf("signal SIGUSR1 failed");
return HDF_ERR_IO;
}
tid = syscall(SYS_gettid);
tid = (pid_t)syscall(SYS_gettid);
while (!g_speedFlag) {
r = ioctl(fd, USBDEVFS_REAPURB, &urbrecv);
@@ -248,7 +248,7 @@ static int32_t BeginProcess(unsigned char endPoint)
printf("parameter error\n");
return -1;
}
for (int32_t i = 0; i < TEST_CYCLE; i++) {
for (i = 0; i < TEST_CYCLE; i++) {
urb[i].urb = calloc(1, sizeof(struct UsbAdapterUrb));
if (urb[i].urb == NULL) {
return -1;
@@ -297,7 +297,7 @@ static int32_t BeginProcess(unsigned char endPoint)
while (!exitOk) {
OsalMSleep(10);
}
for (int32_t i = 0; i < TEST_CYCLE; i++) {
for (i = 0; i < TEST_CYCLE; i++) {
munmap(urb[i].urb->buffer, TEST_LENGTH);
free(urb[i].urb);
}
@@ -315,21 +315,21 @@ int32_t main(int32_t argc, char *argv[])
{
int32_t ret;
if (argc == 6) {
g_busNum = atoi(argv[1]);
g_devAddr = atoi(argv[2]);
ifaceNum = atoi(argv[3]);
endNum = atoi(argv[4]);
if (endNum >> 7 != 0) {
g_busNum = (unsigned int)atoi(argv[1]);
g_devAddr = (unsigned int)atoi(argv[2]);
ifaceNum = (unsigned int)atoi(argv[3]);
endNum = (unsigned char)atoi(argv[4]);
if ((endNum >> 7) != 0) { // the offset value is 7
g_printData = (strncmp(argv[5], "printdata", 1)) ? false : true;
}
} else if (argc == 5) {
g_busNum = atoi(argv[1]);
g_devAddr = atoi(argv[2]);
ifaceNum = atoi(argv[3]);
endNum = atoi(argv[4]);
g_busNum = (unsigned int)atoi(argv[1]);
g_devAddr = (unsigned int)atoi(argv[2]);
ifaceNum = (unsigned int)atoi(argv[3]);
endNum = (unsigned char)atoi(argv[4]);
} else if (argc == 3) {
ifaceNum = atoi(argv[1]);
endNum = atoi(argv[2]);
ifaceNum = (unsigned int)atoi(argv[1]);
endNum = (unsigned char)atoi(argv[2]);
} else {
printf("Error: parameter error!\n\n");
ShowHelp(argv[0]);
+2 -2
View File
@@ -181,7 +181,7 @@ static int32_t SerialBegin(struct AcmDevice *acm)
int32_t ret;
struct AcmDb *db = NULL;
int32_t dbn;
if (AcmDbIsAvail(acm)) {
if (AcmDbIsAvail(acm) != 0) {
dbn = AcmDbAlloc(acm);
} else {
HDF_LOGE("no buf\n");
@@ -194,7 +194,7 @@ static int32_t SerialBegin(struct AcmDevice *acm)
db = &acm->db[dbn];
db->len = acm->dataSize;
ret = AcmStartDb(acm, db, NULL);
return size;
return (int32_t)size;
}
static struct UsbInterface *GetUsbInterfaceById(const struct AcmDevice *acm, uint8_t interfaceIndex)
+11 -11
View File
@@ -204,7 +204,7 @@ static int32_t UsbGetConfigDescriptor(UsbRawHandle * const devHandle, struct Usb
}
ret = UsbRawGetConfiguration(devHandle, &activeConfig);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbRawGetConfiguration failed, ret=%d", __func__, __LINE__, ret);
return HDF_FAILURE;
}
@@ -216,7 +216,7 @@ static int32_t UsbGetConfigDescriptor(UsbRawHandle * const devHandle, struct Usb
}
ret = UsbRawGetConfigDescriptor(dev, activeConfig, config);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("UsbRawGetConfigDescriptor failed, ret=%d\n", ret);
return HDF_FAILURE;
}
@@ -300,7 +300,7 @@ static int32_t UsbParseConfigDescriptor(struct AcmDevice * const acm, struct Usb
const struct UsbRawInterface *interface = config->interface[interfaceIndex];
ret = UsbRawClaimInterface(acm->devHandle, interfaceIndex);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d claim interface %u failed", __func__, __LINE__, i);
return ret;
}
@@ -333,7 +333,7 @@ static int32_t UsbAllocDataRequests(struct AcmDevice * const acm)
reqData.length = acm->dataSize;
ret = UsbRawFillBulkRequest(snd->request, acm->devHandle, &reqData);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: FillInterruptRequest failed, ret=%d", __func__, ret);
return HDF_FAILURE;
}
@@ -402,7 +402,7 @@ static int32_t AcmStartdb(struct AcmDevice *acm, struct AcmDb * const db)
(void)acm;
int32_t ret;
ret = UsbRawSubmitRequest(db->request);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("UsbRawSubmitRequest failed, ret=%d", ret);
db->use = 0;
}
@@ -479,7 +479,7 @@ static int32_t SerialBegin(struct AcmDevice *acm)
int32_t ret;
struct AcmDb *db = NULL;
int32_t dbn;
if (AcmDbIsAvail(acm)) {
if (AcmDbIsAvail(acm) != 0) {
dbn = AcmDbAlloc(acm);
} else {
HDF_LOGE("no buf\n");
@@ -504,13 +504,13 @@ static int32_t SerialBegin(struct AcmDevice *acm)
reqData.length = acm->dataSize;
ret = UsbRawFillBulkRequest(db->request, acm->devHandle, &reqData);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: FillInterruptRequest failed, ret=%d", __func__, ret);
return HDF_FAILURE;
}
ret = AcmStartdb(acm, db);
return size;
return (int32_t)size;
}
static void SignalHandler(int32_t signo)
@@ -602,7 +602,7 @@ static int32_t InitUsbDdk(void)
UsbRawHandle *devHandle = NULL;
ret = UsbRawInit(&session);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbRawInit failed", __func__);
goto END;
}
@@ -621,7 +621,7 @@ static int32_t InitUsbDdk(void)
}
g_acm->devHandle = devHandle;
ret = UsbGetConfigDescriptor(devHandle, &g_acm->config);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbGetConfigDescriptor failed", __func__);
goto END;
}
@@ -666,7 +666,7 @@ int32_t main(int32_t argc, char *argv[])
}
ret = UsbStartIo(g_acm);
if (ret) {
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: UsbAllocReadRequests failed", __func__);
goto END;
}
+2 -2
View File
@@ -226,7 +226,7 @@ static int32_t TestCmdLoop(int32_t cmdType, const char *param)
bool asyncFlag = false;
int32_t cnt = 0;
if (TestGetExitFlag()) {
if (TestGetExitFlag() == true) {
HDF_LOGD("%s:%d g_exitFlag is true!", __func__, __LINE__);
return HDF_FAILURE;
}
@@ -280,7 +280,7 @@ static int32_t GetCharThread(void *arg)
{
char str[STR_LEN] = {0};
while (run) {
str[0] = getchar();
str[0] = (char)getchar();
}
return 0;
}
+3 -3
View File
@@ -805,7 +805,7 @@ static int32_t UsbStdCtrlCmd(struct SerialDevice *port, SerialOPCmd cmd, struct
static int32_t SerialWriteSync(const struct SerialDevice *port, const struct HdfSBuf *data)
{
uint32_t size;
int32_t size;
int32_t ret;
const char *tmp = NULL;
int32_t wbn;
@@ -954,7 +954,7 @@ static int32_t SerialClose(const struct SerialDevice *port, struct HdfSBuf *data
static int32_t SerialWrite(const struct SerialDevice *port, struct HdfSBuf *data)
{
uint32_t size;
int32_t size;
int32_t ret;
const char *tmp = NULL;
@@ -999,7 +999,7 @@ static int32_t SerialWrite(const struct SerialDevice *port, struct HdfSBuf *data
HDF_LOGE("%{public}s: AcmStartWb failed, ret=%d", __func__, ret);
return HDF_FAILURE;
}
return (int32_t)size;
return size;
}
static int32_t SerialAddOrRemoveInterface(int32_t cmd, const struct SerialDevice *port, const struct HdfSBuf *data)
+4 -4
View File
@@ -726,7 +726,7 @@ static int32_t SerialWrite(struct SerialDevice *port, struct HdfSBuf *data)
struct AcmDevice *acm = NULL;
struct AcmWb *wb = NULL;
const char *tmp = NULL;
uint32_t size;
int32_t size;
int32_t ret;
int32_t wbn;
@@ -804,7 +804,7 @@ static int32_t SerialWriteSync(const struct SerialDevice *port, const struct Hdf
struct AcmDevice *acm = NULL;
struct AcmWb *wb = NULL;
const char *tmp = NULL;
uint32_t size;
int32_t size;
int32_t ret;
int32_t wbn;
@@ -1129,7 +1129,7 @@ static void AcmNotifyReqCallback(const void *requestArg)
acm->nbIndex = 0;
}
if (UsbRawSubmitRequest(req)) {
if (UsbRawSubmitRequest(req) != HDF_SUCCESS) {
HDF_LOGE("%s - UsbRawSubmitRequest failed", __func__);
}
@@ -1146,7 +1146,7 @@ static void AcmReadBulkCallback(const void *requestArg)
}
struct AcmDevice *acm = (struct AcmDevice *)req->userData;
if (acm == NULL || acm->port == NULL) {
HDF_LOGE("%s:%d userData(acm) is NULL!", __func__, __LINE__);
HDF_LOGE("%s:%d request userData is NULL!", __func__, __LINE__);
return;
}
size_t size = (size_t)req->actualLength;
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include <csignal>
#include <cstdio>
#include <cstring>
#include <csignal>
#include <unistd.h>
#include <gtest/gtest.h>
#include <unistd.h>
#include "hdf_base.h"
#include "usb_utils.h"
@@ -74,7 +75,7 @@ HWTEST_F(UsbHostPerformanceTest, CheckHostSdkProcInfo, TestSize.Level1)
char *pch = nullptr;
FILE *res = nullptr;
struct ProcInfo info = {0, 0, 0, 0, 0};
ASSERT_EQ(access(script.c_str(), F_OK) , 0) << "ErrInfo: shell script not exists";
ASSERT_EQ(access(script.c_str(), F_OK), 0) << "ErrInfo: shell script not exists";
if (access(script.c_str(), X_OK) == -1) {
system(("chmod +x " + script).c_str());
}
@@ -100,4 +101,4 @@ HWTEST_F(UsbHostPerformanceTest, CheckHostSdkProcInfo, TestSize.Level1)
EXPECT_EQ(processCount, 1) << "ErrInfo: host sdk process count is not equal to 1";
printf("------end CheckHostSdkProcInfo------\n");
}
}
} // namespace
+8 -6
View File
@@ -34,12 +34,14 @@ bool HasLog(const string &target, double startTs, const string &file)
while (getline(logFile, lineStr)) {
double logTs;
pos = lineStr.find(flagStr);
if (pos != string::npos) {
logTs = stod(lineStr.substr(pos + tsStartPos, tsLength));
if ((logTs - startTs) >= 0) {
if (lineStr.find(target) != string::npos) {
ret = true;
}
if (pos == string::npos) {
lineStr.clear();
continue;
}
logTs = stod(lineStr.substr(pos + tsStartPos, tsLength));
if ((logTs - startTs) >= 0) {
if (lineStr.find(target) != string::npos) {
ret = true;
}
}
lineStr.clear();
@@ -364,18 +364,20 @@ static int32_t ParseInterfaces(struct AcmDevice * const acmDevice)
acmDevice->notifyPipe.maxPacketSize = pipeInfo.maxPacketSize;
acmDevice->ctrlIface.fn = fnIface;
acmDevice->ctrlIface.handle = handle;
} else if (pipeInfo.type == USB_PIPE_TYPE_BULK) {
if (pipeInfo.dir == USB_PIPE_DIRECTION_IN) {
acmDevice->dataInPipe.id = pipeInfo.id;
acmDevice->dataInPipe.maxPacketSize = pipeInfo.maxPacketSize;
acmDevice->dataIface.fn = fnIface;
acmDevice->dataIface.handle = handle;
} else {
acmDevice->dataOutPipe.id = pipeInfo.id;
acmDevice->dataOutPipe.maxPacketSize = pipeInfo.maxPacketSize;
acmDevice->dataIface.fn = fnIface;
acmDevice->dataIface.handle = handle;
}
continue;
}
if (pipeInfo.type == USB_PIPE_TYPE_BULK && pipeInfo.dir == USB_PIPE_DIRECTION_IN) {
acmDevice->dataInPipe.id = pipeInfo.id;
acmDevice->dataInPipe.maxPacketSize = pipeInfo.maxPacketSize;
acmDevice->dataIface.fn = fnIface;
acmDevice->dataIface.handle = handle;
continue;
}
if (pipeInfo.type == USB_PIPE_TYPE_BULK) {
acmDevice->dataOutPipe.id = pipeInfo.id;
acmDevice->dataOutPipe.maxPacketSize = pipeInfo.maxPacketSize;
acmDevice->dataIface.fn = fnIface;
acmDevice->dataIface.handle = handle;
}
}
}
@@ -16,9 +16,9 @@
#ifndef USB_CDCACM_TEST_H
#define USB_CDCACM_TEST_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include "osal_atomic.h"
@@ -24,8 +24,7 @@ using namespace std;
using namespace testing::ext;
namespace {
static struct AcmDevice *g_acmDevice = nullptr;
class UsbDeviceSdkIoTest : public testing::Test {
};
class UsbDeviceSdkIoTest : public testing::Test {};
HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCreateDevice001, TestSize.Level1)
{
@@ -48,8 +47,7 @@ static void ReadComplete(uint8_t pipe, struct UsbFnRequest *req)
uint8_t *data = (uint8_t *)req->buf;
data[req->actual] = '\0';
printf("receive [%d] bytes data: %s\n", req->actual, data);
if (strcmp((const char *)data, "q") == 0 || \
strcmp((const char *)data, "q\n") == 0) {
if (strcmp((const char *)data, "q") == 0 || strcmp((const char *)data, "q\n") == 0) {
g_acmDevice->submitExit = 1;
}
}
@@ -64,8 +62,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync002, TestSize.Level1)
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("wait receiving data form host, please connect\n");
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
req->complete = ReadComplete;
req->context = g_acmDevice;
@@ -75,7 +73,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync002, TestSize.Level1)
if (ret != HDF_SUCCESS) {
continue;
}
while(g_acmDevice->submit == 0) {
while (g_acmDevice->submit == 0) {
OsalMSleep(waitMs);
}
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -98,8 +96,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync003, TestSize.Level1)
printf("recv data until 'q' exit\n");
g_acmDevice->submitExit = 0;
while (g_acmDevice->submitExit == 0) {
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
req->complete = ReadComplete;
req->context = g_acmDevice;
@@ -107,7 +105,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync003, TestSize.Level1)
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
EXPECT_EQ(0, g_acmDevice->submit);
while(g_acmDevice->submit == 0) {
while (g_acmDevice->submit == 0) {
OsalMSleep(waitMs);
}
g_acmDevice->submit = 0;
@@ -126,11 +124,11 @@ static void WriteComplete(uint8_t pipe, struct UsbFnRequest *req)
HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync004, TestSize.Level1)
{
int32_t ret;
struct UsbFnRequest *req = nullptr;
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
req->complete = WriteComplete;
req->context = g_acmDevice;
@@ -140,7 +138,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync004, TestSize.Level1)
req->length = strlen("abc");
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
while(g_acmDevice->submit == 0) {
while (g_acmDevice->submit == 0) {
OsalMSleep(1);
}
g_acmDevice->submit = 0;
@@ -152,13 +150,13 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync005, TestSize.Level1)
{
int32_t ret;
int32_t loopTime = TEST_TIMES;
struct UsbFnRequest *req = nullptr;
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("------send \"xyz\" 10 times to host------\n");
while (loopTime > 0) {
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
req->complete = WriteComplete;
req->context = g_acmDevice;
@@ -167,7 +165,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestAsync005, TestSize.Level1)
req->length = strlen("xyz");
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
while(g_acmDevice->submit == 0) {
while (g_acmDevice->submit == 0) {
OsalMSleep(1);
}
g_acmDevice->submit = 0;
@@ -192,8 +190,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync002, TestSize.Level1)
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("wait receiving data form host:\n");
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
ret = UsbFnSubmitRequestSync(req, 0);
EXPECT_TRUE(ret == 0);
@@ -214,9 +212,9 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync003, TestSize.Level1)
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("receive data until 'q' exit\n");
while (submitExit == 0){
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
while (submitExit == 0) {
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
ret = UsbFnSubmitRequestSync(req, 0);
EXPECT_TRUE(ret == 0);
@@ -224,8 +222,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync003, TestSize.Level1)
EXPECT_TRUE(req->status == USB_REQUEST_COMPLETED);
data = (uint8_t *)req->buf;
data[req->actual] = '\0';
if (strcmp((const char *)data, "q") == 0 || \
strcmp((const char *)data, "q\n") == 0) {
if (strcmp((const char *)data, "q") == 0 || strcmp((const char *)data, "q\n") == 0) {
submitExit = 1;
}
printf("receive data from host: %s------\n", data);
@@ -237,11 +234,11 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync003, TestSize.Level1)
HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync004, TestSize.Level1)
{
int32_t ret;
struct UsbFnRequest *req = nullptr;
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
printf("------send \"abc\" to host------\n");
memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc"));
@@ -258,13 +255,13 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync005, TestSize.Level1)
{
int32_t ret;
int32_t loopTime = TEST_TIMES;
struct UsbFnRequest *req = nullptr;
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("------send \"abcdefg\" 10 times to host------\n");
while (loopTime > 0) {
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abcdefg", strlen("abcdefg"));
req->length = strlen("abcdefg");
@@ -285,8 +282,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRequestSync006, TestSize.Level1)
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
printf("test sync timeout 5s:\n");
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
ret = UsbFnSubmitRequestSync(req, SYNC_5000MS);
EXPECT_TRUE(ret != 0);
@@ -309,8 +306,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfGetReqStatus001, TestSize.Level1)
struct UsbFnRequest *notifyReq = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->ctrlIface.handle);
notifyReq = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id,
sizeof(struct UsbCdcNotification));
notifyReq =
UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, sizeof(struct UsbCdcNotification));
EXPECT_TRUE(notifyReq != nullptr);
ret = UsbFnGetRequestStatus(notifyReq, &status);
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -341,8 +338,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfGetReqStatus003, TestSize.Level1)
struct UsbFnRequest *notifyReq = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->ctrlIface.handle);
notifyReq = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
notifyReq = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_TRUE(notifyReq != nullptr);
ret = UsbFnGetRequestStatus(notifyReq, nullptr);
EXPECT_TRUE(ret != HDF_SUCCESS);
@@ -357,8 +354,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfGetReqStatus004, TestSize.Level1)
struct UsbFnRequest *notifyReq = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->ctrlIface.handle);
notifyReq = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
notifyReq = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_TRUE(notifyReq != nullptr);
ret = UsbFnSubmitRequestAsync(notifyReq);
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -394,8 +391,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq002, TestSize.Level1)
struct UsbFnRequest *notifyReq = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->ctrlIface.handle);
notifyReq = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id,
sizeof(struct UsbCdcNotification));
notifyReq =
UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, sizeof(struct UsbCdcNotification));
EXPECT_TRUE(notifyReq != nullptr);
ret = UsbFnSubmitRequestAsync(notifyReq);
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -408,11 +405,11 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq002, TestSize.Level1)
HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq003, TestSize.Level1)
{
int32_t ret;
struct UsbFnRequest *req = nullptr;
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_NE(nullptr, req);
req->complete = WriteComplete;
req->context = g_acmDevice;
@@ -422,7 +419,7 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq003, TestSize.Level1)
req->length = strlen("abcdef");
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
while(g_acmDevice->submit == 0) {
while (g_acmDevice->submit == 0) {
OsalMSleep(1);
}
g_acmDevice->submit = 0;
@@ -438,8 +435,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq004, TestSize.Level1)
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_TRUE(req != nullptr);
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -455,8 +452,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq005, TestSize.Level1)
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id,
g_acmDevice->dataInPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, g_acmDevice->dataInPipe.maxPacketSize);
EXPECT_TRUE(req != nullptr);
ret = UsbFnCancelRequest(req);
EXPECT_TRUE(ret != HDF_SUCCESS);
@@ -470,8 +467,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq006, TestSize.Level1)
struct UsbFnRequest *req = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_TRUE(req != nullptr);
ret = UsbFnCancelRequest(req);
EXPECT_TRUE(ret != HDF_SUCCESS);
@@ -485,8 +482,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq007, TestSize.Level1)
struct UsbFnRequest *ctrlReq = nullptr;
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->ctrlIface.handle);
ctrlReq = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle,
sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding));
ctrlReq = UsbFnAllocCtrlRequest(
g_acmDevice->ctrlIface.handle, sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding));
EXPECT_TRUE(ctrlReq != nullptr);
ret = UsbFnCancelRequest(ctrlReq);
EXPECT_TRUE(ret != HDF_SUCCESS);
@@ -502,8 +499,8 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfCancelReq008, TestSize.Level1)
EXPECT_NE(nullptr, g_acmDevice);
EXPECT_NE(nullptr, g_acmDevice->dataIface.handle);
for (count = 0; count < TEST_TIMES; count++) {
req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id,
g_acmDevice->dataOutPipe.maxPacketSize);
req = UsbFnAllocRequest(
g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, g_acmDevice->dataOutPipe.maxPacketSize);
EXPECT_TRUE(req != nullptr);
ret = UsbFnSubmitRequestAsync(req);
EXPECT_TRUE(ret == HDF_SUCCESS);
@@ -525,4 +522,4 @@ HWTEST_F(UsbDeviceSdkIoTest, CheckDeviceSdkIfRemoveDevice002, TestSize.Level1)
EXPECT_EQ(HDF_SUCCESS, ret);
OsalMemFree(g_acmDevice);
}
}
} // namespace
+12 -12
View File
@@ -26,21 +26,21 @@ struct DataFifo {
};
#ifndef MIN
static inline int32_t MIN(int32_t a, int32_t b)
inline int32_t MIN(int32_t a, int32_t b)
{
return ((a) < (b) ? (a) : (b));
}
#endif
#ifndef MAX
static inline int32_t MAX(int32_t a, int32_t b)
inline int32_t MAX(int32_t a, int32_t b)
{
return ((a) > (b) ? (a) : (b));
}
#endif
/* DataFifo Helper function */
static inline void DataFifoInit(struct DataFifo *fifo, uint32_t size, void *data)
inline void DataFifoInit(struct DataFifo *fifo, uint32_t size, void *data)
{
fifo->rdIdx = 0;
fifo->wrIdx = 0;
@@ -48,42 +48,42 @@ static inline void DataFifoInit(struct DataFifo *fifo, uint32_t size, void *data
fifo->data = data;
}
static inline bool DataFifoIsInitialized(struct DataFifo *fifo)
inline bool DataFifoIsInitialized(struct DataFifo *fifo)
{
return fifo->size != 0;
}
static inline void DataFifoReset(struct DataFifo *fifo)
inline void DataFifoReset(struct DataFifo *fifo)
{
fifo->rdIdx = fifo->wrIdx = 0;
}
static inline uint32_t DataFifoLen(struct DataFifo *fifo)
inline uint32_t DataFifoLen(struct DataFifo *fifo)
{
return fifo->wrIdx - fifo->rdIdx;
}
static inline bool DataFifoIsEmpty(struct DataFifo *fifo)
inline bool DataFifoIsEmpty(struct DataFifo *fifo)
{
return fifo->wrIdx == fifo->rdIdx;
}
static inline bool DataFifoIsFull(struct DataFifo *fifo)
inline bool DataFifoIsFull(struct DataFifo *fifo)
{
return DataFifoLen(fifo) > (fifo->size - 1);
}
static inline uint32_t DataFifoAvailSize(struct DataFifo *fifo)
inline uint32_t DataFifoAvailSize(struct DataFifo *fifo)
{
return fifo->size - DataFifoLen(fifo);
}
static inline void DataFifoSkip(struct DataFifo *fifo, uint32_t size)
inline void DataFifoSkip(struct DataFifo *fifo, uint32_t size)
{
fifo->rdIdx += size;
}
static inline uint32_t DataFifoWrite(struct DataFifo *fifo, uint8_t *data, uint32_t size)
inline uint32_t DataFifoWrite(struct DataFifo *fifo, uint8_t *data, uint32_t size)
{
uint32_t mask = fifo->size - 1;
uint8_t *buf = (uint8_t *)fifo->data;
@@ -97,7 +97,7 @@ static inline uint32_t DataFifoWrite(struct DataFifo *fifo, uint8_t *data, uint3
return size;
}
static inline uint32_t DataFifoRead(struct DataFifo *fifo, uint8_t *data, uint32_t size)
inline uint32_t DataFifoRead(struct DataFifo *fifo, uint8_t *data, uint32_t size)
{
uint32_t mask = fifo->size - 1;
uint8_t *buf = (uint8_t *)fifo->data;
@@ -278,7 +278,7 @@ static void AcmNotifyReqCallback(const void *requestArg)
AcmProcessNotification(acm, (unsigned char *)dr);
acm->nbIndex = 0;
}
if (UsbRawSubmitRequest(req))
if (UsbRawSubmitRequest(req) != HDF_SUCCESS)
printf("%s - UsbRawSubmitRequest failed", __func__);
EXIT:
printf("%s:%d exit", __func__, __LINE__);