commit
392e4c2cec
|
@ -27,7 +27,18 @@
|
|||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("test_posix") {
|
||||
sources = [ "pthread_func_test.c" ]
|
||||
sources = [
|
||||
"pthread/It_posix_pthread.c",
|
||||
"pthread/It_posix_pthread_001.c",
|
||||
"pthread/It_posix_pthread_002.c",
|
||||
"pthread/It_posix_pthread_003.c",
|
||||
"pthread/It_posix_pthread_004.c",
|
||||
"pthread/It_posix_pthread_005.c",
|
||||
"pthread/It_posix_pthread_006.c",
|
||||
"pthread/It_posix_pthread_007.c",
|
||||
"pthread/It_posix_pthread_008.c",
|
||||
"pthread_func_test.c",
|
||||
]
|
||||
|
||||
configs += [ "//kernel/liteos_m/testsuites:include" ]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
/*
|
||||
* return value of pthread_self() is 0 when
|
||||
* pthread create from LOS_TaskCreate()
|
||||
*/
|
||||
pthread_t TestPthreadSelf(void)
|
||||
{
|
||||
pthread_t tid = pthread_self();
|
||||
if (tid == 0) {
|
||||
tid = ((LosTaskCB *)(OsCurrTaskGet()))->taskID;
|
||||
}
|
||||
return tid;
|
||||
}
|
||||
|
||||
VOID ItSuitePosixPthread()
|
||||
{
|
||||
printf("************** begin SAMPLE POSIX pthread test *************\n");
|
||||
ItPosixPthread001();
|
||||
ItPosixPthread002();
|
||||
ItPosixPthread003();
|
||||
ItPosixPthread004();
|
||||
ItPosixPthread005();
|
||||
ItPosixPthread006();
|
||||
ItPosixPthread007();
|
||||
ItPosixPthread008();
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef IT_POSIX_PTHREAD_H
|
||||
#define IT_POSIX_PTHREAD_H
|
||||
|
||||
#include "sched.h"
|
||||
#include "signal.h"
|
||||
#include "semaphore.h"
|
||||
#include "sched.h"
|
||||
#include "osTest.h"
|
||||
#include "pthread.h"
|
||||
#include "limits.h"
|
||||
#include "unistd.h"
|
||||
#include "mqueue.h"
|
||||
#include "signal.h"
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#define PTHREAD_IS_ERROR (-1)
|
||||
#define PTHREAD_PRIORITY_TEST 20
|
||||
#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
|
||||
#define PTHREAD_KEY_NUM 10
|
||||
#define THREAD_NUM 3
|
||||
#define PTHREAD_TIMEOUT (THREAD_NUM * 2)
|
||||
#define PTHREAD_INTHREAD_TEST 0 /* Control going to or is already for Thread */
|
||||
#define PTHREAD_INMAIN_TEST 1 /* Control going to or is already for Main */
|
||||
#define INVALID_PSHARED_VALUE (-100)
|
||||
#define NUM_OF_CONDATTR 10
|
||||
#define RUNTIME 5
|
||||
#define PTHREAD_THREADS_NUM 3
|
||||
#define TCOUNT 5 // Number of single-threaded polling
|
||||
#define COUNT_LIMIT 7 // The number of times the signal is sent
|
||||
#define HIGH_PRIORITY 5
|
||||
#define LOW_PRIORITY 10
|
||||
#define PTHREAD_EXIT_VALUE ((void *)100) /* The return code of the thread when using pthread_exit(). */
|
||||
|
||||
#define PTHREAD_EXISTED_NUM TASK_EXISTED_NUM
|
||||
#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
#define PTHREAD_MUTEX_RECURSIVE 0
|
||||
#define PTHREAD_MUTEX_ERRORCHECK 0
|
||||
|
||||
#define PRIORITY_OTHER (-1)
|
||||
#define PRIORITY_FIFO 20
|
||||
#define PRIORITY_RR 20
|
||||
|
||||
#ifdef LOSCFG_AARCH64
|
||||
#define PTHREAD_STACK_MIN_TEST (PTHREAD_STACK_MIN * 3)
|
||||
#else
|
||||
#define PTHREAD_STACK_MIN_TEST PTHREAD_STACK_MIN
|
||||
#endif
|
||||
|
||||
pthread_t TestPthreadSelf(void);
|
||||
|
||||
VOID ItPosixPthread001(VOID);
|
||||
VOID ItPosixPthread002(VOID);
|
||||
VOID ItPosixPthread003(VOID);
|
||||
VOID ItPosixPthread004(VOID);
|
||||
VOID ItPosixPthread005(VOID);
|
||||
VOID ItPosixPthread006(VOID);
|
||||
VOID ItPosixPthread007(VOID);
|
||||
VOID ItPosixPthread008(VOID);
|
||||
VOID ItPosixPthread009(VOID);
|
||||
VOID ItPosixPthread010(VOID);
|
||||
VOID ItPosixPthread011(VOID);
|
||||
VOID ItPosixPthread012(VOID);
|
||||
VOID ItPosixPthread013(VOID);
|
||||
VOID ItPosixPthread014(VOID);
|
||||
VOID ItPosixPthread015(VOID);
|
||||
VOID ItPosixPthread016(VOID);
|
||||
VOID ItPosixPthread017(VOID);
|
||||
VOID ItPosixPthread018(VOID);
|
||||
VOID ItPosixPthread019(VOID);
|
||||
VOID ItPosixPthread020(VOID);
|
||||
VOID ItPosixPthread021(VOID);
|
||||
VOID ItPosixPthread022(VOID);
|
||||
VOID ItPosixPthread023(VOID);
|
||||
VOID ItPosixPthread024(VOID);
|
||||
VOID ItPosixPthread025(VOID);
|
||||
|
||||
#endif /* IT_POSIX_PTHREAD_H */
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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 *ThreadF01(void *arg)
|
||||
{
|
||||
sleep(1);
|
||||
|
||||
/* Shouldn't reach here. If we do, then the pthread_cancel()
|
||||
* function did not succeed. */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_t newTh;
|
||||
UINT32 ret;
|
||||
UINTPTR temp;
|
||||
|
||||
if (pthread_create(&newTh, NULL, ThreadF01, NULL) < 0) {
|
||||
uart_printf_func("Error creating thread\n");
|
||||
ICUNIT_ASSERT_EQUAL(1, 0, errno);
|
||||
}
|
||||
|
||||
LOS_TaskDelay(1);
|
||||
/* Try to cancel the newly created thread. If an error is returned,
|
||||
* then the thread wasn't created successfully. */
|
||||
if (pthread_cancel(newTh) != 0) {
|
||||
dprintf("Test FAILED: pthread cancel failed\n");
|
||||
ICUNIT_ASSERT_EQUAL(1, 0, errno);
|
||||
}
|
||||
|
||||
ret = pthread_join(newTh, (void *)&temp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(temp, 0, temp);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread001
|
||||
* @tc.desc: Test interface pthread_cancel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread001(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread001", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 *ThreadF01(void *arg)
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
sleep(1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
void *temp = NULL;
|
||||
pthread_t a;
|
||||
|
||||
if (pthread_create(&a, NULL, ThreadF01, NULL) != 0) {
|
||||
uart_printf_func("Error creating thread\n");
|
||||
ICUNIT_ASSERT_EQUAL(1, 0, errno);
|
||||
}
|
||||
|
||||
LOS_TaskDelay(1);
|
||||
if (pthread_cancel(a) != 0) {
|
||||
dprintf("Test failed: pthread cancel failed\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
/* If 'main' has reached here, then the test passed because it means
|
||||
* that the thread is truly asynchronise, and main isn't waiting for
|
||||
* it to return in order to move on. */
|
||||
|
||||
ret = pthread_join(a, &temp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(temp, PTHREAD_CANCELED, ret);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread002
|
||||
* @tc.desc: Test interface pthread_cancel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread002(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread002", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
ret = pthread_attr_init(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_attr_destroy(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread003
|
||||
* @tc.desc: Test interface pthread_attr_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread003(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread003", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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 attr;
|
||||
UINT32 ret;
|
||||
int detachstate;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setdetachstate(NULL, PTHREAD_CREATE_DETACHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE - 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, 3); // 3, test the param of function.
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getdetachstate(NULL, &detachstate);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getdetachstate(&attr, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getdetachstate(&attr, &detachstate);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(detachstate, PTHREAD_CREATE_DETACHED, detachstate, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread004
|
||||
* @tc.desc: Test interface pthread_setdetachstate
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread004(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread004", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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 attr;
|
||||
UINT32 ret;
|
||||
int inherit;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(NULL, PTHREAD_INHERIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED - 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED + 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getinheritsched(NULL, &inherit);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getinheritsched(&attr, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_getinheritsched(&attr, &inherit);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(inherit, PTHREAD_EXPLICIT_SCHED, inherit, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread005
|
||||
* @tc.desc: Test interface pthread_attr_setinheritsched
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread005(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread005", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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_condattr_t condattr;
|
||||
pthread_cond_t cond1;
|
||||
pthread_cond_t cond2;
|
||||
int rc;
|
||||
|
||||
rc = pthread_condattr_init(&condattr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_cond_init(&cond1, &condattr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_destroy(&cond1);
|
||||
ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT);
|
||||
rc = pthread_cond_destroy(&cond2);
|
||||
ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(void)pthread_cond_destroy(&cond1);
|
||||
(void)pthread_cond_destroy(&cond2);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread006
|
||||
* @tc.desc: Test interface pthread_cond_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread006(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread006", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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_condattr_t condattr;
|
||||
int rc;
|
||||
pthread_cond_t cond1, cond2;
|
||||
pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
/* Initialize a condition variable attribute object */
|
||||
rc = pthread_condattr_init(&condattr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Initialize cond1 with the default condition variable attribute */
|
||||
rc = pthread_cond_init(&cond1, &condattr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Initialize cond2 with NULL attributes */
|
||||
rc = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Destroy the condition variable attribute object */
|
||||
rc = pthread_condattr_destroy(&condattr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Destroy cond1 */
|
||||
rc = pthread_cond_destroy(&cond1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Destroy cond2 */
|
||||
rc = pthread_cond_destroy(&cond2);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Destroy cond3 */
|
||||
rc = pthread_cond_destroy(&cond3);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread007
|
||||
* @tc.desc: Test interface pthread_cond_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread007(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread007", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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 UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
INT32 ret;
|
||||
struct sched_param param;
|
||||
INT32 priority;
|
||||
INT32 offset = 0xff;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_pthreadSchedPolicy = SCHED_FIFO;
|
||||
ret = pthread_attr_setschedpolicy(&attr, g_pthreadSchedPolicy);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
priority = sched_get_priority_max(g_pthreadSchedPolicy);
|
||||
ICUNIT_ASSERT_EQUAL(priority, PTHREAD_IS_ERROR, priority);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
param.sched_priority = priority + offset;
|
||||
ret = pthread_attr_setschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOTSUP, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixPthread008
|
||||
* @tc.desc: Test interface pthread_attr_setschedpolicy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TIRQ
|
||||
*/
|
||||
|
||||
VOID ItPosixPthread008(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixPthread008", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
|
@ -34,6 +34,7 @@ void ItSuitePosix(void)
|
|||
{
|
||||
PRINTF("***********************BEGIN POSIX TEST**********************\n");
|
||||
PthreadFuncTestSuite();
|
||||
ItSuitePosixPthread();
|
||||
PosixCtypeFuncTest();
|
||||
PosixIsdigitFuncTest();
|
||||
PosixIslowerFuncTest();
|
||||
|
|
Loading…
Reference in New Issue