refactor: 删除旧测试套,拆分process用例适配门禁90s规则
close: #I4RE80 Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: I353fe4aa10e4f03e7cbaca572c8e73289c599c29
This commit is contained in:
66
testsuites/unittest/process/basic/pthread/config.gni
Normal file
66
testsuites/unittest/process/basic/pthread/config.gni
Normal file
@@ -0,0 +1,66 @@
|
||||
# Copyright (c) 2022-2022 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.
|
||||
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
pthread_include_dirs = [ "$TEST_UNITTEST_DIR/process/basic/pthread" ]
|
||||
|
||||
pthread_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/process/basic/pthread/process_pthread_test.cpp" ]
|
||||
|
||||
pthread_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_atfork_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_atfork_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_once_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_019.cpp",
|
||||
]
|
||||
|
||||
pthread_sources_full = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_014.cpp",
|
||||
]
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* 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 int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_pthreadTestCount = 0;
|
||||
static int g_threadTestCount1 = 0;
|
||||
|
||||
static void *ThreadFunc5(void *ptr)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
int ret;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_threadTestCount1, 2, g_threadTestCount1, EXIT); // 2, here assert the result.
|
||||
g_threadTestCount1++;
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc4(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
pid_t pid = getpid();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 9, g_pthreadTestCount, EXIT); // 9, here assert the result.
|
||||
g_pthreadTestCount++; // 10
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
pid_t pid = getpid();
|
||||
|
||||
g_pthreadTestCount++; // 7
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(i, 10, i, EXIT); // 10, here assert the result.
|
||||
return (void *)i;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
pid_t pid = getpid();
|
||||
unsigned int ret;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 3, g_pthreadTestCount, EXIT); // 3, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 4
|
||||
|
||||
ret = pthread_join(pthread_self(), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc6(void *arg)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 12, g_pthreadTestCount, EXIT); // 12, here assert the result.
|
||||
g_pthreadTestCount++; // 13
|
||||
|
||||
return (void *)pthread_self();
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread;
|
||||
struct sched_param param = { 0 };
|
||||
pid_t pid = getpid();
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 2, g_pthreadTestCount, EXIT); // 2, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 3
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc2, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
usleep(1000 * 10 * 2); // 1000 * 10 * 2, for timing control.
|
||||
#endif
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 4, g_pthreadTestCount, EXIT); // 4, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 5
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc3, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_pthreadTestCount++; // 6
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 7, g_pthreadTestCount, EXIT); // 7, here assert the result.
|
||||
g_pthreadTestCount++; // 8
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc4, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 8, g_pthreadTestCount, EXIT); // 8, here assert the result.
|
||||
g_pthreadTestCount++; // 9
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 10, g_pthreadTestCount, EXIT); // 10, here assert the result.
|
||||
g_pthreadTestCount++; // 11
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PthreadTest001()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 0xf0000;
|
||||
g_threadTestCount1 = 0;
|
||||
g_pthreadTestCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_pthreadTestCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, g_currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 1, g_pthreadTestCount);
|
||||
g_pthreadTestCount++; // 2
|
||||
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc5, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 1, g_threadTestCount1);
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 2, g_threadTestCount1); // 2, here assert the result.
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 3, g_threadTestCount1); // 3, here assert the result.
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 11, g_pthreadTestCount); // 11, here assert the result.
|
||||
g_pthreadTestCount++; // 12
|
||||
|
||||
param.sched_priority = g_currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc6, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, for timing control.
|
||||
#endif
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 13, g_pthreadTestCount); // 13, here assert the result.
|
||||
g_pthreadTestCount++; // 14
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 14, g_pthreadTestCount); // 14, here assert the result.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_001", PthreadTest001, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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 int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_testCnt1 = 0;
|
||||
static volatile int g_testCnt2 = 0;
|
||||
static volatile int g_testPthredCount = 0;
|
||||
|
||||
static void ThreadWaitCount(int scount, volatile int *ent)
|
||||
{
|
||||
int count = 0xf0000;
|
||||
while (*ent < scount) {
|
||||
while (count > 0) {
|
||||
count--;
|
||||
}
|
||||
count = 0xf0000;
|
||||
(*ent)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
struct sched_param param = { 0 };
|
||||
int threadPolicy, threadPri;
|
||||
int old;
|
||||
const int waitCount1 = 20;
|
||||
const int waitCount2 = 50;
|
||||
g_testCnt2 = 0;
|
||||
|
||||
ThreadWaitCount(waitCount1 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
while (g_testCnt1 < 10) { // 10, wait until g_testCnt1 >= 10.
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt1;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_FIFO, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, (g_currThreadPri + 1), param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, old, g_testCnt1, EXIT);
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt1;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_RR, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, g_currThreadPri, param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, old, g_testCnt1, EXIT);
|
||||
|
||||
ret = pthread_setschedprio(pthread_self(), g_currThreadPri + 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, 170, g_testCnt2, EXIT); // 170, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
struct sched_param param = { 0 };
|
||||
int threadPolicy, threadPri;
|
||||
int ret;
|
||||
int old = 0;
|
||||
const int waitCount1 = 20;
|
||||
const int waitCount2 = 50;
|
||||
|
||||
g_testCnt1 = 0;
|
||||
|
||||
ThreadWaitCount(waitCount1 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
while (g_testCnt2 < 10) { // 10, wait until g_testCnt2 >= 10.
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
g_testPthredCount++;
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt2;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_FIFO, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, (g_currThreadPri + 1), param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, old, g_testCnt2, EXIT);
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt2;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_RR, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, g_currThreadPri, param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, old, g_testCnt2, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, 120, g_testCnt1, EXIT); // 120, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
|
||||
g_testPthredCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 1, g_testPthredCount);
|
||||
g_testPthredCount++; // 2
|
||||
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 2, g_testPthredCount); // 2, here assert the result.
|
||||
g_testPthredCount++; // 3
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 7, g_testPthredCount); // 7, here assert the result.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* 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 int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_pthreadTestCount = 0;
|
||||
static volatile int g_threadTestCount1 = 0;
|
||||
static pthread_spinlock_t g_spinTestLock;
|
||||
|
||||
static void *ThreadFunc8(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int ret;
|
||||
|
||||
ret = pthread_detach(pthread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc7(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int ret;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ret = pthread_detach(pthread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc8, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
sleep(2); // 2, delay
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc5(void *arg)
|
||||
{
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc7, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc6(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 12, g_pthreadTestCount, EXIT); // 12, here assert the result.
|
||||
g_pthreadTestCount++; // 13
|
||||
|
||||
return (void *)(uintptr_t)pthread;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc4(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 9, g_pthreadTestCount, EXIT); // 9, here assert the result.
|
||||
g_pthreadTestCount++; // 10
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 6, g_pthreadTestCount, EXIT); // 6, here assert the result.
|
||||
g_pthreadTestCount++; // 7
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(i, 10, i, EXIT); // 10, here assert the result.
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *threadFunc2(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 3, g_pthreadTestCount, EXIT); // 3, here assert the result.
|
||||
g_pthreadTestCount++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(pthread_self(), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *threadFunc(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 2, g_pthreadTestCount, EXIT); // 2, here assert the result.
|
||||
g_pthreadTestCount++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
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.
|
||||
g_pthreadTestCount++; // 5
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 2; // 2, adjust priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc3, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 5, g_pthreadTestCount, EXIT); // 5, here assert the result.
|
||||
g_pthreadTestCount++; // 6
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 7, g_pthreadTestCount, EXIT); // 7, here assert the result.
|
||||
g_pthreadTestCount++; // 8
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 3; // 3, adjust priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc4, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 8, g_pthreadTestCount, EXIT); // 8, here assert the result.
|
||||
g_pthreadTestCount++; // 9
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 10, g_pthreadTestCount, EXIT); // 10, here assert the result.
|
||||
g_pthreadTestCount++; // 11
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PthreadTest004()
|
||||
{
|
||||
int exitCount = 0;
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
const int testCount = 5;
|
||||
int count = 5;
|
||||
pthread_spin_init(&g_spinTestLock, 0);
|
||||
|
||||
g_threadTestCount1 = 0;
|
||||
g_pthreadTestCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_pthreadTestCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, threadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 1, g_pthreadTestCount);
|
||||
g_pthreadTestCount++;
|
||||
|
||||
while (count > 0) {
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc5, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
count--;
|
||||
}
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 1, g_threadTestCount1);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_threadTestCount1 != (1 + (testCount * 3))) { // 3
|
||||
sleep(2); // 2, delay
|
||||
printf("Wait for the concurrent thread to end \n");
|
||||
exitCount++;
|
||||
if (exitCount > 10) { // wait time > 10 * 2s, cancel wait.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 11, g_pthreadTestCount); // 11, here assert the result.
|
||||
g_pthreadTestCount++; // 12
|
||||
|
||||
param.sched_priority = g_currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc6, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 13, g_pthreadTestCount); // 13, here assert the result.
|
||||
g_pthreadTestCount++; // 14
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 14, g_pthreadTestCount); // 14, here assert the result.
|
||||
|
||||
pthread_spin_destroy(&g_spinTestLock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_004", PthreadTest004, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
extern int PthreadTest001(void);
|
||||
extern int PthreadTest004(void);
|
||||
|
||||
static void *threadFunc(void *a)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
(void)PthreadTest004();
|
||||
(void)PthreadTest001();
|
||||
exit(12); // 12, set a special exit code.
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
sleep(10); // 10, delay for timimg control.
|
||||
|
||||
ret = PthreadTest001();
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
(void)waitpid(pid, &status, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
pthread_t tid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = pthread_create(&tid, NULL, threadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(10); // 10, set a special exit code.
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
sleep(10); // 10, delay for timimg control.
|
||||
(void)PthreadTest004();
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 10, status); // 10, assert the exit code.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, The pid will never exceed 100000.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_005", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "threads.h"
|
||||
static const int TEST_LOOP = 5000;
|
||||
|
||||
static int g_testCnt = 0;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int count = 1;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
g_testCnt = TEST_LOOP + 1000; // 1000, here set a special num.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc1(void *arg)
|
||||
{
|
||||
int count = 2;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int count = 3;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
int count = 4;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid, tid1, tid2, tid3;
|
||||
pthread_attr_t attr = { 0 };
|
||||
int scope = 0;
|
||||
int threadPolicy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
g_testCnt = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_create(&tid, NULL, ThreadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid1, NULL, ThreadFunc1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, NULL, ThreadFunc2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid3, NULL, ThreadFunc3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
g_testCnt++;
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
param.sched_priority -= 2; // 2, adjust the priority.
|
||||
ret = pthread_setschedparam(tid, SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt, TEST_LOOP + 1000, g_testCnt, EXIT); // 1000, here assert the special num.
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid3, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority += 2; // 2, adjust the priority.
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread014(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_014", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
84
testsuites/unittest/process/basic/pthread/it_pthread_test.h
Normal file
84
testsuites/unittest/process/basic/pthread/it_pthread_test.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef _IT_PTHREAD_TEST_H
|
||||
#define _IT_PTHREAD_TEST_H
|
||||
|
||||
#include "osTest.h"
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
|
||||
#define SLEEP_AND_YIELD(tick) usleep((tick)*10 * 1000)
|
||||
|
||||
#include "sys/syscall.h"
|
||||
|
||||
static inline int Syscall(int nbr, int parm1, int parm2, int parm3, int parm4)
|
||||
{
|
||||
register int reg7 __asm__("r7") = (int)(nbr);
|
||||
register int reg3 __asm__("r3") = (int)(parm4);
|
||||
register int reg2 __asm__("r2") = (int)(parm3);
|
||||
register int reg1 __asm__("r1") = (int)(parm2);
|
||||
register int reg0 __asm__("r0") = (int)(parm1);
|
||||
|
||||
__asm__ __volatile__("svc 0" : "=r"(reg0) : "r"(reg7), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3) : "memory");
|
||||
|
||||
return reg0;
|
||||
}
|
||||
extern INT32 g_iCunitErrCode;
|
||||
extern INT32 g_iCunitErrLineNo;
|
||||
|
||||
extern void ItTestPthread001(void);
|
||||
extern void ItTestPthread002(void);
|
||||
extern void ItTestPthread003(void);
|
||||
extern void ItTestPthread004(void);
|
||||
extern void ItTestPthread005(void);
|
||||
extern void ItTestPthread006(void);
|
||||
extern void ItTestPthread007(void);
|
||||
extern void ItTestPthread008(void);
|
||||
extern void ItTestPthread009(void);
|
||||
extern void ItTestPthread010(void);
|
||||
extern void ItTestPthread012(void);
|
||||
extern void ItTestPthread011(void);
|
||||
extern void ItTestPthread013(void);
|
||||
extern void ItTestPthread014(void);
|
||||
extern void ItTestPthread015(void);
|
||||
extern void ItTestPthread016(void);
|
||||
extern void ItTestPthread017(void);
|
||||
extern void ItTestPthread018(void);
|
||||
extern void ItTestPthread019(void);
|
||||
extern void ItTestPthreadAtfork001(void);
|
||||
extern void ItTestPthreadAtfork002(void);
|
||||
extern void ItTestPthreadOnce001(void);
|
||||
extern void ItTestPthreadCond001(void);
|
||||
extern void ItTestPthreadCond002(void);
|
||||
extern void ItTestPthreadCond003(void);
|
||||
extern void ItTestPthreadCond004(void);
|
||||
#endif
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* 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 "stdio.h"
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include "it_pthread_test.h"
|
||||
#include <sys/resource.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessPthreadTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int currThreadPolicy, ret;
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret);
|
||||
param.sched_priority = TASK_PRIO_TEST;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret);
|
||||
}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_003
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread003();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_006
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread006, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread006();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_007
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread007, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_008
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread008, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread008();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_009
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread009, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread009();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_010
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread010, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread010();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_011
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread011, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread011();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_012
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread012, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread012();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_013
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread013, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread013();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_015
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread015, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread015();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_016
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread016, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread016();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_018
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread018, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread018();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_019
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
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
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadOnce001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadOnce001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_atfork_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadAtfork001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_atfork_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadAtfork002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
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_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread001();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread002();
|
||||
}
|
||||
#endif
|
||||
/* *
|
||||
* @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_014
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread014, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread014();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 volatile int g_count = 0;
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_testAtforkCount = 0;
|
||||
static int g_testAtforkPrepare = 0;
|
||||
static int g_testAtforkParent = 0;
|
||||
static int g_testAtforkChild = 0;
|
||||
static const int SLEEP_TIME = 2;
|
||||
|
||||
static void Prepare()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkPrepare++;
|
||||
}
|
||||
|
||||
static void Parent()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkParent++;
|
||||
}
|
||||
|
||||
static void child()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkChild++;
|
||||
}
|
||||
|
||||
static void *ThreadProc(void *arg)
|
||||
{
|
||||
int err;
|
||||
|
||||
while (g_count < 5) { // 5, wait until g_count == 5.
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_count++;
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadAtforkTest(void *arg)
|
||||
{
|
||||
int err;
|
||||
pid_t pid;
|
||||
pthread_t tid;
|
||||
int status = 0;
|
||||
|
||||
g_count = 0;
|
||||
g_testAtforkCount = 0;
|
||||
g_testAtforkPrepare = 0;
|
||||
g_testAtforkParent = 0;
|
||||
g_testAtforkChild = 0;
|
||||
|
||||
err = pthread_create(&tid, NULL, ThreadProc, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
err = pthread_atfork(Prepare, Parent, child);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
g_testAtforkCount++;
|
||||
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT);
|
||||
|
||||
if (pid == 0) {
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkChild, 1, g_testAtforkChild, EXIT);
|
||||
int status;
|
||||
while (g_count < 5) { // 5, wait until g_count == 5.
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_count++;
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
}
|
||||
exit(15); // 15, set exit status
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT);
|
||||
err = pthread_join(tid, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT);
|
||||
|
||||
err = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(err, pid, err, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(status, 15, status, EXIT); // 15, get exit status.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
|
||||
EXIT_WAIT:
|
||||
(void)waitpid(pid, &status, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadAtfork001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ATFORK_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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"
|
||||
#include <time.h>
|
||||
|
||||
extern int nanosleep(const struct timespec *req, struct timespec *rem);
|
||||
|
||||
static pthread_mutex_t g_mux = PTHREAD_MUTEX_INITIALIZER;
|
||||
static volatile int g_testAtforkCount = 0;
|
||||
static int g_testAtforkPrepare = 0;
|
||||
static int g_testAtforkParent = 0;
|
||||
|
||||
static void *Doit(void *arg)
|
||||
{
|
||||
int err;
|
||||
struct timespec ts = { 2, 0 }; // 2, set time 2s.
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT);
|
||||
|
||||
err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
(void)nanosleep(&ts, NULL);
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *Doit1(void *arg)
|
||||
{
|
||||
int err;
|
||||
struct timespec ts = { 2, 0 }; // 2, set time 2s.
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT);
|
||||
|
||||
err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
(void)nanosleep(&ts, NULL);
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void Prepare(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkPrepare++;
|
||||
}
|
||||
|
||||
static void Parent(void)
|
||||
{
|
||||
int err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkParent++;
|
||||
}
|
||||
|
||||
static void *PthreadAtforkTest(void *arg)
|
||||
{
|
||||
int err, ret;
|
||||
int pid;
|
||||
int status = 0;
|
||||
struct timespec ts = { 1, 0 };
|
||||
pthread_t tid;
|
||||
|
||||
g_testAtforkCount = 0;
|
||||
g_testAtforkPrepare = 0;
|
||||
g_testAtforkParent = 0;
|
||||
|
||||
err = pthread_atfork(Prepare, Parent, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_testAtforkCount++;
|
||||
err = pthread_create(&tid, NULL, Doit, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
nanosleep(&ts, NULL);
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT);
|
||||
if (pid == 0) {
|
||||
Doit1(NULL);
|
||||
exit(10); // 10, set exit status.
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT_WAIT); // 100000, The pid will never exceed 100000.
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT);
|
||||
|
||||
err = pthread_join(tid, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT);
|
||||
|
||||
|
||||
err = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(err, pid, err, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(status, 10, status, EXIT); // 10, get exit status.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
|
||||
EXIT_WAIT:
|
||||
(void)waitpid(pid, 0, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadAtfork002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ATFORK_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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_mutex_t g_pthreadMuxTest1;
|
||||
static pthread_cond_t g_pthdCondTest1;
|
||||
|
||||
static void *PthreadF01(void *t)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
LosTaskDelay(100);
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, here assert the result.
|
||||
g_testCount++;
|
||||
|
||||
rc = pthread_cond_wait(&g_pthdCondTest1, &g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // 5, here assert the result.
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadF02(void *t)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
|
||||
g_testCount++;
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, here assert the result.
|
||||
g_testCount++;
|
||||
rc = pthread_cond_signal(&g_pthdCondTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, here assert the result.
|
||||
g_testCount++;
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
LosTaskDelay(2); // 2, delay for Timing control.
|
||||
|
||||
EXIT:
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int i;
|
||||
long t1 = 1;
|
||||
long t2 = 2;
|
||||
int rc;
|
||||
pthread_t threads[3]; // 3, need 3 pthread for test.
|
||||
pthread_attr_t attr;
|
||||
const int loopNum = 2;
|
||||
|
||||
g_testCount = 0;
|
||||
pthread_mutex_init(&g_pthreadMuxTest1, NULL);
|
||||
pthread_cond_init(&g_pthdCondTest1, NULL);
|
||||
|
||||
rc = pthread_create(&threads[0], NULL, PthreadF01, (void *)t1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_create(&threads[1], NULL, PthreadF02, (void *)t2);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
for (i = 0; i < loopNum; i++) {
|
||||
rc = pthread_join(threads[i], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
rc = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&g_pthreadMuxTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
rc = pthread_cond_destroy(&g_pthdCondTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_001", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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_mutex_t g_pthreadMuxTest1;
|
||||
static pthread_cond_t g_pthrdCondTest1;
|
||||
static unsigned int g_pthreadExit = 0;
|
||||
|
||||
static void *PthreadF01(void *t)
|
||||
{
|
||||
int rc;
|
||||
unsigned int count = 0;
|
||||
const int testLoop = 2000;
|
||||
while (count < testLoop) {
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_wait(&g_pthrdCondTest1, &g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
count++;
|
||||
}
|
||||
|
||||
g_pthreadExit = 1;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadF02(void *t)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
while (g_pthreadExit != 1) {
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_signal(&g_pthrdCondTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int i;
|
||||
long t1 = 1;
|
||||
long t2 = 2;
|
||||
int rc;
|
||||
pthread_t threads[3];
|
||||
pthread_attr_t attr;
|
||||
const int loopNum = 2;
|
||||
|
||||
g_pthreadExit = 0;
|
||||
g_testCount = 0;
|
||||
pthread_mutex_init(&g_pthreadMuxTest1, NULL);
|
||||
pthread_cond_init(&g_pthrdCondTest1, NULL);
|
||||
|
||||
rc = pthread_create(&threads[0], NULL, PthreadF01, (void *)t1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_create(&threads[1], NULL, PthreadF02, (void *)t2);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
for (i = 0; i < loopNum; i++) {
|
||||
rc = pthread_join(threads[i], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
rc = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&g_pthreadMuxTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
rc = pthread_cond_destroy(&g_pthrdCondTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_002", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 int g_number = 0;
|
||||
static int g_okStatus = 777; // 777, a special number indicate the status is ok.
|
||||
static pthread_once_t g_onceCtrl = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void InitRoutine(void)
|
||||
{
|
||||
g_number++;
|
||||
}
|
||||
|
||||
static void *Threadfunc(void *parm)
|
||||
{
|
||||
int err;
|
||||
err = pthread_once(&g_onceCtrl, InitRoutine);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
return (void *)g_okStatus;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest(void *arg)
|
||||
{
|
||||
pthread_t thread[3];
|
||||
int rc = 0;
|
||||
int i = 3;
|
||||
void *status;
|
||||
const int threadsNum = 3;
|
||||
|
||||
g_number = 0;
|
||||
|
||||
for (i = 0; i < threadsNum; ++i) {
|
||||
rc = pthread_create(&thread[i], NULL, Threadfunc, NULL);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
}
|
||||
|
||||
for (i = 0; i < threadsNum; ++i) {
|
||||
rc = pthread_join(thread[i], &status);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
ICUNIT_GOTO_EQUAL((unsigned int)status, (unsigned int)g_okStatus, status, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_number, 1, g_number, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
g_onceCtrl = PTHREAD_ONCE_INIT;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadOnce001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ONCE_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* ***************************************************************************
|
||||
* Public Functions
|
||||
* ************************************************************************** */
|
||||
|
||||
static int g_currThreadPri, g_currThreadPolicy;
|
||||
static int g_testPthredCount;
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int policy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_getschedparam(pthread, &policy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPri, param.sched_priority, param.sched_priority, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPolicy, policy, policy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testPthredCount, 2, g_testPthredCount, EXIT); // 2, here assert the result.
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int policy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_getschedparam(pthread, &policy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPri, param.sched_priority, param.sched_priority, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(policy, SCHED_FIFO, policy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testPthredCount, 4, g_testPthredCount, EXIT); // 4, here assert the result.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
|
||||
g_testPthredCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_testPthredCount++;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 2, g_testPthredCount); // 2, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 4, g_testPthredCount); // 4, here assert the result.
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_003", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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_barrier_t g_barrier;
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_threadTest[10];
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, PTHREAD_BARRIER_SERIAL_THREAD, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread;
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
int threadParam[10];
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
currThreadPri = param.sched_priority;
|
||||
const int testCount = 10;
|
||||
|
||||
g_testToCount001 = 0;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
ret = pthread_barrier_init(&g_barrier, NULL, testCount);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadParam[0] = 0;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest0, &threadParam[0]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_threadTest[0] = 0;
|
||||
|
||||
index = 1;
|
||||
while (index < (testCount - 1)) {
|
||||
threadParam[index] = index;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest1, &threadParam[index]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_threadTest[index] = 0;
|
||||
index++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount - 1, g_testToCount001);
|
||||
|
||||
threadParam[index] = index;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest2, &threadParam[index]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount, g_testToCount001);
|
||||
|
||||
index = 0;
|
||||
while (index < testCount) {
|
||||
threadParam[index] = index;
|
||||
ret = pthread_join(newPthread[index], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTest[index], index, g_threadTest[index]);
|
||||
index++;
|
||||
}
|
||||
|
||||
ret = pthread_barrier_destroy(&g_barrier);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_006", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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_t g_th;
|
||||
VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
sleep(1);
|
||||
g_testCount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc1115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc2115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 15); // 1000 * 10 * 15, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc3115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 6); // 1000 * 10 * 6, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
|
||||
int ret = 0;
|
||||
pthread_t th1;
|
||||
pthread_t th2;
|
||||
pthread_t th3;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&th1, &attr, PthreadFunc1115, NULL);
|
||||
pthread_create(&th2, &attr, PthreadFunc2115, NULL);
|
||||
pthread_create(&th3, &attr, PthreadFunc3115, NULL);
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 50); // 1000 * 10 * 50, delay for timimg control.
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 8, g_testCount); // 8, assert the exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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_t g_th;
|
||||
static VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
sleep(1);
|
||||
g_testCount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc1115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc2115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 15); // 1000 * 10 * 15, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc3115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 6); // 1000 * 10 * 6, delay for timimg control.
|
||||
|
||||
ret = pthread_detach(g_th);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_testCount++;
|
||||
;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
|
||||
int ret = 0;
|
||||
pthread_t th1;
|
||||
pthread_t th2;
|
||||
pthread_t th3;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&th1, &attr, PthreadFunc1115, NULL);
|
||||
pthread_create(&th2, &attr, PthreadFunc2115, NULL);
|
||||
pthread_create(&th3, &attr, PthreadFunc3115, NULL);
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 50); // 1000 * 10 * 50, delay for timimg control.
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 8, g_testCount); // 8, assert the exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_008", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_t g_th;
|
||||
static VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
int ret = pthread_detach(g_th);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_testCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
sleep(1);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread009(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_009", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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_barrier_t g_barrier;
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_threadTest[30];
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int currThreadPolicy;
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(uintptr_t)ret);
|
||||
int currThreadPri = param.sched_priority;
|
||||
|
||||
g_testToCount001++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread[30];
|
||||
int index = 0;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
const int testCount = 30;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
currThreadPri = param.sched_priority;
|
||||
g_testToCount001 = 0;
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = currThreadPri - 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index < testCount) {
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest0, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
index++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount, g_testToCount001);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread010(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_010", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "sys/syscall.h"
|
||||
|
||||
void child1(void)
|
||||
{
|
||||
int count = 0;
|
||||
int policy, pri, newPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t pthread = pthread_self();
|
||||
int tid = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
|
||||
int ret = pthread_getschedparam(pthread, &policy, ¶m);
|
||||
|
||||
pri = param.sched_priority;
|
||||
|
||||
while (1) {
|
||||
ret = pthread_getschedparam(pthread, &newPolicy, ¶m);
|
||||
if (ret != 0) {
|
||||
printf("pthread_getschedparam failed ! %d erro: %d\n", __LINE__, errno);
|
||||
exit(255); // 255, set a special exit code.
|
||||
}
|
||||
|
||||
if (newPolicy != policy || pri != param.sched_priority) {
|
||||
printf("pthread_getschedparam failed ! %d policy %d newPolicy pri %d param.sched_priority :%d\n", __LINE__,
|
||||
policy, newPolicy, pri, param.sched_priority);
|
||||
exit(255); // 255, set a special exit code.
|
||||
}
|
||||
|
||||
count++;
|
||||
};
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void child(void)
|
||||
{
|
||||
int ret;
|
||||
int loop = 0;
|
||||
int status = 0;
|
||||
const int loopNum = 50;
|
||||
const int countNum = 128;
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
child1();
|
||||
}
|
||||
|
||||
int tid = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
|
||||
for (int count = 0; count < countNum; count++) {
|
||||
if (count == tid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_pthread_join, count, 0, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_pthread_set_detach, count, 0, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_pthread_deatch, count, 0, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_sched_setparam, count, 20, -1, 0); // 20, param test
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_sched_getparam, count, -1, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_sched_setscheduler, count, SCHED_RR, 20, -1); // 20, param test
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_sched_getscheduler, count, -1, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = Syscall(SYS_tkill, count, SIGPWR, 0, 0);
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (count == countNum - 1) {
|
||||
loop++;
|
||||
if (loop == loopNum) {
|
||||
break;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kill(pid, SIGKILL);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
EXIT:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
if (pid == 0) {
|
||||
child();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(0);
|
||||
}
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert exit code.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthread011(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_011", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
ret = Syscall(SYS_set_thread_area, NULL, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = Syscall(SYS_set_thread_area, 0x100, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = Syscall(SYS_set_thread_area, 0x5000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = Syscall(SYS_set_thread_area, 0x5000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
ret = Syscall(SYS_set_thread_area, 0x40000000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = Syscall(SYS_set_thread_area, 0x40001000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
#else
|
||||
ret = Syscall(SYS_set_thread_area, 0x80000000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = Syscall(SYS_set_thread_area, 0x80001000, 0, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread012(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_012", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr = { 0 };
|
||||
int scope = 0;
|
||||
|
||||
ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOTSUP, ret);
|
||||
|
||||
ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_getscope(&attr, &scope);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(scope, PTHREAD_SCOPE_PROCESS, scope);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread013(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_013", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 VOID *PthreadTest115(VOID *arg) {}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t th1;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
int policy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
const int testThreadCount = 2000;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority += 2; // 2, adjust the priority.
|
||||
ret = pthread_attr_setschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int i = 0; i < testThreadCount; i++) {
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(th1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert the special exit code.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthread015(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_015", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
int ret = pthread_detach(pthread_self());
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(intptr_t)ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t th1;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
int policy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
const int testThreadCount = 2000;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority -= 2; // 2, adjust the priority.
|
||||
ret = pthread_attr_setschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int i = 0; i < testThreadCount; i++) {
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert the special exit code.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthread016(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_016", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 VOID *PthreadTest115(VOID *arg) {}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t th1;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
int policy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
const int testThreadCount = 2000;
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority -= 2; // 2, adjust the priority.
|
||||
ret = pthread_attr_setschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int i = 0; i < testThreadCount; i++) {
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert the special exit code.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthread017(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_017", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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"
|
||||
#define TEST_THREAD_COUNT 2000
|
||||
|
||||
static int g_testCnt = 0;
|
||||
|
||||
static void *PthreadTest116(VOID *arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadTest115(VOID *arg)
|
||||
{
|
||||
pthread_t th1;
|
||||
|
||||
int ret = pthread_create(&th1, NULL, PthreadTest116, 0);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(intptr_t)ret);
|
||||
|
||||
ret = pthread_join(th1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(intptr_t)ret);
|
||||
|
||||
g_testCnt++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t th1;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
int policy = 0;
|
||||
unsigned int *getStack = NULL;
|
||||
size_t getSize;
|
||||
struct sched_param param = { 0 };
|
||||
int stackSize = 0x3000;
|
||||
|
||||
g_testCnt = 0;
|
||||
|
||||
void *stack = malloc(stackSize);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)stack, 0, stack);
|
||||
|
||||
ret = pthread_attr_setstack(&attr, stack, stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_getstack(&attr, (void **)&getStack, &getSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getStack, stack, getStack);
|
||||
ICUNIT_ASSERT_EQUAL(getSize, stackSize, getSize);
|
||||
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(th1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testCnt, 1, g_testCnt);
|
||||
|
||||
free(stack);
|
||||
|
||||
stackSize = 3000;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
stack = malloc(stackSize);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)stack, 0, stack);
|
||||
|
||||
ret = pthread_attr_setstack(&attr, stack, stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_getstack(&attr, (void **)&getStack, &getSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getStack, stack, getStack);
|
||||
ICUNIT_ASSERT_EQUAL(getSize, stackSize, getSize);
|
||||
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(th1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testCnt, 2, g_testCnt); // 2, here, assert the result.
|
||||
|
||||
free(stack);
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert the special exit code.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthread018(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_018", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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"
|
||||
#define TEST_THREAD_COUNT 2000
|
||||
|
||||
static int g_testCnt = 0;
|
||||
|
||||
static void *PthreadTest116(VOID *arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadTest115(VOID *arg)
|
||||
{
|
||||
pthread_t th1;
|
||||
|
||||
int ret = pthread_create(&th1, NULL, PthreadTest116, 0);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(intptr_t)ret);
|
||||
|
||||
ret = pthread_join(th1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, (void *)(intptr_t)ret);
|
||||
|
||||
g_testCnt++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t th1;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
int policy = 0;
|
||||
unsigned int *getStack = NULL;
|
||||
size_t getSize;
|
||||
struct sched_param param = { 0 };
|
||||
int stackSize = 2047;
|
||||
void *stack = (void *)&getSize;
|
||||
|
||||
g_testCnt = 0;
|
||||
|
||||
ret = pthread_attr_setstack(&attr, stack, stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_attr_getstack(&attr, (void **)&getStack, &getSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
stackSize = 3000; // 3000, change stackSize, test again.
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
stack = (void *)0x1000;
|
||||
|
||||
ret = pthread_attr_setstack(&attr, stack, stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_getstack(&attr, (void **)&getStack, &getSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getStack, stack, getStack);
|
||||
ICUNIT_ASSERT_EQUAL(getSize, stackSize, getSize);
|
||||
|
||||
ret = pthread_create(&th1, &attr, PthreadTest115, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, set a special exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(WIFEXITED(status), 0, WIFEXITED(status));
|
||||
ICUNIT_ASSERT_EQUAL(WTERMSIG(status), SIGUSR2, WTERMSIG(status));
|
||||
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread019(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_019", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
Reference in New Issue
Block a user