diff --git a/testsuites/unittest/common/include/osTest.h b/testsuites/unittest/common/include/osTest.h index 0623b40a..3ee6fb5d 100644 --- a/testsuites/unittest/common/include/osTest.h +++ b/testsuites/unittest/common/include/osTest.h @@ -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) diff --git a/testsuites/unittest/common/osTest.cpp b/testsuites/unittest/common/osTest.cpp index a771a147..0c02e5e6 100644 --- a/testsuites/unittest/common/osTest.cpp +++ b/testsuites/unittest/common/osTest.cpp @@ -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; diff --git a/testsuites/unittest/posix/mqueue/full/It_posix_queue_075.cpp b/testsuites/unittest/posix/mqueue/full/It_posix_queue_075.cpp index 137b60a2..2fea2090 100644 --- a/testsuites/unittest/posix/mqueue/full/It_posix_queue_075.cpp +++ b/testsuites/unittest/posix/mqueue/full/It_posix_queue_075.cpp @@ -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); diff --git a/testsuites/unittest/posix/mqueue/full/It_posix_queue_097.cpp b/testsuites/unittest/posix/mqueue/full/It_posix_queue_097.cpp index e11c5034..00fad7b1 100644 --- a/testsuites/unittest/posix/mqueue/full/It_posix_queue_097.cpp +++ b/testsuites/unittest/posix/mqueue/full/It_posix_queue_097.cpp @@ -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); diff --git a/testsuites/unittest/posix/mqueue/smoke/It_posix_queue_053.cpp b/testsuites/unittest/posix/mqueue/smoke/It_posix_queue_053.cpp index 2308073d..01dd6aa2 100644 --- a/testsuites/unittest/posix/mqueue/smoke/It_posix_queue_053.cpp +++ b/testsuites/unittest/posix/mqueue/smoke/It_posix_queue_053.cpp @@ -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);