feat 支持容器限额
BREAKING CHANGE: 支持容器限额对外变更: 1.在proc目录下增加sys/user目录,支持max_容器_container 配额文件 Close #I6HDQK Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: Ieaac046182f679a6f49cbdc74593ab39fcb31f5f
This commit is contained in:
@@ -88,6 +88,63 @@ int WaitChild(pid_t pid, int *status, int errNo1, int errNo2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ReadFile(const char *filepath, char *buf)
|
||||
{
|
||||
FILE *fpid = nullptr;
|
||||
fpid = fopen(filepath, "r");
|
||||
if (fpid == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
size_t trd = fread(buf, 1, 512, fpid);
|
||||
(void)fclose(fpid);
|
||||
return trd;
|
||||
}
|
||||
|
||||
int WriteFile(const char *filepath, const char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
size_t twd = write(fd, buf, strlen(buf));
|
||||
if (twd == -1) {
|
||||
(void)close(fd);
|
||||
return -1;
|
||||
}
|
||||
(void)close(fd);
|
||||
return twd;
|
||||
}
|
||||
|
||||
int GetLine(char *buf, int count, int maxLen, char **array)
|
||||
{
|
||||
char *head = buf;
|
||||
char *tail = buf;
|
||||
char index = 0;
|
||||
if ((buf == NULL) || (strlen(buf) == 0)) {
|
||||
return 0;
|
||||
}
|
||||
while (*tail != '\0') {
|
||||
if (*tail != '\n') {
|
||||
tail++;
|
||||
continue;
|
||||
}
|
||||
if (index >= count) {
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
array[index] = head;
|
||||
index++;
|
||||
*tail = '\0';
|
||||
if (strlen(head) > maxLen) {
|
||||
return index + 1;
|
||||
}
|
||||
tail++;
|
||||
head = tail;
|
||||
tail++;
|
||||
}
|
||||
return (index + 1);
|
||||
}
|
||||
|
||||
std::string GenContainerLinkPath(int pid, const std::string& containerType)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
@@ -125,6 +182,79 @@ HWTEST_F(ContainerTest, ItContainer001, TestSize.Level0)
|
||||
ItContainer001();
|
||||
}
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_USER_CONTAINER)
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_001
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer001, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_002
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer002, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_003
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer003, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_004
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer004, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_006
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer006, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_007
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer007, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer007();
|
||||
}
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_023
|
||||
@@ -221,6 +351,30 @@ HWTEST_F(ContainerTest, ItPidContainer031, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer031();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_032
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer032, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer032();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_Pid_Test_033
|
||||
* @tc.desc: pid container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItPidContainer033, TestSize.Level0)
|
||||
{
|
||||
ItPidContainer033();
|
||||
}
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
|
||||
/**
|
||||
@@ -282,6 +436,30 @@ HWTEST_F(ContainerTest, ItUtsContainer006, TestSize.Level0)
|
||||
{
|
||||
ItUtsContainer006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_007
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUtsContainer007, TestSize.Level0)
|
||||
{
|
||||
ItUtsContainer007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_008
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUtsContainer008, TestSize.Level0)
|
||||
{
|
||||
ItUtsContainer008();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_MNT_CONTAINER)
|
||||
@@ -381,6 +559,30 @@ HWTEST_F(ContainerTest, ItMntContainer008, TestSize.Level0)
|
||||
ItMntContainer008();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_MNT_Test_009
|
||||
* @tc.desc: mnt container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItMntContainer009, TestSize.Level0)
|
||||
{
|
||||
ItMntContainer009();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_MNT_Test_010
|
||||
* @tc.desc: mnt container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItMntContainer010, TestSize.Level0)
|
||||
{
|
||||
ItMntContainer010();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: chroot_Test_001
|
||||
* @tc.desc: chroot function test case
|
||||
@@ -478,6 +680,30 @@ HWTEST_F(ContainerTest, ItIpcContainer006, TestSize.Level0)
|
||||
{
|
||||
ItIpcContainer006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_IPC_Test_007
|
||||
* @tc.desc: ipc container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItIpcContainer007, TestSize.Level0)
|
||||
{
|
||||
ItIpcContainer007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_IPC_Test_008
|
||||
* @tc.desc: ipc container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItIpcContainer008, TestSize.Level0)
|
||||
{
|
||||
ItIpcContainer008();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_TIME_CONTAINER)
|
||||
@@ -541,6 +767,18 @@ HWTEST_F(ContainerTest, ItTimeContainer005, TestSize.Level0)
|
||||
ItTimeContainer005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_TIME_Test_006
|
||||
* @tc.desc: time container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6HDQK
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItTimeContainer006, TestSize.Level0)
|
||||
{
|
||||
ItTimeContainer006();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Container_TIME_Test_007
|
||||
* @tc.desc: time container function test case
|
||||
@@ -589,55 +827,6 @@ HWTEST_F(ContainerTest, ItTimeContainer010, TestSize.Level0)
|
||||
ItTimeContainer010();
|
||||
}
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_USER_CONTAINER)
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_001
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer001, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_002
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer002, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_003
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer003, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Container_UTS_Test_004
|
||||
* @tc.desc: uts container function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6EC0A
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ContainerTest, ItUserContainer004, TestSize.Level0)
|
||||
{
|
||||
ItUserContainer004();
|
||||
}
|
||||
#endif
|
||||
#endif /* LOSCFG_USER_TEST_SMOKE */
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
|
||||
@@ -91,6 +91,10 @@ extern "C" {
|
||||
#define CLONE_NEWTIME 0x00000080
|
||||
}
|
||||
|
||||
int WriteFile(const char *filepath, const char *buf);
|
||||
int ReadFile(const char *filepath, char *buf);
|
||||
int GetLine(char *buf, int count, int maxLen, char **array);
|
||||
|
||||
int ChildFunction(void *args);
|
||||
|
||||
pid_t CloneWrapper(int (*func)(void *), int flag, void *args);
|
||||
@@ -142,11 +146,11 @@ void ItUserContainer002(void);
|
||||
void ItUserContainer003(void);
|
||||
void ItUserContainer004(void);
|
||||
void ItUserContainer005(void);
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
void ItUserContainer006(void);
|
||||
void ItUserContainer007(void);
|
||||
void ItContainer001(void);
|
||||
void ItContainerChroot001(void);
|
||||
void ItContainerChroot002(void);
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
void ItPidContainer023(void);
|
||||
void ItPidContainer025(void);
|
||||
void ItPidContainer026(void);
|
||||
@@ -155,15 +159,15 @@ void ItPidContainer028(void);
|
||||
void ItPidContainer029(void);
|
||||
void ItPidContainer030(void);
|
||||
void ItPidContainer031(void);
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
|
||||
void ItPidContainer032(void);
|
||||
void ItPidContainer033(void);
|
||||
void ItUtsContainer001(void);
|
||||
void ItUtsContainer002(void);
|
||||
void ItUtsContainer004(void);
|
||||
void ItUtsContainer005(void);
|
||||
void ItUtsContainer006(void);
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_MNT_CONTAINER)
|
||||
void ItUtsContainer007(void);
|
||||
void ItUtsContainer008(void);
|
||||
void ItMntContainer001(void);
|
||||
void ItMntContainer002(void);
|
||||
void ItMntContainer003(void);
|
||||
@@ -172,16 +176,16 @@ void ItMntContainer005(void);
|
||||
void ItMntContainer006(void);
|
||||
void ItMntContainer007(void);
|
||||
void ItMntContainer008(void);
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_IPC_CONTAINER)
|
||||
void ItMntContainer009(void);
|
||||
void ItMntContainer010(void);
|
||||
void ItIpcContainer001(void);
|
||||
void ItIpcContainer002(void);
|
||||
void ItIpcContainer003(void);
|
||||
void ItIpcContainer004(void);
|
||||
void ItIpcContainer005(void);
|
||||
void ItIpcContainer006(void);
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_TIME_CONTAINER)
|
||||
void ItIpcContainer007(void);
|
||||
void ItIpcContainer008(void);
|
||||
void ItTimeContainer001(void);
|
||||
void ItTimeContainer002(void);
|
||||
void ItTimeContainer003(void);
|
||||
@@ -192,11 +196,6 @@ void ItTimeContainer007(void);
|
||||
void ItTimeContainer008(void);
|
||||
void ItTimeContainer009(void);
|
||||
void ItTimeContainer010(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_FULL)
|
||||
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
|
||||
void ItPidContainer001(void);
|
||||
void ItPidContainer002(void);
|
||||
void ItPidContainer003(void);
|
||||
@@ -220,10 +219,6 @@ void ItPidContainer020(void);
|
||||
void ItPidContainer021(void);
|
||||
void ItPidContainer022(void);
|
||||
void ItPidContainer024(void);
|
||||
#endif
|
||||
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
|
||||
void ItUtsContainer003(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _IT_CONTAINER_TEST_H */
|
||||
|
||||
@@ -50,6 +50,8 @@ if (defined(LOSCFG_USER_TEST_PID_CONTAINER)) {
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_029.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_030.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_031.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_032.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_pid_container_033.cpp",
|
||||
]
|
||||
sources_full += [
|
||||
"$TEST_UNITTEST_DIR/container/full/It_pid_container_001.cpp",
|
||||
@@ -84,6 +86,8 @@ if (defined(LOSCFG_USER_TEST_UTS_CONTAINER)) {
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_uts_container_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_uts_container_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_uts_container_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_uts_container_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_uts_container_008.cpp",
|
||||
]
|
||||
sources_full +=
|
||||
[ "$TEST_UNITTEST_DIR/container/full/It_uts_container_003.cpp" ]
|
||||
@@ -100,6 +104,8 @@ if (defined(LOSCFG_USER_TEST_MNT_CONTAINER)) {
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_010.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -111,6 +117,8 @@ if (defined(LOSCFG_USER_TEST_IPC_CONTAINER)) {
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_ipc_container_008.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -135,6 +143,8 @@ if (defined(LOSCFG_USER_TEST_USER_CONTAINER)) {
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_user_container_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_user_container_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_user_container_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_user_container_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/container/smoke/It_user_container_007.cpp",
|
||||
]
|
||||
sources_full +=
|
||||
[ "$TEST_UNITTEST_DIR/container/full/It_user_container_005.cpp" ]
|
||||
|
||||
@@ -33,13 +33,11 @@
|
||||
#include "pthread.h"
|
||||
#include "sched.h"
|
||||
|
||||
const int SLEEP_TIME_US = 1000;
|
||||
const int LOOP_NUM = 1000;
|
||||
const int LOOP_NUM = 100;
|
||||
|
||||
static int ChildFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
usleep(SLEEP_TIME_US);
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
}
|
||||
|
||||
@@ -61,6 +59,7 @@ static int GroupProcess(void *arg)
|
||||
if (status != EXIT_CODE_ERRNO_5) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
exit(EXIT_CODE_ERRNO_5);
|
||||
|
||||
100
testsuites/unittest/container/smoke/It_ipc_container_007.cpp
Normal file
100
testsuites/unittest/container/smoke/It_ipc_container_007.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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItIpcContainer007(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_ipc_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWIPC, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
auto pid2 = clone(childFunc, stackTop, CLONE_NEWIPC, NULL);
|
||||
ASSERT_EQ(pid2, -1);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
105
testsuites/unittest/container/smoke/It_ipc_container_008.cpp
Normal file
105
testsuites/unittest/container/smoke/It_ipc_container_008.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWIPC);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItIpcContainer008(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_ipc_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWIPC, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
100
testsuites/unittest/container/smoke/It_mnt_container_009.cpp
Normal file
100
testsuites/unittest/container/smoke/It_mnt_container_009.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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItMntContainer009(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_mnt_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWNS, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
auto pid2 = clone(childFunc, stackTop, CLONE_NEWNS, NULL);
|
||||
ASSERT_EQ(pid2, -1);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
105
testsuites/unittest/container/smoke/It_mnt_container_010.cpp
Normal file
105
testsuites/unittest/container/smoke/It_mnt_container_010.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWNS);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItMntContainer010(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_mnt_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWNS, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
100
testsuites/unittest/container/smoke/It_pid_container_032.cpp
Normal file
100
testsuites/unittest/container/smoke/It_pid_container_032.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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer032(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_pid_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWPID, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
auto pid2 = clone(childFunc, stackTop, CLONE_NEWPID, NULL);
|
||||
ASSERT_EQ(pid2, -1);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
105
testsuites/unittest/container/smoke/It_pid_container_033.cpp
Normal file
105
testsuites/unittest/container/smoke/It_pid_container_033.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWPID);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItPidContainer033(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_pid_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWPID, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
@@ -27,26 +27,85 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
const int MAX_TIME_CONTAINER = 64;
|
||||
const int STR_LEN = 100;
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWTIME);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
ret = unshare(CLONE_NEWTIME);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItTimeContainer006(void)
|
||||
{
|
||||
int ret;
|
||||
char *fileName = "/proc/sys/user/max_time_container";
|
||||
FILE *fp = nullptr;
|
||||
char strBuf[STR_LEN] = {0};
|
||||
std::string path = "/proc/sys/user/max_time_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
fp = fopen(fileName, "rb");
|
||||
ASSERT_TRUE(fp != 0);
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = fread(strBuf, 1, STR_LEN, fp);
|
||||
ASSERT_TRUE(ret != -1);
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
ret = atoi(strBuf);
|
||||
ASSERT_EQ(ret, MAX_TIME_CONTAINER);
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
(void)fclose(fp);
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWTIME, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_2);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
|
||||
100
testsuites/unittest/container/smoke/It_user_container_006.cpp
Normal file
100
testsuites/unittest/container/smoke/It_user_container_006.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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUserContainer006(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_user_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWUSER, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
auto pid2 = clone(childFunc, stackTop, CLONE_NEWUSER, NULL);
|
||||
ASSERT_EQ(pid2, -1);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
105
testsuites/unittest/container/smoke/It_user_container_007.cpp
Normal file
105
testsuites/unittest/container/smoke/It_user_container_007.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWUSER);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUserContainer007(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_user_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWUSER, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
@@ -38,54 +38,83 @@ static int ChildFun(void *p)
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
void ItUtsContainer005(void)
|
||||
static int UtsContainerTest(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
pid_t callerPid;
|
||||
int childPid;
|
||||
int fd = -1;
|
||||
int ret;
|
||||
int status;
|
||||
int setFlag;
|
||||
int ret, status, setFlag;
|
||||
char targetpath[100];
|
||||
char old_uts_link[100];
|
||||
char new_uts_link[100];
|
||||
const char *containerType = "uts";
|
||||
|
||||
callerPid = getpid();
|
||||
childPid = clone(ChildFun, NULL, CLONE_NEWUTS | SIGCHLD, NULL);
|
||||
ASSERT_NE(childPid, -1);
|
||||
if (childPid == -1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
|
||||
auto linkBuffer = ReadlinkContainer(callerPid, containerType);
|
||||
ASSERT_TRUE(linkBuffer.c_str() != NULL);
|
||||
ret = sprintf_s(old_uts_link, sizeof(old_uts_link), "%s", linkBuffer.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
auto linkBuffer1 = ReadlinkContainer(callerPid, containerType);
|
||||
if (linkBuffer1.c_str() == NULL) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
ret = sprintf_s(targetpath, sizeof(targetpath), "/proc/%d/container/uts", childPid);
|
||||
ASSERT_NE(ret, -1);
|
||||
if (ret == -1) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
|
||||
fd = open(targetpath, O_RDONLY | O_CLOEXEC);
|
||||
ASSERT_NE(fd, -1);
|
||||
if (fd == -1) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
setFlag = CLONE_NEWUTS;
|
||||
ret = setns(fd, setFlag);
|
||||
ASSERT_NE(ret, -1);
|
||||
(void)close(fd);
|
||||
if (ret == -1) {
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
/* NOTE: close fd, otherwise test fail */
|
||||
ret = close(fd);
|
||||
fd = -1;
|
||||
ASSERT_NE(ret, -1);
|
||||
auto linkBuffer2 = ReadlinkContainer(callerPid, containerType);
|
||||
|
||||
linkBuffer = ReadlinkContainer(callerPid, containerType);
|
||||
|
||||
ret = sprintf_s(new_uts_link, sizeof(new_uts_link), "%s", linkBuffer.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ASSERT_STRNE(old_uts_link, new_uts_link);
|
||||
ret = linkBuffer2.compare(linkBuffer1);
|
||||
if (ret == 0) {
|
||||
return EXIT_CODE_ERRNO_7;
|
||||
}
|
||||
|
||||
ret = waitpid(childPid, &status, 0);
|
||||
ASSERT_EQ(ret, childPid);
|
||||
if (ret != childPid) {
|
||||
return EXIT_CODE_ERRNO_8;
|
||||
}
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, EXIT_CODE_ERRNO_3);
|
||||
if (exitCode != EXIT_CODE_ERRNO_3) {
|
||||
return EXIT_CODE_ERRNO_9;
|
||||
}
|
||||
|
||||
ret = setns(fd, setFlag);
|
||||
ASSERT_EQ(ret, -1);
|
||||
if (ret != -1) {
|
||||
return EXIT_CODE_ERRNO_10;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUtsContainer005(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(UtsContainerTest, CLONE_NEWUTS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
int status;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
}
|
||||
|
||||
@@ -29,35 +29,70 @@
|
||||
*/
|
||||
#include "It_container_test.h"
|
||||
|
||||
void ItUtsContainer006(void)
|
||||
static int UtsContainerTest(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
std::string containerType = "uts";
|
||||
|
||||
int parentPid = getpid();
|
||||
auto parentlink = ReadlinkContainer(parentPid, containerType);
|
||||
|
||||
int childsPid = CloneWrapper(ChildFunction, CLONE_NEWUTS, NULL);
|
||||
ASSERT_NE(childsPid, -1);
|
||||
if (childsPid == -1) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
auto childlink = ReadlinkContainer(childsPid, containerType);
|
||||
|
||||
std::string filePath = GenContainerLinkPath(childsPid, containerType);
|
||||
int fd = open(filePath.c_str(), O_RDONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
if (fd == -1) {
|
||||
return EXIT_CODE_ERRNO_2;
|
||||
}
|
||||
|
||||
int ret = setns(fd, CLONE_NEWUTS);
|
||||
ASSERT_NE(ret, -1);
|
||||
(void)close(fd);
|
||||
if (ret == -1) {
|
||||
return EXIT_CODE_ERRNO_3;
|
||||
}
|
||||
|
||||
auto parentlink1 = ReadlinkContainer(parentPid, containerType);
|
||||
|
||||
ret = parentlink.compare(parentlink1);
|
||||
ASSERT_NE(ret, 0);
|
||||
if (ret == 0) {
|
||||
return EXIT_CODE_ERRNO_4;
|
||||
}
|
||||
ret = parentlink1.compare(childlink);
|
||||
ASSERT_EQ(ret, 0);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_5;
|
||||
}
|
||||
|
||||
int status;
|
||||
ret = waitpid(childsPid, &status, 0);
|
||||
ASSERT_EQ(ret, childsPid);
|
||||
if (ret != childsPid) {
|
||||
return EXIT_CODE_ERRNO_6;
|
||||
}
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
if (exitCode != 0) {
|
||||
return EXIT_CODE_ERRNO_7;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUtsContainer006(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
auto pid = CloneWrapper(UtsContainerTest, CLONE_NEWUTS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
int status;
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
|
||||
100
testsuites/unittest/container/smoke/It_uts_container_007.cpp
Normal file
100
testsuites/unittest/container/smoke/It_uts_container_007.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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUtsContainer007(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_uts_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWUTS, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
auto pid2 = clone(childFunc, stackTop, CLONE_NEWUTS, NULL);
|
||||
ASSERT_EQ(pid2, -1);
|
||||
|
||||
ret = waitpid(pid1, NULL, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
105
testsuites/unittest/container/smoke/It_uts_container_008.cpp
Normal file
105
testsuites/unittest/container/smoke/It_uts_container_008.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <cstdio>
|
||||
#include "It_container_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static const int MAX_CONTAINER = 10;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
int ret = unshare(CLONE_NEWUTS);
|
||||
if (ret != 0) {
|
||||
return EXIT_CODE_ERRNO_1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItUtsContainer008(void)
|
||||
{
|
||||
std::string path = "/proc/sys/user/max_uts_container";
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int status = 0;
|
||||
|
||||
int ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
int value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
|
||||
int usedCount = atoi(array[2] + strlen("count: "));
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", usedCount + 1);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, nullptr);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid1 = clone(childFunc, stackTop, CLONE_NEWUTS, NULL);
|
||||
ASSERT_NE(pid1, -1);
|
||||
|
||||
ret = waitpid(pid1, &status, 0);
|
||||
ASSERT_EQ(ret, pid1);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
ret = WEXITSTATUS(status);
|
||||
ASSERT_EQ(ret, EXIT_CODE_ERRNO_1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
ret = WriteFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(buf, configLen, 0, configLen);
|
||||
ret = ReadFile(path.c_str(), buf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
|
||||
value = atoi(array[1] + strlen("limit: "));
|
||||
ASSERT_EQ(value, MAX_CONTAINER);
|
||||
}
|
||||
Reference in New Issue
Block a user