test: 修复mqueue_unittest全量用例ItPosixQueue075与ItPosixQueue097,冒烟用例 ItPosixQueue053用例存在偶尔无法通过的问题
【背景】mqueue_unittest用例ItPosixQueue075、ItPosixQueue053 与ItPosixQueue097用例存在偶尔无法通过的问题,现在将其修复 【修改方案】ItPosixQueue075中原来是通过延时来实现线程同步,现在更改为静态全局变量实现; ItPosixQueue097中的关于g_testCount利用延时来置标志位,实现线程同步。这里通过延时来期望线程调度,写的不合理,这里更改为等待标志位来实现线程同步。 re #I3Z9H9 Signed-off-by: vcbchang <vcbchang@qq.com> Change-Id: Ib1bb945a5393cb03f4d92e4332e20acd82eb1845
This commit is contained in:
parent
feae60c8fe
commit
e7c4b1963a
|
@ -132,6 +132,7 @@ extern void TestBusyTaskDelay(UINT32 tick);
|
|||
extern void *malloc(size_t size);
|
||||
extern void TEST_DumpCpuid(void);
|
||||
extern u_long T_random(void);
|
||||
extern VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag);
|
||||
|
||||
UINT32 LosTaskDelay(UINT32 tick);
|
||||
#define TEST_HwiDelete(ID) TEST_TEST_HwiDelete(ID, NULL)
|
||||
|
|
|
@ -215,6 +215,13 @@ VOID TestAssertBusyTaskDelay(UINT32 timeout, UINT32 flag)
|
|||
}
|
||||
}
|
||||
|
||||
VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag)
|
||||
{
|
||||
while (*testCount != flag) {
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri)
|
||||
{
|
||||
UINT32 uwRet = 0;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_posix_queue.h"
|
||||
static int g_testFlag = 0;
|
||||
|
||||
static VOID *PthreadF01(VOID *arg)
|
||||
{
|
||||
|
@ -37,12 +38,12 @@ static VOID *PthreadF01(VOID *arg)
|
|||
CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0};
|
||||
struct timespec ts = { 0 };
|
||||
ts.tv_sec = 0xffff;
|
||||
|
||||
for (i = 0; i < MQUEUE_STANDARD_NAME_LENGTH * 2; i++) { // 2, The loop frequency name length.
|
||||
ret = mq_timedreceive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT);
|
||||
ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT);
|
||||
}
|
||||
g_testFlag = 0; // 0 means the sub thread has executed
|
||||
return NULL;
|
||||
EXIT:
|
||||
return NULL;
|
||||
|
@ -62,6 +63,7 @@ static UINT32 Testcase(VOID)
|
|||
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
|
||||
attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH;
|
||||
|
||||
g_testFlag = 1; // 1 initialize the flag
|
||||
LOS_TaskLock();
|
||||
snprintf(mqname, MQUEUE_STANDARD_NAME_LENGTH, "/mq075_%d", LosCurTaskIDGet());
|
||||
|
||||
|
@ -85,7 +87,10 @@ static UINT32 Testcase(VOID)
|
|||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
|
||||
}
|
||||
|
||||
TestExtraTaskDelay(10); // 10, Set delay time.
|
||||
// waitting for the flag is 0, means the sub thread has executed
|
||||
while (g_testFlag) {
|
||||
usleep(1);
|
||||
}
|
||||
|
||||
ret = mq_close(g_gqueue);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
|
||||
|
|
|
@ -107,9 +107,6 @@ static UINT32 Testcase(VOID)
|
|||
ret = pthread_create(&newTh, &attr1, PthreadF01, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
|
||||
|
||||
LosTaskDelay(1);
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT1);
|
||||
|
||||
ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST2);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
||||
|
@ -119,7 +116,7 @@ static UINT32 Testcase(VOID)
|
|||
ret = LosTaskDelay(10); // 10, Set delay time.
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT2); // 4, Here, assert the g_testCount.
|
||||
TestAssertWaitDelay(&g_testCount, 4); // 4, Here, assert the g_testCount.
|
||||
|
||||
ret = PosixPthreadDestroy(&attr1, newTh2);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
|
|
@ -37,10 +37,7 @@ static VOID *PthreadF01(VOID *argument)
|
|||
|
||||
g_testCount = 1;
|
||||
|
||||
ret = LosTaskDelay(5); // 5, Set the timeout of task delay;
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert the g_testCount.
|
||||
TestAssertWaitDelay(&g_testCount, 3); // 3, Here, assert the g_testCount.
|
||||
|
||||
ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT);
|
||||
|
@ -105,8 +102,7 @@ static UINT32 Testcase(VOID)
|
|||
ret = pthread_create(&newTh1, &attr1, PthreadF01, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
|
||||
|
||||
LosTaskDelay(1);
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT1);
|
||||
TestAssertWaitDelay(&g_testCount, 1);
|
||||
|
||||
ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST2);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
@ -121,7 +117,7 @@ static UINT32 Testcase(VOID)
|
|||
#endif
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT2); // 4, Here, assert the g_testCount.
|
||||
TestAssertWaitDelay(&g_testCount, 4); // 4, Here, assert the g_testCount.
|
||||
|
||||
ret = PosixPthreadDestroy(&attr1, newTh2);
|
||||
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT2);
|
||||
|
|
Loading…
Reference in New Issue