From f793dc10971cb9a961d8fb75ec800b0b0fca7e6d Mon Sep 17 00:00:00 2001 From: vcbchang Date: Sat, 19 Jun 2021 16:35:14 +0800 Subject: [PATCH] =?UTF-8?q?test:=E4=BF=AE=E5=A4=8Drwlock=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=9C=A8=E5=BE=AA=E7=8E=AF=E5=A4=84=E4=BC=9A=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】修复rwlock门禁用例多次测试出现的程序会卡死在某一个地方的问题,经查找程序会卡在循环里面 【修改方案】 1.经测试,发现用例在创建线程后对退出标志位做了初始化,但卡在循环中不动的原因是在创建线程后立刻发生了调度,没有来得及初始化,则发生了错误,故会出现卡在循环中的情况。 而且,由于卡在循环中时线程是同一优先级,可能不会发生调度,故在循环里面加了一句可以调度的语句,防止在一处循环卡的太久。 2.将该用例挪出门禁,待稳定后恢复。 【影响】 对其它用例无影响。 re #I3VUX4 Signed-off-by:vcbchang Change-Id: Ie0f908001f59bfc832c2519104aa2e3188206910 Signed-off-by: vcbchang --- testsuites/unittest/process/rwlock/BUILD.gn | 2 +- .../{smoke => full}/pthread_rwlock_test_002.cpp | 11 +++++++---- .../unittest/process/rwlock/process_rwlock_test.cpp | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) rename testsuites/unittest/process/rwlock/{smoke => full}/pthread_rwlock_test_002.cpp (99%) diff --git a/testsuites/unittest/process/rwlock/BUILD.gn b/testsuites/unittest/process/rwlock/BUILD.gn index aedc928f..4ed9394f 100644 --- a/testsuites/unittest/process/rwlock/BUILD.gn +++ b/testsuites/unittest/process/rwlock/BUILD.gn @@ -43,10 +43,10 @@ sources_entry = [ sources_smoke = [ "smoke/pthread_rwlock_test_001.cpp", - "smoke/pthread_rwlock_test_002.cpp", ] sources_full = [ + "full/pthread_rwlock_test_002.cpp", ] if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) { diff --git a/testsuites/unittest/process/rwlock/smoke/pthread_rwlock_test_002.cpp b/testsuites/unittest/process/rwlock/full/pthread_rwlock_test_002.cpp similarity index 99% rename from testsuites/unittest/process/rwlock/smoke/pthread_rwlock_test_002.cpp rename to testsuites/unittest/process/rwlock/full/pthread_rwlock_test_002.cpp index 544748e5..075c2aa8 100644 --- a/testsuites/unittest/process/rwlock/smoke/pthread_rwlock_test_002.cpp +++ b/testsuites/unittest/process/rwlock/full/pthread_rwlock_test_002.cpp @@ -100,6 +100,7 @@ static void *ThreadReadFunc(void *a) ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); while (loop > 0) { + SLEEP_AND_YIELD(1); ret = pthread_rwlock_rdlock(&g_rwlockLock); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); g_isReading[threadCount] = 1; @@ -139,6 +140,7 @@ static void *ThreadWriteFunc1(void *a) ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); while (CheckReadThreadExit()) { + SLEEP_AND_YIELD(1); ret = pthread_rwlock_wrlock(&g_rwlockLock); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); @@ -180,6 +182,7 @@ static void *ThreadWriteFunc(void *a) int threadCount = *((int *)a); while (CheckReadThreadExit() || CheckWriteThreadExit()) { + SLEEP_AND_YIELD(1); ret = pthread_rwlock_wrlock(&g_rwlockLock); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); @@ -247,20 +250,20 @@ static int PthreadRwlockTest(void) count = 1; while (count < WRITE_THREAD_COUNT) { g_writePar[count] = count; - ret = pthread_create(&newPthread, &a, ThreadWriteFunc1, &g_writePar[count]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); g_isWriting[count] = 0; g_isWriteExit[count] = 0; + ret = pthread_create(&newPthread, &a, ThreadWriteFunc1, &g_writePar[count]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); count++; } count = 0; while (count < READ_THREAD_COUNT) { g_readPar[count] = count; - ret = pthread_create(&newPthread, &a, ThreadReadFunc, &g_readPar[count]); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); g_isReading[count] = 0; g_isReadExit[count] = 0; + ret = pthread_create(&newPthread, &a, ThreadReadFunc, &g_readPar[count]); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); count++; } diff --git a/testsuites/unittest/process/rwlock/process_rwlock_test.cpp b/testsuites/unittest/process/rwlock/process_rwlock_test.cpp index b4a6753d..2a0f5f7d 100644 --- a/testsuites/unittest/process/rwlock/process_rwlock_test.cpp +++ b/testsuites/unittest/process/rwlock/process_rwlock_test.cpp @@ -52,7 +52,9 @@ HWTEST_F(ProcessRwlockTest, ItTestPthreadRwlock001, TestSize.Level0) { ItTestPthreadRwlock001(); } +#endif +#if defined(LOSCFG_USER_TEST_FULL) /* * * @tc.name: it_test_pthread_rwlock_002 * @tc.desc: function for ProcessRwlockTest