Signed-off-by: vincent <zhangadong@huawei.com>
This commit is contained in:
vincent 2022-10-28 09:33:36 +08:00
parent 478b41b457
commit 47f883c11a
19 changed files with 1426 additions and 0 deletions

View File

@ -49,6 +49,22 @@ static_library("test_posix") {
"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",

View File

@ -99,4 +99,20 @@ VOID ItSuitePosixMutex(void)
ItPosixMux018();
ItPosixMux019();
ItPosixMux020();
ItPosixMux021();
ItPosixMux022();
ItPosixMux023();
ItPosixMux024();
ItPosixMux025();
ItPosixMux026();
ItPosixMux027();
ItPosixMux028();
ItPosixMux029();
ItPosixMux030();
ItPosixMux031();
ItPosixMux032();
ItPosixMux033();
ItPosixMux034();
ItPosixMux035();
ItPosixMux036();
}

View File

@ -80,6 +80,22 @@ 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);

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_posix_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);
}

View 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);
}

View 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);
}

View 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);
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_posix_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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}