refactor: 删除旧测试套,拆分process用例适配门禁90s规则
close: #I4RE80 Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: I353fe4aa10e4f03e7cbaca572c8e73289c599c29
This commit is contained in:
@@ -74,44 +74,3 @@ if (LOSCFG_USER_TEST_MEM_VM == true) {
|
||||
sources_smoke += mem_vm_sources_smoke
|
||||
sources_full += mem_vm_sources_full
|
||||
}
|
||||
|
||||
# process module
|
||||
if (LOSCFG_USER_TEST_MUTEX == true) {
|
||||
import("./process/mutex/config.gni")
|
||||
common_include_dirs += mutex_include_dirs
|
||||
sources_entry += mutex_sources_entry
|
||||
sources_smoke += mutex_sources_smoke
|
||||
sources_full += mutex_sources_full
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_PROCESS == true) {
|
||||
import("./process/process/config.gni")
|
||||
common_include_dirs += process_include_dirs
|
||||
sources_entry += process_sources_entry
|
||||
sources_smoke += process_sources_smoke
|
||||
sources_full += process_sources_full
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_PTHREAD == true) {
|
||||
import("./process/pthread/config.gni")
|
||||
common_include_dirs += pthread_include_dirs
|
||||
sources_entry += pthread_sources_entry
|
||||
sources_smoke += pthread_sources_smoke
|
||||
sources_full += pthread_sources_full
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_RWLOCK == true) {
|
||||
import("./process/rwlock/config.gni")
|
||||
common_include_dirs += rwlock_include_dirs
|
||||
sources_entry += rwlock_sources_entry
|
||||
sources_smoke += rwlock_sources_smoke
|
||||
sources_full += rwlock_sources_full
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_SPINLOCK == true) {
|
||||
import("./process/spinlock/config.gni")
|
||||
common_include_dirs += spinlock_include_dirs
|
||||
sources_entry += spinlock_sources_entry
|
||||
sources_smoke += spinlock_sources_smoke
|
||||
sources_full += spinlock_sources_full
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# Copyright (c) 2022-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.
|
||||
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
mutex_include_dirs = [ "$TEST_UNITTEST_DIR/basic/process/mutex" ]
|
||||
|
||||
mutex_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/basic/process/mutex/process_mutex_test.cpp" ]
|
||||
|
||||
mutex_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_014.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/smoke/pthread_mutex_test_022.cpp",
|
||||
]
|
||||
|
||||
mutex_sources_full = [
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/full/pthread_mutex_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/full/pthread_mutex_test_023.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/full/pthread_mutex_test_024.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/mutex/full/pthread_mutex_test_025.cpp",
|
||||
]
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 10;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
if(timeVal.tv_usec + 100000 >= 1000000) { // 100000us, delay time; 1000000us, compare
|
||||
time.tv_sec = timeVal.tv_sec + 1;
|
||||
time.tv_nsec = (timeVal.tv_usec + 100000 - 1000000) * 1000; // 100000, delaytime; 1000, us to ns; 1000000us=1s;
|
||||
} else {
|
||||
time.tv_sec = timeVal.tv_sec + 0;
|
||||
time.tv_nsec = (timeVal.tv_usec + 100000) * 1000; // 1000, 100000us to ns
|
||||
}
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testToCount002, 1, g_testToCount002, EXIT);
|
||||
|
||||
g_testToCount001 = 1;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
int gCurrThreadPri, gCurrThreadPolicy;
|
||||
struct timeval time = { 0 };
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &gCurrThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
gCurrThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = gCurrThreadPri + 2;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2
|
||||
|
||||
ret = pthread_create(&newPthread1, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
while (1) {
|
||||
gettimeofday(&time, nullptr);
|
||||
if ((time.tv_sec - timeVal.tv_sec) >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex018(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_018", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_mutexLock;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
|
||||
static void *ThreadFuncTest1(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, EOWNERDEAD, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_consistent(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002++;
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid1, tid2;
|
||||
pthread_mutexattr_t attr;
|
||||
int robust;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, 0, robust);
|
||||
|
||||
ret = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, PTHREAD_MUTEX_ROBUST, robust);
|
||||
|
||||
pthread_mutex_init(&g_mutexLock, &attr);
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
|
||||
ret = pthread_create(&tid1, nullptr, ThreadFuncTest1, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, nullptr, ThreadFuncTest2, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_join(tid1, nullptr);
|
||||
pthread_join(tid2, nullptr);
|
||||
|
||||
while (g_testToCount001 == 0 || g_testToCount002 == 0) {
|
||||
}
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
|
||||
pthread_mutex_destroy(&g_mutexLock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex023(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_023", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest1(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ret = pthread_mutex_consistent(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, EOWNERDEAD, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
while (g_testToCount003 == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
g_testToCount002++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_consistent(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, EXIT);
|
||||
g_testToCount003 = 1;
|
||||
|
||||
for (int i = 0; i < 5; i++) { // 5
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
g_testToCount003++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount003 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid1, tid2, tid3;
|
||||
pthread_mutexattr_t attr;
|
||||
int robust;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, 0, robust);
|
||||
|
||||
ret = pthread_mutexattr_setrobust(&attr, 2); // 2
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_mutex_init(&g_muxLock002, &attr);
|
||||
ret = pthread_mutex_consistent(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, PTHREAD_MUTEX_ROBUST, robust);
|
||||
|
||||
pthread_mutex_init(&g_muxLock001, &attr);
|
||||
pthread_mutex_init(&g_muxLock003, &attr);
|
||||
|
||||
ret = pthread_mutex_consistent(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EPERM, ret);
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
|
||||
ret = pthread_create(&tid1, nullptr, ThreadFuncTest1, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, nullptr, ThreadFuncTest2, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_testToCount002 == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
ret = pthread_create(&tid3, nullptr, ThreadFuncTest3, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_join(tid1, nullptr);
|
||||
pthread_join(tid2, nullptr);
|
||||
pthread_join(tid3, nullptr);
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount003, -1, g_testToCount003);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock001);
|
||||
pthread_mutex_destroy(&g_muxLock002);
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex024(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_024", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_mutexLock;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
|
||||
static void *ThreadFuncTest1(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, EOWNERDEAD, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_consistent(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002++;
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Child()
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid1, tid2;
|
||||
pthread_mutexattr_t attr;
|
||||
int robust;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, 0, robust);
|
||||
|
||||
ret = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, PTHREAD_MUTEX_ROBUST, robust);
|
||||
|
||||
ret = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_STALLED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_mutexattr_getrobust(&attr, &robust);
|
||||
ICUNIT_ASSERT_EQUAL(robust, PTHREAD_MUTEX_STALLED, robust);
|
||||
|
||||
pthread_mutex_init(&g_mutexLock, &attr);
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
|
||||
ret = pthread_create(&tid1, nullptr, ThreadFuncTest1, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, nullptr, ThreadFuncTest2, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
for (int i = 0; i < 5; i++) { // 5
|
||||
if (g_testToCount002 == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_join(tid1, nullptr);
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount002, 0, g_testToCount002);
|
||||
|
||||
pthread_mutex_destroy(&g_mutexLock);
|
||||
|
||||
exit(255); // 255, set exitcode
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The expected value
|
||||
|
||||
if (pid == 0) {
|
||||
Child();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(status, 255, status); // 255, exitcode is 255
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex025(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_025", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_TEST_MUTEX_H
|
||||
#define _IT_TEST_MUTEX_H
|
||||
#include "osTest.h"
|
||||
#include "sys/time.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SLEEP_AND_YIELD(tick) usleep((tick)*10 * 1000)
|
||||
|
||||
extern int Gettid(void);
|
||||
extern void ItTestPthreadMutex001(void);
|
||||
extern void ItTestPthreadMutex002(void);
|
||||
extern void ItTestPthreadMutex003(void);
|
||||
extern void ItTestPthreadMutex004(void);
|
||||
extern void ItTestPthreadMutex005(void);
|
||||
extern void ItTestPthreadMutex006(void);
|
||||
extern void ItTestPthreadMutex007(void);
|
||||
extern void ItTestPthreadMutex008(void);
|
||||
extern void ItTestPthreadMutex009(void);
|
||||
extern void ItTestPthreadMutex010(void);
|
||||
extern void ItTestPthreadMutex011(void);
|
||||
extern void ItTestPthreadMutex012(void);
|
||||
extern void ItTestPthreadMutex013(void);
|
||||
extern void ItTestPthreadMutex014(void);
|
||||
extern void ItTestPthreadMutex015(void);
|
||||
extern void ItTestPthreadMutex016(void);
|
||||
extern void ItTestPthreadMutex017(void);
|
||||
extern void ItTestPthreadMutex018(void);
|
||||
extern void ItTestPthreadMutex019(void);
|
||||
extern void ItTestPthreadMutex020(void);
|
||||
extern void ItTestPthreadMutex021(void);
|
||||
extern void ItTestPthreadMutex022(void);
|
||||
extern void ItTestPthreadMutex023(void);
|
||||
extern void ItTestPthreadMutex024(void);
|
||||
extern void ItTestPthreadMutex025(void);
|
||||
|
||||
#endif
|
||||
@@ -1,334 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 "stdio.h"
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__attribute__((weak)) int Gettid()
|
||||
{
|
||||
return syscall(SYS_gettid);
|
||||
}
|
||||
|
||||
#include "it_mutex_test.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessMutexTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_001
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_002
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_003
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex003, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_004
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_005
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex005, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex005();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_006
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex006, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex006();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_007
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex007, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_008
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex008, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex008();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_009
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex009, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex009();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_010
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex010, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex010();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_011
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex011, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex011();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_012
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex012, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex012();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_013
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex013, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex013();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_014
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex014, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex014();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_015
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex015, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex015();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_016
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex016, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex016();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_017
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex017, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex017();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_019
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex019, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex019();
|
||||
}
|
||||
|
||||
#endif
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_020
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex020, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex020();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_021
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex021, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex021();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_022
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex022, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex022();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_018
|
||||
* @tc.desc: function for ProcessMutexTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex018, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex018();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_023
|
||||
* @tc.desc: function for test mutexattr robust
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex023, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex023();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_024
|
||||
* @tc.desc: function for test mutexattr robust:error return value
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex024, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex024();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_mutex_025
|
||||
* @tc.desc: test mutexattr robust:robustness product deadlock is not set
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessMutexTest, ItTestPthreadMutex025, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadMutex025();
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_mutexLock;
|
||||
|
||||
static const unsigned int TEST_COUNT = 5;
|
||||
static int g_testInfo[5] = { 0 };
|
||||
static int g_testToCount = 0;
|
||||
static int g_testBackCount = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[g_testToCount] = tid;
|
||||
g_testToCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[g_testBackCount], tid, tid, EXIT);
|
||||
g_testBackCount++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_mutexLock, &mutex);
|
||||
|
||||
while (index < 1) {
|
||||
g_testToCount = 0;
|
||||
g_testBackCount = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int count = 0; count < TEST_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testBackCount, TEST_COUNT, g_testBackCount);
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount, TEST_COUNT, g_testToCount);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&g_mutexLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock;
|
||||
|
||||
static const unsigned int TEST_COUNT = 5;
|
||||
static int g_testInfo[5] = { 0 };
|
||||
static int g_testToCount = 0;
|
||||
static int g_testBackCount = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[g_testToCount] = tid;
|
||||
g_testToCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testBackCount--;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock, &mutex);
|
||||
|
||||
param.sched_priority = 20; // 20, Set Priorities
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currThreadPri = param.sched_priority;
|
||||
|
||||
while (index < 2) { // 2
|
||||
g_testToCount = 0;
|
||||
g_testBackCount = TEST_COUNT - 1;
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int count = 0; count < TEST_COUNT; count++) {
|
||||
ret = pthread_attr_init(&a);
|
||||
param.sched_priority = currThreadPri - count - 1;
|
||||
if (param.sched_priority < 0) {
|
||||
param.sched_priority = 0;
|
||||
printf("sched_priority is zero !!!\n");
|
||||
}
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testBackCount, -1, g_testBackCount);
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount, TEST_COUNT, g_testToCount);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static const unsigned int THREAD_COUNT = 5;
|
||||
static pthread_mutex_t g_muxLock;
|
||||
static int g_preTaskPri = 0;
|
||||
static int g_testCnt = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testCnt++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
currThreadPri = param.sched_priority;
|
||||
|
||||
if (g_preTaskPri == 0xffffffff) {
|
||||
ICUNIT_GOTO_EQUAL(currThreadPri, 0, currThreadPri, EXIT);
|
||||
} else {
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(currThreadPri, g_preTaskPri, 31, currThreadPri, EXIT); // 31, Lowest priority
|
||||
}
|
||||
|
||||
g_preTaskPri = currThreadPri;
|
||||
g_testCnt--;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int count = 0;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
|
||||
g_preTaskPri = 0xffffffff;
|
||||
g_testCnt = 0;
|
||||
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock, &mutex);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = currThreadPri - 2 * count;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
param.sched_priority = currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
// 6, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = currThreadPri - 6;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority = 0;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority = currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority = currThreadPri;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
sleep(1);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testCnt, 0, g_testCnt);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_003", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int THREAD_COUNT = 10;
|
||||
|
||||
static int g_testInfo[3][10] = { 0 };
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_testBackCount001 = 0;
|
||||
static int g_testToCount002 = 0;
|
||||
static int g_testBackCount002 = 0;
|
||||
static int g_testToCount003 = 0;
|
||||
static int g_testBackCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[2][g_testToCount003] = tid; // 2, max indx
|
||||
g_testToCount003++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[2][g_testBackCount003], tid, tid, EXIT); // 2, max indx
|
||||
g_testBackCount003++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[1][g_testToCount002] = tid;
|
||||
g_testToCount002++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[1][g_testBackCount002], tid, tid, EXIT);
|
||||
g_testBackCount002++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
;
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[0][g_testToCount001] = tid;
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[0][g_testBackCount001], tid, tid, EXIT);
|
||||
g_testBackCount001++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
pthread_mutex_init(&g_muxLock002, &mutex);
|
||||
pthread_mutex_init(&g_muxLock003, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testBackCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testBackCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
g_testBackCount003 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock001);
|
||||
pthread_mutex_destroy(&g_muxLock002);
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_004", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int THREAD_COUNT = 10;
|
||||
|
||||
static int g_testInfo[3][10] = { 0 };
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_testBackCount001 = 0;
|
||||
static int g_testToCount002 = 0;
|
||||
static int g_testBackCount002 = 0;
|
||||
static int g_testToCount003 = 0;
|
||||
static int g_testBackCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid;
|
||||
pthread_t thread = pthread_self();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[2][g_testToCount003] = Gettid(); // 2, max indx
|
||||
g_testToCount003++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
tid = Gettid();
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[2][g_testBackCount003], tid, tid, EXIT); // 2, max indx
|
||||
g_testBackCount003++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid;
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[1][g_testToCount002] = Gettid();
|
||||
g_testToCount002++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
tid = Gettid();
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[1][g_testBackCount002], tid, tid, EXIT);
|
||||
g_testBackCount002++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid;
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[0][g_testToCount001] = Gettid();
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
tid = Gettid();
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[0][g_testBackCount001], tid, tid, EXIT);
|
||||
g_testBackCount001++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
pthread_mutex_init(&g_muxLock002, &mutex);
|
||||
pthread_mutex_init(&g_muxLock003, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testBackCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testBackCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
g_testBackCount003 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock001);
|
||||
pthread_mutex_destroy(&g_muxLock002);
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_005", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_mutexLock001;
|
||||
static pthread_mutex_t g_mutexLock002;
|
||||
static pthread_mutex_t g_mutexLock003;
|
||||
|
||||
static const unsigned int THREAD_COUNT = 10;
|
||||
|
||||
static int g_testInfo[3][10] = { 0 };
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_testBackCount001 = 0;
|
||||
static int g_testToCount002 = 0;
|
||||
static int g_testBackCount002 = 0;
|
||||
static int g_testToCount003 = 0;
|
||||
static int g_testBackCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[2][g_testToCount003] = tid; // 2, max indx
|
||||
g_testToCount003++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[2][g_testBackCount003], tid, tid, EXIT); // 2, max indx
|
||||
g_testBackCount003++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[1][g_testToCount002] = tid;
|
||||
g_testToCount002++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[1][g_testBackCount002], tid, tid, EXIT);
|
||||
g_testBackCount002++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testInfo[0][g_testToCount001] = tid;
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testInfo[0][g_testBackCount001], tid, tid, EXIT);
|
||||
g_testBackCount001++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_mutexLock001, &mutex);
|
||||
pthread_mutex_init(&g_mutexLock002, &mutex);
|
||||
pthread_mutex_init(&g_mutexLock003, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testBackCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testBackCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
g_testBackCount003 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
for (int count = 0; count < THREAD_COUNT; count++) {
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
ret = pthread_mutex_unlock(&g_mutexLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
ret = pthread_mutex_unlock(&g_mutexLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
pthread_mutex_destroy(&g_mutexLock001);
|
||||
pthread_mutex_destroy(&g_mutexLock002);
|
||||
pthread_mutex_destroy(&g_mutexLock003);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_006", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 1;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 10; // 10, for test
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock003, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount003++;
|
||||
|
||||
while (g_testToCount002 == 0) {
|
||||
SLEEP_AND_YIELD(2); // 2, delay enouge time
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount003 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 5; // 5, for test
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock002, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount002++;
|
||||
|
||||
while (g_testToCount001 == 0) {
|
||||
SLEEP_AND_YIELD(2); // 2, delay enouge time
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 2; // 2, for test
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex = { 0 };
|
||||
int index = TEST_COUNT;
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
pthread_mutex_init(&g_muxLock002, &mutex);
|
||||
pthread_mutex_init(&g_muxLock003, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_testToCount001 == 0 || g_testToCount002 == 0 || g_testToCount003 == 0) {
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount003, -1, g_testToCount003);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock003);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
index--;
|
||||
|
||||
SLEEP_AND_YIELD(2); // 2, delay enouge time
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock001);
|
||||
pthread_mutex_destroy(&g_muxLock002);
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
|
||||
static const unsigned int TEST_COUNT = 1;
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
int currThreadPri, currThreadPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 15; // 15
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount003++;
|
||||
|
||||
return nullptr;
|
||||
EXIT:
|
||||
g_testToCount003 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 10; // 10
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount002++;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 5; // 5
|
||||
time.tv_nsec = timeVal.tv_usec + 0;
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
|
||||
return nullptr;
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread, newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount003 = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_testToCount001 == 0 || g_testToCount002 == 0 || g_testToCount003 == 0) {
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
index--;
|
||||
|
||||
SLEEP_AND_YIELD(2); // 2, delay enouge time
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount003, -1, g_testToCount003);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock001);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_008", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static pthread_mutex_t g_muxLock;
|
||||
|
||||
static void *TaskF01(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
ret = pthread_mutex_trylock(&g_muxLock);
|
||||
ICUNIT_TRACK_EQUAL(ret, EBUSY, ret);
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
g_testCount++;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
pthread_t newThread;
|
||||
pthread_attr_t attr;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
struct sched_param sp;
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
|
||||
ret = pthread_mutex_init(&g_muxLock, &mutexAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
sp.sched_priority = 4; // 4, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
ret = pthread_attr_setschedparam(&attr, &sp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newThread, &attr, TaskF01, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
LosTaskDelay(5); // 5, delay enouge time
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
LosTaskDelay(5); // 5, delay enouge time
|
||||
#endif
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount); // 2,The expected value
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_muxLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newThread, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex009(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_009", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static pthread_mutex_t g_mutexLock001;
|
||||
static pthread_mutex_t g_mutexLock002;
|
||||
|
||||
static void *TaskF01(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
ret = pthread_mutex_lock(&g_mutexLock001);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock001);
|
||||
ICUNIT_TRACK_EQUAL(ret, 0, ret);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
pthread_t newThread;
|
||||
pthread_attr_t attr;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
struct sched_param sp;
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutexLock001, &mutexAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_init(&g_mutexLock002, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EDEADLK, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
sp.sched_priority = 4; // 4, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
ret = pthread_attr_setschedparam(&attr, &sp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newThread, &attr, TaskF01, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
LosTaskDelay(5); // 5, delay enouge time
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutexLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&g_mutexLock002);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newThread, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex010(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_010", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
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 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex011(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_011", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
|
||||
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_unlock(&mutex);
|
||||
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_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 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex012(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_012", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
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, 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_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex013(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_013", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_t mutex;
|
||||
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);
|
||||
|
||||
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 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex014(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_014", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
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_unlock(&mutex);
|
||||
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, 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_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex015(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_015", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttr);
|
||||
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
|
||||
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_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 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex016(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_016", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_mutexLock;
|
||||
|
||||
static int g_testToCount = 0;
|
||||
static int g_testBackCount = 0;
|
||||
|
||||
static void *ThreadFuncTest3(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount++;
|
||||
ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount++;
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int tid = Gettid();
|
||||
pthread_t thread = pthread_self();
|
||||
|
||||
g_testBackCount++;
|
||||
ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testBackCount++;
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = nullptr;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread;
|
||||
pthread_mutexattr_t mutex;
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_mutexLock, &mutex);
|
||||
|
||||
g_testToCount = 0;
|
||||
g_testBackCount = 0;
|
||||
|
||||
SLEEP_AND_YIELD(1);
|
||||
|
||||
ret = pthread_mutex_lock(&g_mutexLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currThreadPri = param.sched_priority;
|
||||
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = currThreadPri - 2;
|
||||
pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(5); // 5, delay enouge time
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount, 1, g_testToCount);
|
||||
|
||||
ret = pthread_create(&newPthread, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
SLEEP_AND_YIELD(5); // 5, delay enouge time
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testBackCount, 1, g_testBackCount);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_mutexLock);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testBackCount, 2, g_testBackCount); // 2,The expected value
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount, 2, g_testToCount); // 2,The expected value
|
||||
|
||||
pthread_mutex_destroy(&g_mutexLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex017(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_017", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 10;
|
||||
static const unsigned int NEW_THREAD_COUNT = 10;
|
||||
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount003 = 0;
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
if(timeVal.tv_usec + 100000 >= 1000000) { // 100000us, delay time; 1000000us, compare
|
||||
time.tv_sec = timeVal.tv_sec + 1;
|
||||
time.tv_nsec = (timeVal.tv_usec + 100000 - 1000000) * 1000; // 100000, delaytime; 1000, us to ns; 1000000us=1s;
|
||||
} else {
|
||||
time.tv_sec = timeVal.tv_sec + 0;
|
||||
time.tv_nsec = (timeVal.tv_usec + 100000) * 1000; // 1000, 100000us to ns
|
||||
}
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testToCount002, 1, g_testToCount002, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* futexList :
|
||||
* 30(20) -> -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) ->
|
||||
* -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) -> -1(-1) ->
|
||||
*
|
||||
*/
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int threadCount;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
int gCurrThreadPri, gCurrThreadPolicy;
|
||||
struct timeval time = { 0 };
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &gCurrThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
gCurrThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = gCurrThreadPri + 2;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
threadCount = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 7); // 1000, 10, 7
|
||||
|
||||
ret = pthread_create(&newPthread1, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
while (1) {
|
||||
gettimeofday(&time, nullptr);
|
||||
if ((time.tv_sec - timeVal.tv_sec) >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 0;
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_join(newPthread[threadCount], nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, NEW_THREAD_COUNT, g_testToCount001);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex019(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_019", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 10;
|
||||
static const unsigned int NEW_THREAD_COUNT = 10;
|
||||
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount000 = 0;
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 0;
|
||||
time.tv_nsec = (timeVal.tv_usec + 1000 * 10 * 10) * 1000; // 1000, 10 ms to ns
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
g_testToCount000++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount000 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* futexlist:
|
||||
* 21(20) -> -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
*/
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int threadCount;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
int gCurrThreadPri, gCurrThreadPolicy;
|
||||
struct timeval time = { 0 };
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &gCurrThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
gCurrThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = gCurrThreadPri + 2;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount000 = 0;
|
||||
threadCount = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 1;
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 2; // 2
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 8); // 1000, 10, 8
|
||||
|
||||
ret = pthread_create(&newPthread1, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
while (1) {
|
||||
gettimeofday(&time, nullptr);
|
||||
if ((time.tv_sec - timeVal.tv_sec) >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 0;
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_join(newPthread[threadCount], nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, NEW_THREAD_COUNT - 2, g_testToCount001); // 2, test value
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex020(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_020", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 10;
|
||||
static const unsigned int NEW_THREAD_COUNT = 10;
|
||||
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount000 = 0;
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 0;
|
||||
time.tv_nsec = (timeVal.tv_usec + 1000 * 10 * 10) * 1000; // 1000, 10 ms to ns
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
g_testToCount000++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount000 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* futexlist:
|
||||
* 21(20) -> -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
*/
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int threadCount;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
int gCurrThreadPri, gCurrThreadPolicy;
|
||||
struct timeval time = { 0 };
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &gCurrThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
gCurrThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = gCurrThreadPri + 2;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount000 = 0;
|
||||
threadCount = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
if ((threadCount % 2) == 0) { // 2, for index
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
} else {
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 8); // 1000, 10, 8
|
||||
|
||||
ret = pthread_create(&newPthread1, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
while (1) {
|
||||
gettimeofday(&time, nullptr);
|
||||
if ((time.tv_sec - timeVal.tv_sec) >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 0;
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_join(newPthread[threadCount], nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount000, -1, g_testToCount000);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex021(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_021", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mutex_test.h"
|
||||
|
||||
static pthread_mutex_t g_muxLock001;
|
||||
static pthread_mutex_t g_muxLock002;
|
||||
static pthread_mutex_t g_muxLock003;
|
||||
|
||||
static const unsigned int TEST_COUNT = 10;
|
||||
static const unsigned int NEW_THREAD_COUNT = 10;
|
||||
|
||||
static volatile int g_testToCount001 = 0;
|
||||
static volatile int g_testToCount002 = 0;
|
||||
static volatile int g_testToCount000 = 0;
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_detach(thread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount002 = 1;
|
||||
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount002 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testToCount001++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount001 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
int ret;
|
||||
pthread_t thread = pthread_self();
|
||||
struct timespec time;
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
|
||||
time.tv_sec = timeVal.tv_sec + 0;
|
||||
time.tv_nsec = (timeVal.tv_usec + 1000 * 10 * 10) * 1000; // 1000, 10 ms to ns
|
||||
|
||||
ret = pthread_mutex_timedlock(&g_muxLock001, &time);
|
||||
|
||||
while (g_testToCount002 != 1) {
|
||||
if (g_testToCount002 == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
g_testToCount000++;
|
||||
return nullptr;
|
||||
|
||||
EXIT:
|
||||
g_testToCount000 = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* futexlist:
|
||||
* 21(20) -> -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* -1(-1) -> 28(22) -> 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
* 27(22) -> 26(22) -> 25(22) -> 24(22) -> 23(22) ->
|
||||
*/
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int threadCount;
|
||||
void *res = nullptr;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = TEST_COUNT;
|
||||
int gCurrThreadPri, gCurrThreadPolicy;
|
||||
struct timeval time = { 0 };
|
||||
struct timeval timeVal = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &gCurrThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
gCurrThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
// 2, Set the priority according to the task purpose,a smaller number means a higher priority.
|
||||
param.sched_priority = gCurrThreadPri + 2;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
while (index) {
|
||||
pthread_mutexattr_settype(&mutex, PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutex_init(&g_muxLock001, &mutex);
|
||||
|
||||
g_testToCount001 = 0;
|
||||
g_testToCount002 = 0;
|
||||
g_testToCount000 = 0;
|
||||
threadCount = 0;
|
||||
|
||||
ret = pthread_mutex_lock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
if ((threadCount % 2) == 0) { // 2, for index
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
} else {
|
||||
ret = pthread_create(&newPthread[threadCount], &a, ThreadFuncTest0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 8); // 1000, 10, 8
|
||||
|
||||
ret = pthread_create(&newPthread1, nullptr, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
gettimeofday(&timeVal, nullptr);
|
||||
while (1) {
|
||||
gettimeofday(&time, nullptr);
|
||||
if ((time.tv_sec - timeVal.tv_sec) >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&g_muxLock001);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadCount = 0;
|
||||
while (threadCount < NEW_THREAD_COUNT) {
|
||||
ret = pthread_join(newPthread[threadCount], nullptr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
threadCount++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount001, -1, g_testToCount001);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount002, -1, g_testToCount002);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_testToCount000, -1, g_testToCount000);
|
||||
|
||||
pthread_mutex_destroy(&g_muxLock003);
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadMutex022(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_MUTEX_022", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
# Copyright (c) 2022-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.
|
||||
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
process_include_dirs = [ "$TEST_UNITTEST_DIR/basic/process/process" ]
|
||||
|
||||
process_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/basic/process/process/process_process_test.cpp" ]
|
||||
|
||||
process_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_014.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_022.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_023.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_024.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_025.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_026.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_027.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_029.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_030.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_038.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_039.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_043.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_044.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_045.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_046.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_047.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_048.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_054.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smoke/process_test_061.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/smp/process_test_smp_008.cpp",
|
||||
]
|
||||
|
||||
process_sources_full = [
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_031.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_032.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_033.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_034.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_035.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_036.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_037.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_040.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_041.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_042.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_049.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_050.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_051.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_055.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_056.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_057.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_058.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_059.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_060.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_063.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_064.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_065.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_066.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_067.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_068.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_069.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_053.cpp",
|
||||
"$TEST_UNITTEST_DIR/basic/process/process/full/process_test_062.cpp",
|
||||
]
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static const int TEST_COUNT = 10;
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
exit(254); // 254, exit args
|
||||
}
|
||||
|
||||
static int ProcessTest001(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int data;
|
||||
int pri;
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 4;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert that function Result is equal to this.
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
data = ret;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, &data);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int count = TEST_COUNT;
|
||||
int temp = GetCpuCount();
|
||||
if (temp <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001();
|
||||
exit(10); // 10, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_TWO_EQUAL(status, 255, 254, status); // 255, 254, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
count--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), gid, getpgrp());
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid1, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess031(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_031", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
int ret;
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgid(getpid(), gid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), gid, getpgrp());
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess032(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_032", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 1); // 1000, 10, Used to calculate the delay time.
|
||||
ret = setpgid(pid, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid1, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess033(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_033", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid1, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess034(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_034", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
sleep(1);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgid(getpid(), gid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess035(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_035", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpid(), getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 10); // 1000, 10, 10, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(getpid(), currGid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), currGid, getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgid(getpid(), gid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), gid, getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 12); // 1000, 10, 12, Used to calculate the delay time.
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int ProcessGroup(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currGid = getpgrp();
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ProcessGroup();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess036(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_036", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpid(), getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 12); // 1000, 10, 12, Used to calculate the delay time.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgid(getpid(), getpid());
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 12); // 1000, 10, 12, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), gid, getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int ProcessGroup(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currGid = getpgrp();
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid1, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
status = 0;
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ProcessGroup();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess037(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_037", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int count = 1000;
|
||||
int waitProcess = 0;
|
||||
int testPid;
|
||||
bool thread = false;
|
||||
int processCount = 0;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 50); // 1000, 10, 50, Used to calculate the delay time.
|
||||
exit(0);
|
||||
} else if (pid < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
sleep(1);
|
||||
}
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
testPid = pid;
|
||||
processCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess040(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_040", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static void *Thread(void *arg)
|
||||
{
|
||||
sleep(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int testPid;
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int count = 500;
|
||||
int waitProcess = 0;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t pthread[1000] = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
bool thread = false;
|
||||
|
||||
int processCount = 0;
|
||||
|
||||
pthread_attr_init(&a);
|
||||
param.sched_priority = 31; // 31, set pthread priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
for (int i = 0; i < 40; i++) { // 40, number of cycles
|
||||
ret = pthread_create(&pthread[i], &a, Thread, NULL);
|
||||
if (ret != 0) {
|
||||
exit(10); // 10, exit args
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
pthread_create(&pthread[100], &a, Thread, NULL); // 100, pthread array subscript
|
||||
pthread_create(&pthread[100], &a, Thread, NULL); // 100, pthread array subscript
|
||||
pthread_create(&pthread[100], &a, Thread, NULL); // 100, pthread array subscript
|
||||
usleep(1000 * 10 * 50); // 1000, 10, 50, Used to calculate the delay time.
|
||||
exit(0);
|
||||
} else if (pid < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
sleep(1);
|
||||
}
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
processCount++;
|
||||
testPid = pid;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess041(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_041", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static const int TEST_THREAD = 40;
|
||||
static const int TEST_LOOP = 3000;
|
||||
|
||||
static void Child2(int shmid)
|
||||
{
|
||||
int count = 2; // 2, Set the calculation number to determine the cycle status.
|
||||
int *shared = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_VOID(shared, (void *)-1, shared);
|
||||
|
||||
while ((*shared) < (TEST_LOOP + 2)) { // 2, Set the cycle number.
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*shared, count, *shared);
|
||||
(*shared)++;
|
||||
count += 3; // 3, Set the calculation number to determine the cycle status.
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return;
|
||||
}
|
||||
|
||||
static void Child1(int shmid)
|
||||
{
|
||||
int count = 1;
|
||||
int *shared = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_VOID(shared, (void *)-1, shared);
|
||||
|
||||
while ((*shared) < (TEST_LOOP + 1)) {
|
||||
ICUNIT_ASSERT_EQUAL_VOID(*shared, count, *shared);
|
||||
(*shared)++;
|
||||
count += 3; // 3, Set the calculation number to determine the cycle status.
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
(*shared) = 100000; // 100000, shared num.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int testPid;
|
||||
int ret;
|
||||
int policy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
const int memSize = 1024;
|
||||
int shmid;
|
||||
int *shared = NULL;
|
||||
|
||||
ret = sched_getparam(getpid(), ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
int processPrio = param.sched_priority;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
shmid = shmget((key_t)1234, memSize, 0666 | IPC_CREAT); // 1234, Sets the shmget key; 0666 config of shmget
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
Child1(shmid);
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid1 == 0) {
|
||||
Child2(shmid);
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
shared = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shared, (void *)-1, shared);
|
||||
|
||||
(*shared) = 0;
|
||||
|
||||
while ((*shared) < TEST_LOOP) {
|
||||
(*shared)++;
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
(*shared) = TEST_LOOP + 10; // 10, Set the cycle number.
|
||||
|
||||
param.sched_priority = processPrio - 2; // 2, set pthread priority.
|
||||
ret = sched_setscheduler(pid, SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(*shared, 100000, *shared); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(status, 255, status); // 255, assert that function Result is equal to this.
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(status, 255, status); // 255, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess042(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_042", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static int *g_shmptr = NULL;
|
||||
static int g_usetTestCount = 0;
|
||||
static VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_usetTestCount++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestThread(void *arg)
|
||||
{
|
||||
int data = *((int *)arg);
|
||||
int ret = 0;
|
||||
pthread_t gTh;
|
||||
ret = pthread_create(&gTh, NULL, PthreadTest115, NULL);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(gTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(g_usetTestCount, 1, g_usetTestCount);
|
||||
|
||||
*g_shmptr = 100; // 100, set shared num.
|
||||
|
||||
pid_t pid = fork();
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
sleep(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
*g_shmptr = 200; // 200, set shared num.
|
||||
|
||||
ret = waitpid(pid, NULL, 0);
|
||||
printf("waitpid ret : %d errno : %d pid : %d getpid : %d\n", ret, errno, pid, getpid());
|
||||
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, pid, ret);
|
||||
|
||||
*g_shmptr = data;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int arg = 0x2000;
|
||||
int status;
|
||||
int ret;
|
||||
char *stackTop;
|
||||
char *stack;
|
||||
pid_t pid;
|
||||
|
||||
g_usetTestCount = 0;
|
||||
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // // 0600, set shmget config.
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
g_shmptr = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr);
|
||||
|
||||
*g_shmptr = 0;
|
||||
|
||||
stack = (char *)malloc(arg);
|
||||
ICUNIT_GOTO_NOT_EQUAL(stack, NULL, stack, EXIT1);
|
||||
|
||||
stackTop = (char *)((unsigned long)stack + arg);
|
||||
pid = clone(TestThread, (void *)stackTop, CLONE_VFORK, &arg);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(*g_shmptr, arg, *g_shmptr, EXIT2);
|
||||
|
||||
ret = waitpid(pid, &status, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT2);
|
||||
|
||||
EXIT2:
|
||||
free(stack);
|
||||
|
||||
EXIT1:
|
||||
shmdt(g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess049(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_049", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static int *g_shmptr = NULL;
|
||||
static int g_ppid;
|
||||
static int TestThread(void *arg)
|
||||
{
|
||||
pid_t ppid = getppid();
|
||||
|
||||
printf("TestThread ppid : %d g_ppid : %d\n", ppid, g_ppid);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ppid, g_ppid, g_ppid);
|
||||
|
||||
*g_shmptr = 100; // 100, set shared num.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int arg = 0x2000;
|
||||
int status;
|
||||
void *stack;
|
||||
char *stackTop;
|
||||
int ret;
|
||||
int count;
|
||||
pid_t pid;
|
||||
|
||||
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // 0600 config of shmget
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
g_shmptr = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr);
|
||||
|
||||
*g_shmptr = 0;
|
||||
|
||||
g_ppid = getppid();
|
||||
printf("testcase ppid : %d\n", g_ppid);
|
||||
|
||||
stack = malloc(arg);
|
||||
ICUNIT_GOTO_NOT_EQUAL(stack, NULL, stack, EXIT1);
|
||||
|
||||
stackTop = (char *)((unsigned long)stack + arg);
|
||||
pid = clone(TestThread, (void *)stackTop, CLONE_PARENT, &arg);
|
||||
|
||||
ret = waitpid(pid, &status, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT2);
|
||||
|
||||
count = 0;
|
||||
while ((count < 100) || (*g_shmptr == 0)) { // 100, Number of cycles.
|
||||
usleep(1000 * 100); // 1000, 100, set usleep time.
|
||||
count++;
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(*g_shmptr, 100, *g_shmptr, EXIT2); // 100, assert g_shmptr equal to this.
|
||||
EXIT2:
|
||||
free(stack);
|
||||
|
||||
EXIT1:
|
||||
shmdt(g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess050(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_050", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static int *g_shmptr = NULL;
|
||||
static int g_ppid;
|
||||
static int TestThread(void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
pid_t pid;
|
||||
pid_t ppid = getppid();
|
||||
|
||||
printf("TestThread ppid : %d g_ppid : %d\n", ppid, g_ppid);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ppid, g_ppid, g_ppid);
|
||||
|
||||
*g_shmptr = 1000; // 1000, set shared num.
|
||||
|
||||
pid = fork();
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
sleep(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, NULL, 0);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, pid, ret);
|
||||
|
||||
*g_shmptr = 100; // 100, set shared num.
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int arg = 0x2000;
|
||||
int status;
|
||||
pid_t pid;
|
||||
void *stack;
|
||||
char *stackTop;
|
||||
int ret;
|
||||
|
||||
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // 0600 config of shmget
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
g_shmptr = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr);
|
||||
|
||||
*g_shmptr = 0;
|
||||
|
||||
g_ppid = getppid();
|
||||
printf("testcase ppid : %d\n", g_ppid);
|
||||
|
||||
stack = malloc(arg);
|
||||
ICUNIT_GOTO_NOT_EQUAL(stack, NULL, stack, EXIT1);
|
||||
|
||||
stackTop = (char *)((unsigned long)stack + arg);
|
||||
pid = clone(TestThread, (void *)stackTop, CLONE_PARENT | CLONE_VFORK, &arg);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(*g_shmptr, 100, *g_shmptr, EXIT2); // 100, assert g_shmptr equal to this.
|
||||
|
||||
ret = waitpid(pid, &status, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT2);
|
||||
|
||||
EXIT2:
|
||||
free(stack);
|
||||
|
||||
EXIT1:
|
||||
shmdt(g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess051(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_051", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static int *g_shmptr = NULL;
|
||||
static int g_ppid;
|
||||
static void *TestThread(void *arg)
|
||||
{
|
||||
int data = *((int *)arg);
|
||||
int ret = 0;
|
||||
|
||||
pid_t ppid = getppid();
|
||||
|
||||
printf("TestThread ppid : %d g_ppid : %d\n", ppid, g_ppid);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(ppid, g_ppid, g_ppid);
|
||||
|
||||
*g_shmptr = 100; // 100, set shared num.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int arg = 0x2000;
|
||||
int status;
|
||||
|
||||
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // 0600 config of shmget
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
g_shmptr = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr);
|
||||
|
||||
*g_shmptr = 0;
|
||||
|
||||
g_ppid = getppid();
|
||||
printf("testcase ppid : %d\n", g_ppid);
|
||||
|
||||
void *stack = (void *)malloc(arg);
|
||||
ICUNIT_GOTO_NOT_EQUAL(stack, NULL, stack, EXIT1);
|
||||
|
||||
char *stackTop = (char *)((unsigned long)stack + arg);
|
||||
pid_t pid = clone(TestThread, (char *)stackTop, CLONE_PARENT | CLONE_VFORK | CLONE_FILES, &arg);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(*g_shmptr, 100, *g_shmptr, EXIT2); // 100, assert g_shmptr equal to this.
|
||||
|
||||
int ret = waitpid(pid, &status, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT2);
|
||||
|
||||
EXIT2:
|
||||
free(stack);
|
||||
|
||||
EXIT1:
|
||||
shmdt(g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess052(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_052", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_signal = 0;
|
||||
|
||||
static void Handler(int sig)
|
||||
{
|
||||
g_signal = sig;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
void (*retSig)(int);
|
||||
int status;
|
||||
int ret;
|
||||
retSig = signal(SIGUSR1, Handler);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(retSig, SIG_ERR, retSig);
|
||||
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ret = killpg(getpgrp(), SIGUSR1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
exit(10); // 10, exit args
|
||||
}
|
||||
|
||||
while (g_signal == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(g_signal, SIGUSR1, g_signal);
|
||||
|
||||
ret = wait(&status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(status, 10, status); // 10, assert that function Result is equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess053(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_053", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(void)
|
||||
{
|
||||
int ret;
|
||||
siginfo_t info = { 0 };
|
||||
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ret = kill(getpid(), SIGKILL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
ret = waitid(P_PID, pid, &info, WEXITED);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_status, SIGKILL, info.si_status);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_code, 2, info.si_code); // 2, assert that function Result is equal to this.
|
||||
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
|
||||
exit(8); // 8, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
int ret;
|
||||
pid = fork();
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
Child1();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
} else {
|
||||
siginfo_t info = { 0 };
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, WEXITED);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_status, 8, info.si_status); // 8, assert that function Result is equal to this.
|
||||
ICUNIT_ASSERT_EQUAL(info.si_code, 1, info.si_code);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
exit(11); // 11, exit args
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
ret = waitid(P_PGID, getpgrp(), &info, WNOHANG);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_status, 11, info.si_status); // 11, assert that function Result is equal to this.
|
||||
ICUNIT_ASSERT_EQUAL(info.si_code, 1, info.si_code);
|
||||
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
|
||||
}
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess055(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_055", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int ret;
|
||||
int status = 0;
|
||||
char *argv1[] = {"tftp", NULL};
|
||||
|
||||
ret = posix_spawn(&pid, "/bin/tftp", NULL, NULL, argv1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess056(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_056", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int ret;
|
||||
int status = 0;
|
||||
char *argv1[] = {"tftp", NULL};
|
||||
|
||||
ret = posix_spawnp(&pid, "tftp", NULL, NULL, argv1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess057(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_057", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int HIGH_PRIORITY = 10; // 10, set high prio.
|
||||
|
||||
static int TestSpawnAttrDef(posix_spawnattr_t *attr)
|
||||
{
|
||||
sigset_t signalset;
|
||||
sigset_t signalset1;
|
||||
int ret;
|
||||
|
||||
ret = sigemptyset(&signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigaddset(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setsigdefault(attr, &signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getsigdefault(attr, &signalset1);
|
||||
ret = memcmp(&signalset, &signalset1, sizeof(sigset_t));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigismember(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrMask(posix_spawnattr_t *attr)
|
||||
{
|
||||
sigset_t signalset;
|
||||
sigset_t signalset1;
|
||||
int ret;
|
||||
|
||||
ret = sigemptyset(&signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigaddset(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setsigmask(attr, &signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getsigmask(attr, &signalset1);
|
||||
ret = memcmp(&signalset, &signalset1, sizeof(sigset_t));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigismember(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrGroup(posix_spawnattr_t *attr)
|
||||
{
|
||||
pid_t val = -1;
|
||||
pid_t pid = getpgrp();
|
||||
int ret;
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = getpgid(getpid());
|
||||
ret = posix_spawnattr_setpgroup(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, pid, val, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPrio(posix_spawnattr_t *attr)
|
||||
{
|
||||
struct sched_param val = { -1 };
|
||||
struct sched_param val1 = { -1 };
|
||||
int ret;
|
||||
posix_spawnattr_getschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val.sched_priority, 0, ret, EXIT);
|
||||
|
||||
val.sched_priority = HIGH_PRIORITY;
|
||||
ret = posix_spawnattr_setschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getschedparam(attr, &val1);
|
||||
ICUNIT_GOTO_EQUAL(val1.sched_priority, HIGH_PRIORITY, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPol(posix_spawnattr_t *attr)
|
||||
{
|
||||
int val = -1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = SCHED_RR;
|
||||
ret = posix_spawnattr_setschedpolicy(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, SCHED_RR, val, EXIT);
|
||||
|
||||
ret = TestSpawnAttrPrio(attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttr(short flag)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
char *argv1[] = {"tftp", NULL};
|
||||
short iflag = -1;
|
||||
int ret;
|
||||
|
||||
ret = posix_spawnattr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, 0, iflag, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, flag);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
iflag = -1;
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, flag, iflag, EXIT);
|
||||
|
||||
if (POSIX_SPAWN_SETSIGDEF == flag) {
|
||||
ret = TestSpawnAttrDef(&attr);
|
||||
} else if (POSIX_SPAWN_SETSIGMASK == flag) {
|
||||
ret = TestSpawnAttrMask(&attr);
|
||||
} else if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
ret = TestSpawnAttrGroup(&attr);
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
ret = TestSpawnAttrPrio(&attr);
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
ret = TestSpawnAttrPol(&attr);
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawn(&pid, "/bin/tftp", NULL, &attr, argv1, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_destroy(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_RESETIDS);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETPGROUP);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSIGDEF);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSIGMASK);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDPARAM);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDULER);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess058(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_058", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int HIGH_PRIORITY = 31;
|
||||
|
||||
static int TestSpawnAttrDef(posix_spawnattr_t *attr)
|
||||
{
|
||||
sigset_t signalset;
|
||||
sigset_t signalset1;
|
||||
int ret;
|
||||
|
||||
ret = sigemptyset(&signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigaddset(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setsigdefault(attr, &signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getsigdefault(attr, &signalset1);
|
||||
ret = memcmp(&signalset, &signalset1, sizeof(sigset_t));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigismember(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrMask(posix_spawnattr_t *attr)
|
||||
{
|
||||
sigset_t signalset;
|
||||
sigset_t signalset1;
|
||||
int ret;
|
||||
|
||||
ret = sigemptyset(&signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigaddset(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setsigmask(attr, &signalset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getsigmask(attr, &signalset1);
|
||||
ret = memcmp(&signalset, &signalset1, sizeof(sigset_t));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = sigismember(&signalset, SIGPIPE);
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrGroup(posix_spawnattr_t *attr)
|
||||
{
|
||||
pid_t val = -1;
|
||||
pid_t pid = getpgrp();
|
||||
int ret;
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = getpgid(getpid());
|
||||
ret = posix_spawnattr_setpgroup(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, pid, val, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPrio(posix_spawnattr_t *attr)
|
||||
{
|
||||
struct sched_param val = { -1 };
|
||||
struct sched_param val1 = { -1 };
|
||||
int ret;
|
||||
posix_spawnattr_getschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val.sched_priority, 0, ret, EXIT);
|
||||
|
||||
val.sched_priority = HIGH_PRIORITY;
|
||||
ret = posix_spawnattr_setschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getschedparam(attr, &val1);
|
||||
ICUNIT_GOTO_EQUAL(val1.sched_priority, HIGH_PRIORITY, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPol(posix_spawnattr_t *attr)
|
||||
{
|
||||
int val = -1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = SCHED_RR;
|
||||
ret = posix_spawnattr_setschedpolicy(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, SCHED_RR, val, EXIT);
|
||||
|
||||
ret = TestSpawnAttrPrio(attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnpAttr(short flag)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
char *argv1[] = {"tftp", NULL};
|
||||
short iflag = -1;
|
||||
int ret;
|
||||
|
||||
ret = posix_spawnattr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, 0, iflag, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, flag);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
iflag = -1;
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, flag, iflag, EXIT);
|
||||
|
||||
if (POSIX_SPAWN_SETSIGDEF == flag) {
|
||||
ret = TestSpawnAttrDef(&attr);
|
||||
} else if (POSIX_SPAWN_SETSIGMASK == flag) {
|
||||
ret = TestSpawnAttrMask(&attr);
|
||||
} else if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
ret = TestSpawnAttrGroup(&attr);
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
ret = TestSpawnAttrPrio(&attr);
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
ret = TestSpawnAttrPol(&attr);
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnp(&pid, "/bin/tftp", NULL, &attr, argv1, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnattr_destroy(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_RESETIDS);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_SETSIGDEF);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_SETSIGMASK);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_SETSCHEDPARAM);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_SETSCHEDULER);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnpAttr(POSIX_SPAWN_SETPGROUP);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess059(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_059", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static int TestGroupError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP);
|
||||
posix_spawnattr_setpgroup(&attr, 1);
|
||||
ret = posix_spawnp(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EPERM, ret);
|
||||
|
||||
posix_spawnattr_setpgroup(&attr, 65); // 65, set group num.
|
||||
ret = posix_spawnp(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int TestPolError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
struct sched_param val = { -1 };
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER);
|
||||
val.sched_priority = 15; // 15, set pthread priority.
|
||||
posix_spawnattr_setschedparam(&attr, &val);
|
||||
posix_spawnattr_setschedpolicy(&attr, SCHED_FIFO);
|
||||
ret = posix_spawnp(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int TestPrioError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
struct sched_param val = { -1 };
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM);
|
||||
posix_spawnattr_getschedparam(&attr, &val);
|
||||
|
||||
val.sched_priority = 0;
|
||||
ret = posix_spawnattr_setschedparam(&attr, &val);
|
||||
ret = posix_spawnp(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
val.sched_priority = 32; // 32, set pthread priority.
|
||||
ret = posix_spawnattr_setschedparam(&attr, &val);
|
||||
ret = posix_spawnp(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int TestCase(void)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, 128); // 128, set flags num.
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, 0xff);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setschedpolicy(&attr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setschedpolicy(&attr, 3); // 3, set policy num.
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
posix_spawnattr_destroy(&attr);
|
||||
|
||||
ret = TestGroupError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = TestPolError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = TestPrioError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess060(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_060", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sys/shm.h"
|
||||
|
||||
static volatile int *g_shmptr = NULL;
|
||||
|
||||
static void Handler(int sig)
|
||||
{
|
||||
(*g_shmptr)++;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int status;
|
||||
(void)signal(SIGUSR2, Handler);
|
||||
int ret;
|
||||
pid_t pid;
|
||||
|
||||
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // 0600 config of shmget
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
|
||||
g_shmptr = (int *)shmat(shmid, nullptr, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr, EXIT);
|
||||
|
||||
*g_shmptr = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
pid_t pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
|
||||
|
||||
if (pid1 == 0) {
|
||||
ret = killpg(getpgrp(), SIGUSR2);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (*g_shmptr < 3) { // 3, Number of cycles.
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
exit(11); // 11, exit args
|
||||
}
|
||||
|
||||
while (*g_shmptr < 3) { // 3, Number of cycles.
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid1, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 11, status, EXIT); // 11, assert status equal to this.
|
||||
|
||||
exit(10); // 10, exit args
|
||||
}
|
||||
|
||||
while (*g_shmptr < 3) { // 3, wait function running.
|
||||
sleep(1);
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(*g_shmptr, 3, *g_shmptr); // 3, assert that function Result is equal to this.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 10, status, EXIT); // 10, assert that function Result is equal to this.
|
||||
|
||||
shmdt((void *)g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
shmdt((void *)g_shmptr);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess062(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_062", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int FILE_NAME_BYTES = 200; // 200, set test name len.
|
||||
static const int LONG_FILE_NAME_BYTES = 500; // 500, set test name len.
|
||||
static const int RANDOM_MAX = 127; // 127, set random max.
|
||||
static const unsigned int INVALID_USER_VADDR = 0x1200000;
|
||||
|
||||
static int GetRandomNumber(int max)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (max > 0) {
|
||||
n = rand() % max;
|
||||
}
|
||||
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
static void GetRandomData(char **buf, int bufSize)
|
||||
{
|
||||
char *p = *buf;
|
||||
int i;
|
||||
|
||||
srand((unsigned)time(0));
|
||||
for (i = 0; i < bufSize - 1; ++i) {
|
||||
int r = GetRandomNumber(RANDOM_MAX);
|
||||
*(p + i) = (char)r;
|
||||
}
|
||||
*(p + i) = (char)0;
|
||||
}
|
||||
|
||||
static int TestCase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int err;
|
||||
pid_t pid;
|
||||
char *fileName = NULL;
|
||||
char *childFileName = NULL;
|
||||
char **childArgv = NULL;
|
||||
char **childEnvp = NULL;
|
||||
|
||||
ret = posix_spawn(&pid, NULL, NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
childFileName = (char *)1;
|
||||
ret = posix_spawn(&pid, childFileName, NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
childArgv = (char **)1;
|
||||
ret = posix_spawn(&pid, "/usr/bin/testsuits_app", NULL, NULL, childArgv, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
childEnvp = (char **)1;
|
||||
ret = posix_spawn(&pid, "/usr/bin/testsuits_app", NULL, NULL, NULL, childEnvp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawn(&pid, "/bin", NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
|
||||
|
||||
fileName = (char *)malloc(FILE_NAME_BYTES);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fileName, NULL, fileName);
|
||||
GetRandomData(&fileName, FILE_NAME_BYTES);
|
||||
ret = posix_spawn(&pid, fileName, NULL, NULL, NULL, NULL);
|
||||
free(fileName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
|
||||
|
||||
fileName = (char *)malloc(LONG_FILE_NAME_BYTES);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fileName, NULL, fileName);
|
||||
GetRandomData(&fileName, LONG_FILE_NAME_BYTES);
|
||||
ret = posix_spawn(&pid, fileName, NULL, NULL, NULL, NULL);
|
||||
free(fileName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENAMETOOLONG, ret);
|
||||
|
||||
ret = posix_spawn(&pid, (char *)INVALID_USER_VADDR, NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EFAULT, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void ItTestProcess063(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_063", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int FILE_NAME_BYTES = 200; // 200, set test name len.
|
||||
static const int LONG_FILE_NAME_BYTES = 500; // 500, set test name len.
|
||||
static const int RANDOM_MAX = 127; // 127, set random max.
|
||||
static const unsigned int INVALID_USER_VADDR = 0x1200000;
|
||||
|
||||
static int GetRandomNumber(int max)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (max > 0) {
|
||||
n = rand() % max;
|
||||
}
|
||||
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
static void GetRandomData(char **buf, int bufSize)
|
||||
{
|
||||
char *p = *buf;
|
||||
int i;
|
||||
|
||||
srand((unsigned)time(0));
|
||||
for (i = 0; i < bufSize - 1; ++i) {
|
||||
int r = GetRandomNumber(RANDOM_MAX);
|
||||
*(p + i) = (char)r;
|
||||
}
|
||||
*(p + i) = (char)0;
|
||||
}
|
||||
|
||||
static int TestCase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int err;
|
||||
pid_t pid;
|
||||
char *fileName = NULL;
|
||||
char *childFileName = NULL;
|
||||
char **childArgv = NULL;
|
||||
char **childEnvp = NULL;
|
||||
|
||||
childArgv = (char **)1;
|
||||
ret = posix_spawnp(&pid, "/usr/bin/testsuits_app", NULL, NULL, childArgv, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
childEnvp = (char **)1;
|
||||
ret = posix_spawnp(&pid, "/usr/bin/testsuits_app", NULL, NULL, NULL, childEnvp);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnp(&pid, "/bin", NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
|
||||
|
||||
fileName = (char *)malloc(FILE_NAME_BYTES);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fileName, NULL, fileName);
|
||||
GetRandomData(&fileName, FILE_NAME_BYTES);
|
||||
ret = posix_spawnp(&pid, fileName, NULL, NULL, NULL, NULL);
|
||||
free(fileName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
|
||||
|
||||
fileName = (char *)malloc(LONG_FILE_NAME_BYTES);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fileName, NULL, fileName);
|
||||
GetRandomData(&fileName, LONG_FILE_NAME_BYTES);
|
||||
ret = posix_spawnp(&pid, fileName, NULL, NULL, NULL, NULL);
|
||||
free(fileName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENAMETOOLONG, ret);
|
||||
|
||||
ret = posix_spawnp(&pid, "test_spawnp", NULL, NULL, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ENOENT, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void ItTestProcess064(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_064", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static int TestGroupError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP);
|
||||
posix_spawnattr_setpgroup(&attr, 1);
|
||||
ret = posix_spawn(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EPERM, ret);
|
||||
|
||||
posix_spawnattr_setpgroup(&attr, 65); // 65, set group num.
|
||||
ret = posix_spawn(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
return 0;
|
||||
}
|
||||
static int TestPolError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
struct sched_param val = { -1 };
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER);
|
||||
val.sched_priority = 15; // 15, set pthread priority.
|
||||
posix_spawnattr_setschedparam(&attr, &val);
|
||||
posix_spawnattr_setschedpolicy(&attr, SCHED_FIFO);
|
||||
ret = posix_spawn(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int TestPrioError(void)
|
||||
{
|
||||
int ret;
|
||||
posix_spawnattr_t attr;
|
||||
struct sched_param val = { -1 };
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM);
|
||||
posix_spawnattr_getschedparam(&attr, &val);
|
||||
|
||||
val.sched_priority = 0;
|
||||
ret = posix_spawnattr_setschedparam(&attr, &val);
|
||||
ret = posix_spawn(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
val.sched_priority = 32; // 32, set pthread priority.
|
||||
ret = posix_spawnattr_setschedparam(&attr, &val);
|
||||
ret = posix_spawn(NULL, "/bin/tftp", NULL, &attr, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
return 0;
|
||||
}
|
||||
static int TestCase(void)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_init(&attr);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, -1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, 128); // 128, set group num.
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, 0xff);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setschedpolicy(&attr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = posix_spawnattr_setschedpolicy(&attr, 3); // 3, set policy num.
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
posix_spawnattr_destroy(&attr);
|
||||
|
||||
ret = TestGroupError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = TestPolError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = TestPrioError();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess065(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_065", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int HIGH_PRIORITY = 10;
|
||||
static const int NUMMAX = 16;
|
||||
|
||||
static int TestSpawnAttrGroup(posix_spawnattr_t *attr)
|
||||
{
|
||||
pid_t val = -1;
|
||||
pid_t pid = getpgrp();
|
||||
int ret;
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = getpgid(getpid());
|
||||
ret = posix_spawnattr_setpgroup(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, pid, val, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPrio(posix_spawnattr_t *attr)
|
||||
{
|
||||
struct sched_param val = { -1 };
|
||||
struct sched_param val1 = { -1 };
|
||||
int ret;
|
||||
posix_spawnattr_getschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val.sched_priority, 0, ret, EXIT);
|
||||
|
||||
val.sched_priority = HIGH_PRIORITY;
|
||||
ret = posix_spawnattr_setschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getschedparam(attr, &val1);
|
||||
ICUNIT_GOTO_EQUAL(val1.sched_priority, HIGH_PRIORITY, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPol(posix_spawnattr_t *attr)
|
||||
{
|
||||
int val = -1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = SCHED_RR;
|
||||
ret = posix_spawnattr_setschedpolicy(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, SCHED_RR, val, EXIT);
|
||||
|
||||
ret = TestSpawnAttrPrio(attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttr(short flag)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
char *argv1[] = {"xxx", NULL};
|
||||
char temp[NUMMAX] = {0};
|
||||
char temp1[NUMMAX] = {0};
|
||||
short iflag = -1;
|
||||
int ret;
|
||||
int fd;
|
||||
ret = posix_spawnattr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, 0, iflag, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, flag);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
iflag = -1;
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, flag, iflag, EXIT);
|
||||
|
||||
if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
ret = TestSpawnAttrGroup(&attr);
|
||||
argv1[0] = "group";
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
ret = TestSpawnAttrPrio(&attr);
|
||||
argv1[0] = "prio";
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
ret = TestSpawnAttrPol(&attr);
|
||||
argv1[0] = "pol";
|
||||
} else if (POSIX_SPAWN_RESETIDS == flag) {
|
||||
argv1[0] = "ids";
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawn(&pid, "/storage/test_spawn", NULL, &attr, argv1, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
fd = open("/storage/testspawnattr.txt", O_RDWR | O_CREAT, 0644); // 0644, open config
|
||||
ret = read(fd, temp, NUMMAX);
|
||||
ICUNIT_GOTO_EQUAL(ret, NUMMAX, ret, EXIT1);
|
||||
|
||||
if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "pgid = %d", attr.__pgrp);
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "prio = %d", attr.__prio);
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "pol = %d", attr.__pol);
|
||||
} else if (POSIX_SPAWN_RESETIDS == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "uid = %d", getuid());
|
||||
}
|
||||
ret = strncmp(temp, temp1, strlen(temp));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
return 0;
|
||||
EXIT1:
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
close(fd);
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_RESETIDS);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDPARAM);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDULER);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETPGROUP);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess066(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_066", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int HIGH_PRIORITY = 10;
|
||||
static const int NUMMAX = 16;
|
||||
|
||||
static int TestSpawnAttrGroup(posix_spawnattr_t *attr)
|
||||
{
|
||||
pid_t val = -1;
|
||||
pid_t pid = getpgrp();
|
||||
int ret;
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = getpgid(getpid());
|
||||
ret = posix_spawnattr_setpgroup(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getpgroup(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, pid, val, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPrio(posix_spawnattr_t *attr)
|
||||
{
|
||||
struct sched_param val = { -1 };
|
||||
struct sched_param val1 = { -1 };
|
||||
int ret;
|
||||
posix_spawnattr_getschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val.sched_priority, 0, ret, EXIT);
|
||||
|
||||
val.sched_priority = HIGH_PRIORITY;
|
||||
ret = posix_spawnattr_setschedparam(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getschedparam(attr, &val1);
|
||||
ICUNIT_GOTO_EQUAL(val1.sched_priority, HIGH_PRIORITY, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttrPol(posix_spawnattr_t *attr)
|
||||
{
|
||||
int val = -1;
|
||||
int ret;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, 0, val, EXIT);
|
||||
|
||||
val = SCHED_RR;
|
||||
ret = posix_spawnattr_setschedpolicy(attr, val);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
val = -1;
|
||||
|
||||
posix_spawnattr_getschedpolicy(attr, &val);
|
||||
ICUNIT_GOTO_EQUAL(val, SCHED_RR, val, EXIT);
|
||||
|
||||
ret = TestSpawnAttrPrio(attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestSpawnAttr(short flag)
|
||||
{
|
||||
pid_t pid;
|
||||
posix_spawnattr_t attr;
|
||||
int status = 1;
|
||||
char *argv1[] = {"xxx", NULL};
|
||||
char temp[NUMMAX] = {0};
|
||||
char temp1[NUMMAX] = {0};
|
||||
short iflag = -1;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
ret = posix_spawnattr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, 0, iflag, EXIT);
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr, flag);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
iflag = -1;
|
||||
|
||||
posix_spawnattr_getflags(&attr, &iflag);
|
||||
ICUNIT_GOTO_EQUAL(iflag, flag, iflag, EXIT);
|
||||
|
||||
if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
ret = TestSpawnAttrGroup(&attr);
|
||||
argv1[0] = "group";
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
ret = TestSpawnAttrPrio(&attr);
|
||||
argv1[0] = "prio";
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
ret = TestSpawnAttrPol(&attr);
|
||||
argv1[0] = "pol";
|
||||
} else if (POSIX_SPAWN_RESETIDS == flag) {
|
||||
argv1[0] = "ids";
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = posix_spawnp(&pid, "/storage/test_spawn", NULL, &attr, argv1, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
fd = open("/storage/testspawnattr.txt", O_RDWR | O_CREAT, 0644); // 0644, open config
|
||||
ret = read(fd, temp, NUMMAX);
|
||||
ICUNIT_GOTO_EQUAL(ret, NUMMAX, ret, EXIT1);
|
||||
|
||||
if (POSIX_SPAWN_SETPGROUP == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "pgid = %d", attr.__pgrp);
|
||||
} else if (POSIX_SPAWN_SETSCHEDPARAM == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "prio = %d", attr.__prio);
|
||||
} else if (POSIX_SPAWN_SETSCHEDULER == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "pol = %d", attr.__pol);
|
||||
} else if (POSIX_SPAWN_RESETIDS == flag) {
|
||||
sprintf_s(temp1, NUMMAX, "uid = %d", getuid());
|
||||
}
|
||||
ret = strncmp(temp, temp1, strlen(temp));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
return 0;
|
||||
EXIT1:
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_RESETIDS);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDPARAM);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETSCHEDULER);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = TestSpawnAttr(POSIX_SPAWN_SETPGROUP);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess067(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_067", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int NUMMAX = 16;
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
char *envp[] = {"ABC=asddfg", NULL};
|
||||
char *argv1[] = {"envp", NULL};
|
||||
pid_t pid;
|
||||
int status = 1;
|
||||
char temp[NUMMAX] = {0};
|
||||
int fd;
|
||||
|
||||
int ret = posix_spawn(&pid, "/storage/test_spawn", NULL, NULL, argv1, envp);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
fd = open("/storage/testspawnattr.txt", O_RDWR | O_CREAT, 0644); // 0644, open config
|
||||
ret = read(fd, temp, NUMMAX);
|
||||
ICUNIT_GOTO_EQUAL(ret, NUMMAX, ret, EXIT1);
|
||||
|
||||
ret = strncmp(temp, "ABC=asddfg", strlen(temp));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
return 0;
|
||||
EXIT1:
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess068(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_068", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include <spawn.h>
|
||||
|
||||
static const int NUMMAX = 16;
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
char *envp[] = {"ABC=asddfg", NULL};
|
||||
char *argv1[] = {"envp", NULL};
|
||||
pid_t pid;
|
||||
int status = 1;
|
||||
char temp[NUMMAX] = {0};
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
ret = posix_spawnp(&pid, "/storage/test_spawn", NULL, NULL, argv1, envp);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
fd = open("/storage/testspawnattr.txt", O_RDWR | O_CREAT, 0644); // 0644, open config
|
||||
ret = read(fd, temp, NUMMAX);
|
||||
ICUNIT_GOTO_EQUAL(ret, NUMMAX, ret, EXIT1);
|
||||
|
||||
ret = strncmp(temp, "ABC=asddfg", strlen(temp));
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
return 0;
|
||||
EXIT1:
|
||||
close(fd);
|
||||
unlink("/storage/testspawnattr.txt");
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess069(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_069", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_TEST_PROCESS_H
|
||||
#define IT_TEST_PROCESS_H
|
||||
|
||||
#include "osTest.h"
|
||||
#include "sys/resource.h"
|
||||
#include "sys/wait.h"
|
||||
|
||||
#define WAIT_PARENT_FIRST_TO_RUN(tick) usleep((tick)*10 * 1000) // 10, 1000, wait time.
|
||||
#include "sys/syscall.h"
|
||||
|
||||
static inline int Syscall(int nbr, int parm1, int parm2, int parm3, int parm4)
|
||||
{
|
||||
register int reg7 __asm__("r7") = (int)(nbr);
|
||||
register int reg3 __asm__("r3") = (int)(parm4);
|
||||
register int reg2 __asm__("r2") = (int)(parm3);
|
||||
register int reg1 __asm__("r1") = (int)(parm2);
|
||||
register int reg0 __asm__("r0") = (int)(parm1);
|
||||
|
||||
__asm__ __volatile__("svc 0" : "=r"(reg0) : "r"(reg7), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3) : "memory");
|
||||
|
||||
return reg0;
|
||||
}
|
||||
extern INT32 g_iCunitErrCode;
|
||||
extern INT32 g_iCunitErrLineNo;
|
||||
extern int GetCpuCount(void);
|
||||
|
||||
extern void Wait(const char *ptr, int scount);
|
||||
extern void ItTestProcess001(void);
|
||||
extern void ItTestProcess002(void);
|
||||
extern void ItTestProcess004(void);
|
||||
extern void ItTestProcess005(void);
|
||||
extern void ItTestProcess006(void);
|
||||
extern void ItTestProcess007(void);
|
||||
extern void ItTestProcess008(void);
|
||||
extern void ItTestProcess009(void);
|
||||
extern void ItTestProcess010(void);
|
||||
extern void ItTestProcess011(void);
|
||||
extern void ItTestProcess012(void);
|
||||
extern void ItTestProcess013(void);
|
||||
extern void ItTestProcess014(void);
|
||||
extern void ItTestProcess015(void);
|
||||
extern void ItTestProcess016(void);
|
||||
extern void ItTestProcess017(void);
|
||||
extern void ItTestProcess018(void);
|
||||
extern void ItTestProcess019(void);
|
||||
extern void ItTestProcess020(void);
|
||||
extern void ItTestProcess021(void);
|
||||
extern void ItTestProcess022(void);
|
||||
extern void ItTestProcess023(void);
|
||||
extern void ItTestProcess024(void);
|
||||
extern void ItTestProcess025(void);
|
||||
extern void ItTestProcess026(void);
|
||||
extern void ItTestProcess027(void);
|
||||
extern void ItTestProcess029(void);
|
||||
extern void ItTestProcess030(void);
|
||||
extern void ItTestProcess031(void);
|
||||
extern void ItTestProcess032(void);
|
||||
extern void ItTestProcess033(void);
|
||||
extern void ItTestProcess034(void);
|
||||
extern void ItTestProcess035(void);
|
||||
extern void ItTestProcess036(void);
|
||||
extern void ItTestProcess037(void);
|
||||
extern void ItTestProcess038(void);
|
||||
extern void ItTestProcess039(void);
|
||||
extern void ItTestProcess040(void);
|
||||
extern void ItTestProcess041(void);
|
||||
extern void ItTestProcess042(void);
|
||||
extern void ItTestProcess043(void);
|
||||
extern void ItTestProcess044(void);
|
||||
extern void ItTestProcess045(void);
|
||||
extern void ItTestProcess046(void);
|
||||
extern void ItTestProcess047(void);
|
||||
extern void ItTestProcess048(void);
|
||||
extern void ItTestProcess049(void);
|
||||
extern void ItTestProcess050(void);
|
||||
extern void ItTestProcess051(void);
|
||||
extern void ItTestProcess052(void);
|
||||
extern void ItTestProcess053(void);
|
||||
extern void ItTestProcess054(void);
|
||||
extern void ItTestProcess055(void);
|
||||
extern void ItTestProcess056(void);
|
||||
extern void ItTestProcess057(void);
|
||||
extern void ItTestProcess058(void);
|
||||
extern void ItTestProcess059(void);
|
||||
extern void ItTestProcess060(void);
|
||||
extern void ItTestProcess061(void);
|
||||
extern void ItTestProcess062(void);
|
||||
extern void ItTestProcess063(void);
|
||||
extern void ItTestProcess064(void);
|
||||
extern void ItTestProcess065(void);
|
||||
extern void ItTestProcess066(void);
|
||||
extern void ItTestProcess067(void);
|
||||
extern void ItTestProcess068(void);
|
||||
extern void ItTestProcess069(void);
|
||||
extern void ItTestProcessSmp001(void);
|
||||
extern void ItTestProcessSmp002(void);
|
||||
extern void ItTestProcessSmp003(void);
|
||||
extern void ItTestProcessSmp004(void);
|
||||
extern void ItTestProcessSmp005(void);
|
||||
extern void ItTestProcessSmp006(void);
|
||||
extern void ItTestProcessSmp007(void);
|
||||
extern void ItTestProcessSmp008(void);
|
||||
#endif
|
||||
@@ -1,729 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 "stdio.h"
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include "it_test_process.h"
|
||||
|
||||
void Wait(const char *ptr, int scount)
|
||||
{
|
||||
int count = 0xffffffff;
|
||||
while (scount > 0) {
|
||||
while (count > 0) {
|
||||
printf("\r");
|
||||
count--;
|
||||
}
|
||||
count = 0xffffffff;
|
||||
scount--;
|
||||
if (ptr) {
|
||||
printf("%s\n", ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GetCpuCount(void)
|
||||
{
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
int temp = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
if (temp != 0) {
|
||||
printf("%s %d Error : %d\n", __FUNCTION__, __LINE__, temp);
|
||||
}
|
||||
|
||||
return CPU_COUNT(&cpuset);
|
||||
}
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessProcessTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/* *
|
||||
* @tc.name: it_test_process_001
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess001, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_002
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess002, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_004
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess004, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_005
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess005, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess005();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_006
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess006, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess006();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_008
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess008, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess008();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_010
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess010, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess010();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_009
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess009, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess009();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_011
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess011, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess011();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_012
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess012, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess012();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_013
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess013, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess013();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_014
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess014, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess014();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_015
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess015, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess015();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_016
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess016, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess016();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_017
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess017, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess017();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_018
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess018, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess018();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_019
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess019, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess019();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_020
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess020, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess020();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_021
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess021, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess021();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_022
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess022, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess022();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_023
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess023, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess023();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_024
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess024, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess024();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_025
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess025, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess025();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_026
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess026, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess026();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_027
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess027, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess027();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_029
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess029, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess029();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_030
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess030, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess030();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_038
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess038, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess038();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_039
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess039, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess039();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_043
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess043, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess043();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_044
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess044, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess044();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_045
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: DTS202101040I5J4KP0H00
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess045, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess045();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_046
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: DTS202101040I5J4KP0H00
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess046, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess046();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_047
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: DTS202101040I5J4KP0H00
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess047, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess047();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_048
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: DTS202101040I5J4KP0H00
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess048, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess048();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_054
|
||||
* @tc.desc: function for waitid: The waitid parameter is incorrect and the error code is verified.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess054, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess054();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_061
|
||||
* @tc.desc: function for killpg: The killpg parameter is incorrect and the error code is verified.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess061, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess061();
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_001
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp001, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_002
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp002, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_003
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp003, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_004
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp004, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_005
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp005, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp005();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_006
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp006, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp006();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_007
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp007, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_smp_008
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcessSmp008, TestSize.Level0)
|
||||
{
|
||||
ItTestProcessSmp008();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
/* *
|
||||
* @tc.name: it_test_process_007
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess007, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_031
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess031, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess031();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_032
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess032, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess032();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_033
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess033, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess033();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_034
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess034, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess034();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_035
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess035, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess035();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_036
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess036, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess036();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_037
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess037, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess037();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_040
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess040, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess040();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_041
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess041, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess041();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_042
|
||||
* @tc.desc: function for ProcessProcessTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess042, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess042();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_053
|
||||
* @tc.desc: function for killpg:Sends a signal to the process group,
|
||||
* Other processes in the process group can receive the signal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess053, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess053();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_055
|
||||
* @tc.desc: function for waitid:To test the function of transferring different parameters of the waitid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess055, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess055();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_process_062
|
||||
* @tc.desc: function for killpg:Fork two processes. The killpg sends a signal to the current process group.
|
||||
* The other two processes can receive the signal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000E0QAB
|
||||
*/
|
||||
HWTEST_F(ProcessProcessTest, ItTestProcess062, TestSize.Level0)
|
||||
{
|
||||
ItTestProcess062();
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static const int PROCESS_PRIORITY_MAX = 10;
|
||||
static const int PROCESS_PRIORITY_MIN = 31;
|
||||
static const int PROCESS_SCHED_RR_INTERVAL = 20000000;
|
||||
|
||||
static int Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
struct sched_param param = { 0 };
|
||||
struct timespec ts = { 0 };
|
||||
int err;
|
||||
ret = sched_getparam(getpid(), NULL);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_getparam(-1, ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_setparam(getpid(), NULL);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_setparam(-1, ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
|
||||
param.sched_priority = PROCESS_PRIORITY_MIN + 1;
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = 15; // 15, set pthread priority.
|
||||
ret = sched_setparam(20, ¶m); // 20, set the param.
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, ESRCH, err);
|
||||
|
||||
ret = getpriority(PRIO_USER, getpid());
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_get_priority_min(SCHED_RR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, PROCESS_PRIORITY_MAX, ret);
|
||||
|
||||
ret = sched_get_priority_max(SCHED_FIFO);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_get_priority_max(SCHED_OTHER);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_get_priority_max(SCHED_RR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, PROCESS_PRIORITY_MIN, ret);
|
||||
|
||||
ret = sched_get_priority_min(SCHED_OTHER);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_get_priority_min(SCHED_FIFO);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = PROCESS_PRIORITY_MAX - 1;
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = PROCESS_PRIORITY_MAX - 1;
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR, ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = 11; // 11, set pthread priority.
|
||||
ret = sched_setscheduler(1000, SCHED_RR, ¶m); // 1000, input the pid.
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = PROCESS_PRIORITY_MAX - 1;
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), param.sched_priority);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(ret, SCHED_RR, ret);
|
||||
|
||||
ret = sched_getscheduler(10000); // 10000, input the pid.
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_getscheduler(-1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
param.sched_priority = PROCESS_PRIORITY_MAX - 1;
|
||||
ret = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
return 0;
|
||||
|
||||
ERROR_OUT:
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ItTestProcess001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sched.h"
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
#define CURRENT_PROCESS_POLICY SCHED_RR
|
||||
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri, ERROR_OUT); // 31, assert function Result equal to this.
|
||||
|
||||
#define PROCESS_TEST_PRI1 (currProcessPri + 1)
|
||||
#define PROCESS_TEST_PRI2 (currProcessPri - 1)
|
||||
|
||||
ret = sched_getparam(getpid(), ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, currProcessPri, param.sched_priority, ERROR_OUT);
|
||||
|
||||
ret = sched_getscheduler(getpid());
|
||||
ICUNIT_GOTO_EQUAL(ret, CURRENT_PROCESS_POLICY, ret, ERROR_OUT);
|
||||
|
||||
param.sched_priority = PROCESS_TEST_PRI1;
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(ret, 0, 100000, ret, ERROR_OUT); // 100000, assert ret equal to this.
|
||||
|
||||
ret = sched_getparam(getpid(), ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, PROCESS_TEST_PRI1, param.sched_priority, ERROR_OUT);
|
||||
|
||||
param.sched_priority = PROCESS_TEST_PRI2;
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_GOTO_EQUAL(ret, PROCESS_TEST_PRI2, ret, ERROR_OUT);
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_GOTO_EQUAL(ret, currProcessPri, ret, ERROR_OUT);
|
||||
|
||||
param.sched_priority = currProcessPri;
|
||||
ret = sched_setscheduler(getpid(), CURRENT_PROCESS_POLICY, ¶m);
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(ret, 0, 100000, ret, ERROR_OUT); // 100000, assert ret equal to this.
|
||||
|
||||
ret = setpgid(getpid(), 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EPERM, errno, ERROR_OUT);
|
||||
|
||||
ret = setpgid(getpid(), 2); // 2, set pid num.
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EPERM, errno, ERROR_OUT);
|
||||
|
||||
return 0;
|
||||
ERROR_OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItTestProcess002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
exit(5); // 5, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(0, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(WEXITSTATUS(status), 5, status); // 5, assert that function Result is equal to this.
|
||||
ICUNIT_ASSERT_EQUAL(WIFEXITED(status), 1, status);
|
||||
}
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(6); // 6, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(0, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 6, status); // 6, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
exit(1);
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 1, status);
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(2); // 2, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 2, status); // 2, assert that function Result is equal to this.
|
||||
}
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
exit(3); // 3, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 3, status); // 3, assert that function Result is equal to this.
|
||||
}
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(4); // 4, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(ret, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 4, status); // 4, assert that function Result is equal to this.
|
||||
}
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_004", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int ProcessTest002(void)
|
||||
{
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(1);
|
||||
exit(8); // 8, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ProcessTest001(int *id)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ProcessTest002();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
WAIT_PARENT_FIRST_TO_RUN(200); // 200, wait time.
|
||||
exit(7); // 7, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
*id = pid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001(&pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 7, status); // 7, assert that function Result is equal to this.
|
||||
exit(8); // 8, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 8, status); // 8, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_005", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static const int TEST_COUNT = 10;
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
pid_t pid = *((pid_t *)arg);
|
||||
int ret;
|
||||
int status = 0;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL_NULL(status, 12, status); // 12, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
static int ProcessTest001(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
int pid, pid1;
|
||||
int data;
|
||||
int pri;
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 4;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert that function Result is equal to this.
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(50); // 50, wait time.
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
WAIT_PARENT_FIRST_TO_RUN(40); // 40, wait time.
|
||||
exit(10); // 10, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid1, 0, 100000, pid1); // 100000, assert that function Result is equal to this.
|
||||
data = pid;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, &data);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 10, status); // 10, assert that function Result is equal to this.
|
||||
|
||||
ret = pthread_detach(newPthread);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int count = TEST_COUNT;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001();
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 11, status); // 11, assert that function Result is equal to this.
|
||||
}
|
||||
count--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_006", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static const int TEST_COUNT = 10;
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
exit(254); // 254, exit args
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
static int ProcessTest001(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int policy = 0;
|
||||
int data;
|
||||
int pri;
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 4;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert that function Result is equal to this.
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
param.sched_priority += 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc3, &data);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
data = ret;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, &data);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int count = TEST_COUNT;
|
||||
int temp = GetCpuCount();
|
||||
if (temp <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001();
|
||||
exit(10); // 10, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_TWO_EQUAL(status, 255, 254, status); // 255, 254, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
count--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_008", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
static int ProcessTest001(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
int pid;
|
||||
int data;
|
||||
int pri;
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 4;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert that function Result is equal to this.
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
sleep(1);
|
||||
exit(12); // 12, exit args
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 12, status); // 12, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int temp = GetCpuCount();
|
||||
if (temp <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001();
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 255, status); // 255, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, assert that function Result is equal to this.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess009(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_009", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static const int TEST_COUNT = 10;
|
||||
|
||||
static void *ThreadFunc2(void *arg) {}
|
||||
|
||||
static int ProcessTest001(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int data;
|
||||
pthread_t newPthread, newPthread1;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert currProcessPri equal to this.
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
data = ret;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, &data);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
int count = TEST_COUNT;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp <= 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = ProcessTest001();
|
||||
exit(10); // 10, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 255, status); // 255, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
|
||||
count--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess010(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_010", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
sleep(10); // 10, sleep 10 second.
|
||||
g_testThreadExit++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
} else {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testThreadExit, 0, g_testThreadExit, EXIT);
|
||||
|
||||
g_testExit++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
EXIT:
|
||||
if (pid == 0) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testExit, 1, g_testExit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess011(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_011", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
sleep(10); // 10, sleep 10 second.
|
||||
g_testThreadExit++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc001(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
} else {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testThreadExit, 0, g_testThreadExit, EXIT);
|
||||
|
||||
g_testExit++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
EXIT:
|
||||
if (pid == 0) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
|
||||
int ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
param.sched_priority = curThreadPri - 2; // 2, set pthread priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc001, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
return NULL;
|
||||
|
||||
EXIT:
|
||||
g_testExit = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testExit, 1, g_testExit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess012(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_012", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
#include "sched.h"
|
||||
|
||||
static int TestCase()
|
||||
{
|
||||
#define PROCESS_TEST_PRI1 (currProcessPri + 1)
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
int val, currPolicy;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri, ERROR_OUT); // 31, assert currProcessPri equal to this.
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_GOTO_EQUAL(currPolicy, SCHED_RR, currPolicy, ERROR_OUT);
|
||||
|
||||
val = getpriority(PRIO_PROCESS, 0);
|
||||
ICUNIT_GOTO_EQUAL(val, currProcessPri, val, ERROR_OUT);
|
||||
|
||||
ret = sched_getparam(0, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, currProcessPri, param.sched_priority, ERROR_OUT);
|
||||
|
||||
val = sched_getscheduler(0);
|
||||
ICUNIT_GOTO_EQUAL(val, currPolicy, val, ERROR_OUT);
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 0, PROCESS_TEST_PRI1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, PROCESS_TEST_PRI1, ret, ERROR_OUT);
|
||||
|
||||
param.sched_priority = currProcessPri;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, getpid());
|
||||
ICUNIT_GOTO_EQUAL(ret, currProcessPri, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setscheduler(1, SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setscheduler(2, SCHED_FIFO, ¶m); // 2, input the pid.
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setparam(1, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
ret = sched_setparam(2, ¶m); // 2, set the param.
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 1, PROCESS_TEST_PRI1);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 2, PROCESS_TEST_PRI1); // 2, Used to calculate priorities.
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EPERM, ret, ERROR_OUT);
|
||||
|
||||
return 0;
|
||||
|
||||
ERROR_OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItTestProcess013(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_013", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (count < 5) { // 5, Number of cycles.
|
||||
g_testExit++;
|
||||
count++;
|
||||
usleep(1000 * 10 * 1); // 1000, 10, Used to calculate the delay time.
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid;
|
||||
int count = 0;
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
while (count < 10) { // 10, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(0);
|
||||
} else {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 0, status, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testExit, 5, g_testExit, EXIT); // 5, assert status equal to this.
|
||||
}
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess014(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_014", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, NULL, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
status = errno;
|
||||
ICUNIT_GOTO_EQUAL(status, ECHILD, status, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid;
|
||||
int count = 0;
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
g_waitPid = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_waitPid = -1;
|
||||
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 20); // 1000, 10, 20, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess015(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_015", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, NULL, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
status = errno;
|
||||
ICUNIT_GOTO_EQUAL(status, ECHILD, status, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid;
|
||||
int count = 0;
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_waitPid = 0;
|
||||
|
||||
if (pid == 0) {
|
||||
while (count < 10) { // 10, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ItTestProcess016(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_016", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, NULL, 0);
|
||||
printf("%s 22222 pid : %d\n", __FUNCTION__, ret);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
status = errno;
|
||||
ICUNIT_GOTO_EQUAL(status, ECHILD, status, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid;
|
||||
int count = 0;
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
g_waitPid = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 10); // 1000, 10, 10, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
g_waitPid = pid;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
printf("%s 11111 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess017(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_017", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, g_waitPid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
g_testThreadExit = 0;
|
||||
g_testExit = 0;
|
||||
|
||||
g_waitPid = 0;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_waitPid = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
while (count < 10) { // 10, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
if (pid1 == 0) {
|
||||
while (count < 10) { // 10, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid1, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert that function Result is equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess018(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_018", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_testThreadExit = 0;
|
||||
static int g_testExit = 0;
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, g_waitPid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert that function Result is equal to this.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
while (count < 20) { // 20, number of cycles
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
g_waitPid = pid;
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
if (pid1 == 0) {
|
||||
while (count < 15) { // 15, number of cycles
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid1, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess019(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_019", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, &status, 0);
|
||||
if (ret == g_backPid) {
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
} else if (ret == g_backPid1) {
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
} else {
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
g_waitPid = 0;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_waitPid = -1;
|
||||
g_backPid = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
while (count < 20) { // 20, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
while (count < 15) { // 15, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
if (ret == pid) {
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
} else if (ret == pid1) {
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
} else {
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess020(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_020", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
static int g_backPidFlag = 0;
|
||||
static int g_backPid1Flag = 0;
|
||||
static int g_errorFalg = 0;
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_waitPid, &status, 0);
|
||||
if ((ret == g_backPid) && (g_backPidFlag == 0)) {
|
||||
g_backPidFlag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
} else if ((ret == g_backPid1) && (g_backPid1Flag == 0)) {
|
||||
g_backPid1Flag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
} else if (g_errorFalg == 0) {
|
||||
g_errorFalg = 1;
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
} else {
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc1(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
int ret = waitpid(g_waitPid, &status, 0);
|
||||
if ((ret == g_backPid) && (g_backPidFlag == 0)) {
|
||||
g_backPidFlag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
} else if ((ret == g_backPid1) && (g_backPid1Flag == 0)) {
|
||||
g_backPid1Flag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
} else if (g_errorFalg == 0) {
|
||||
g_errorFalg = 1;
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
} else {
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread, newPthread1;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
g_errorFalg = 0;
|
||||
g_backPid1Flag = 0;
|
||||
g_errorFalg = 0;
|
||||
|
||||
g_waitPid = 0;
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_waitPid = -1;
|
||||
g_backPid = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
while (count < 20) { // 20, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
while (count < 15) { // 15, Number of cycles.
|
||||
count++;
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
}
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = pthread_create(&newPthread1, NULL, ThreadFunc1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
if ((ret == pid) && (g_backPidFlag == 0)) {
|
||||
g_backPidFlag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
} else if ((ret == pid1) && (g_backPid1Flag == 0)) {
|
||||
g_backPid1Flag = 1;
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 4, status, EXIT); // 4, assert status equal to this.
|
||||
} else if (g_errorFalg == 0) {
|
||||
g_errorFalg = 1;
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
} else {
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess021(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_021", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
|
||||
static int g_thread001;
|
||||
static int g_thread002;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(0, &status, 0);
|
||||
printf("3333333333333 pid : %u\n", ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(g_thread002, 0, g_thread002);
|
||||
g_thread001++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(0, &status, 0);
|
||||
printf("222222222222222222 pid : %u\n", ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(g_thread001, 0, g_thread001);
|
||||
g_thread002++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread, newPthread1;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_thread001 = 0;
|
||||
g_thread002 = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_backPid = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 30); // 1000, 10, 30, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
usleep(1000 * 10 * 20); // 1000, 10, 20, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
pid2 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid2, 0, 100000, pid, EXIT); // 100000, assert pid2 equal to this.
|
||||
if (pid2 == 0) {
|
||||
usleep(1000 * 10 * 15); // 1000, 10, 15, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
ret = pthread_create(&newPthread1, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(0, &status, 0);
|
||||
printf("111111111111111 pid : %u\n", ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret);
|
||||
g_thread001++;
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_thread002, 1, g_thread001);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_thread001, 2, g_thread001); // 2, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess022(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_022", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
|
||||
static int g_thread001;
|
||||
static int g_thread002;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(-1, &status, 0);
|
||||
printf("%s 33333 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(g_thread002, 0, g_thread002);
|
||||
g_thread001++;
|
||||
|
||||
return (void *)9; // 9, set thread return value.
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(-1, &status, 0);
|
||||
g_thread002++;
|
||||
printf("%s 222222 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(g_thread001, 0, g_thread001);
|
||||
|
||||
return (void *)9; // 9, set thread return value.
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int *error = nullptr;
|
||||
int status = 100;
|
||||
pthread_t newPthread, newPthread1;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
g_thread001 = 0;
|
||||
g_thread002 = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_backPid = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 20); // 1000, 10, 20, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
usleep(1000 * 10 * 15); // 1000, 10, 15, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
pid2 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid2, 0, 100000, pid, EXIT); // 100000, assert pid2 equal to this.
|
||||
if (pid2 == 0) {
|
||||
usleep(1000 * 10 * 10); // 1000, 10, 10, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
ret = pthread_create(&newPthread1, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
g_thread001++;
|
||||
printf("%s 11111 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_thread002, 1, g_thread001);
|
||||
|
||||
ret = pthread_join(newPthread1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_thread001, 2, g_thread001); // 2, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess023(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_023", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
|
||||
static int g_thread001;
|
||||
static int g_thread002;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(-1, &status, 0);
|
||||
printf("%s 3333333 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
g_thread001++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(0, &status, 0);
|
||||
g_thread002++;
|
||||
printf("%s 11111111 pid %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread, newPthread1;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
g_thread001 = 0;
|
||||
g_thread002 = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_backPid = pid;
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 20); // 1000, 10, 20, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
usleep(1000 * 10 * 15); // 1000, 10, 15, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
pid2 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid2, 0, 100000, pid, EXIT); // 100000, assert pid2 equal to this.
|
||||
if (pid2 == 0) {
|
||||
usleep(1000 * 10 * 10); // 1000, 10, 10, Used to calculate the delay time.
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = pthread_create(&newPthread1, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
g_thread001++;
|
||||
printf("%s 222222 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_thread002, 0, g_thread002);
|
||||
|
||||
ret = pthread_join(newPthread1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_thread001, 2, g_thread001); // 2, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess024(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int g_waitPid;
|
||||
static int g_backPid;
|
||||
static int g_backPid1;
|
||||
|
||||
static int g_thread001;
|
||||
static int g_thread002;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(-1, &status, 0);
|
||||
printf("%s 3333333 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
g_thread001++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
int ret = waitpid(g_backPid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, g_backPid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
g_thread002++;
|
||||
|
||||
printf("%s 11111111 pid %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, -1, ret);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread, newPthread1;
|
||||
pid_t pid, pid1, pid2;
|
||||
int count = 0;
|
||||
|
||||
g_thread001 = 0;
|
||||
g_thread002 = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
g_backPid = pid;
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 40); // 1000, 10, 40, Used to calculate the delay time.
|
||||
printf("child exit 1\n");
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid, EXIT); // 100000, assert pid1 equal to this.
|
||||
g_backPid1 = pid1;
|
||||
if (pid1 == 0) {
|
||||
usleep(1000 * 10 * 45); // 1000, 10, 45, Used to calculate the delay time.
|
||||
printf("child exit 2\n");
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
pid2 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid2, 0, 100000, pid, EXIT); // 100000, assert pid2 equal to this.
|
||||
if (pid2 == 0) {
|
||||
usleep(1000 * 10 * 50); // 1000, 10, 50, Used to calculate the delay time.
|
||||
printf("child exit 3\n");
|
||||
exit(4); // 4, exit args
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFunc2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = pthread_create(&newPthread1, NULL, ThreadFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = waitpid(-1, &status, 0);
|
||||
g_thread001++;
|
||||
printf("%s 222222 pid : %d\n", __FUNCTION__, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(g_thread002, 0, g_thread002);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_thread001, 2, g_thread001); // 2, assert that function Result is equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess025(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_025", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int pid = 3;
|
||||
int status = 0;
|
||||
|
||||
ret = waitpid(pid, &status, -1);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 4); // 4, waitpid options.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, WUNTRACED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, WCONTINUED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 10); // 10, waitpid options.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 21); // 21, waitpid options.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess026(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_026", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int ProcessTest(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 100;
|
||||
pthread_t newPthread;
|
||||
pid_t pid;
|
||||
int count = 0;
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
usleep(1000 * 10 * 20); // 1000, 10, 20, Used to calculate the delay time.
|
||||
exit(3); // 3, exit args
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, WNOHANG);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 3, status, EXIT); // 3, assert status equal to this.
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
if (pid == 0) {
|
||||
ProcessTest();
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess027(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_027", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
usleep(1000 * 10 * 5); // 1000, 10, 5, Used to calculate the delay time.
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usleep(1000 * 10 * 2); // 1000, 10, 2, Used to calculate the delay time.
|
||||
|
||||
ret = setpgid(pid, pid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess029(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_029", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(currGid, getpgrp(), getpgrp());
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(getpgrp(), getpid(), getpgrp());
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess030(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_030", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Child1(int currGid)
|
||||
{
|
||||
sleep(1);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int Child2(int currGid, int gid)
|
||||
{
|
||||
sleep(1);
|
||||
|
||||
exit(255); // 255, exit args
|
||||
}
|
||||
|
||||
static int ProcessGroup(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
|
||||
ret = setpgrp();
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currGid = getpgrp();
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
Child1(currGid);
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
pid1 = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid equal to this.
|
||||
ICUNIT_GOTO_NOT_EQUAL(pid1, pid, pid1, EXIT);
|
||||
|
||||
if (pid1 == 0) {
|
||||
Child2(currGid, pid);
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
int count = 30;
|
||||
|
||||
while (count > 0) {
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
ProcessGroup();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
sleep(1);
|
||||
count--;
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess038(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_038", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int count = 1000;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
continue;
|
||||
} else {
|
||||
exit(5); // 5, exit args
|
||||
}
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess039(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_039", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Testcase(VOID)
|
||||
{
|
||||
int priority;
|
||||
int err;
|
||||
int ret;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
int count = 0;
|
||||
priority = getpriority(PRIO_PGRP, 0);
|
||||
struct sched_param param = { 0 };
|
||||
err = errno;
|
||||
|
||||
priority = getpriority(PRIO_PGRP, 0);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = getpriority(PRIO_USER, 0);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
for (count = 1; count < 1000; ++count) { // 1000, Number of cycles.
|
||||
priority = getpriority(PRIO_USER + count, 0);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = setpriority(PRIO_USER + count, getpid(), currProcessPri);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = getpriority(-count, 0);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = setpriority(-count, getpid(), currProcessPri);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = sched_get_priority_max(SCHED_RR - count);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = sched_get_priority_max(SCHED_RR + count);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = sched_get_priority_min(SCHED_RR - count);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = sched_get_priority_min(SCHED_RR + count);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR - count, ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR + count, ¶m);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
}
|
||||
|
||||
priority = setpriority(PRIO_PGRP, getpid(), currProcessPri);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
priority = setpriority(PRIO_USER, getpid(), currProcessPri);
|
||||
err = errno;
|
||||
ICUNIT_ASSERT_EQUAL(priority, -1, priority);
|
||||
ICUNIT_ASSERT_EQUAL(err, EINVAL, err);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess043(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_043", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
sleep(1);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int GroupProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
pthread_t newPthread;
|
||||
struct timespec ts = { 0 };
|
||||
|
||||
ret = sched_rr_get_interval(getpid(), &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ts.tv_sec, 0, ts.tv_sec);
|
||||
if (ts.tv_nsec <= 5000000 || ts.tv_nsec > 20000000) { // 5000000, 20000000, expected range of tv_nsec.
|
||||
ICUNIT_ASSERT_EQUAL(ts.tv_nsec, -1, ts.tv_nsec);
|
||||
}
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sched_rr_get_interval(getpid(), &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ts.tv_sec, 0, ts.tv_sec);
|
||||
if (ts.tv_nsec <= 10000000 || ts.tv_nsec > 40000000) { // 10000000, 40000000, expected range of tv_nsec.
|
||||
ICUNIT_ASSERT_EQUAL(ts.tv_nsec, -1, ts.tv_nsec);
|
||||
}
|
||||
|
||||
exit(255); // 255, exit args
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid, pid1;
|
||||
int currGid = getpgrp();
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
|
||||
|
||||
if (pid == 0) {
|
||||
prctl(PR_SET_NAME, "mainFork", 0UL, 0UL, 0UL);
|
||||
GroupProcess();
|
||||
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
|
||||
exit(g_iCunitErrLineNo);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(status, 255, status, EXIT); // 255, assert status equal to this.
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess044(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_044", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
|
||||
ret = pthread_getaffinity_np(pthread_self(), 0, &cpuset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_setaffinity_np(pthread_self(), 0, &cpuset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = sched_setaffinity(getpid(), 0, &cpuset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sched_getaffinity(getpid(), 0, &cpuset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sched_setaffinity(-15, sizeof(cpu_set_t), &cpuset); // -15, pid num
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno);
|
||||
|
||||
ret = sched_setaffinity(1, sizeof(cpu_set_t), &cpuset); // init process, no permission
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
|
||||
|
||||
ret = sched_setaffinity(128, sizeof(cpu_set_t), &cpuset); // 128, pid num
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno);
|
||||
|
||||
ret = sched_getaffinity(128, sizeof(cpu_set_t), &cpuset); // 128, pid num
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno);
|
||||
|
||||
ret = sched_getaffinity(-15, sizeof(cpu_set_t), &cpuset); // -15, pid num
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess045(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_045", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 unsupported operation */
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT);
|
||||
CPU_ZERO(&cpuset);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset); /* cpu0 */
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
CPU_ZERO(&cpuset);
|
||||
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ERROR_OUT:
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(ret, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 11, status); // 11, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess046(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_046", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int pid;
|
||||
int status;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int temp;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
temp = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(temp, 0, temp, ERROR_OUT);
|
||||
|
||||
temp = CPU_COUNT(&cpuset);
|
||||
ICUNIT_GOTO_EQUAL(temp, 1, temp, ERROR_OUT); /* one cpu with the undefination of LOSCFG_USER_TEST_SMP */
|
||||
|
||||
ERROR_OUT:
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(ret, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 11, status); // 11, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess047(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_047", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
// This testcase us used for undefination of LOSCFG_USER_TEST_SMP
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
int temp = GetCpuCount();
|
||||
if (temp != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 unsupported operation */
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, ERROR_OUT);
|
||||
CPU_ZERO(&cpuset);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset); /* cpu0 */
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
CPU_ZERO(&cpuset);
|
||||
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ERROR_OUT:
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(ret, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 11, status); // 11, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcess048(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_048", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
int pid = 3;
|
||||
siginfo_t info = { 0 };
|
||||
|
||||
ret = waitid((idtype_t)3, getpgrp(), &info, WEXITED); // 3, set tid.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_PID, 0, &info, WEXITED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_PID, 999, &info, WEXITED); // 999, set group.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, ECHILD, ret, EXIT);
|
||||
|
||||
ret = waitid(P_PGID, 0, &info, WEXITED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, -1);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, 0);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, 32); // 32, set exit num.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, WSTOPPED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, WCONTINUED);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, WNOWAIT);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
|
||||
|
||||
ret = waitid(P_ALL, getpgrp(), &info, 21); // 21, set exit num.
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess054(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_054", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret = killpg(-1, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
ret = killpg(99999, 0); // 99999, set group
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, ESRCH, errno, EXIT);
|
||||
|
||||
ret = killpg(2, 0); // 2, set group
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EPERM, errno, EXIT);
|
||||
|
||||
ret = killpg(0, 65); // 65, set signal
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
return 0;
|
||||
EXIT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ItTestProcess061(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_061", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_test_process.h"
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 */
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT);
|
||||
exit(11); // 11, exit args
|
||||
ERROR_OUT:
|
||||
exit(11); // 11, exit args
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
ret = waitpid(ret, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 11, status); // 11, assert that function Result is equal to this.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcessSmp001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user