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

@@ -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

View File

@@ -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 = []

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View 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);
}