fix: POSIX 测试用例补充
【背景】 kernel_litos_m 中需要补充 POSIX 相关的测试用例 【修改方案】 从 A 核中移植了一部分的POSIX 相关的测试用例 到 sample/posix 目录下 【影响】 对现有的产品编译不会有影响 Signed-off-by: yinjiaming <yinjiaming@huawei.com> Change-Id: Ib8ab772f9893e243ace9319cb7af1486a6bd2937
This commit is contained in:
parent
b24353cf4b
commit
383a1d23e9
|
@ -28,6 +28,16 @@
|
||||||
|
|
||||||
static_library("test_posix") {
|
static_library("test_posix") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"mutex/It_posix_mutex.c",
|
||||||
|
"mutex/It_posix_mutex_001.c",
|
||||||
|
"mutex/It_posix_mutex_002.c",
|
||||||
|
"mutex/It_posix_mutex_003.c",
|
||||||
|
"mutex/It_posix_mutex_004.c",
|
||||||
|
"mutex/It_posix_mutex_005.c",
|
||||||
|
"mutex/It_posix_mutex_006.c",
|
||||||
|
"mutex/It_posix_mutex_007.c",
|
||||||
|
"mutex/It_posix_mutex_008.c",
|
||||||
|
"mutex/It_posix_mutex_009.c",
|
||||||
"pthread/It_posix_pthread.c",
|
"pthread/It_posix_pthread.c",
|
||||||
"pthread/It_posix_pthread_001.c",
|
"pthread/It_posix_pthread_001.c",
|
||||||
"pthread/It_posix_pthread_002.c",
|
"pthread/It_posix_pthread_002.c",
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread)
|
||||||
|
{
|
||||||
|
UINT32 uwRet = 0;
|
||||||
|
|
||||||
|
uwRet = pthread_join(thread, NULL);
|
||||||
|
ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
|
||||||
|
|
||||||
|
uwRet = pthread_attr_destroy(attr);
|
||||||
|
ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
NOK:
|
||||||
|
return LOS_NOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri)
|
||||||
|
{
|
||||||
|
UINT32 uwRet = 0;
|
||||||
|
struct sched_param sp;
|
||||||
|
|
||||||
|
uwRet = pthread_attr_init(attr);
|
||||||
|
ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
|
||||||
|
|
||||||
|
uwRet = pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
|
||||||
|
ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
|
||||||
|
|
||||||
|
sp.sched_priority = pri;
|
||||||
|
uwRet = pthread_attr_setschedparam(attr, &sp);
|
||||||
|
ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
NOK:
|
||||||
|
return LOS_NOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TestExtraTaskDelay(UINT32 uwTick)
|
||||||
|
{
|
||||||
|
#ifdef LOSCFG_KERNEL_SMP
|
||||||
|
// trigger task schedule may occor on another core
|
||||||
|
// needs adding delay and checking status later
|
||||||
|
LosTaskDelay(uwTick);
|
||||||
|
#else
|
||||||
|
// do nothing
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID ItSuitePosixMutex(void)
|
||||||
|
{
|
||||||
|
PRINTF("*********** Begin sample posix mutex test ************\n");
|
||||||
|
ItPosixMux001();
|
||||||
|
ItPosixMux002();
|
||||||
|
ItPosixMux003();
|
||||||
|
ItPosixMux004();
|
||||||
|
ItPosixMux005();
|
||||||
|
ItPosixMux006();
|
||||||
|
ItPosixMux007();
|
||||||
|
ItPosixMux008();
|
||||||
|
ItPosixMux009();
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* 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_MUTEX_H
|
||||||
|
#define _IT_POSIX_MUTEX_H
|
||||||
|
|
||||||
|
#include "osTest.h"
|
||||||
|
#include "pthread.h"
|
||||||
|
#include "errno.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "semaphore.h"
|
||||||
|
#include "unistd.h"
|
||||||
|
|
||||||
|
#ifdef LOSCFG_DEBUG_DEADLOCK
|
||||||
|
#define TEST_MUTEX_INIT \
|
||||||
|
{ \
|
||||||
|
{ 0, 0, 0, 0 }, \
|
||||||
|
{ \
|
||||||
|
{ 0, 0 }, { 0, 0 }, 0, 0 \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define TEST_MUTEX_INIT \
|
||||||
|
{ \
|
||||||
|
{ 0, 0, 0, 0 }, \
|
||||||
|
{ \
|
||||||
|
{ 0, 0 }, 0, 0 \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread);
|
||||||
|
UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri);
|
||||||
|
void TestExtraTaskDelay(UINT32 tick);
|
||||||
|
|
||||||
|
VOID ItPosixMux001(void);
|
||||||
|
VOID ItPosixMux002(void);
|
||||||
|
VOID ItPosixMux003(void);
|
||||||
|
VOID ItPosixMux004(void);
|
||||||
|
VOID ItPosixMux005(void);
|
||||||
|
VOID ItPosixMux006(void);
|
||||||
|
VOID ItPosixMux007(void);
|
||||||
|
VOID ItPosixMux008(void);
|
||||||
|
VOID ItPosixMux009(void);
|
||||||
|
|
||||||
|
VOID ItSuitePosixMutex(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -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_mutex.h"
|
||||||
|
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
pthread_mutex_t mutex1084 = TEST_MUTEX_INIT;
|
||||||
|
pthread_mutex_t mutex2084 = TEST_MUTEX_INIT;
|
||||||
|
|
||||||
|
ret = pthread_mutex_init(&mutex1084, NULL);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_trylock(&mutex1084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_init(&mutex2084, NULL);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_lock(&mutex2084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_trylock(&mutex2084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_unlock(&mutex1084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_destroy(&mutex1084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_unlock(&mutex2084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_destroy(&mutex2084);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux001
|
||||||
|
* @tc.desc: Test interface pthread_mutex_trylock
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux001(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux001", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL0, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
/* pthread_mutexattr_init 3-1.c
|
||||||
|
* Test that pthread_mutexattr_init()
|
||||||
|
* Upon successful completion, pthread_mutexattr_init() shall return a value of 0.
|
||||||
|
|
||||||
|
* Steps:
|
||||||
|
* 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
|
||||||
|
* 2. ENOMEM is the only uwErr it returns, so if it doesn't return that uwErr,
|
||||||
|
* the return number should be 0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t *mta = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = pthread_mutexattr_init(mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, EINVAL, rc, EXIT);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT:
|
||||||
|
pthread_mutexattr_destroy(mta);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux002
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_init
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux002(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux002", Testcase, TEST_POSIX, TEST_MUX, 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_mutex.h"
|
||||||
|
|
||||||
|
/* pthread_mutexattr_destroy 1-1.c
|
||||||
|
* Test that pthread_mutexattr_destroy()
|
||||||
|
* shall destroy a mutex attributes object.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init()
|
||||||
|
* 2. Destroy the attributes object using pthread_mutexattr_destroy()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t mta;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = pthread_mutexattr_init(&mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
rc = pthread_mutexattr_destroy(&mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT:
|
||||||
|
pthread_mutexattr_destroy(&mta);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux003
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_destroy
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux003(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux003", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
/* pthread_mutexattr_destroy 2-1.c
|
||||||
|
* Test pthread_mutexattr_destroy()
|
||||||
|
* A destroyed 'attr' attributes object can be reinitialized using
|
||||||
|
* pthread_mutexattr_init(); the results of otherwise referencing the
|
||||||
|
* object after it has been destroyed are undefined.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init()
|
||||||
|
* 2. Destroy that initialized attribute using pthread_mutexattr_destroy()
|
||||||
|
* 3. Initialize the pthread_mutexattr_t object again. This should not result
|
||||||
|
* in any uwErr.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t mta;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Initialize a mutex attributes object */
|
||||||
|
rc = pthread_mutexattr_init(&mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
/* Destroy the mutex attributes object */
|
||||||
|
rc = pthread_mutexattr_destroy(&mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||||
|
|
||||||
|
/* Initialize the mutex attributes object again. This shouldn't result in an uwErr. */
|
||||||
|
rc = pthread_mutexattr_init(&mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
rc = pthread_mutexattr_destroy(&mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT:
|
||||||
|
pthread_mutexattr_destroy(&mta);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux004
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_destroy
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux004(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux004", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
/* pthread_mutexattr_destroy 3-1.c
|
||||||
|
* Test pthread_mutexattr_destroy()
|
||||||
|
* Upon successful completion, pthread_mutexattr_destroy() shall
|
||||||
|
* return a value of 0.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init()
|
||||||
|
* 2. Destroy that initialized attribute using pthread_mutexattr_destroy().
|
||||||
|
* This should return 0;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t mta;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Initialize a mutex attributes object */
|
||||||
|
rc = pthread_mutexattr_init(&mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
/* Destroy the mutex attributes object */
|
||||||
|
rc = pthread_mutexattr_destroy(&mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT:
|
||||||
|
pthread_mutexattr_destroy(&mta);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux005
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_init
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux005(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux005", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
/* pthread_mutexattr_destroy 4-1.c
|
||||||
|
* Test pthread_mutexattr_destroy()
|
||||||
|
* If it fails, an uwErr number shall be returned to indicate the uwErr:
|
||||||
|
* [EINVAL] The value specified by 'attr' is invalid
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* Try to destroy a NULL mutex attributes object using pthread_mutexattr_destroy().
|
||||||
|
* If it returns EINVAL, the test passes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t *mta = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Try to destroy a NULL mutex attributes object using pthread_mutexattr_destroy()
|
||||||
|
* It should return EINVAL */
|
||||||
|
rc = pthread_mutexattr_destroy(mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, EINVAL, rc);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux006
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_destroy
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux006(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux006", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
static pthread_mutex_t g_mutex1, g_mutex2;
|
||||||
|
|
||||||
|
/* pthread_mutex_init 1-1.c
|
||||||
|
* Test that pthread_mutex_init()
|
||||||
|
* initializes a mutex referenced by 'mutex' with attributes specified
|
||||||
|
* by 'attr'. If 'attr' is NULL, the default mutex attributes are used.
|
||||||
|
* The effect shall be the same as passing the address of a default
|
||||||
|
* mutex attributes.
|
||||||
|
|
||||||
|
* NOTE: There is no direct way to judge if two mutexes have the same effect,
|
||||||
|
* thus this test does not cover the statement in the last sentence.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t mta;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Initialize a mutex attributes object */
|
||||||
|
rc = pthread_mutexattr_init(&mta);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
/* Initialize mutex1 with the default mutex attributes */
|
||||||
|
rc = pthread_mutex_init(&g_mutex1, &mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||||
|
|
||||||
|
/* Initialize mutex2 with NULL attributes */
|
||||||
|
rc = pthread_mutex_init(&g_mutex2, NULL);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||||
|
|
||||||
|
rc = pthread_mutexattr_destroy(&mta);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||||
|
|
||||||
|
rc = pthread_mutex_destroy(&g_mutex1);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||||
|
|
||||||
|
rc = pthread_mutex_destroy(&g_mutex2);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT3);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT1:
|
||||||
|
pthread_mutexattr_destroy(&mta);
|
||||||
|
|
||||||
|
EXIT2:
|
||||||
|
pthread_mutex_destroy(&g_mutex1);
|
||||||
|
|
||||||
|
EXIT3:
|
||||||
|
pthread_mutex_destroy(&g_mutex2);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux007
|
||||||
|
* @tc.desc: Test interface pthread_mutexattr_init
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux007(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux007", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -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_mutex.h"
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Initialize a mutex object */
|
||||||
|
rc = pthread_mutex_init(&mutex, NULL);
|
||||||
|
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||||
|
|
||||||
|
/* Acquire the mutex object using pthread_mutex_lock */
|
||||||
|
rc = pthread_mutex_lock(&mutex);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
/* Release the mutex object using pthread_mutex_unlock */
|
||||||
|
rc = pthread_mutex_unlock(&mutex);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||||
|
|
||||||
|
/* Destroy the mutex object */
|
||||||
|
rc = pthread_mutex_destroy(&mutex);
|
||||||
|
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||||
|
|
||||||
|
return LOS_OK;
|
||||||
|
|
||||||
|
EXIT2:
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
|
||||||
|
EXIT1:
|
||||||
|
pthread_mutex_destroy(&mutex);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux008
|
||||||
|
* @tc.desc: Test interface pthread_mutex_lock
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux008(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux008", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL0, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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_mutex.h"
|
||||||
|
|
||||||
|
static pthread_mutex_t g_mutex049;
|
||||||
|
|
||||||
|
static VOID *TaskF01(void *argument)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = pthread_mutex_trylock(&g_mutex049);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, 16, ret, EXIT); // 16, Here, assert the g_testCount.
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
EXIT:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static UINT32 Testcase(VOID)
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t mta;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pthread_attr_t attr;
|
||||||
|
pthread_t newTh;
|
||||||
|
|
||||||
|
ret = pthread_mutexattr_init(&mta);
|
||||||
|
ret = pthread_mutex_init(&g_mutex049, &mta);
|
||||||
|
|
||||||
|
ret = pthread_mutex_lock(&g_mutex049);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = PosixPthreadInit(&attr, 4); // 4, Set thread priority.
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_create(&newTh, &attr, TaskF01, NULL);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
|
||||||
|
ret = pthread_mutex_unlock(&g_mutex049);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
pthread_mutex_destroy(&g_mutex049);
|
||||||
|
|
||||||
|
ret = pthread_join(newTh, NULL);
|
||||||
|
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||||
|
return LOS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: ItPosixMux009
|
||||||
|
* @tc.desc: Test interface pthread_mutex_unlock
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueI5WZI6
|
||||||
|
*/
|
||||||
|
|
||||||
|
VOID ItPosixMux009(void)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("ItPosixMux009", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -35,6 +35,7 @@ void ItSuitePosix(void)
|
||||||
PRINTF("***********************BEGIN POSIX TEST**********************\n");
|
PRINTF("***********************BEGIN POSIX TEST**********************\n");
|
||||||
PthreadFuncTestSuite();
|
PthreadFuncTestSuite();
|
||||||
ItSuitePosixPthread();
|
ItSuitePosixPthread();
|
||||||
|
ItSuitePosixMutex();
|
||||||
PosixCtypeFuncTest();
|
PosixCtypeFuncTest();
|
||||||
PosixIsdigitFuncTest();
|
PosixIsdigitFuncTest();
|
||||||
PosixIslowerFuncTest();
|
PosixIslowerFuncTest();
|
||||||
|
|
Loading…
Reference in New Issue