fix: POSIX 测试用例后续补充

【背景】
POSIX 测试用例不完善

【修改方案】
继续将 A 核posix 相关的测试用例移植一部分到M核

【影响】
对现有的产品编译不会有影响。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I9a7fff077c5bc00609e51ba9121d93dc67895656
This commit is contained in:
yinjiaming 2022-10-09 15:13:15 +08:00
parent f3d606b6dd
commit 54a5365a25
11 changed files with 661 additions and 0 deletions

View File

@ -45,6 +45,15 @@ static_library("test_posix") {
"pthread/It_posix_pthread_014.c",
"pthread/It_posix_pthread_015.c",
"pthread/It_posix_pthread_016.c",
"pthread/It_posix_pthread_017.c",
"pthread/It_posix_pthread_018.c",
"pthread/It_posix_pthread_019.c",
"pthread/It_posix_pthread_020.c",
"pthread/It_posix_pthread_021.c",
"pthread/It_posix_pthread_022.c",
"pthread/It_posix_pthread_023.c",
"pthread/It_posix_pthread_024.c",
"pthread/It_posix_pthread_025.c",
"pthread_func_test.c",
]

View File

@ -62,4 +62,13 @@ VOID ItSuitePosixPthread()
ItPosixPthread014();
ItPosixPthread015();
ItPosixPthread016();
ItPosixPthread017();
ItPosixPthread018();
ItPosixPthread019();
ItPosixPthread020();
ItPosixPthread021();
ItPosixPthread022();
ItPosixPthread023();
ItPosixPthread024();
ItPosixPthread025();
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static int g_testCnt;
static VOID *PthreadF01(VOID *num)
{
intptr_t i = (intptr_t)num;
PRINTK("Passed argument for thread: %d, g_testCnt = %d\n", (int)i, g_testCnt);
ICUNIT_TRACK_EQUAL(g_testCnt, i, g_testCnt);
g_testCnt++;
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh;
long i;
INT32 ret;
g_testCnt = 1;
for (i = 1; i < PTHREAD_THREADS_NUM + 1; i++) {
ret = pthread_create(&newTh, NULL, PthreadF01, (void *)i);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_join(newTh, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
return LOS_OK;
EXIT:
pthread_detach(newTh);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread017
* @tc.desc: Test interface pthread_create
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread017(VOID)
{
TEST_ADD_CASE("ItPosixPthread017", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static VOID *PthreadF01(VOID *num)
{
int *arg = (int *)num;
for (int i = 0; i < PTHREAD_THREADS_NUM; i++) {
dprintf("Passed argument %d for thread\n", arg[i]);
ICUNIT_TRACK_EQUAL(arg[i], i + 1, arg[i]);
}
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh;
INT32 arg[PTHREAD_THREADS_NUM], ret;
for (int i = 0; i < PTHREAD_THREADS_NUM; i++) {
arg[i] = i + 1;
}
ret = pthread_create(&newTh, NULL, PthreadF01, (void *)&arg);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_join(newTh, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return LOS_OK;
EXIT:
pthread_detach(newTh);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread018
* @tc.desc: Test interface pthread_join
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread018(VOID)
{
TEST_ADD_CASE("ItPosixPthread018", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static VOID *PthreadF01(VOID *argument)
{
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh;
INT32 ret;
ret = pthread_create(&newTh, NULL, PthreadF01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_equal(newTh, newTh);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread019
* @tc.desc: Test interface pthread_equal
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread019(VOID)
{
TEST_ADD_CASE("ItPosixPthread019", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static VOID *PthreadF01(VOID *argument)
{
sleep(1);
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh1, newTh2;
INT32 ret;
ret = pthread_create(&newTh1, NULL, PthreadF01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh2, NULL, PthreadF01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_equal(newTh1, newTh2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh1, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh2, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread020
* @tc.desc: Test interface pthread_equal
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread020(VOID)
{
TEST_ADD_CASE("ItPosixPthread020", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static UINT32 Testcase(VOID)
{
pthread_attr_t newAttr;
INT32 detachState, ret;
ret = pthread_attr_init(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* The test passes if the attribute object has a detachstate of
* PTHREAD_CREATE_JOINABLE, which is the default value for this
* attribute. */
ret = pthread_attr_getdetachstate(&newAttr, &detachState);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(detachState, PTHREAD_CREATE_JOINABLE, detachState);
ret = pthread_attr_destroy(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread021
* @tc.desc: Test interface pthread_getdetachstate
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread021(VOID)
{
TEST_ADD_CASE("ItPosixPthread021", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static INT32 g_pthreadSchedPolicy = 0;
static VOID *PthreadF01(VOID *argument)
{
struct sched_param sparam;
INT32 priority, policy;
INT32 ret;
g_pthreadSchedPolicy = SCHED_RR;
priority = sched_get_priority_max(g_pthreadSchedPolicy);
sparam.sched_priority = priority;
ret = pthread_setschedparam(pthread_self(), g_pthreadSchedPolicy, &sparam);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ICUNIT_TRACK_EQUAL(policy, g_pthreadSchedPolicy, policy);
ICUNIT_TRACK_EQUAL(sparam.sched_priority, priority, sparam.sched_priority);
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh;
INT32 ret;
ret = pthread_create(&newTh, NULL, PthreadF01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread022
* @tc.desc: Test interface pthread_setschedparam
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread022(VOID)
{
TEST_ADD_CASE("ItPosixPthread022", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static UINT32 Testcase(VOID)
{
pthread_attr_t newAttr;
INT32 ret;
ret = pthread_attr_init(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_destroy(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_init(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_destroy(&newAttr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread023
* @tc.desc: Test interface pthread_attr_init
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread023(VOID)
{
TEST_ADD_CASE("ItPosixPthread023", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static VOID *PthreadF01(VOID *arg)
{
return NULL;
}
static UINT32 Testcase(VOID)
{
pthread_t newTh;
pthread_attr_t attr;
size_t stackSize = PTHREAD_STACK_MIN;
size_t ssize;
INT32 ret;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_getstacksize(&attr, &ssize);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(ssize, PTHREAD_DEFAULT_STACK_SIZE, ssize);
ret = pthread_attr_setstacksize(&attr, stackSize);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_getstacksize(&attr, &ssize);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(ssize, stackSize, ssize);
ret = pthread_create(&newTh, &attr, PthreadF01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_destroy(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread024
* @tc.desc: Test interface pthread_attr_getstacksize
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread024(VOID)
{
TEST_ADD_CASE("ItPosixPthread024", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 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.
*/
#include "It_posix_pthread.h"
static UINT32 Testcase(VOID)
{
INT32 ret;
pthread_attr_t attr;
INT32 g_pthreadScopeValue = 999; // 999, init
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setscope(&attr, g_pthreadScopeValue);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, errno);
ret = pthread_attr_destroy(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
/**
* @tc.name: ItPosixPthread025
* @tc.desc: Test interface pthread_attr_setscope
* @tc.type: FUNC
* @tc.require: issueI5TIRQ
*/
VOID ItPosixPthread025(VOID)
{
TEST_ADD_CASE("ItPosixPthread025", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
}