feat: 支持time容器

BREAKING CHANGE:
支持ipc容器及增强对外变更:
1.clone 支持CLONE_NEWTIME
2.增加”/proc/[pid]/container/time" 用于查询容器信息
3.增加”/proc/[pid]/container/time_for_children" 用于查询容器信息
4.增加”/proc/[pid]/container/pid_for_children" 用于查询容器信息
5.增加”/proc/[pid]/time_offsets" 用于查询和配置time容器信息

Close #I6B0A3

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I54d79937ca608a10a4384f61e11c88757f833edf
This commit is contained in:
zhushengle
2023-01-18 15:05:45 +08:00
parent 7e0dfb79f7
commit 16ed05e844
39 changed files with 1834 additions and 130 deletions

View File

@@ -44,6 +44,9 @@ config("container_config") {
if (defined(LOSCFG_USER_TEST_IPC_CONTAINER)) {
cflags += [ "-DLOSCFG_USER_TEST_IPC_CONTAINER" ]
}
if (defined(LOSCFG_USER_TEST_TIME_CONTAINER)) {
cflags += [ "-DLOSCFG_USER_TEST_TIME_CONTAINER" ]
}
cflags_cc = cflags
}

View File

@@ -126,6 +126,30 @@ HWTEST_F(ContainerTest, ItPidContainer023, TestSize.Level0)
{
ItPidContainer023();
}
/**
* @tc.name: Container_Pid_Test_025
* @tc.desc: pid container function test case
* @tc.type: FUNC
* @tc.require: issueI68LVW
* @tc.author:
*/
HWTEST_F(ContainerTest, ItPidContainer025, TestSize.Level0)
{
ItPidContainer025();
}
/**
* @tc.name: Container_Pid_Test_026
* @tc.desc: pid container function test case
* @tc.type: FUNC
* @tc.require: issueI68LVW
* @tc.author:
*/
HWTEST_F(ContainerTest, ItPidContainer026, TestSize.Level0)
{
ItPidContainer026();
}
#endif
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
/**
@@ -242,6 +266,56 @@ HWTEST_F(ContainerTest, ItIpcContainer004, TestSize.Level0)
ItIpcContainer004();
}
#endif
#if defined(LOSCFG_USER_TEST_TIME_CONTAINER)
/**
* @tc.name: Container_TIME_Test_001
* @tc.desc: time container function test case
* @tc.type: FUNC
* @tc.require: issueI6B0A3
* @tc.author:
*/
HWTEST_F(ContainerTest, ItTimeContainer001, TestSize.Level0)
{
ItTimeContainer001();
}
/*
* @tc.name: Container_TIME_Test_007
* @tc.desc: time container function test case
* @tc.type: FUNC
* @tc.require: issueI6B0A3
* @tc.author:
*/
HWTEST_F(ContainerTest, ItTimeContainer007, TestSize.Level0)
{
ItTimeContainer007();
}
/**
* @tc.name: Container_TIME_Test_009
* @tc.desc: time container function test case
* @tc.type: FUNC
* @tc.require: issueI6B0A3
* @tc.author:
*/
HWTEST_F(ContainerTest, ItTimeContainer009, TestSize.Level0)
{
ItTimeContainer009();
}
/**
* @tc.name: Container_TIME_Test_010
* @tc.desc: time container function test case
* @tc.type: FUNC
* @tc.require: issueI6B0A3
* @tc.author:
*/
HWTEST_F(ContainerTest, ItTimeContainer010, TestSize.Level0)
{
ItTimeContainer010();
}
#endif
#endif /* LOSCFG_USER_TEST_SMOKE */
#if defined(LOSCFG_USER_TEST_FULL)

View File

