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:
@@ -137,6 +137,7 @@ LOSCFG_USER_TEST_PID_CONTAINER = false
|
||||
LOSCFG_USER_TEST_UTS_CONTAINER = false
|
||||
LOSCFG_USER_TEST_MNT_CONTAINER = false
|
||||
LOSCFG_USER_TEST_IPC_CONTAINER = false
|
||||
LOSCFG_USER_TEST_TIME_CONTAINER = false
|
||||
if (defined(LOSCFG_KERNEL_CONTAINER)) {
|
||||
LOSCFG_USER_TEST_CONTAINER = true
|
||||
if (defined(LOSCFG_PID_CONTAINER)) {
|
||||
@@ -151,4 +152,7 @@ if (defined(LOSCFG_KERNEL_CONTAINER)) {
|
||||
if (defined(LOSCFG_IPC_CONTAINER)) {
|
||||
LOSCFG_USER_TEST_IPC_CONTAINER = true
|
||||
}
|
||||
if (defined(LOSCFG_TIME_CONTAINER)) {
|
||||
LOSCFG_USER_TEST_TIME_CONTAINER = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
69
testsuites/unittest/container/smoke/It_pid_container_025.cpp
Normal file
69
testsuites/unittest/container/smoke/It_pid_container_025.cpp
Normal 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);
|
||||
}
|
||||
70
testsuites/unittest/container/smoke/It_pid_container_026.cpp
Normal file
70
testsuites/unittest/container/smoke/It_pid_container_026.cpp
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
139
testsuites/unittest/container/smoke/It_time_container_002.cpp
Normal file
139
testsuites/unittest/container/smoke/It_time_container_002.cpp
Normal 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);
|
||||
}
|
||||
100
testsuites/unittest/container/smoke/It_time_container_003.cpp
Normal file
100
testsuites/unittest/container/smoke/It_time_container_003.cpp
Normal 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);
|
||||
}
|
||||
114
testsuites/unittest/container/smoke/It_time_container_004.cpp
Normal file
114
testsuites/unittest/container/smoke/It_time_container_004.cpp
Normal 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);
|
||||
}
|
||||
114
testsuites/unittest/container/smoke/It_time_container_005.cpp
Normal file
114
testsuites/unittest/container/smoke/It_time_container_005.cpp
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -54,5 +54,12 @@ extern void ItProcessFs012(void);
|
||||
extern void ItProcessFs013(void);
|
||||
extern void ItProcessFs014(void);
|
||||
extern void ItProcessFs015(void);
|
||||
extern void ItProcessFs015(void);
|
||||
extern void ItProcessFs016(void);
|
||||
extern void ItProcessFs017(void);
|
||||
extern void ItProcessFs018(void);
|
||||
extern void ItProcessFs019(void);
|
||||
extern void ItProcessFs020(void);
|
||||
extern void ItProcessFs021(void);
|
||||
extern void ItProcessFs022(void);
|
||||
#endif
|
||||
|
||||
@@ -61,7 +61,13 @@ process_fs_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_013.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_014.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_015.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_016.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_022.cpp",
|
||||
]
|
||||
|
||||
process_fs_sources_full = []
|
||||
|
||||
@@ -36,7 +36,7 @@ VOID PrintTest(const CHAR *fmt, ...)
|
||||
{
|
||||
#ifdef PRINT_TEST
|
||||
va_list ap;
|
||||
if (g_osLkHook != NULL) {
|
||||
if (g_osLkHook != nullptr) {
|
||||
va_start(ap, fmt);
|
||||
printf(fmt, ap);
|
||||
va_end(ap);
|
||||
@@ -224,5 +224,17 @@ HWTEST_F(ProcessFsTest, ItProcessFs021, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs021();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_022
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6B0A3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs022, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs022();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ static int childFunc(void *arg)
|
||||
|
||||
void ItProcessFs016(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_uts_container";
|
||||
int fd = open(path.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
@@ -59,9 +57,9 @@ void ItProcessFs016(void)
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
|
||||
|
||||
@@ -46,8 +46,6 @@ static int childFunc(void *arg)
|
||||
|
||||
void ItProcessFs017(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_user_container";
|
||||
int fd = open(path.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
@@ -60,9 +58,9 @@ void ItProcessFs017(void)
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
|
||||
|
||||
@@ -46,8 +46,6 @@ static int childFunc(void *arg)
|
||||
|
||||
void ItProcessFs018(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_mnt_container";
|
||||
int fd = open(path.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
@@ -60,9 +58,9 @@ void ItProcessFs018(void)
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
|
||||
|
||||
@@ -46,8 +46,6 @@ static int childFunc(void *arg)
|
||||
|
||||
void ItProcessFs019(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_pid_container";
|
||||
int fd = open(path.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
@@ -60,9 +58,9 @@ void ItProcessFs019(void)
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
|
||||
|
||||
@@ -46,23 +46,21 @@ static int childFunc(void *arg)
|
||||
|
||||
void ItProcessFs020(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_net_container";
|
||||
int fd = open(path.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
|
||||
char buf[configLen];
|
||||
size_t ret = sprintf(buf, configLen, "%d", invalidNum);
|
||||
size_t ret = sprintf_s(buf, configLen, "%d", invalidNum);
|
||||
ASSERT_GT(ret, 0);
|
||||
ret = write(fd, buf, (strlen(buf) + 1));
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
|
||||
char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
|
||||
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_022.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_022.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 <sched.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
void ItProcessFs022(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "time");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'time:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
Reference in New Issue
Block a user