Compare commits
10 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
972d765c6e | ||
|
|
47f883c11a | ||
|
|
478b41b457 | ||
|
|
69d17d522c | ||
|
|
6e6cbe5de6 | ||
|
|
383a1d23e9 | ||
|
|
b24353cf4b | ||
|
|
f1ad086665 | ||
|
|
8fff50f59f | ||
|
|
a502a0917c |
@@ -449,6 +449,53 @@ LITE_TEST_CASE(CmsisFuncTestSuite, TestCmsis002, Function | MediumTest | Level1)
|
||||
return LOS_OK;
|
||||
};
|
||||
|
||||
static VOID timerCallback(void *arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestCmsisTimer001
|
||||
* @tc.desc: Timer Management test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5TQ0T
|
||||
*/
|
||||
LITE_TEST_CASE(CmsisFuncTestSuite, TestCmsisTimer001, Function | MediumTest | Level1)
|
||||
{
|
||||
osTimerId_t time_id;
|
||||
const char *timerGetName = NULL;
|
||||
osStatus_t ret;
|
||||
|
||||
time_id = osTimerNew(timerCallback, osTimerOnce, NULL, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(time_id, NULL, time_id);
|
||||
|
||||
ret = osTimerStart(time_id, 100U); // 100, just for test
|
||||
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
|
||||
|
||||
timerGetName = osTimerGetName(time_id);
|
||||
ICUNIT_GOTO_EQUAL(timerGetName, NULL, timerGetName, EXIT1);
|
||||
|
||||
ret = osTimerIsRunning(time_id);
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT1);
|
||||
|
||||
ret = osTimerStop(time_id);
|
||||
ICUNIT_GOTO_EQUAL(ret, osOK, ret, EXIT1);
|
||||
|
||||
ret = osTimerIsRunning(time_id);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
ret = osTimerDelete(time_id);
|
||||
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT1:
|
||||
ret = osTimerDelete(time_id);
|
||||
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
};
|
||||
|
||||
|
||||
void CmsisFuncTestSuite(void)
|
||||
{
|
||||
@@ -465,5 +512,7 @@ void CmsisFuncTestSuite(void)
|
||||
#endif
|
||||
|
||||
ADD_TEST_CASE(TestCmsis007);
|
||||
|
||||
ADD_TEST_CASE(TestCmsisTimer001);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,43 @@
|
||||
|
||||
static_library("test_posix") {
|
||||
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",
|
||||
"mutex/It_posix_mutex_010.c",
|
||||
"mutex/It_posix_mutex_011.c",
|
||||
"mutex/It_posix_mutex_012.c",
|
||||
"mutex/It_posix_mutex_013.c",
|
||||
"mutex/It_posix_mutex_014.c",
|
||||
"mutex/It_posix_mutex_015.c",
|
||||
"mutex/It_posix_mutex_016.c",
|
||||
"mutex/It_posix_mutex_017.c",
|
||||
"mutex/It_posix_mutex_018.c",
|
||||
"mutex/It_posix_mutex_019.c",
|
||||
"mutex/It_posix_mutex_020.c",
|
||||
"mutex/It_posix_mutex_021.c",
|
||||
"mutex/It_posix_mutex_022.c",
|
||||
"mutex/It_posix_mutex_023.c",
|
||||
"mutex/It_posix_mutex_024.c",
|
||||
"mutex/It_posix_mutex_025.c",
|
||||
"mutex/It_posix_mutex_026.c",
|
||||
"mutex/It_posix_mutex_027.c",
|
||||
"mutex/It_posix_mutex_028.c",
|
||||
"mutex/It_posix_mutex_029.c",
|
||||
"mutex/It_posix_mutex_030.c",
|
||||
"mutex/It_posix_mutex_031.c",
|
||||
"mutex/It_posix_mutex_032.c",
|
||||
"mutex/It_posix_mutex_033.c",
|
||||
"mutex/It_posix_mutex_034.c",
|
||||
"mutex/It_posix_mutex_035.c",
|
||||
"mutex/It_posix_mutex_036.c",
|
||||
"pthread/It_posix_pthread.c",
|
||||
"pthread/It_posix_pthread_001.c",
|
||||
"pthread/It_posix_pthread_002.c",
|
||||
|
||||
118
testsuites/sample/posix/mutex/It_posix_mutex.c
Normal file
118
testsuites/sample/posix/mutex/It_posix_mutex.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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();
|
||||
ItPosixMux010();
|
||||
ItPosixMux011();
|
||||
ItPosixMux012();
|
||||
ItPosixMux013();
|
||||
ItPosixMux014();
|
||||
ItPosixMux015();
|
||||
ItPosixMux016();
|
||||
ItPosixMux017();
|
||||
ItPosixMux018();
|
||||
ItPosixMux019();
|
||||
ItPosixMux020();
|
||||
ItPosixMux021();
|
||||
ItPosixMux022();
|
||||
ItPosixMux023();
|
||||
ItPosixMux024();
|
||||
ItPosixMux025();
|
||||
ItPosixMux026();
|
||||
ItPosixMux027();
|
||||
ItPosixMux028();
|
||||
ItPosixMux029();
|
||||
ItPosixMux030();
|
||||
ItPosixMux031();
|
||||
ItPosixMux032();
|
||||
ItPosixMux033();
|
||||
ItPosixMux034();
|
||||
ItPosixMux035();
|
||||
ItPosixMux036();
|
||||
}
|
||||
102
testsuites/sample/posix/mutex/It_posix_mutex.h
Normal file
102
testsuites/sample/posix/mutex/It_posix_mutex.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 ItPosixMux010(void);
|
||||
VOID ItPosixMux011(void);
|
||||
VOID ItPosixMux012(void);
|
||||
VOID ItPosixMux013(void);
|
||||
VOID ItPosixMux014(void);
|
||||
VOID ItPosixMux015(void);
|
||||
VOID ItPosixMux016(void);
|
||||
VOID ItPosixMux017(void);
|
||||
VOID ItPosixMux018(void);
|
||||
VOID ItPosixMux019(void);
|
||||
VOID ItPosixMux020(void);
|
||||
VOID ItPosixMux021(void);
|
||||
VOID ItPosixMux022(void);
|
||||
VOID ItPosixMux023(void);
|
||||
VOID ItPosixMux024(void);
|
||||
VOID ItPosixMux025(void);
|
||||
VOID ItPosixMux026(void);
|
||||
VOID ItPosixMux027(void);
|
||||
VOID ItPosixMux028(void);
|
||||
VOID ItPosixMux029(void);
|
||||
VOID ItPosixMux030(void);
|
||||
VOID ItPosixMux031(void);
|
||||
VOID ItPosixMux032(void);
|
||||
VOID ItPosixMux033(void);
|
||||
VOID ItPosixMux034(void);
|
||||
VOID ItPosixMux035(void);
|
||||
VOID ItPosixMux036(void);
|
||||
|
||||
VOID ItSuitePosixMutex(void);
|
||||
|
||||
#endif
|
||||
79
testsuites/sample/posix/mutex/It_posix_mutex_001.c
Normal file
79
testsuites/sample/posix/mutex/It_posix_mutex_001.c
Normal file
@@ -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);
|
||||
}
|
||||
68
testsuites/sample/posix/mutex/It_posix_mutex_002.c
Normal file
68
testsuites/sample/posix/mutex/It_posix_mutex_002.c
Normal file
@@ -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);
|
||||
}
|
||||
71
testsuites/sample/posix/mutex/It_posix_mutex_003.c
Normal file
71
testsuites/sample/posix/mutex/It_posix_mutex_003.c
Normal file
@@ -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);
|
||||
}
|
||||
84
testsuites/sample/posix/mutex/It_posix_mutex_004.c
Normal file
84
testsuites/sample/posix/mutex/It_posix_mutex_004.c
Normal file
@@ -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);
|
||||
}
|
||||
74
testsuites/sample/posix/mutex/It_posix_mutex_005.c
Normal file
74
testsuites/sample/posix/mutex/It_posix_mutex_005.c
Normal file
@@ -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);
|
||||
}
|
||||
66
testsuites/sample/posix/mutex/It_posix_mutex_006.c
Normal file
66
testsuites/sample/posix/mutex/It_posix_mutex_006.c
Normal file
@@ -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);
|
||||
}
|
||||
95
testsuites/sample/posix/mutex/It_posix_mutex_007.c
Normal file
95
testsuites/sample/posix/mutex/It_posix_mutex_007.c
Normal file
@@ -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);
|
||||
}
|
||||
76
testsuites/sample/posix/mutex/It_posix_mutex_008.c
Normal file
76
testsuites/sample/posix/mutex/It_posix_mutex_008.c
Normal 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_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);
|
||||
}
|
||||
86
testsuites/sample/posix/mutex/It_posix_mutex_009.c
Normal file
86
testsuites/sample/posix/mutex/It_posix_mutex_009.c
Normal file
@@ -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);
|
||||
}
|
||||
74
testsuites/sample/posix/mutex/It_posix_mutex_010.c
Normal file
74
testsuites/sample/posix/mutex/It_posix_mutex_010.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_mutexattr_t mta;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
int rc;
|
||||
|
||||
/* Initialize a mutex attributes object */
|
||||
rc = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Initialize a mutex object with the default mutex attributes */
|
||||
rc = pthread_mutex_init(&mutex, &mta);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||
|
||||
rc = pthread_mutexattr_destroy(&mta);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT2:
|
||||
pthread_mutex_destroy(&mutex);
|
||||
|
||||
EXIT1:
|
||||
pthread_mutexattr_destroy(&mta);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux010
|
||||
* @tc.desc: Test interface pthread_mutexattr_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux010(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux010", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
62
testsuites/sample/posix/mutex/It_posix_mutex_011.c
Normal file
62
testsuites/sample/posix/mutex/It_posix_mutex_011.c
Normal 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_mutex.h"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutexattr_t mta;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
(void)pthread_mutexattr_destroy(&mta);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux011
|
||||
* @tc.desc: Test interface pthread_mutexattr_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux011(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux011", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
66
testsuites/sample/posix/mutex/It_posix_mutex_012.c
Normal file
66
testsuites/sample/posix/mutex/It_posix_mutex_012.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
int rc;
|
||||
|
||||
/* Initialize a mutex attributes object */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Destroy the mutex attributes object */
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Initialize the mutex attributes object again. This shouldn't result in an error. */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux012
|
||||
* @tc.desc: Test interface pthread_mutex_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux012(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux012", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
105
testsuites/sample/posix/mutex/It_posix_mutex_013.c
Normal file
105
testsuites/sample/posix/mutex/It_posix_mutex_013.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
struct _scenar_028 {
|
||||
int m_type; /* Mutex type to use */
|
||||
int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */
|
||||
char *descr; /* Case description */
|
||||
};
|
||||
|
||||
struct _scenar_028 g_scenarii028[] = {
|
||||
{PTHREAD_MUTEX_DEFAULT, 0, "Default mutex"},
|
||||
{PTHREAD_MUTEX_NORMAL, 0, "Normal mutex"},
|
||||
{PTHREAD_MUTEX_ERRORCHECK, 0, "Errorcheck mutex"},
|
||||
{PTHREAD_MUTEX_RECURSIVE, 0, "Recursive mutex"},
|
||||
{PTHREAD_MUTEX_DEFAULT, 1, "Pshared mutex"},
|
||||
{PTHREAD_MUTEX_NORMAL, 1, "Pshared Normal mutex"},
|
||||
{PTHREAD_MUTEX_ERRORCHECK, 1, "Pshared Errorcheck mutex"},
|
||||
{PTHREAD_MUTEX_RECURSIVE, 1, "Pshared Recursive mutex"}
|
||||
};
|
||||
|
||||
#define NSCENAR (sizeof(g_scenarii028) / sizeof(g_scenarii028[0]))
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int i, j;
|
||||
pthread_mutex_t mtx;
|
||||
pthread_mutexattr_t ma[NSCENAR + 1];
|
||||
pthread_mutexattr_t *pma[NSCENAR + 2]; // 2, The loop frequency.
|
||||
|
||||
for (i = 0; i < NSCENAR; i++) {
|
||||
ret = pthread_mutexattr_init(&ma[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
ret = pthread_mutexattr_init(&ma[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (i = 0; i < NSCENAR + 2; i++) { // 2, The loop frequency.
|
||||
pma[i] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < NSCENAR + 2; i++) { // 2, The loop frequency.
|
||||
for (j = 0; j < NSCENAR + 2; j++) { // 2, The loop frequency.
|
||||
ret = pthread_mutex_init(&mtx, pma[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mtx);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mtx, pma[j]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mtx);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < NSCENAR + 1; i++) {
|
||||
ret = pthread_mutexattr_destroy(&ma[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux013
|
||||
* @tc.desc: Test interface pthread_mutexattr_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux013(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux013", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
62
testsuites/sample/posix/mutex/It_posix_mutex_014.c
Normal file
62
testsuites/sample/posix/mutex/It_posix_mutex_014.c
Normal 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_mutex.h"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
int rc;
|
||||
|
||||
/* Initialize a mutex object */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
pthread_mutex_destroy(&mutex);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux014
|
||||
* @tc.desc: Test interface pthread_mutex_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux014(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux014", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
79
testsuites/sample/posix/mutex/It_posix_mutex_015.c
Normal file
79
testsuites/sample/posix/mutex/It_posix_mutex_015.c
Normal file
@@ -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"
|
||||
|
||||
/* pthread_mutex_destroy 4-2.c
|
||||
* Test that when a pthread_mutex_destroy is called on a
|
||||
* locked mutex, it fails and returns EBUSY
|
||||
|
||||
* Steps:
|
||||
* 1. Create a mutex
|
||||
* 2. Lock the mutex
|
||||
* 3. Try to destroy the mutex
|
||||
* 4. Check that this may fail with EBUSY
|
||||
*/
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
int rc;
|
||||
|
||||
/* Lock the mutex */
|
||||
rc = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Try to destroy the locked mutex */
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, EBUSY, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux015
|
||||
* @tc.desc: Test interface pthread_mutex_lock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux015(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux015", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
80
testsuites/sample/posix/mutex/It_posix_mutex_016.c
Normal file
80
testsuites/sample/posix/mutex/It_posix_mutex_016.c
Normal file
@@ -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_mutex.h"
|
||||
|
||||
/* pthread_mutex_destroy 5-1.c
|
||||
* Test that pthread_mutex_destroy()
|
||||
* It shall be safe to destroy an initialized mutex that is unlocked.
|
||||
*/
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
/* Initialize mutex with the default mutex attributes */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Lock mutex */
|
||||
rc = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
sleep(1);
|
||||
/* Unlock */
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||
|
||||
/* Destroy mutex after it is unlocked */
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT1:
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
EXIT:
|
||||
pthread_mutex_destroy(&mutex);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux016
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux016(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux016", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
95
testsuites/sample/posix/mutex/It_posix_mutex_017.c
Normal file
95
testsuites/sample/posix/mutex/It_posix_mutex_017.c
Normal file
@@ -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 UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutexattr_t mta;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
sem_t sem;
|
||||
int pshared;
|
||||
|
||||
ret = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_init(&sem, pshared, 2); // 2, The initial number of available semaphores.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
(void)pthread_mutexattr_destroy(&mta);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux017
|
||||
* @tc.desc: Test interface sem_wait
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux017(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux017", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
71
testsuites/sample/posix/mutex/It_posix_mutex_018.c
Normal file
71
testsuites/sample/posix/mutex/It_posix_mutex_018.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
int rc;
|
||||
|
||||
/* Initialize a mutex object with the default mutex attributes */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Lock the mutex using pthread_mutex_lock() */
|
||||
rc = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT1);
|
||||
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT2);
|
||||
|
||||
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: ItPosixMux018
|
||||
* @tc.desc: Test interface pthread_mutex_lock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux018(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux018", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
60
testsuites/sample/posix/mutex/It_posix_mutex_019.c
Normal file
60
testsuites/sample/posix/mutex/It_posix_mutex_019.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_init(NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux019
|
||||
* @tc.desc: Test interface pthread_mutex_init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux019(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux019", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
87
testsuites/sample/posix/mutex/It_posix_mutex_020.c
Normal file
87
testsuites/sample/posix/mutex/It_posix_mutex_020.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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_mutex_unlock 1-1.c
|
||||
* Test that pthread_mutex_unlock()
|
||||
* shall release the mutex object 'mutex'.
|
||||
|
||||
* Steps:
|
||||
* -- initialize a mutex object
|
||||
* -- Get the mutex using pthread_mutex_lock()
|
||||
* -- Release the mutex using pthread_mutex_unlock()
|
||||
* -- Try to get the mutex using pthread_mutex_trylock()
|
||||
* -- Release the mutex using pthread_mutex_unlock()
|
||||
*
|
||||
*/
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* Get the mutex using pthread_mutex_lock() */
|
||||
rc = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Release the mutex using pthread_mutex_unlock() */
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Get the mutex using pthread_mutex_trylock() */
|
||||
rc = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Release the mutex using pthread_mutex_unlock() */
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
pthread_mutex_destroy(&mutex);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux020
|
||||
* @tc.desc: Test interface pthread_mutex_trylock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux020(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux020", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
66
testsuites/sample/posix/mutex/It_posix_mutex_021.c
Normal file
66
testsuites/sample/posix/mutex/It_posix_mutex_021.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_destroy(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux021
|
||||
* @tc.desc: Test interface pthread_mutex_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux021(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux021", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
99
testsuites/sample/posix/mutex/It_posix_mutex_022.c
Normal file
99
testsuites/sample/posix/mutex/It_posix_mutex_022.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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_mutex042;
|
||||
|
||||
static void *TaskF01(void *arg)
|
||||
{
|
||||
int ret;
|
||||
ret = pthread_mutex_unlock(&g_mutex042);
|
||||
ICUNIT_TRACK_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutexattr_t ma;
|
||||
pthread_t th;
|
||||
|
||||
ret = pthread_mutexattr_init(&ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutex042, &ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex042);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* destroy the mutex attribute object */
|
||||
ret = pthread_mutexattr_destroy(&ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&th, NULL, TaskF01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* Let the thread terminate */
|
||||
ret = pthread_join(th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
/* We can clean everything and exit */
|
||||
ret = pthread_mutex_unlock(&g_mutex042);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex042);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT3);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT1:
|
||||
pthread_mutex_unlock(&g_mutex042);
|
||||
|
||||
EXIT2:
|
||||
pthread_mutex_destroy(&g_mutex042);
|
||||
|
||||
EXIT3:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux022
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux022(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux022", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
89
testsuites/sample/posix/mutex/It_posix_mutex_023.c
Normal file
89
testsuites/sample/posix/mutex/It_posix_mutex_023.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 mutex = TEST_MUTEX_INIT;
|
||||
pthread_mutexattr_t ma;
|
||||
|
||||
ret = pthread_mutexattr_init(&ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
/* destroy the mutex attribute object */
|
||||
ret = pthread_mutexattr_destroy(&ma);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux023
|
||||
* @tc.desc: Test interface pthread_mutexattr_settype
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux023(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux023", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
87
testsuites/sample/posix/mutex/It_posix_mutex_024.c
Normal file
87
testsuites/sample/posix/mutex/It_posix_mutex_024.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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_mutex045;
|
||||
|
||||
static VOID *TaskF01(void *argument)
|
||||
{
|
||||
int ret;
|
||||
ret = pthread_mutex_trylock(&g_mutex045);
|
||||
ICUNIT_TRACK_EQUAL(ret, EBUSY, ret);
|
||||
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_mutex045, &mta);
|
||||
|
||||
ret = pthread_mutex_trylock(&g_mutex045);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_trylock(&g_mutex045);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, 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_mutex045);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_mutex_destroy(&g_mutex045);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux024
|
||||
* @tc.desc: Test interface pthread_mutex_trylock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux024(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux024", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
69
testsuites/sample/posix/mutex/It_posix_mutex_025.c
Normal file
69
testsuites/sample/posix/mutex/It_posix_mutex_025.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_lock(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux025
|
||||
* @tc.desc: Test interface pthread_mutex_lock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux025(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux025", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
76
testsuites/sample/posix/mutex/It_posix_mutex_026.c
Normal file
76
testsuites/sample/posix/mutex/It_posix_mutex_026.c
Normal 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_mutex.h"
|
||||
|
||||
/* pthread_mutex_trylock 3-1.c
|
||||
* Test that pthread_mutex_trylock()
|
||||
* Upon successful completion, it shall return a 0
|
||||
*
|
||||
*/
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
/* Initialize a mutex object with the default mutex attributes */
|
||||
rc = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Try to lock the mutex using pthread_mutex_trylock() */
|
||||
rc = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
(void)pthread_mutex_destroy(&mutex);
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux026
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux026(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux026", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
78
testsuites/sample/posix/mutex/It_posix_mutex_027.c
Normal file
78
testsuites/sample/posix/mutex/It_posix_mutex_027.c
Normal file
@@ -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_mutex.h"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_trylock(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux027
|
||||
* @tc.desc: Test interface pthread_mutex_trylock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux027(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux027", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
70
testsuites/sample/posix/mutex/It_posix_mutex_028.c
Normal file
70
testsuites/sample/posix/mutex/It_posix_mutex_028.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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_mutexattr_t mta;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutexattr_destroy(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux028
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux028(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux028", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
73
testsuites/sample/posix/mutex/It_posix_mutex_029.c
Normal file
73
testsuites/sample/posix/mutex/It_posix_mutex_029.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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_mutexattr_t mta;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutexattr_destroy(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux029
|
||||
* @tc.desc: Test interface pthread_mutex_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux029(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux029", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
72
testsuites/sample/posix/mutex/It_posix_mutex_030.c
Normal file
72
testsuites/sample/posix/mutex/It_posix_mutex_030.c
Normal 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_mutex.h"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_unlock(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_trylock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux030
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux030(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux030", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
66
testsuites/sample/posix/mutex/It_posix_mutex_031.c
Normal file
66
testsuites/sample/posix/mutex/It_posix_mutex_031.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux031
|
||||
* @tc.desc: Test interface pthread_mutex_destroy
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux031(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux031", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
111
testsuites/sample/posix/mutex/It_posix_mutex_032.c
Normal file
111
testsuites/sample/posix/mutex/It_posix_mutex_032.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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_mutex1076;
|
||||
static pthread_mutex_t g_mutex2076;
|
||||
|
||||
static VOID *TaskF01(void *arg)
|
||||
{
|
||||
UINT32 ret;
|
||||
ret = pthread_mutex_lock(&g_mutex1076);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex1076);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_t newTh;
|
||||
pthread_attr_t attr;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
g_testCount = 0;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutex1076, &mutexAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutex2076, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex1076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex1076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex1076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex1076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = PosixPthreadInit(&attr, 4); // 4, Set thread priority.
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, TaskF01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
LOS_TaskDelay(5); // 5, set delay time.
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex1076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex2076);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = PosixPthreadDestroy(&attr, newTh);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux032
|
||||
* @tc.desc: Test interface pthread_mutexattr_settype
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux032(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux032", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
74
testsuites/sample/posix/mutex/It_posix_mutex_033.c
Normal file
74
testsuites/sample/posix/mutex/It_posix_mutex_033.c
Normal file
@@ -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"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
|
||||
ret = pthread_mutex_init(&mutex, &mutexAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux033
|
||||
* @tc.desc: Test interface pthread_mutexattr_settype
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux033(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux033", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
86
testsuites/sample/posix/mutex/It_posix_mutex_034.c
Normal file
86
testsuites/sample/posix/mutex/It_posix_mutex_034.c
Normal file
@@ -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_mutex080;
|
||||
|
||||
static VOID *TaskF01(void *arg)
|
||||
{
|
||||
INT32 ret;
|
||||
ret = pthread_mutex_unlock(&g_mutex080);
|
||||
ICUNIT_TRACK_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
INT32 ret;
|
||||
pthread_t newTh;
|
||||
pthread_attr_t attr;
|
||||
|
||||
ret = pthread_mutex_init(&g_mutex080, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = PosixPthreadInit(&attr, 4); // 4, Set thread priority.
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, TaskF01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex080);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
LOS_TaskDelay(1);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex080);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex080);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = PosixPthreadDestroy(&attr, newTh);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux034
|
||||
* @tc.desc: Test interface pthread_mutex_lock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux034(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux034", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
131
testsuites/sample/posix/mutex/It_posix_mutex_035.c
Normal file
131
testsuites/sample/posix/mutex/It_posix_mutex_035.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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_mutex077;
|
||||
|
||||
static VOID *TaskF01(void *arg)
|
||||
{
|
||||
UINT32 ret;
|
||||
ret = pthread_mutex_trylock(&g_mutex077);
|
||||
ICUNIT_TRACK_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
g_testCount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
pthread_t newTh;
|
||||
pthread_attr_t attr;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
|
||||
g_testCount = 0;
|
||||
ret = pthread_mutex_lock(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutex077, &mutexAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = PosixPthreadInit(&attr, 4); // 4, Set thread priority.
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, TaskF01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
LOS_TaskDelay(5); // 5, set delay time.
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
TestExtraTaskDelay(1);
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount); // 2, Assert that g_testCount.
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutex077);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutex077);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux035
|
||||
* @tc.desc: Test interface pthread_mutexattr_settype
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux035(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux035", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
131
testsuites/sample/posix/mutex/It_posix_mutex_036.c
Normal file
131
testsuites/sample/posix/mutex/It_posix_mutex_036.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#define THREAD_NUM 5
|
||||
#define LOOPS 4
|
||||
|
||||
static g_value;
|
||||
static pthread_mutex_t g_mutex036 = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* pthread_mutex_lock 1-1.c
|
||||
* Test that pthread_mutex_lock()
|
||||
* shall lock the mutex object referenced by 'mutex'. If the mutex is
|
||||
* already locked, the calling thread shall block until the mutex becomes
|
||||
* available. This operation shall return with the mutex object referenced
|
||||
* by 'mutex' in the locked state with the calling thread as its owner.
|
||||
|
||||
* Steps:
|
||||
* -- Initialize a mutex to protect a global variable 'value'
|
||||
* -- Create N threads. Each is looped M times to acquire the mutex,
|
||||
* increase the value, and then release the mutex.
|
||||
* -- Check if the value has increased properly (M*N); a broken mutex
|
||||
* implementation may cause lost augments.
|
||||
*
|
||||
*/
|
||||
|
||||
static void *TaskF01(void *parm)
|
||||
{
|
||||
int i, tmp;
|
||||
int rc;
|
||||
|
||||
/* Loopd M times to acquire the mutex, increase the value,
|
||||
and then release the mutex. */
|
||||
for (i = 0; i < LOOPS; ++i) {
|
||||
rc = pthread_mutex_lock(&g_mutex036);
|
||||
if (rc != 0) {
|
||||
return (void *)(LOS_NOK);
|
||||
}
|
||||
|
||||
tmp = g_value;
|
||||
tmp = tmp + 1;
|
||||
sleep(1);
|
||||
g_value = tmp;
|
||||
|
||||
rc = pthread_mutex_unlock(&g_mutex036);
|
||||
if (rc != 0) {
|
||||
return (void *)(LOS_NOK);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return (void *)(LOS_OK);
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int i, rc;
|
||||
pthread_attr_t pta;
|
||||
pthread_t threads[THREAD_NUM];
|
||||
|
||||
g_value = 0;
|
||||
|
||||
rc = pthread_attr_init(&pta);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Create threads */
|
||||
for (i = 0; i < THREAD_NUM; ++i) {
|
||||
rc = pthread_create(&threads[i], &pta, TaskF01, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
/* Wait to join all threads */
|
||||
for (i = 0; i < THREAD_NUM; ++i) {
|
||||
rc = pthread_join(threads[i], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
rc = pthread_attr_destroy(&pta);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&g_mutex036);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
/* Check if the final value is as expected */
|
||||
ICUNIT_ASSERT_EQUAL(g_value, (THREAD_NUM) * LOOPS, g_value);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ItPosixMux035
|
||||
* @tc.desc: Test interface pthread_mutex_unlock
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5WZI6
|
||||
*/
|
||||
|
||||
VOID ItPosixMux036(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItPosixMux036", Testcase, TEST_POSIX, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ static UINT32 Testcase(VOID)
|
||||
ret = pthread_attr_setdetachstate(NULL, PTHREAD_CREATE_DETACHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE - 1);
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE - 2);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setdetachstate(&attr, 3); // 3, test the param of function.
|
||||
|
||||
@@ -47,9 +47,9 @@ static UINT32 Testcase(VOID)
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_destroy(&cond1);
|
||||
ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
rc = pthread_cond_destroy(&cond2);
|
||||
ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
|
||||
@@ -35,6 +35,7 @@ void ItSuitePosix(void)
|
||||
PRINTF("***********************BEGIN POSIX TEST**********************\n");
|
||||
PthreadFuncTestSuite();
|
||||
ItSuitePosixPthread();
|
||||
ItSuitePosixMutex();
|
||||
PosixCtypeFuncTest();
|
||||
PosixIsdigitFuncTest();
|
||||
PosixIslowerFuncTest();
|
||||
|
||||
Reference in New Issue
Block a user