@@ -38,6 +38,7 @@
#include <csignal>
#include <sys/syscall.h>
#include <sys/capability.h>
#include <cstring>
#include "osTest.h"
#include "mqueue.h"
#include "sys/time.h"
@@ -86,6 +87,10 @@ extern const int CHILD_FUNC_ARG;
const int MQUEUE_STANDARD_NAME_LENGTH = 255;
extern "C" {
#define CLONE_NEWTIME 0x00000080
}
int ChildFunction(void *args);
pid_t CloneWrapper(int (*func)(void *), int flag, void *args);
@@ -135,6 +140,8 @@ void ItContainer001(void);
void ItContainerChroot001(void);
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
void ItPidContainer023(void);
void ItPidContainer025(void);
void ItPidContainer026(void);
#endif
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
void ItUtsContainer001(void);
@@ -158,6 +165,18 @@ void ItIpcContainer004(void);
void ItIpcContainer005(void);
void ItIpcContainer006(void);
#endif
#if defined(LOSCFG_USER_TEST_TIME_CONTAINER)
void ItTimeContainer001(void);
void ItTimeContainer002(void);
void ItTimeContainer003(void);
void ItTimeContainer004(void);
void ItTimeContainer005(void);
void ItTimeContainer006(void);
void ItTimeContainer007(void);
void ItTimeContainer008(void);
void ItTimeContainer009(void);
void ItTimeContainer010(void);
#endif
#endif
#if defined(LOSCFG_USER_TEST_FULL)

View File

