!645 队列支持变长读

Merge pull request !645 from chenliming_kh/master
This commit is contained in:
openharmony_ci 2022-03-24 01:51:31 +00:00 committed by Gitee
commit 2f19ba3653
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 6 additions and 13 deletions

View File

@ -245,6 +245,7 @@ static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
} else {
if (OS_QUEUE_IS_READ(operateType)) {
msgDataSize = *((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32)));
msgDataSize = (*bufferSize < msgDataSize) ? *bufferSize : msgDataSize;
rc = memcpy_s((VOID *)bufferAddr, *bufferSize, (VOID *)queueNode, msgDataSize);
if (rc != EOK) {
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
@ -269,9 +270,7 @@ static INLINE UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32
return LOS_ERRNO_QUEUE_NOT_CREATE;
}
if (OS_QUEUE_IS_READ(operateType) && (*bufferSize < (queueCB->queueSize - sizeof(UINT32)))) {
return LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL;
} else if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
}

View File

@ -48,7 +48,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@ -47,7 +47,7 @@ static UINT32 Testcase(VOID)
// 6, Set a value less than QUEUE_BASE_MSGSIZE, for test erro code LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL
ret = LOS_QueueRead(g_testQueueID01, &buff2, 6, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@ -45,9 +45,6 @@ static UINT32 Testcase(VOID)
ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, for boundary value test
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
// 6, to verify the correct value

View File

@ -45,7 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 6, 0); // 6 < QUEUE_BASE_MSGSIZE for erro code LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:
ret = LOS_QueueDelete(g_testQueueID01);

View File

@ -45,9 +45,6 @@ static UINT32 Testcase(VOID)
ret = LOS_QueueWriteHead(g_testQueueID01, buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, read size
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ICUNIT_GOTO_EQUAL(*((char *)(intptr_t)buff2 + 6), buff1[6], *((char *)(intptr_t)buff2 + 6), EXIT); // 6, In order to verify the content

View File

@ -45,7 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 7, 0); // 7, buffer2 max - 1
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL, ret, EXIT);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:
ret = LOS_QueueDelete(g_testQueueID01);