feat: 添加pid容器测试用例
Close #I69Z22 Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: If2d737766f4cecef70a57be9574cf3785b6900a8
This commit is contained in:
parent
251abede16
commit
c403fdf8ed
|
@ -151,5 +151,15 @@ group("unittest") {
|
|||
deps += [ "security:liteos_a_security_unittest" ]
|
||||
}
|
||||
}
|
||||
|
||||
# container test
|
||||
if (LOSCFG_USER_TEST_CONTAINER == true) {
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
deps += [ "container:liteos_a_container_unittest_door" ]
|
||||
}
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
|
||||
deps += [ "container:liteos_a_container_unittest" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("$root_out_dir/config.gni")
|
||||
TEST_UNITTEST_DIR = rebase_path(".")
|
||||
|
||||
TEST_LEVEL_LOW = 1
|
||||
|
@ -124,3 +125,13 @@ LOSCFG_USER_TEST_SECURITY = true
|
|||
LOSCFG_USER_TEST_SECURITY_CAPABILITY = true
|
||||
LOSCFG_USER_TEST_SECURITY_REUGID = true
|
||||
LOSCFG_USER_TEST_SECURITY_VID = true
|
||||
|
||||
########## container test ##########
|
||||
LOSCFG_USER_TEST_CONTAINER = false
|
||||
LOSCFG_USER_TEST_PID_CONTAINER = false
|
||||
if (defined(LOSCFG_KERNEL_CONTAINER)) {
|
||||
LOSCFG_USER_TEST_CONTAINER = true
|
||||
if (defined(LOSCFG_PID_CONTAINER)) {
|
||||
LOSCFG_USER_TEST_PID_CONTAINER = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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")
|
||||
|
||||
config("container_config") {
|
||||
cflags = []
|
||||
if (defined(LOSCFG_USER_TEST_PID_CONTAINER)) {
|
||||
cflags += [ "-DLOSCFG_USER_TEST_PID_CONTAINER" ]
|
||||
}
|
||||
cflags_cc = cflags
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
unittest("liteos_a_container_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",
|
||||
":container_config",
|
||||
]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
|
||||
unittest("liteos_a_container_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",
|
||||
":container_config",
|
||||
]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,410 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
const char *USERDATA_DIR_NAME = "/userdata";
|
||||
const char *ACCESS_FILE_NAME = "/userdata/mntcontainertest";
|
||||
const char *USERDATA_DEV_NAME = "/dev/mmcblk0p2";
|
||||
const char *FS_TYPE = "vfat";
|
||||
|
||||
const int BIT_ON_RETURN_VALUE = 8;
|
||||
const int STACK_SIZE = 1024 * 1024;
|
||||
const int CHILD_FUNC_ARG = 0x2088;
|
||||
|
||||
int ChildFunction(void *args)
|
||||
{
|
||||
(void)args;
|
||||
const int sleep_time = 2;
|
||||
sleep(sleep_time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t CloneWrapper(int (*func)(void *), int flag, void *args)
|
||||
{
|
||||
pid_t pid;
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
if (stack == MAP_FAILED) {
|
||||
return -1;
|
||||
}
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
pid = clone(func, stackTop, flag, args);
|
||||
munmap(stack, STACK_SIZE);
|
||||
return pid;
|
||||
}
|
||||
|
||||
std::string GenContainerLinkPath(int pid, const std::string& containerType)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid << "/container/" << containerType;
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
std::string ReadlinkContainer(int pid, const std::string& containerType)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
auto path = GenContainerLinkPath(pid, containerType);
|
||||
|
||||
struct stat sb;
|
||||
int ret = lstat(path.data(), &sb);
|
||||
if (ret == -1) {
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
size_t bufsiz = sb.st_size + 1;
|
||||
if (sb.st_size == 0) {
|
||||
bufsiz = PATH_MAX;
|
||||
}
|
||||
|
||||
(void)memset_s(buf, PATH_MAX, 0, PATH_MAX);
|
||||
ssize_t nbytes = readlink(path.c_str(), buf, bufsiz);
|
||||
if (nbytes == -1) {
|
||||
throw std::exception();
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ContainerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
|
||||
protected:
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
HWTEST_F(ContainerTest, ItContainer001, TestSize.Level0)
|
||||
{
|
||||
ItContainer001();
|
||||
}
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_023
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer023, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer023();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_001
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer001, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_002
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer002, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_003
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer003, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_004
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer004, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_006
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer006, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_007
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer007, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_008
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer008, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer008();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_009
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer009, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer009();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_010
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer010, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer010();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_011
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer011, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer011();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_012
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer012, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer012();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_013
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer013, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer013();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_014
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer014, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer014();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_015
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer015, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer015();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_016
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer016, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer016();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_017
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer017, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer017();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_018
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer018, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer018();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_019
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer019, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer019();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_020
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer020, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer020();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_021
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer021, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer021();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_022
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer022, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer022();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_024
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI68LVW
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer024, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer024();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
|
||||
namespace OHOS {
|
||||
void ContainerTest::SetUp()
|
||||
{
|
||||
mode_t mode = 0;
|
||||
(void)mkdir(ACCESS_FILE_NAME, S_IFDIR | mode);
|
||||
}
|
||||
void ContainerTest::TearDown()
|
||||
{
|
||||
(void)rmdir(ACCESS_FILE_NAME);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_CONTAINER_TEST_H
|
||||
#define _IT_CONTAINER_TEST_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/capability.h>
|
||||
#include "osTest.h"
|
||||
|
||||
const int EXIT_CODE_ERRNO_1 = 1;
|
||||
const int EXIT_CODE_ERRNO_2 = 2;
|
||||
const int EXIT_CODE_ERRNO_3 = 3;
|
||||
const int EXIT_CODE_ERRNO_4 = 4;
|
||||
const int EXIT_CODE_ERRNO_5 = 5;
|
||||
const int EXIT_CODE_ERRNO_6 = 6;
|
||||
const int EXIT_CODE_ERRNO_7 = 7;
|
||||
const int EXIT_CODE_ERRNO_8 = 8;
|
||||
const int EXIT_CODE_ERRNO_9 = 9;
|
||||
const int EXIT_CODE_ERRNO_10 = 10;
|
||||
const int EXIT_CODE_ERRNO_11 = 11;
|
||||
const int EXIT_CODE_ERRNO_12 = 12;
|
||||
const int EXIT_CODE_ERRNO_13 = 13;
|
||||
const int EXIT_CODE_ERRNO_14 = 14;
|
||||
const int EXIT_CODE_ERRNO_15 = 15;
|
||||
const int EXIT_CODE_ERRNO_16 = 16;
|
||||
const int EXIT_CODE_ERRNO_255 = 255;
|
||||
const int CONTAINER_FIRST_PID = 1;
|
||||
const int CONTAINER_SECOND_PID = 2;
|
||||
const int CONTAINER_THIRD_PID = 3;
|
||||
|
||||
|
||||
extern const char *USERDATA_DIR_NAME;
|
||||
extern const char *ACCESS_FILE_NAME;
|
||||
extern const char *USERDATA_DEV_NAME;
|
||||
extern const char *FS_TYPE;
|
||||
|
||||
extern const int BIT_ON_RETURN_VALUE;
|
||||
extern const int STACK_SIZE;
|
||||
extern const int CHILD_FUNC_ARG;
|
||||
|
||||
int ChildFunction(void *args);
|
||||
|
||||
pid_t CloneWrapper(int (*func)(void *), int flag, void *args);
|
||||
|
||||
std::string GenContainerLinkPath(int pid, const std::string& containerType);
|
||||
|
||||
extern std::string ReadlinkContainer(int pid, const std::string& containerType);
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
void ItContainer001(void);
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
void ItPidContainer023(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
void ItPidContainer001(void);
|
||||
void ItPidContainer002(void);
|
||||
void ItPidContainer003(void);
|
||||
void ItPidContainer004(void);
|
||||
void ItPidContainer006(void);
|
||||
void ItPidContainer007(void);
|
||||
void ItPidContainer008(void);
|
||||
void ItPidContainer009(void);
|
||||
void ItPidContainer010(void);
|
||||
void ItPidContainer011(void);
|
||||
void ItPidContainer012(void);
|
||||
void ItPidContainer013(void);
|
||||
void ItPidContainer014(void);
|
||||
void ItPidContainer015(void);
|
||||
void ItPidContainer016(void);
|
||||
void ItPidContainer017(void);
|
||||
void ItPidContainer018(void);
|
||||
void ItPidContainer019(void);
|
||||
void ItPidContainer020(void);
|
||||
void ItPidContainer021(void);
|
||||
void ItPidContainer022(void);
|
||||
void ItPidContainer024(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _IT_CONTAINER_TEST_H */
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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")
|
||||
|
||||
common_include_dirs = [
|
||||
"//third_party/googletest/googletest/include",
|
||||
"../common/include",
|
||||
"$TEST_UNITTEST_DIR/container",
|
||||
]
|
||||
|
||||
sources_entry = [ "$TEST_UNITTEST_DIR/container/It_container_test.cpp" ]
|
||||
|
||||
sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_container_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_023.cpp",
|
||||
]
|
||||
|
||||
sources_full = [
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_014.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_022.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_024.cpp",
|
||||
]
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
void ItPidContainer001(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone3(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int childPid;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
pid_t parent_pid = getppid();
|
||||
if (parent_pid != CONTAINER_FIRST_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_THIRD_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
static int ChildFunClone2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone3, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = wait(&status);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_SECOND_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone2, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_FIRST_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer002(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone2()
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWUTS | SIGCHLD, NULL);
|
||||
|
||||
free(pstk);
|
||||
return childPid;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid = getpid();
|
||||
const int COUNT = 1000;
|
||||
int childPid;
|
||||
int childFunRet = (int)pid;
|
||||
int processCount = 0;
|
||||
int ret;
|
||||
int status;
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
childPid = ChildFunClone2();
|
||||
if (childPid != -1) {
|
||||
processCount++;
|
||||
} else {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
}
|
||||
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer003(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFunClone2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid != -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ChildFunClone1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = 0;
|
||||
int status;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFunClone2, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != 0) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer004(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFunClone1, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return getpid();
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid = getpid();
|
||||
int childFunRet = (int)pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
if (pstk == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
int childPid = clone(ChildFun1, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_SECOND_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
childPid = clone(ChildFun1, (char *)pstk + STACK_SIZE, SIGCHLD, NULL);
|
||||
if (childPid == -1) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ret = WIFEXITED(status);
|
||||
ret = WEXITSTATUS(status);
|
||||
if (ret != CONTAINER_THIRD_PID) {
|
||||
free(pstk);
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
free(pstk);
|
||||
return childFunRet;
|
||||
}
|
||||
|
||||
void ItPidContainer006(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
pid_t parentPid = getpid();
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, CONTAINER_FIRST_PID);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int status;
|
||||
int pid = getpid();
|
||||
if (pid != CONTAINER_FIRST_PID) {
|
||||
return -1;
|
||||
}
|
||||
ret = fork();
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
} else if (ret == 0) {
|
||||
if (getpid() != CONTAINER_SECOND_PID) {
|
||||
return -1;
|
||||
}
|
||||
exit(0);
|
||||
} else {
|
||||
wait(&status);
|
||||
}
|
||||
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
void ItPidContainer007(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_5);
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
cpu_set_t cpuset;
|
||||
cpu_set_t initCpuset;
|
||||
|
||||
CPU_ZERO(&initCpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &initCpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(1, &cpuset);
|
||||
ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
ret = sched_getaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
ret = (CPU_ISSET(0, &cpuset) > 0) ? 1 : 0;
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
ret = (CPU_ISSET(1, &cpuset) > 0) ? 1 : 0;
|
||||
if (ret != 1) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer008(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
int count = 1000;
|
||||
int processCount = 0;
|
||||
|
||||
pid = getpid();
|
||||
if (pid != CONTAINER_FIRST_PID) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
sleep(5); /* delay 5s */
|
||||
exit(0);
|
||||
} else if (pid < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
sleep(1);
|
||||
}
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
processCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while (processCount > 0) {
|
||||
ret = wait(&status);
|
||||
if (ret > 0) {
|
||||
processCount--;
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
exit(EXIT_CODE_ERRNO_255);
|
||||
}
|
||||
|
||||
void ItPidContainer009(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_255);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int currGid = getpgrp();
|
||||
if (currGid != CONTAINER_FIRST_PID) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = setpgid(getpid(), 0);
|
||||
if (ret == 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer010(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return execl("/bin/toybox", "toybox", "ps", (char *)0);
|
||||
}
|
||||
|
||||
void ItPidContainer011(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
return execl("/bin/shell", "shell", "kill", "-9", "1", (char *)0);
|
||||
}
|
||||
|
||||
void ItPidContainer012(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
const int SIGNAL_NUM = 9;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ret = WTERMSIG(status);
|
||||
ASSERT_EQ(ret, SIGNAL_NUM);
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid = getpid();
|
||||
if (pid != 1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
struct timespec ts = { 0 };
|
||||
const int MIN_NSEC = 5000000;
|
||||
const int MAX_NSEC = 20000000;
|
||||
int ret = sched_rr_get_interval(pid, &ts);
|
||||
if ((ts.tv_nsec < MIN_NSEC) || (ts.tv_nsec > MAX_NSEC)) {
|
||||
if (ts.tv_nsec != -1) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItPidContainer013(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = 0;
|
||||
int val, currPolicy;
|
||||
struct sched_param param = { 0 };
|
||||
const int DEFALUTE_PRIORITY = 31;
|
||||
int testProcessPri = 0;
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
if ((currProcessPri > DEFALUTE_PRIORITY) || (currProcessPri < 0)) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
testProcessPri = currProcessPri + 1;
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
if (currPolicy != SCHED_RR) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
val = getpriority(PRIO_PROCESS, 0);
|
||||
if (val != currProcessPri) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
ret = sched_getparam(0, ¶m);
|
||||
if ((ret != 0) || (param.sched_priority != currProcessPri)) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
val = sched_getscheduler(0);
|
||||
if (val != currPolicy) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 0, testProcessPri);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, 0);
|
||||
if (ret != testProcessPri) {
|
||||
return EXIT_CODE_ERRNO_7;
|
||||
}
|
||||
|
||||
param.sched_priority = currProcessPri;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_8;
|
||||
}
|
||||
|
||||
ret = getpriority(PRIO_PROCESS, getpid());
|
||||
if (ret != currProcessPri) {
|
||||
return EXIT_CODE_ERRNO_9;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_FIFO, ¶m);
|
||||
if ((ret != -1) || (errno != EINVAL)) {
|
||||
return EXIT_CODE_ERRNO_10;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(0, SCHED_RR, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_11;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(1, SCHED_FIFO, ¶m);
|
||||
if ((ret != -1) || (errno != EINVAL)) {
|
||||
return EXIT_CODE_ERRNO_12;
|
||||
}
|
||||
|
||||
ret = sched_setscheduler(2, SCHED_FIFO, ¶m); // 2, input the pid.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_13;
|
||||
}
|
||||
|
||||
ret = sched_setparam(1, ¶m);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_14;
|
||||
}
|
||||
|
||||
ret = sched_setparam(2, ¶m); // 2, set the param.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_15;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 1, testProcessPri);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_16;
|
||||
}
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, 2, testProcessPri); // 2, Used to calculate priorities.
|
||||
if ((ret != -1) || (errno != ESRCH)) {
|
||||
return EXIT_CODE_ERRNO_255;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer014(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "v2p", "1", "0x1000000", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer015(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "vmm", "1", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer016(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret = execl("/bin/shell", "shell", "cpup", "0", "1", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer017(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_PARENT_SLEEP_TIME = 2;
|
||||
const int TEST_CHILD_SLEEP_TIME = 5;
|
||||
static int ChildShell(void *p)
|
||||
{
|
||||
printf("\n###################### %s pid container process info ####################\n", (char *)p);
|
||||
int ret = execl("/bin/shell", "shell", "task", "-a", (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Child2(void *p)
|
||||
{
|
||||
(void)p;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int Child1(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid, NULL, 0);
|
||||
if (ret != pid) {
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
ret = Child1(NULL);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
pid_t pid2 = fork();
|
||||
if (pid2 == 0) {
|
||||
(void)Child2(NULL);
|
||||
}
|
||||
|
||||
pid_t pid3 = fork();
|
||||
if (pid3 == 0) {
|
||||
ret = ChildShell(static_cast<void *>(const_cast<char*>("Child")));
|
||||
if (ret != 0) {
|
||||
exit(EXIT_CODE_ERRNO_1);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
if (ret != pid1) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
|
||||
ret = waitpid(pid2, NULL, 0);
|
||||
if (ret != pid2) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
|
||||
ret = waitpid(pid3, NULL, 0);
|
||||
if (ret != pid3) {
|
||||
exit(EXIT_CODE_ERRNO_4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer018(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildShell(static_cast<void *>(const_cast<char*>("Parent")));
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_CMD_LEN = 20;
|
||||
const int TEST_PARENT_SLEEP_TIME = 2;
|
||||
const int TEST_CHILD_SLEEP_TIME = 5;
|
||||
static int ChildShell(void *p)
|
||||
{
|
||||
pid_t pid = (pid_t)(uintptr_t)p;
|
||||
char param[TEST_CMD_LEN] = {0};
|
||||
int ret = snprintf_s(param, TEST_CMD_LEN, TEST_CMD_LEN - 1, "-p %d", pid);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
printf("\n###################### Pid %d thread info ####################\n", pid);
|
||||
ret = execl("/bin/shell", "shell", "task", param, (char *)0);
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
|
||||
pthread_t pthread[TEST_COUNT] = {0};
|
||||
for (int count = 0; count < TEST_COUNT; count++) {
|
||||
pthread_create(&pthread[count], NULL, PthreadFunc, NULL);
|
||||
}
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
ret = ChildShell(reinterpret_cast<void *>(getppid()));
|
||||
if (ret != 0) {
|
||||
exit(EXIT_CODE_ERRNO_1);
|
||||
}
|
||||
}
|
||||
|
||||
sleep(TEST_CHILD_SLEEP_TIME);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
if (ret != pid1) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer019(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
pid_t pid;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildShell((void *)childPid);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
const int TEST_COUNT = 5;
|
||||
const int TEST_PARENT_SLEEP_TIME = 3;
|
||||
static int Child(void *p)
|
||||
{
|
||||
(void)p;
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
pid_t pid3 = fork();
|
||||
if (pid3 == 0) {
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
if (getppid() != 1) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pid_t pid2 = fork();
|
||||
if (pid2 == 0) {
|
||||
sleep(TEST_PARENT_SLEEP_TIME);
|
||||
|
||||
if (getppid() != 1) {
|
||||
exit(EXIT_CODE_ERRNO_4);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
int count = 2;
|
||||
int status = 0;
|
||||
|
||||
pid_t pid1 = fork();
|
||||
if (pid1 == 0) {
|
||||
(void)Child(NULL);
|
||||
}
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
if ((ret != pid1) || (WIFEXITED(status) == 0)) {
|
||||
exit(EXIT_CODE_ERRNO_2);
|
||||
}
|
||||
if (WEXITSTATUS(status) != 0) {
|
||||
exit(WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
ret = wait(&status);
|
||||
if ((ret < 0) || (WIFEXITED(status) == 0)) {
|
||||
exit(EXIT_CODE_ERRNO_3);
|
||||
}
|
||||
if (WEXITSTATUS(status) != 0) {
|
||||
exit(WEXITSTATUS(status));
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer020(void)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
struct timespec ts;
|
||||
clockid_t clockid;
|
||||
int ret;
|
||||
const int TEST_PID = 2;
|
||||
ret = clock_getcpuclockid(TEST_PID, &clockid);
|
||||
if (ret != EINVAL) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = clock_getcpuclockid(getpid(), &clockid);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
ret = clock_gettime(clockid, &ts);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer021(void)
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int ret;
|
||||
int status;
|
||||
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
|
||||
static int ChildFun(void *p)
|
||||
{
|
||||
(void)p;
|
||||
int ret;
|
||||
unsigned int cap;
|
||||
pid_t pid = getpid();
|
||||
|
||||
ret = ohos_capget(pid, &cap);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = kill(pid, SIGKILL);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItPidContainer022(void)
|
||||
{
|
||||
void *pstk = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(pstk != NULL);
|
||||
int ret;
|
||||
siginfo_t info = { 0 };
|
||||
|
||||
int childPid = clone(ChildFun, (char *)pstk + STACK_SIZE, CLONE_NEWPID | SIGCHLD, NULL);
|
||||
free(pstk);
|
||||
ASSERT_NE(childPid, -1);
|
||||
|
||||
ret = waitid(P_PID, childPid, &info, WEXITED);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
#include "sys/resource.h"
|
||||
#include "sys/wait.h"
|
||||
#include "pthread.h"
|
||||
#include "sched.h"
|
||||
|
||||
const int SLEEP_TIME_US = 1000;
|
||||
const int LOOP_NUM = 1000;
|
||||
|
||||
static int ChildFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
usleep(SLEEP_TIME_US);
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
static int GroupProcess(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int ret;
|
||||
int status = 0;
|
||||
|
||||
for (int i = 0; i < LOOP_NUM; i++) {
|
||||
int argTmp = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(ChildFunc, CLONE_NEWPID, &argTmp);
|
||||
if (pid == -1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
status = WEXITSTATUS(status);
|
||||
if (status != EXIT_CODE_ERRNO_5) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
}
|
||||
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
void ItPidContainer024(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(GroupProcess, CLONE_NEWPID, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
status = WEXITSTATUS(status);
|
||||
ASSERT_EQ(status, EXIT_CODE_ERRNO_5);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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_container_test.h"
|
||||
using namespace std;
|
||||
|
||||
const int TIMER_INTERVAL_3S = 3;
|
||||
|
||||
static int ChildFunc(void *arg)
|
||||
{
|
||||
int value = *((int *)arg);
|
||||
if (value != CHILD_FUNC_ARG) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
sleep(TIMER_INTERVAL_3S);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItContainer001(void)
|
||||
{
|
||||
int ret;
|
||||
int status = 0;
|
||||
int childReturn = 0;
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
char *stack = nullptr;
|
||||
char *stackTop = nullptr;
|
||||
stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||
ASSERT_NE(stack, MAP_FAILED);
|
||||
stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(ChildFunc, stackTop, SIGCHLD, &arg);
|
||||
(void)munmap(stack, STACK_SIZE);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
childReturn = (status >> BIT_ON_RETURN_VALUE) & 0xff;
|
||||
ASSERT_EQ(childReturn, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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_container_test.h"
|
||||
|
||||
static int ChildFunc(void *arg)
|
||||
{
|
||||
int value = *((int*)arg);
|
||||
if (value != CHILD_FUNC_ARG) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
if (getpid() != CONTAINER_FIRST_PID) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
if (getppid() != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer023(void)
|
||||
{
|
||||
int ret;
|
||||
void *stack = malloc(STACK_SIZE);
|
||||
ASSERT_TRUE(stack != NULL);
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
auto pid = clone(ChildFunc, (char *)stack + STACK_SIZE, CLONE_NEWPID, &arg);
|
||||
free(stack);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
int status;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
}
|
Loading…
Reference in New Issue