@@ -44,8 +44,11 @@ sources_smoke = [
sources_full = []
if (defined(LOSCFG_USER_TEST_PID_CONTAINER)) {
sources_smoke +=
[ "$TEST_UNITTEST_DIR/container/smoke/It_pid_container_023.cpp" ]
sources_smoke += [
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_023.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_025.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_026.cpp",
]
sources_full += [
"$TEST_UNITTEST_DIR/container/full/It_pid_container_001.cpp",
"$TEST_UNITTEST_DIR/container/full/It_pid_container_002.cpp",
@@ -102,3 +105,18 @@ if (defined(LOSCFG_USER_TEST_IPC_CONTAINER)) {
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_006.cpp",
]
}
if (defined(LOSCFG_USER_TEST_TIME_CONTAINER)) {
sources_smoke += [
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_001.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_002.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_003.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_004.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_005.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_006.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_007.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_008.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_009.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_time_container_010.cpp",
]
}

View File

@@ -0,0 +1,69 @@
/*
* 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 childFunc(void *arg)
{
(void)arg;
return 0;
}
void ItPidContainer025(void)
{
int ret;
int status;
char *containerType = "pid";
char *containerType1 = "pid_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
std::cout << getpid() << std::endl;
auto linkBuffer = ReadlinkContainer(getpid(), containerType);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer.compare(linkBuffer1);
ASSERT_EQ(ret, 0);
auto pid = clone(childFunc, stackTop, CLONE_NEWPID | SIGCHLD, NULL);
ASSERT_TRUE(pid != -1);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_NE(ret, 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
auto linkBuffer2 = ReadlinkContainer(getpid(), containerType);
ret = linkBuffer.compare(linkBuffer2);
ASSERT_EQ(ret, 0);
}

View File

@@ -0,0 +1,70 @@
/*
* 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 childFunc(void *arg)
{
(void)arg;
sleep(1);
return 0;
}
void ItPidContainer026(void)
{
int ret;
int status;
char *containerType = "pid";
char *containerType1 = "pid_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
std::cout << getpid() << std::endl;
auto linkBuffer = ReadlinkContainer(getpid(), containerType);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer.compare(linkBuffer1);
ASSERT_EQ(ret, 0);
auto pid = clone(childFunc, stackTop, CLONE_NEWPID | SIGCHLD, NULL);
ASSERT_TRUE(pid != -1);
auto linkBuffer2 = ReadlinkContainer(pid, containerType);
ret = linkBuffer.compare(linkBuffer2);
ASSERT_NE(ret, 0);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_NE(ret, 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -0,0 +1,74 @@
/*
* 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 childFunc(void *arg)
{
int value = *((int*)arg);
if (value != CHILD_FUNC_ARG) {
return EXIT_CODE_ERRNO_1;
}
sleep(1);
return 0;
}
void ItTimeContainer001(void)
{
int ret;
int status;
char *containerType = "time";
char *containerType1 = "time_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
std::cout << getpid() << std::endl;
auto linkBuffer = ReadlinkContainer(getpid(), containerType);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer.compare(linkBuffer1);
ASSERT_EQ(ret, 0);
int arg = CHILD_FUNC_ARG;
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &arg);
ASSERT_TRUE(pid != -1);
auto linkBuffer2 = ReadlinkContainer(pid, containerType);
ret = linkBuffer.compare(linkBuffer2);
ASSERT_NE(ret, 0);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_NE(ret, 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -0,0 +1,139 @@
/*
* 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 STR_LEN = 50;
const int SEC = 600;
const int NSEC = 800000000;
static int childFunc(void *arg)
{
char path[STR_LEN];
char timeOff[STR_LEN];
char readBuf[STR_LEN];
int ret;
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %d", SEC, NSEC);
if (ret <= 0) {
return EXIT_CODE_ERRNO_4;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", getpid());
if (ret <= 0) {
return EXIT_CODE_ERRNO_5;
}
int fd = open(path, O_RDWR);
if (fd == -1) {
return EXIT_CODE_ERRNO_1;
}
ret = read(fd, readBuf, STR_LEN);
if (ret == -1) {
close(fd);
return EXIT_CODE_ERRNO_2;
}
close(fd);
ret = strncmp(timeOff, readBuf, strlen(timeOff));
if (ret != 0) {
return EXIT_CODE_ERRNO_3;
}
return 0;
}
static int WriteProcTime(int pid)
{
int ret = 0;
char path[STR_LEN];
char timeOff[STR_LEN];
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %d", SEC, NSEC);
if (ret <= 0) {
return EXIT_CODE_ERRNO_6;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", pid);
if (ret <= 0) {
return EXIT_CODE_ERRNO_7;
}
int strLen = strlen(timeOff);
int fd = open(path, O_WRONLY);
if (ret == -1) {
return EXIT_CODE_ERRNO_8;
}
ret = write(fd, timeOff, strLen);
if (ret != strLen) {
close(fd);
return EXIT_CODE_ERRNO_9;
}
close(fd);
return 0;
}
void ItTimeContainer002(void)
{
int ret;
int status;
char *containerType = "time";
char *containerType1 = "time_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
ret = unshare(CLONE_NEWTIME);
ASSERT_EQ(ret, 0);
ret = WriteProcTime(getpid());
ASSERT_EQ(ret, 0);
auto linkBuffer = ReadlinkContainer(getpid(), containerType);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer.compare(linkBuffer1);
ASSERT_TRUE(ret != 0);
int arg = CHILD_FUNC_ARG;
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &arg);
ASSERT_TRUE(pid != -1);
auto linkBuffer2 = ReadlinkContainer(pid, containerType);
ret = linkBuffer1.compare(linkBuffer2);
ASSERT_EQ(ret, 0);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_TRUE(ret != 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -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 childFunc(void *arg)
{
int ret;
char *containerType = "time";
char *containerType1 = "time_for_children";
char pid_link[100]; /* 100: test len */
char targetpath[100]; /* 100: test len */
auto linkBuffer = ReadlinkContainer(getppid(), containerType);
int fd;
ret = sprintf_s(pid_link, 100, "%s", linkBuffer.c_str()); /* 100: test len */
if (ret <= 0) {
return EXIT_CODE_ERRNO_4;
}
ret = sprintf_s(targetpath, 100, "/proc/%d/container/time", getppid()); /* 100: test len */
if (ret <= 0) {
return EXIT_CODE_ERRNO_5;
}
fd = open(targetpath, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
return EXIT_CODE_ERRNO_1;
}
ret = setns(fd, CLONE_NEWTIME);
if (ret != 0) {
close(fd);
return EXIT_CODE_ERRNO_2;
}
close(fd);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType);
auto linkBuffer2 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer1.compare(linkBuffer2);
EXPECT_EQ(ret, 0);
if (ret != 0) {
return EXIT_CODE_ERRNO_3;
}
return 0;
}
void ItTimeContainer003(void)
{
int ret;
int status;
char *containerType = "time";
char *containerType1 = "time_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
ret = unshare(CLONE_NEWTIME);
ASSERT_EQ(ret, 0);
auto linkBuffer = ReadlinkContainer(getpid(), containerType1);
int arg = CHILD_FUNC_ARG;
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &arg);
ASSERT_TRUE(pid != -1);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_TRUE(ret != 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -0,0 +1,114 @@
/*
* 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 STR_LEN = 50;
const int SEC = 172800;
const int NSEC = 800000000;
static int childFunc(void *arg)
{
int ret;
struct timespec tp = *((struct timespec *)arg);
struct timespec tp1;
ret = clock_gettime(CLOCK_MONOTONIC_RAW, &tp1);
if (ret != 0) {
return EXIT_CODE_ERRNO_1;
}
ret = ((tp1.tv_sec >= tp.tv_sec + SEC));
if (ret != 1) {
return EXIT_CODE_ERRNO_2;
}
return 0;
}
static int WriteProcTime(int pid)
{
int ret;
char path[STR_LEN];
char timeOff[STR_LEN];
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %d", SEC, NSEC);
if (ret <= 0) {
return EXIT_CODE_ERRNO_5;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", pid);
if (ret <= 0) {
return EXIT_CODE_ERRNO_6;
}
int strLen = strlen(timeOff);
int fd = open(path, O_WRONLY);
if (fd == -1) {
return EXIT_CODE_ERRNO_3;
}
ret = write(fd, timeOff, strLen);
if (ret != strLen) {
close(fd);
return EXIT_CODE_ERRNO_4;
}
close(fd);
return 0;
}
void ItTimeContainer004(void)
{
int ret;
int status;
struct timespec tp;
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
ret = unshare(CLONE_NEWTIME);
ASSERT_EQ(ret, 0);
ret = WriteProcTime(getpid());
ASSERT_EQ(ret, 0);
ret = clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
ASSERT_EQ(ret, 0);
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &tp);
ASSERT_TRUE(pid != -1);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_NE(ret, 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -0,0 +1,114 @@
/*
* 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 STR_LEN = 50;
const int SEC = 172800;
const int NSEC = 800000000;
static int childFunc(void *arg)
{
int ret;
struct timespec tp = *((struct timespec *)arg);
struct timespec tp1 = {0};
ret = clock_gettime(CLOCK_MONOTONIC, &tp1);
if (ret != 0) {
return EXIT_CODE_ERRNO_1;
}
ret = ((tp1.tv_sec >= tp.tv_sec + SEC));
if (ret != 1) {
return EXIT_CODE_ERRNO_2;
}
return 0;
}
static int WriteProcTime(int pid)
{
int ret;
char path[STR_LEN];
char timeOff[STR_LEN];
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %d", SEC, NSEC);
if (ret <= 0) {
return EXIT_CODE_ERRNO_5;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", pid);
if (ret <= 0) {
return EXIT_CODE_ERRNO_5;
}
int strLen = strlen(timeOff);
int fd = open(path, O_WRONLY);
if (fd == -1) {
return EXIT_CODE_ERRNO_3;
}
ret = write(fd, timeOff, strLen);
if (ret != strLen) {
close(fd);
return EXIT_CODE_ERRNO_4;
}
close(fd);
return 0;
}
void ItTimeContainer005(void)
{
int ret;
int status;
struct timespec tp = {0};
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
ret = unshare(CLONE_NEWTIME);
ASSERT_EQ(ret, 0);
ret = WriteProcTime(getpid());
ASSERT_EQ(ret, 0);
ret = clock_gettime(CLOCK_MONOTONIC, &tp);
ASSERT_EQ(ret, 0);
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &tp);
ASSERT_TRUE(pid != -1);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_TRUE(ret != 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
}

View File

@@ -0,0 +1,52 @@
/*
* 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 MAX_TIME_CONTAINER = 64;
const int STR_LEN = 100;
void ItTimeContainer006(void)
{
int ret;
char *fileName = "/proc/sys/user/max_time_container";
FILE *fp = nullptr;
char strBuf[STR_LEN] = {0};
fp = fopen(fileName, "rb");
ASSERT_TRUE(fp != 0);
ret = fread(strBuf, 1, STR_LEN, fp);
ASSERT_TRUE(ret != -1);
ret = atoi(strBuf);
ASSERT_EQ(ret, MAX_TIME_CONTAINER);
(void)fclose(fp);
}

View File

@@ -0,0 +1,73 @@
/*
* 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 STR_LEN = 50;
const int SEC = 172800;
const int NSEC = 80000000;
static int WriteProcTime(int pid)
{
int ret;
char path[STR_LEN] = {0};
char timeOff[STR_LEN] = {0};
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %d", SEC, NSEC);
if (ret < 0) {
return EXIT_CODE_ERRNO_3;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", pid);
if (ret < 0) {
return EXIT_CODE_ERRNO_4;
}
int strLen = strlen(timeOff);
int fd = open(path, O_WRONLY);
if (fd == -1) {
return EXIT_CODE_ERRNO_1;
}
ret = write(fd, timeOff, strLen);
if (ret != -1) {
close(fd);
return EXIT_CODE_ERRNO_2;
}
close(fd);
return 0;
}
void ItTimeContainer007(void)
{
int ret;
ret = WriteProcTime(getpid());
ASSERT_EQ(ret, 0);
}

View File

@@ -0,0 +1,73 @@
/*
* 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 STR_LEN = 50;
const int SEC = 172800;
const long long NSEC = 800000000000;
static int WriteProcTime(int pid)
{
int ret;
char path[STR_LEN] = {0};
char timeOff[STR_LEN] = {0};
ret = sprintf_s(timeOff, STR_LEN, "monotonic %d %lld", SEC, NSEC);
if (ret < 0) {
return EXIT_CODE_ERRNO_3;
}
ret = sprintf_s(path, STR_LEN, "/proc/%d/time_offsets", pid);
if (ret < 0) {
return EXIT_CODE_ERRNO_3;
}
int strLen = strlen(timeOff);
int fd = open(path, O_WRONLY);
if (fd == -1) {
return EXIT_CODE_ERRNO_1;
}
ret = write(fd, timeOff, strLen);
if (ret != -1) {
close(fd);
return EXIT_CODE_ERRNO_2;
}
close(fd);
return 0;
}
void ItTimeContainer008(void)
{
int ret = unshare(CLONE_NEWTIME);
ASSERT_EQ(ret, 0);
ret = WriteProcTime(getpid());
ASSERT_EQ(ret, 0);
}

View File

@@ -0,0 +1,75 @@
/*
* 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 <iostream>
#include "It_container_test.h"
static std::string GenTimeLinkPath(int pid)
{
std::ostringstream buf;
buf << "/proc/" << pid << "/container/time";
return buf.str();
}
static std::string ReadlinkTime(int pid)
{
auto path = GenTimeLinkPath(pid);
struct stat sb;
int ret = lstat(path.data(), &sb);
if (ret == -1) {
perror("lstat");
return std::string();
}
auto bufsiz = sb.st_size + 1;
if (sb.st_size == 0) {
bufsiz = PATH_MAX;
}
std::vector<char> buf(bufsiz);
auto nbytes = readlink(path.c_str(), buf.data(), bufsiz);
if (nbytes == -1) {
perror("readlink");
return std::string();
}
return buf.data();
}
void ItTimeContainer009(void)
{
auto timelink = ReadlinkTime(getpid());
std::cout << "Contents of the time link is: " << timelink << std::endl;
std::regex reg("'time:\\[[0-9]+\\]'");
bool ret = std::regex_match(timelink, reg);
ASSERT_TRUE(ret);
}

View File

@@ -0,0 +1,73 @@
/*
* 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 childFunc(void *arg)
{
int value = *((int*)arg);
if (value != CHILD_FUNC_ARG) {
return EXIT_CODE_ERRNO_1;
}
return 0;
}
void ItTimeContainer010(void)
{
int ret;
int status;
char *containerType = "time";
char *containerType1 = "time_for_children";
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, CLONE_STACK_MMAP_FLAG, -1, 0);
ASSERT_NE(stack, nullptr);
char *stackTop = stack + STACK_SIZE;
std::cout << getpid() << std::endl;
auto linkBuffer = ReadlinkContainer(getpid(), containerType);
auto linkBuffer1 = ReadlinkContainer(getpid(), containerType1);
ret = linkBuffer.compare(linkBuffer1);
ASSERT_EQ(ret, 0);
int arg = CHILD_FUNC_ARG;
auto pid = clone(childFunc, stackTop, CLONE_NEWTIME | SIGCHLD, &arg);
ASSERT_TRUE(pid != -1);
ret = waitpid(pid, &status, 0);
ASSERT_EQ(ret, pid);
ret = WIFEXITED(status);
ASSERT_NE(ret, 0);
int exitCode = WEXITSTATUS(status);
ASSERT_EQ(exitCode, 0);
auto linkBuffer2 = ReadlinkContainer(getpid(), containerType);
ret = linkBuffer.compare(linkBuffer2);
ASSERT_EQ(ret, 0);
}