!338 修复rwlock门禁用例多次测试出现的超时不通过的问题

Merge pull request !338 from phchang/rwlock
This commit is contained in:
openharmony_ci 2021-06-24 10:55:21 +00:00 committed by Gitee
commit 1e345f18b3
3 changed files with 10 additions and 5 deletions

View File

@ -43,10 +43,10 @@ sources_entry = [
sources_smoke = [ sources_smoke = [
"smoke/pthread_rwlock_test_001.cpp", "smoke/pthread_rwlock_test_001.cpp",
"smoke/pthread_rwlock_test_002.cpp",
] ]
sources_full = [ sources_full = [
"full/pthread_rwlock_test_002.cpp",
] ]
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) { if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {

View File

@ -100,6 +100,7 @@ static void *ThreadReadFunc(void *a)
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
while (loop > 0) { while (loop > 0) {
SLEEP_AND_YIELD(1);
ret = pthread_rwlock_rdlock(&g_rwlockLock); ret = pthread_rwlock_rdlock(&g_rwlockLock);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
g_isReading[threadCount] = 1; g_isReading[threadCount] = 1;
@ -139,6 +140,7 @@ static void *ThreadWriteFunc1(void *a)
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
while (CheckReadThreadExit()) { while (CheckReadThreadExit()) {
SLEEP_AND_YIELD(1);
ret = pthread_rwlock_wrlock(&g_rwlockLock); ret = pthread_rwlock_wrlock(&g_rwlockLock);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
@ -180,6 +182,7 @@ static void *ThreadWriteFunc(void *a)
int threadCount = *((int *)a); int threadCount = *((int *)a);
while (CheckReadThreadExit() || CheckWriteThreadExit()) { while (CheckReadThreadExit() || CheckWriteThreadExit()) {
SLEEP_AND_YIELD(1);
ret = pthread_rwlock_wrlock(&g_rwlockLock); ret = pthread_rwlock_wrlock(&g_rwlockLock);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
@ -247,20 +250,20 @@ static int PthreadRwlockTest(void)
count = 1; count = 1;
while (count < WRITE_THREAD_COUNT) { while (count < WRITE_THREAD_COUNT) {
g_writePar[count] = 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_isWriting[count] = 0;
g_isWriteExit[count] = 0; g_isWriteExit[count] = 0;
ret = pthread_create(&newPthread, &a, ThreadWriteFunc1, &g_writePar[count]);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
count++; count++;
} }
count = 0; count = 0;
while (count < READ_THREAD_COUNT) { while (count < READ_THREAD_COUNT) {
g_readPar[count] = 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_isReading[count] = 0;
g_isReadExit[count] = 0; g_isReadExit[count] = 0;
ret = pthread_create(&newPthread, &a, ThreadReadFunc, &g_readPar[count]);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
count++; count++;
} }

View File

@ -52,7 +52,9 @@ HWTEST_F(ProcessRwlockTest, ItTestPthreadRwlock001, TestSize.Level0)
{ {
ItTestPthreadRwlock001(); ItTestPthreadRwlock001();
} }
#endif
#if defined(LOSCFG_USER_TEST_FULL)
/* * /* *
* @tc.name: it_test_pthread_rwlock_002 * @tc.name: it_test_pthread_rwlock_002
* @tc.desc: function for ProcessRwlockTest * @tc.desc: function for ProcessRwlockTest