refactor: 删除旧测试套,拆分process用例适配门禁90s规则
close: #I4RE80 Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: I353fe4aa10e4f03e7cbaca572c8e73289c599c29
This commit is contained in:
58
testsuites/unittest/process/basic/BUILD.gn
Normal file
58
testsuites/unittest/process/basic/BUILD.gn
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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("//build/lite/config/test.gni")
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
import("./config.gni")
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
unittest("liteos_a_process_basic_unittest_door") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/kernel"
|
||||
include_dirs = common_include_dirs
|
||||
sources = sources_entry
|
||||
sources += sources_smoke
|
||||
sources_full = []
|
||||
sources += sources_full
|
||||
configs = [ "../..:public_config_for_door" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
|
||||
unittest("liteos_a_process_basic_unittest") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/kernel"
|
||||
include_dirs = common_include_dirs
|
||||
sources = sources_entry
|
||||
sources += sources_smoke
|
||||
sources += sources_full
|
||||
configs = [ "../..:public_config_for_all" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
||||
58
testsuites/unittest/process/basic/config.gni
Normal file
58
testsuites/unittest/process/basic/config.gni
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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("//build/lite/config/test.gni")
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
common_include_dirs = [
|
||||
"//third_party/googletest/googletest/include",
|
||||
"../../common/include",
|
||||
]
|
||||
|
||||
sources_entry = [ "../../common/osTest.cpp" ]
|
||||
|
||||
sources_smoke = []
|
||||
|
||||
sources_full = []
|
||||
|
||||
# basic module
|
||||
if (LOSCFG_USER_TEST_PROCESS == true) {
|
||||
import("./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("./pthread/config.gni")
|
||||
common_include_dirs += pthread_include_dirs
|
||||
sources_entry += pthread_sources_entry
|
||||
sources_smoke += pthread_sources_smoke
|
||||
sources_full += pthread_sources_full
|
||||
}
|
||||
114
testsuites/unittest/process/basic/process/config.gni
Normal file
114
testsuites/unittest/process/basic/process/config.gni
Normal file
@@ -0,0 +1,114 @@
|
||||
# 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/process/basic/process" ]
|
||||
|
||||
process_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/process/basic/process/process_process_test.cpp" ]
|
||||
|
||||
process_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_014.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_022.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_023.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_024.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_025.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_026.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_027.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_029.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_030.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_038.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_039.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_043.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_044.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_045.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_046.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_047.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_048.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_054.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smoke/process_test_061.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/smp/process_test_smp_008.cpp",
|
||||
]
|
||||
|
||||
process_sources_full = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_031.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_032.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_033.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_034.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_035.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_036.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_037.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_040.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_041.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_042.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_049.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_050.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_051.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_055.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_056.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_057.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_058.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_059.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_060.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_063.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_064.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_065.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_066.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_067.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_068.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_069.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_053.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/process/full/process_test_062.cpp",
|
||||
]
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
133
testsuites/unittest/process/basic/process/it_test_process.h
Normal file
133
testsuites/unittest/process/basic/process/it_test_process.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -0,0 +1,729 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 *PthreadTest01(VOID *arg)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t 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_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
return NULL;
|
||||
ERROR_OUT1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int pid;
|
||||
int status;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
pthread_t threadA;
|
||||
cpu_set_t initCpuset;
|
||||
|
||||
CPU_ZERO(&initCpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &initCpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
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);
|
||||
|
||||
ret = pthread_create(&threadA, NULL, PthreadTest01, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = pthread_join(threadA, NULL);
|
||||
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);
|
||||
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &initCpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, 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 ItTestProcessSmp002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset);
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = sched_getaffinity(0, 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);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset);
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = sched_getaffinity(0, 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);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset);
|
||||
CPU_SET(1, &cpuset);
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = sched_getaffinity(0, 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, 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 ItTestProcessSmp003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_003", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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;
|
||||
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);
|
||||
ret = sched_getaffinity(getpid(), 0, &cpuset);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestProcessSmp004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_004", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 *PthreadTest01(VOID *arg)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 */
|
||||
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
return NULL;
|
||||
ERROR_OUT1:
|
||||
return NULL;
|
||||
}
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
pthread_t threadA;
|
||||
|
||||
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);
|
||||
|
||||
ret = pthread_create(&threadA, NULL, PthreadTest01, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = pthread_join(threadA, NULL);
|
||||
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);
|
||||
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 ItTestProcessSmp005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_005", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 *PthreadTest01(VOID *arg)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 */
|
||||
ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
return NULL;
|
||||
ERROR_OUT1:
|
||||
return NULL;
|
||||
}
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
pthread_t threadA;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset); /* cpu0 */
|
||||
ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(0, 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);
|
||||
|
||||
ret = pthread_create(&threadA, NULL, PthreadTest01, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = pthread_join(threadA, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(0, 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);
|
||||
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 ItTestProcessSmp006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_006", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 *PthreadTest01(VOID *arg)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
sleep(2); // 2, sleep 10 second.
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
return NULL;
|
||||
ERROR_OUT1:
|
||||
return NULL;
|
||||
}
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
pthread_t threadA;
|
||||
|
||||
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);
|
||||
|
||||
ret = pthread_create(&threadA, NULL, PthreadTest01, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset); /* cpu1 */
|
||||
ret = pthread_setaffinity_np(threadA, sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
|
||||
ret = pthread_join(threadA, NULL);
|
||||
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);
|
||||
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 ItTestProcessSmp007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 *PthreadTest01(VOID *arg)
|
||||
{
|
||||
int ret;
|
||||
cpu_set_t 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_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset); /* cpu0 */
|
||||
CPU_SET(1, &cpuset); /* cpu1 */
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(0, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 1, ret, ERROR_OUT1);
|
||||
ret = (CPU_ISSET(1, &cpuset)) > 0 ? 1 : 0;
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT1);
|
||||
return NULL;
|
||||
ERROR_OUT1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
pthread_t threadA;
|
||||
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);
|
||||
|
||||
ret = pthread_create(&threadA, NULL, PthreadTest01, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROR_OUT);
|
||||
ret = pthread_join(threadA, NULL);
|
||||
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, 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 ItTestProcessSmp008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PROCESS_SMP_008", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
66
testsuites/unittest/process/basic/pthread/config.gni
Normal file
66
testsuites/unittest/process/basic/pthread/config.gni
Normal file
@@ -0,0 +1,66 @@
|
||||
# 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")
|
||||
|
||||
pthread_include_dirs = [ "$TEST_UNITTEST_DIR/process/basic/pthread" ]
|
||||
|
||||
pthread_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/process/basic/pthread/process_pthread_test.cpp" ]
|
||||
|
||||
pthread_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_atfork_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_atfork_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_cond_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_once_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_019.cpp",
|
||||
]
|
||||
|
||||
pthread_sources_full = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/full/pthread_test_014.cpp",
|
||||
]
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_pthreadTestCount = 0;
|
||||
static int g_threadTestCount1 = 0;
|
||||
|
||||
static void *ThreadFunc5(void *ptr)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
int ret;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_threadTestCount1, 2, g_threadTestCount1, EXIT); // 2, here assert the result.
|
||||
g_threadTestCount1++;
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc4(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
pid_t pid = getpid();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 9, g_pthreadTestCount, EXIT); // 9, here assert the result.
|
||||
g_pthreadTestCount++; // 10
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
pid_t pid = getpid();
|
||||
|
||||
g_pthreadTestCount++; // 7
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(i, 10, i, EXIT); // 10, here assert the result.
|
||||
return (void *)i;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
pid_t pid = getpid();
|
||||
unsigned int ret;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 3, g_pthreadTestCount, EXIT); // 3, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 4
|
||||
|
||||
ret = pthread_join(pthread_self(), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc6(void *arg)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 12, g_pthreadTestCount, EXIT); // 12, here assert the result.
|
||||
g_pthreadTestCount++; // 13
|
||||
|
||||
return (void *)pthread_self();
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread;
|
||||
struct sched_param param = { 0 };
|
||||
pid_t pid = getpid();
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 2, g_pthreadTestCount, EXIT); // 2, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 3
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc2, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
usleep(1000 * 10 * 2); // 1000 * 10 * 2, for timing control.
|
||||
#endif
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 4, g_pthreadTestCount, EXIT); // 4, here assert the result.
|
||||
|
||||
g_pthreadTestCount++; // 5
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc3, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_pthreadTestCount++; // 6
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 7, g_pthreadTestCount, EXIT); // 7, here assert the result.
|
||||
g_pthreadTestCount++; // 8
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc4, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 8, g_pthreadTestCount, EXIT); // 8, here assert the result.
|
||||
g_pthreadTestCount++; // 9
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 10, g_pthreadTestCount, EXIT); // 10, here assert the result.
|
||||
g_pthreadTestCount++; // 11
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PthreadTest001()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
int count = 0xf0000;
|
||||
g_threadTestCount1 = 0;
|
||||
g_pthreadTestCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_pthreadTestCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
pthread_attr_setschedpolicy(&a, g_currThreadPolicy);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 1, g_pthreadTestCount);
|
||||
g_pthreadTestCount++; // 2
|
||||
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc5, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 1, g_threadTestCount1);
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 2, g_threadTestCount1); // 2, here assert the result.
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 3, g_threadTestCount1); // 3, here assert the result.
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 11, g_pthreadTestCount); // 11, here assert the result.
|
||||
g_pthreadTestCount++; // 12
|
||||
|
||||
param.sched_priority = g_currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc6, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, for timing control.
|
||||
#endif
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 13, g_pthreadTestCount); // 13, here assert the result.
|
||||
g_pthreadTestCount++; // 14
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 14, g_pthreadTestCount); // 14, here assert the result.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_001", PthreadTest001, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_testCnt1 = 0;
|
||||
static volatile int g_testCnt2 = 0;
|
||||
static volatile int g_testPthredCount = 0;
|
||||
|
||||
static void ThreadWaitCount(int scount, volatile int *ent)
|
||||
{
|
||||
int count = 0xf0000;
|
||||
while (*ent < scount) {
|
||||
while (count > 0) {
|
||||
count--;
|
||||
}
|
||||
count = 0xf0000;
|
||||
(*ent)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
struct sched_param param = { 0 };
|
||||
int threadPolicy, threadPri;
|
||||
int old;
|
||||
const int waitCount1 = 20;
|
||||
const int waitCount2 = 50;
|
||||
g_testCnt2 = 0;
|
||||
|
||||
ThreadWaitCount(waitCount1 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
while (g_testCnt1 < 10) { // 10, wait until g_testCnt1 >= 10.
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt1;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_FIFO, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, (g_currThreadPri + 1), param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, old, g_testCnt1, EXIT);
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt1;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_RR, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, g_currThreadPri, param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, old, g_testCnt1, EXIT);
|
||||
|
||||
ret = pthread_setschedprio(pthread_self(), g_currThreadPri + 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt2, &g_testCnt2);
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, 170, g_testCnt2, EXIT); // 170, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
struct sched_param param = { 0 };
|
||||
int threadPolicy, threadPri;
|
||||
int ret;
|
||||
int old = 0;
|
||||
const int waitCount1 = 20;
|
||||
const int waitCount2 = 50;
|
||||
|
||||
g_testCnt1 = 0;
|
||||
|
||||
ThreadWaitCount(waitCount1 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
while (g_testCnt2 < 10) { // 10, wait until g_testCnt2 >= 10.
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
g_testPthredCount++;
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt2;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_FIFO, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, (g_currThreadPri + 1), param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, old, g_testCnt2, EXIT);
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
old = g_testCnt2;
|
||||
param.sched_priority = 0;
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(threadPolicy, SCHED_RR, threadPolicy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(param.sched_priority, g_currThreadPri, param.sched_priority, EXIT);
|
||||
|
||||
ThreadWaitCount(waitCount2 + g_testCnt1, &g_testCnt1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt2, old, g_testCnt2, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt1, 120, g_testCnt1, EXIT); // 120, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
|
||||
g_testPthredCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 1, g_testPthredCount);
|
||||
g_testPthredCount++; // 2
|
||||
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 2, g_testPthredCount); // 2, here assert the result.
|
||||
g_testPthredCount++; // 3
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 7, g_testPthredCount); // 7, here assert the result.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int g_currThreadPri, g_currThreadPolicy;
|
||||
static volatile int g_pthreadTestCount = 0;
|
||||
static volatile int g_threadTestCount1 = 0;
|
||||
static pthread_spinlock_t g_spinTestLock;
|
||||
|
||||
static void *ThreadFunc8(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int ret;
|
||||
|
||||
ret = pthread_detach(pthread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc7(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int ret;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ret = pthread_detach(pthread);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc8, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
sleep(2); // 2, delay
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc5(void *arg)
|
||||
{
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, -ret, EXIT);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc7, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_threadTestCount1++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc6(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 12, g_pthreadTestCount, EXIT); // 12, here assert the result.
|
||||
g_pthreadTestCount++; // 13
|
||||
|
||||
return (void *)(uintptr_t)pthread;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc4(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 9, g_pthreadTestCount, EXIT); // 9, here assert the result.
|
||||
g_pthreadTestCount++; // 10
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
pthread_t pthread = pthread_self();
|
||||
int i = 0;
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 6, g_pthreadTestCount, EXIT); // 6, here assert the result.
|
||||
g_pthreadTestCount++; // 7
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
while (1) {
|
||||
pthread_testcancel();
|
||||
if (++i == 5) { // 5, in loop 5, set cancel state.
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
}
|
||||
|
||||
if (i == 10) { // 10, in loop 10, cancel pthread.
|
||||
ret = pthread_cancel(pthread);
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(i, 10, i, EXIT); // 10, here assert the result.
|
||||
return (void *)i;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *threadFunc2(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 3, g_pthreadTestCount, EXIT); // 3, here assert the result.
|
||||
g_pthreadTestCount++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(pthread_self(), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
ret = pthread_detach(pthread_self());
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *threadFunc(void *arg)
|
||||
{
|
||||
unsigned int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 2, g_pthreadTestCount, EXIT); // 2, here assert the result.
|
||||
g_pthreadTestCount++;
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, threadFunc2, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
sleep(1);
|
||||
#endif
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 4, g_pthreadTestCount, EXIT); // 4, here assert the result.
|
||||
g_pthreadTestCount++; // 5
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 2; // 2, adjust priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc3, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 5, g_pthreadTestCount, EXIT); // 5, here assert the result.
|
||||
g_pthreadTestCount++; // 6
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 7, g_pthreadTestCount, EXIT); // 7, here assert the result.
|
||||
g_pthreadTestCount++; // 8
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 3; // 3, adjust priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFunc4, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 8, g_pthreadTestCount, EXIT); // 8, here assert the result.
|
||||
g_pthreadTestCount++; // 9
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_spin_lock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 10, g_pthreadTestCount, EXIT); // 10, here assert the result.
|
||||
g_pthreadTestCount++; // 11
|
||||
ret = pthread_spin_unlock(&g_spinTestLock);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PthreadTest004()
|
||||
{
|
||||
int exitCount = 0;
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
const int testCount = 5;
|
||||
int count = 5;
|
||||
pthread_spin_init(&g_spinTestLock, 0);
|
||||
|
||||
g_threadTestCount1 = 0;
|
||||
g_pthreadTestCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_pthreadTestCount++;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = g_currThreadPri + 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, threadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 1, g_pthreadTestCount);
|
||||
g_pthreadTestCount++;
|
||||
|
||||
while (count > 0) {
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc5, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_detach(newPthread1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
count--;
|
||||
}
|
||||
|
||||
g_threadTestCount1++;
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTestCount1, 1, g_threadTestCount1);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_threadTestCount1 != (1 + (testCount * 3))) { // 3
|
||||
sleep(2); // 2, delay
|
||||
printf("Wait for the concurrent thread to end \n");
|
||||
exitCount++;
|
||||
if (exitCount > 10) { // wait time > 10 * 2s, cancel wait.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 11, g_pthreadTestCount); // 11, here assert the result.
|
||||
g_pthreadTestCount++; // 12
|
||||
|
||||
param.sched_priority = g_currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread1, &a, ThreadFunc6, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread1, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 13, g_pthreadTestCount); // 13, here assert the result.
|
||||
g_pthreadTestCount++; // 14
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_pthreadTestCount, 14, g_pthreadTestCount); // 14, here assert the result.
|
||||
|
||||
pthread_spin_destroy(&g_spinTestLock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_004", PthreadTest004, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
extern int PthreadTest001(void);
|
||||
extern int PthreadTest004(void);
|
||||
|
||||
static void *threadFunc(void *a)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
(void)PthreadTest004();
|
||||
(void)PthreadTest001();
|
||||
exit(12); // 12, set a special exit code.
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
sleep(10); // 10, delay for timimg control.
|
||||
|
||||
ret = PthreadTest001();
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
(void)waitpid(pid, &status, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
int status;
|
||||
int pid;
|
||||
pthread_t tid;
|
||||
|
||||
ret = fork();
|
||||
if (ret == 0) {
|
||||
ret = pthread_create(&tid, NULL, threadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
exit(10); // 10, set a special exit code.
|
||||
} else if (ret > 0) {
|
||||
pid = ret;
|
||||
sleep(10); // 10, delay for timimg control.
|
||||
(void)PthreadTest004();
|
||||
ret = wait(&status);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
|
||||
ICUNIT_ASSERT_EQUAL(status, 10, status); // 10, assert the exit code.
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, 100000, pid); // 100000, The pid will never exceed 100000.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread005(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_005", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
#include "threads.h"
|
||||
static const int TEST_LOOP = 5000;
|
||||
|
||||
static int g_testCnt = 0;
|
||||
static void *ThreadFunc(void *arg)
|
||||
{
|
||||
int count = 1;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
g_testCnt = TEST_LOOP + 1000; // 1000, here set a special num.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc1(void *arg)
|
||||
{
|
||||
int count = 2;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc2(void *arg)
|
||||
{
|
||||
int count = 3;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFunc3(void *arg)
|
||||
{
|
||||
int count = 4;
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
if (g_testCnt != count) {
|
||||
printf("%s %d g_testCnt should : %d but is : %d\n", __FUNCTION__, __LINE__, count, g_testCnt);
|
||||
return NULL;
|
||||
}
|
||||
g_testCnt++;
|
||||
count += 5; // total 5 pthreads.
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid, tid1, tid2, tid3;
|
||||
pthread_attr_t attr = { 0 };
|
||||
int scope = 0;
|
||||
int threadPolicy = 0;
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
g_testCnt = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &threadPolicy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_create(&tid, NULL, ThreadFunc, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid1, NULL, ThreadFunc1, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, NULL, ThreadFunc2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid3, NULL, ThreadFunc3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
while (g_testCnt < TEST_LOOP) {
|
||||
g_testCnt++;
|
||||
thrd_yield();
|
||||
}
|
||||
|
||||
param.sched_priority -= 2; // 2, adjust the priority.
|
||||
ret = pthread_setschedparam(tid, SCHED_FIFO, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCnt, TEST_LOOP + 1000, g_testCnt, EXIT); // 1000, here assert the special num.
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid3, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
param.sched_priority += 2; // 2, adjust the priority.
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread014(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_014", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
84
testsuites/unittest/process/basic/pthread/it_pthread_test.h
Normal file
84
testsuites/unittest/process/basic/pthread/it_pthread_test.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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_PTHREAD_TEST_H
|
||||
#define _IT_PTHREAD_TEST_H
|
||||
|
||||
#include "osTest.h"
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
|
||||
#define SLEEP_AND_YIELD(tick) usleep((tick)*10 * 1000)
|
||||
|
||||
#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 void ItTestPthread001(void);
|
||||
extern void ItTestPthread002(void);
|
||||
extern void ItTestPthread003(void);
|
||||
extern void ItTestPthread004(void);
|
||||
extern void ItTestPthread005(void);
|
||||
extern void ItTestPthread006(void);
|
||||
extern void ItTestPthread007(void);
|
||||
extern void ItTestPthread008(void);
|
||||
extern void ItTestPthread009(void);
|
||||
extern void ItTestPthread010(void);
|
||||
extern void ItTestPthread012(void);
|
||||
extern void ItTestPthread011(void);
|
||||
extern void ItTestPthread013(void);
|
||||
extern void ItTestPthread014(void);
|
||||
extern void ItTestPthread015(void);
|
||||
extern void ItTestPthread016(void);
|
||||
extern void ItTestPthread017(void);
|
||||
extern void ItTestPthread018(void);
|
||||
extern void ItTestPthread019(void);
|
||||
extern void ItTestPthreadAtfork001(void);
|
||||
extern void ItTestPthreadAtfork002(void);
|
||||
extern void ItTestPthreadOnce001(void);
|
||||
extern void ItTestPthreadCond001(void);
|
||||
extern void ItTestPthreadCond002(void);
|
||||
extern void ItTestPthreadCond003(void);
|
||||
extern void ItTestPthreadCond004(void);
|
||||
#endif
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
#include <sys/resource.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessPthreadTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int currThreadPolicy, ret;
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret);
|
||||
param.sched_priority = TASK_PRIO_TEST;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, -ret);
|
||||
}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_003
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread003();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_006
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread006, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread006();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_007
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread007, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread007();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_008
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread008, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread008();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_009
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread009, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread009();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_010
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread010, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread010();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_011
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread011, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread011();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_012
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread012, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread012();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_013
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread013, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread013();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_015
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread015, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread015();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_016
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread016, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread016();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_018
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread018, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread018();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_019
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread019();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_017
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread017();
|
||||
}
|
||||
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_once_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadOnce001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadOnce001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_atfork_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadAtfork001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_atfork_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadAtfork002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadAtfork002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond001();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond002();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_003
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond003, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond003();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_cond_004
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthreadCond004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthreadCond004();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_001
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread001, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread001();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_002
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread002, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread002();
|
||||
}
|
||||
#endif
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_004
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_005
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread005();
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_USER_TEST_SMP
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_014
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread014, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread014();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static volatile int g_count = 0;
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_testAtforkCount = 0;
|
||||
static int g_testAtforkPrepare = 0;
|
||||
static int g_testAtforkParent = 0;
|
||||
static int g_testAtforkChild = 0;
|
||||
static const int SLEEP_TIME = 2;
|
||||
|
||||
static void Prepare()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkPrepare++;
|
||||
}
|
||||
|
||||
static void Parent()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkParent++;
|
||||
}
|
||||
|
||||
static void child()
|
||||
{
|
||||
int err;
|
||||
ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount);
|
||||
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkChild++;
|
||||
}
|
||||
|
||||
static void *ThreadProc(void *arg)
|
||||
{
|
||||
int err;
|
||||
|
||||
while (g_count < 5) { // 5, wait until g_count == 5.
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_count++;
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadAtforkTest(void *arg)
|
||||
{
|
||||
int err;
|
||||
pid_t pid;
|
||||
pthread_t tid;
|
||||
int status = 0;
|
||||
|
||||
g_count = 0;
|
||||
g_testAtforkCount = 0;
|
||||
g_testAtforkPrepare = 0;
|
||||
g_testAtforkParent = 0;
|
||||
g_testAtforkChild = 0;
|
||||
|
||||
err = pthread_create(&tid, NULL, ThreadProc, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
err = pthread_atfork(Prepare, Parent, child);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
g_testAtforkCount++;
|
||||
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, The pid will never exceed 100000.
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT);
|
||||
|
||||
if (pid == 0) {
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkChild, 1, g_testAtforkChild, EXIT);
|
||||
int status;
|
||||
while (g_count < 5) { // 5, wait until g_count == 5.
|
||||
err = pthread_mutex_lock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_count++;
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
err = pthread_mutex_unlock(&g_lock);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
SLEEP_AND_YIELD(SLEEP_TIME);
|
||||
}
|
||||
exit(15); // 15, set exit status
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT);
|
||||
err = pthread_join(tid, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT);
|
||||
|
||||
err = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(err, pid, err, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(status, 15, status, EXIT); // 15, get exit status.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
|
||||
EXIT_WAIT:
|
||||
(void)waitpid(pid, &status, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadAtfork001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ATFORK_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
#include <time.h>
|
||||
|
||||
extern int nanosleep(const struct timespec *req, struct timespec *rem);
|
||||
|
||||
static pthread_mutex_t g_mux = PTHREAD_MUTEX_INITIALIZER;
|
||||
static volatile int g_testAtforkCount = 0;
|
||||
static int g_testAtforkPrepare = 0;
|
||||
static int g_testAtforkParent = 0;
|
||||
|
||||
static void *Doit(void *arg)
|
||||
{
|
||||
int err;
|
||||
struct timespec ts = { 2, 0 }; // 2, set time 2s.
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT);
|
||||
|
||||
err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
(void)nanosleep(&ts, NULL);
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *Doit1(void *arg)
|
||||
{
|
||||
int err;
|
||||
struct timespec ts = { 2, 0 }; // 2, set time 2s.
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT);
|
||||
|
||||
err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
(void)nanosleep(&ts, NULL);
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void Prepare(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = pthread_mutex_unlock(&g_mux);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkPrepare++;
|
||||
}
|
||||
|
||||
static void Parent(void)
|
||||
{
|
||||
int err = pthread_mutex_lock(&g_mux);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(err, 0, err);
|
||||
g_testAtforkParent++;
|
||||
}
|
||||
|
||||
static void *PthreadAtforkTest(void *arg)
|
||||
{
|
||||
int err, ret;
|
||||
int pid;
|
||||
int status = 0;
|
||||
struct timespec ts = { 1, 0 };
|
||||
pthread_t tid;
|
||||
|
||||
g_testAtforkCount = 0;
|
||||
g_testAtforkPrepare = 0;
|
||||
g_testAtforkParent = 0;
|
||||
|
||||
err = pthread_atfork(Prepare, Parent, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
g_testAtforkCount++;
|
||||
err = pthread_create(&tid, NULL, Doit, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
|
||||
nanosleep(&ts, NULL);
|
||||
pid = fork();
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT);
|
||||
if (pid == 0) {
|
||||
Doit1(NULL);
|
||||
exit(10); // 10, set exit status.
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT_WAIT); // 100000, The pid will never exceed 100000.
|
||||
ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT);
|
||||
|
||||
err = pthread_join(tid, NULL);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT);
|
||||
|
||||
|
||||
err = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
ICUNIT_GOTO_EQUAL(err, pid, err, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(status, 10, status, EXIT); // 10, get exit status.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
|
||||
EXIT_WAIT:
|
||||
(void)waitpid(pid, 0, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadAtfork002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ATFORK_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static pthread_mutex_t g_pthreadMuxTest1;
|
||||
static pthread_cond_t g_pthdCondTest1;
|
||||
|
||||
static void *PthreadF01(void *t)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
LosTaskDelay(100);
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, here assert the result.
|
||||
g_testCount++;
|
||||
|
||||
rc = pthread_cond_wait(&g_pthdCondTest1, &g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // 5, here assert the result.
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadF02(void *t)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
|
||||
g_testCount++;
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, here assert the result.
|
||||
g_testCount++;
|
||||
rc = pthread_cond_signal(&g_pthdCondTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, here assert the result.
|
||||
g_testCount++;
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
LosTaskDelay(2); // 2, delay for Timing control.
|
||||
|
||||
EXIT:
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int i;
|
||||
long t1 = 1;
|
||||
long t2 = 2;
|
||||
int rc;
|
||||
pthread_t threads[3]; // 3, need 3 pthread for test.
|
||||
pthread_attr_t attr;
|
||||
const int loopNum = 2;
|
||||
|
||||
g_testCount = 0;
|
||||
pthread_mutex_init(&g_pthreadMuxTest1, NULL);
|
||||
pthread_cond_init(&g_pthdCondTest1, NULL);
|
||||
|
||||
rc = pthread_create(&threads[0], NULL, PthreadF01, (void *)t1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_create(&threads[1], NULL, PthreadF02, (void *)t2);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
for (i = 0; i < loopNum; i++) {
|
||||
rc = pthread_join(threads[i], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
rc = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&g_pthreadMuxTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
rc = pthread_cond_destroy(&g_pthdCondTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_001", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static pthread_mutex_t g_pthreadMuxTest1;
|
||||
static pthread_cond_t g_pthrdCondTest1;
|
||||
static unsigned int g_pthreadExit = 0;
|
||||
|
||||
static void *PthreadF01(void *t)
|
||||
{
|
||||
int rc;
|
||||
unsigned int count = 0;
|
||||
const int testLoop = 2000;
|
||||
while (count < testLoop) {
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_wait(&g_pthrdCondTest1, &g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
count++;
|
||||
}
|
||||
|
||||
g_pthreadExit = 1;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PthreadF02(void *t)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
while (g_pthreadExit != 1) {
|
||||
rc = pthread_mutex_lock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_cond_signal(&g_pthrdCondTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
|
||||
rc = pthread_mutex_unlock(&g_pthreadMuxTest1);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static unsigned int TestCase(void)
|
||||
{
|
||||
int i;
|
||||
long t1 = 1;
|
||||
long t2 = 2;
|
||||
int rc;
|
||||
pthread_t threads[3];
|
||||
pthread_attr_t attr;
|
||||
const int loopNum = 2;
|
||||
|
||||
g_pthreadExit = 0;
|
||||
g_testCount = 0;
|
||||
pthread_mutex_init(&g_pthreadMuxTest1, NULL);
|
||||
pthread_cond_init(&g_pthrdCondTest1, NULL);
|
||||
|
||||
rc = pthread_create(&threads[0], NULL, PthreadF01, (void *)t1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_create(&threads[1], NULL, PthreadF02, (void *)t2);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
for (i = 0; i < loopNum; i++) {
|
||||
rc = pthread_join(threads[i], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
}
|
||||
|
||||
rc = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
rc = pthread_mutex_destroy(&g_pthreadMuxTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
rc = pthread_cond_destroy(&g_pthrdCondTest1);
|
||||
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond002(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_002", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static pthread_cond_t g_pthread_cond;
|
||||
static pthread_mutex_t g_pthread_mutex;
|
||||
#define TEST_THREAD_COUNT 5
|
||||
static void *pthread_cond_func001(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 60; /* 60: wait 1 minute */
|
||||
|
||||
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *pthread_f06(void *argument)
|
||||
{
|
||||
int policy;
|
||||
int ret;
|
||||
int i;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedParam = { 0 };
|
||||
pthread_t thread[TEST_THREAD_COUNT];
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_create(&thread[i], &attr, pthread_cond_func001, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_cond_broadcast(&g_pthread_cond);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_join(thread[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int policy;
|
||||
pthread_attr_t attr;
|
||||
pthread_t newTh;
|
||||
struct sched_param schedParam = { 0 };
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_cond_init(&g_pthread_cond, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, pthread_f06, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_003", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
static pthread_cond_t g_pthread_cond;
|
||||
static pthread_mutex_t g_pthread_mutex;
|
||||
#define TEST_THREAD_COUNT 5
|
||||
|
||||
static void *pthread_cond_func002(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
|
||||
g_testCount++;
|
||||
|
||||
ret = pthread_mutex_lock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec += 2; /* 2: wait 2 seconds */
|
||||
|
||||
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
|
||||
|
||||
ret = pthread_mutex_unlock(&g_pthread_mutex);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *pthread_f07(void *argument)
|
||||
{
|
||||
int policy;
|
||||
int ret;
|
||||
int i;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedParam = { 0 };
|
||||
pthread_t thread[TEST_THREAD_COUNT];
|
||||
|
||||
g_testCount = 0;
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_create(&thread[i], &attr, pthread_cond_func002, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
|
||||
|
||||
for (i = 0; i < TEST_THREAD_COUNT; i++) {
|
||||
ret = pthread_join(thread[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int policy;
|
||||
pthread_attr_t attr;
|
||||
pthread_t newTh;
|
||||
struct sched_param schedParam = { 0 };
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_cond_init(&g_pthread_cond, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
schedParam.sched_priority -= 1;
|
||||
ret = pthread_attr_setschedparam(&attr, &schedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newTh, &attr, pthread_f07, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newTh, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadCond004(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_004", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int g_number = 0;
|
||||
static int g_okStatus = 777; // 777, a special number indicate the status is ok.
|
||||
static pthread_once_t g_onceCtrl = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void InitRoutine(void)
|
||||
{
|
||||
g_number++;
|
||||
}
|
||||
|
||||
static void *Threadfunc(void *parm)
|
||||
{
|
||||
int err;
|
||||
err = pthread_once(&g_onceCtrl, InitRoutine);
|
||||
ICUNIT_GOTO_EQUAL(err, 0, err, EXIT);
|
||||
return (void *)g_okStatus;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest(void *arg)
|
||||
{
|
||||
pthread_t thread[3];
|
||||
int rc = 0;
|
||||
int i = 3;
|
||||
void *status;
|
||||
const int threadsNum = 3;
|
||||
|
||||
g_number = 0;
|
||||
|
||||
for (i = 0; i < threadsNum; ++i) {
|
||||
rc = pthread_create(&thread[i], NULL, Threadfunc, NULL);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
}
|
||||
|
||||
for (i = 0; i < threadsNum; ++i) {
|
||||
rc = pthread_join(thread[i], &status);
|
||||
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
|
||||
ICUNIT_GOTO_EQUAL((unsigned int)status, (unsigned int)g_okStatus, status, EXIT);
|
||||
}
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_number, 1, g_number, EXIT);
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t newPthread;
|
||||
int curThreadPri, curThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param param = { 0 };
|
||||
|
||||
g_onceCtrl = PTHREAD_ONCE_INIT;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
curThreadPri = param.sched_priority;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = curThreadPri + 2; // 2, adjust the priority.
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
ret = pthread_create(&newPthread, &a, ThreadFuncTest, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthreadOnce001(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_PTHREAD_ONCE_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
/* ***************************************************************************
|
||||
* Public Functions
|
||||
* ************************************************************************** */
|
||||
|
||||
static int g_currThreadPri, g_currThreadPolicy;
|
||||
static int g_testPthredCount;
|
||||
static void *ThreadFuncTest2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int policy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_getschedparam(pthread, &policy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPri, param.sched_priority, param.sched_priority, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPolicy, policy, policy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testPthredCount, 2, g_testPthredCount, EXIT); // 2, here assert the result.
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int policy;
|
||||
struct sched_param param = { 0 };
|
||||
pthread_t pthread = pthread_self();
|
||||
|
||||
g_testPthredCount++;
|
||||
|
||||
ret = pthread_getschedparam(pthread, &policy, ¶m);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(g_currThreadPri, param.sched_priority, param.sched_priority, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(policy, SCHED_FIFO, policy, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(g_testPthredCount, 4, g_testPthredCount, EXIT); // 4, here assert the result.
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase()
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t newPthread, newPthread1;
|
||||
|
||||
g_testPthredCount = 0;
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &g_currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
g_currThreadPri = param.sched_priority;
|
||||
|
||||
g_testPthredCount++;
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFuncTest2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 2, g_testPthredCount); // 2, here assert the result.
|
||||
g_testPthredCount++;
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&newPthread, NULL, ThreadFuncTest3, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newPthread, &res);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testPthredCount, 4, g_testPthredCount); // 4, here assert the result.
|
||||
|
||||
param.sched_priority = g_currThreadPri;
|
||||
ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread003(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_003", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static pthread_barrier_t g_barrier;
|
||||
static int g_testToCount001 = 0;
|
||||
static int g_threadTest[10];
|
||||
|
||||
static void *ThreadFuncTest0(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, PTHREAD_BARRIER_SERIAL_THREAD, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest2(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *ThreadFuncTest1(void *a)
|
||||
{
|
||||
int ret;
|
||||
int count = *((int *)a);
|
||||
g_testToCount001++;
|
||||
|
||||
ret = pthread_barrier_wait(&g_barrier);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
g_threadTest[count] = count;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Testcase(void)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
void *res = NULL;
|
||||
pthread_attr_t a = { 0 };
|
||||
pthread_t thread;
|
||||
pthread_t newPthread[10], newPthread1;
|
||||
pthread_mutexattr_t mutex;
|
||||
int index = 0;
|
||||
int currThreadPri, currThreadPolicy;
|
||||
int threadParam[10];
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
currThreadPri = param.sched_priority;
|
||||
const int testCount = 10;
|
||||
|
||||
g_testToCount001 = 0;
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
param.sched_priority = currThreadPri - 1;
|
||||
pthread_attr_setschedparam(&a, ¶m);
|
||||
|
||||
ret = pthread_barrier_init(&g_barrier, NULL, testCount);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
threadParam[0] = 0;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest0, &threadParam[0]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_threadTest[0] = 0;
|
||||
|
||||
index = 1;
|
||||
while (index < (testCount - 1)) {
|
||||
threadParam[index] = index;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest1, &threadParam[index]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_threadTest[index] = 0;
|
||||
index++;
|
||||
}
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount - 1, g_testToCount001);
|
||||
|
||||
threadParam[index] = index;
|
||||
ret = pthread_create(&newPthread[index], &a, ThreadFuncTest2, &threadParam[index]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
sleep(1);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount, g_testToCount001);
|
||||
|
||||
index = 0;
|
||||
while (index < testCount) {
|
||||
threadParam[index] = index;
|
||||
ret = pthread_join(newPthread[index], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_threadTest[index], index, g_threadTest[index]);
|
||||
index++;
|
||||
}
|
||||
|
||||
ret = pthread_barrier_destroy(&g_barrier);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread006(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_006", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
|
||||
static pthread_t g_th;
|
||||
VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
sleep(1);
|
||||
g_testCount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc1115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc2115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 15); // 1000 * 10 * 15, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *PthreadFunc3115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 6); // 1000 * 10 * 6, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
|
||||
int ret = 0;
|
||||
pthread_t th1;
|
||||
pthread_t th2;
|
||||
pthread_t th3;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&th1, &attr, PthreadFunc1115, NULL);
|
||||
pthread_create(&th2, &attr, PthreadFunc2115, NULL);
|
||||
pthread_create(&th3, &attr, PthreadFunc3115, NULL);
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 50); // 1000 * 10 * 50, delay for timimg control.
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 8, g_testCount); // 8, assert the exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread007(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
|
||||
static pthread_t g_th;
|
||||
static VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
sleep(1);
|
||||
g_testCount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc1115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 10); // 1000 * 10 * 10, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc2115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 15); // 1000 * 10 * 15, delay for timimg control.
|
||||
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
g_testCount++;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VOID *PthreadFunc3115(VOID *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
g_testCount++;
|
||||
usleep(1000 * 10 * 6); // 1000 * 10 * 6, delay for timimg control.
|
||||
|
||||
ret = pthread_detach(g_th);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_testCount++;
|
||||
;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int rc;
|
||||
|
||||
int ret = 0;
|
||||
pthread_t th1;
|
||||
pthread_t th2;
|
||||
pthread_t th3;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&th1, &attr, PthreadFunc1115, NULL);
|
||||
pthread_create(&th2, &attr, PthreadFunc2115, NULL);
|
||||
pthread_create(&th3, &attr, PthreadFunc3115, NULL);
|
||||
ret = pthread_join(g_th, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(1000 * 10 * 50); // 1000 * 10 * 50, delay for timimg control.
|
||||
ICUNIT_ASSERT_EQUAL(g_testCount, 8, g_testCount); // 8, assert the exit code.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread008(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_008", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static pthread_t g_th;
|
||||
static VOID *PthreadTest115(VOID *arg)
|
||||
{
|
||||
g_testCount++;
|
||||
int ret = pthread_detach(g_th);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
g_testCount++;
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
g_testCount = 0;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(&g_th, &attr, PthreadTest115, NULL);
|
||||
|
||||
#ifdef LOSCFG_USER_TEST_SMP
|
||||
sleep(1);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTestPthread009(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_009", 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