fix: 添加进程线程冒烟用例
Close #I4EOGA Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I0f10f81d41564d4d34fc2f89692da0b3211f5918
This commit is contained in:
@@ -46,12 +46,12 @@ sources_smoke = [
|
||||
"smoke/pthread_atfork_test_002.cpp",
|
||||
"smoke/pthread_cond_test_001.cpp",
|
||||
"smoke/pthread_cond_test_002.cpp",
|
||||
"smoke/pthread_cond_test_003.cpp",
|
||||
"smoke/pthread_cond_test_004.cpp",
|
||||
"smoke/pthread_once_test_001.cpp",
|
||||
"smoke/pthread_test_001.cpp",
|
||||
"smoke/pthread_test_002.cpp",
|
||||
"smoke/pthread_test_003.cpp",
|
||||
"smoke/pthread_test_004.cpp",
|
||||
"smoke/pthread_test_005.cpp",
|
||||
"smoke/pthread_test_006.cpp",
|
||||
"smoke/pthread_test_007.cpp",
|
||||
"smoke/pthread_test_008.cpp",
|
||||
@@ -69,6 +69,8 @@ sources_smoke = [
|
||||
]
|
||||
|
||||
sources_full = [
|
||||
"full/pthread_test_004.cpp",
|
||||
"full/pthread_test_005.cpp",
|
||||
]
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
|
||||
@@ -245,6 +245,10 @@ static void *threadFunc(void *arg)
|
||||
ret = pthread_create(&newPthread, &a, threadFunc2, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
sleep(1);
|
||||
#endif
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 4, g_pthreadTestCount, EXIT); // 4, here assert the result.
|
||||
@@ -79,4 +79,6 @@ extern void ItTestPthreadAtfork002(void);
|
||||
extern void ItTestPthreadOnce001(void);
|
||||
extern void ItTestPthreadCond001(void);
|
||||
extern void ItTestPthreadCond002(void);
|
||||
#endif
|
||||
extern void ItTestPthreadCond003(void);
|
||||
extern void ItTestPthreadCond004(void);
|
||||
#endif
|
||||
|
||||
@@ -87,28 +87,6 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0)
|
||||
ItTestPthread003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_004
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_005
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread005();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_006
|
||||
@@ -236,17 +214,6 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread016, TestSize.Level0)
|
||||
ItTestPthread016();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_017
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread017();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_018
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
@@ -269,6 +236,18 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0)
|
||||
ItTestPthread019();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_017
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread017();
|
||||
}
|
||||
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_once_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
@@ -323,5 +302,52 @@ HWTEST_F(ProcessPthreadTest, ItTestPthreadCond002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_003
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond003, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_004
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond004();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_004
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_005
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread005();
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "it_pthread_test.h"
|
||||
|
||||
static pthread_cond_t g_pthread_cond;
|
||||
static pthread_mutex_t g_pthread_mutex;
|
||||
#define TEST_THREAD_COUNT 5
|
||||
static void *pthread_cond_func001(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 60; /* 60: wait 1 minute */
|
||||
|
||||
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *pthread_f06(void *argument)
|
||||
{
|
||||
int policy;
|
||||
int ret;
|
||||
int i;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedParam = { 0 };
|
||||
pthread_t thread[TEST_THREAD_COUNT];
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_create(&thread[i], &attr, pthread_cond_func001, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_cond_broadcast(&g_pthread_cond);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_join(thread[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int policy;
|
||||
pthread_attr_t attr;
|
||||
pthread_t newTh;
|
||||
struct sched_param schedParam = { 0 };
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_cond_init(&g_pthread_cond, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, pthread_f06, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_003", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "it_pthread_test.h"
|
||||
static pthread_cond_t g_pthread_cond;
|
||||
static pthread_mutex_t g_pthread_mutex;
|
||||
#define TEST_THREAD_COUNT 5
|
||||
|
||||
static void *pthread_cond_func002(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 2; /* 2: wait 2 seconds */
|
||||
|
||||
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *pthread_f07(void *argument)
|
||||
{
|
||||
int policy;
|
||||
int ret;
|
||||
int i;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedParam = { 0 };
|
||||
pthread_t thread[TEST_THREAD_COUNT];
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_create(&thread[i], &attr, pthread_cond_func002, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_join(thread[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int policy;
|
||||
pthread_attr_t attr;
|
||||
pthread_t newTh;
|
||||
struct sched_param schedParam = { 0 };
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_cond_init(&g_pthread_cond, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, pthread_f07, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_004", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -53,10 +53,6 @@ static UINT32 Testcase(VOID)
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
sleep(1);
|
||||
#endif
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount); // 2, assert the exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user