feat: 支持进程挂载目录和进程命名空间增强
BREAKING CHANGE: 支持进程挂载目录和进程命名空间增强对外变更: 1.支持进程挂载目录,在/proc下可以看到进程挂载目录 2.支持pid容器和uts容器信息查询 Close #I6AEVV Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I6777889552d77e49da81249063f9f3db0af96f34
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-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:
|
||||
@@ -135,10 +135,16 @@ group("unittest") {
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
deps += [ "process/basic:liteos_a_process_basic_unittest_door" ]
|
||||
deps += [ "process/lock:liteos_a_process_lock_unittest_door" ]
|
||||
if (LOSCFG_USER_TEST_PROCESS_FS == true) {
|
||||
deps += [ "process/fs:liteos_a_process_fs_unittest_door" ]
|
||||
}
|
||||
}
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
|
||||
deps += [ "process/basic:liteos_a_process_basic_unittest" ]
|
||||
deps += [ "process/lock:liteos_a_process_lock_unittest" ]
|
||||
if (LOSCFG_USER_TEST_PROCESS_FS == true) {
|
||||
deps += [ "process/fs:liteos_a_process_fs_unittest" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,11 @@ LOSCFG_USER_TEST_SECURITY_CAPABILITY = true
|
||||
LOSCFG_USER_TEST_SECURITY_REUGID = true
|
||||
LOSCFG_USER_TEST_SECURITY_VID = true
|
||||
|
||||
LOSCFG_USER_TEST_PROCESS_FS = false
|
||||
if (defined(LOSCFG_PROC_PROCESS_DIR)) {
|
||||
LOSCFG_USER_TEST_PROCESS_FS = true
|
||||
}
|
||||
|
||||
########## container test ##########
|
||||
LOSCFG_USER_TEST_CONTAINER = false
|
||||
LOSCFG_USER_TEST_PID_CONTAINER = false
|
||||
|
||||
58
testsuites/unittest/process/fs/BUILD.gn
Normal file
58
testsuites/unittest/process/fs/BUILD.gn
Normal file
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//build/lite/config/test.gni")
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
import("./config.gni")
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||
unittest("liteos_a_process_fs_unittest_door") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/kernel"
|
||||
include_dirs = common_include_dirs
|
||||
sources = sources_entry
|
||||
sources += sources_smoke
|
||||
sources_full = []
|
||||
sources += sources_full
|
||||
configs = [ "../..:public_config_for_door" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
|
||||
unittest("liteos_a_process_fs_unittest") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/kernel"
|
||||
include_dirs = common_include_dirs
|
||||
sources = sources_entry
|
||||
sources += sources_smoke
|
||||
sources += sources_full
|
||||
configs = [ "../..:public_config_for_all" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
}
|
||||
57
testsuites/unittest/process/fs/It_process_fs_test.h
Normal file
57
testsuites/unittest/process/fs/It_process_fs_test.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _IT_PROCESS_FS_TEST_H
|
||||
#define _IT_PROCESS_FS_TEST_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include "osTest.h"
|
||||
|
||||
extern VOID PrintTest(const CHAR *fmt, ...);
|
||||
|
||||
extern std::string GenProcPidPath(int pid);
|
||||
extern std::string GenProcPidContainerPath(int pid, char *name);
|
||||
|
||||
extern void ItProcessFs001(void);
|
||||
extern void ItProcessFs002(void);
|
||||
extern void ItProcessFs003(void);
|
||||
extern void ItProcessFs004(void);
|
||||
extern void ItProcessFs005(void);
|
||||
extern void ItProcessFs006(void);
|
||||
extern void ItProcessFs007(void);
|
||||
extern void ItProcessFs008(void);
|
||||
extern void ItProcessFs009(void);
|
||||
extern void ItProcessFs010(void);
|
||||
extern void ItProcessFs011(void);
|
||||
extern void ItProcessFs012(void);
|
||||
extern void ItProcessFs013(void);
|
||||
extern void ItProcessFs014(void);
|
||||
extern void ItProcessFs015(void);
|
||||
#endif
|
||||
74
testsuites/unittest/process/fs/config.gni
Normal file
74
testsuites/unittest/process/fs/config.gni
Normal file
@@ -0,0 +1,74 @@
|
||||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//build/lite/config/test.gni")
|
||||
import("//kernel/liteos_a/testsuites/unittest/config.gni")
|
||||
|
||||
common_include_dirs = [
|
||||
"//third_party/googletest/googletest/include",
|
||||
"../../common/include",
|
||||
]
|
||||
|
||||
sources_entry = [ "../../common/osTest.cpp" ]
|
||||
|
||||
sources_smoke = []
|
||||
|
||||
sources_full = []
|
||||
|
||||
process_fs_include_dirs = [ "$TEST_UNITTEST_DIR/process/fs" ]
|
||||
|
||||
process_fs_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/process/fs/process_fs_test.cpp" ]
|
||||
|
||||
process_fs_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_012.cpp",
|
||||
"$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",
|
||||
]
|
||||
|
||||
process_fs_sources_full = []
|
||||
|
||||
# fs module
|
||||
if (LOSCFG_USER_TEST_PROCESS_FS == true) {
|
||||
common_include_dirs += process_fs_include_dirs
|
||||
sources_entry += process_fs_sources_entry
|
||||
sources_smoke += process_fs_sources_smoke
|
||||
sources_full += process_fs_sources_full
|
||||
}
|
||||
155
testsuites/unittest/process/fs/process_fs_test.cpp
Normal file
155
testsuites/unittest/process/fs/process_fs_test.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <cstdio>
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
VOID PrintTest(const CHAR *fmt, ...)
|
||||
{
|
||||
#ifdef PRINT_TEST
|
||||
va_list ap;
|
||||
if (g_osLkHook != NULL) {
|
||||
va_start(ap, fmt);
|
||||
printf(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string GenProcPidPath(int pid)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid;
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
std::string GenProcPidContainerPath(int pid, char *name)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid << "/container/" << name;
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessFsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_001
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs001, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_007
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs007, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_010
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs010, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs010();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_012
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs012, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs012();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_013
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs013, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs013();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_014
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs014, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs014();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_015
|
||||
* @tc.desc: Process mount directory test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AEVV
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs015, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs015();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
44
testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
Normal file
44
testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
void ItProcessFs001(void)
|
||||
{
|
||||
auto path = GenProcPidPath(getpid());
|
||||
DIR *dirp = opendir(path.data());
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
|
||||
(void)closedir(dirp);
|
||||
}
|
||||
52
testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
Normal file
52
testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void ItProcessFs002(void)
|
||||
{
|
||||
const int LEN_BUFF = 512;
|
||||
char szStatBuf[LEN_BUFF];
|
||||
FILE *fp = fopen("/proc/meminfo", "rb");
|
||||
ASSERT_NE(fp, nullptr);
|
||||
|
||||
int ret = fread(szStatBuf, 1, LEN_BUFF, fp);
|
||||
PrintTest("cat /proc/meminfo\n");
|
||||
PrintTest("%s\n", szStatBuf);
|
||||
ASSERT_EQ(ret, strlen(szStatBuf));
|
||||
|
||||
char *res = strstr(szStatBuf, "UsedSize");
|
||||
ASSERT_NE(res, nullptr);
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
54
testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
Normal file
54
testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void ItProcessFs003(void)
|
||||
{
|
||||
const int LEN_STAT = 512;
|
||||
char szStatBuf[LEN_STAT];
|
||||
FILE *fp = fopen("/proc/filesystems", "r");
|
||||
ASSERT_NE(fp, nullptr);
|
||||
|
||||
(void)memset_s(szStatBuf, LEN_STAT, 0, LEN_STAT);
|
||||
int readLen = fread(szStatBuf, 1, LEN_STAT, fp);
|
||||
|
||||
PrintTest("cat /proc/filesystems\n");
|
||||
PrintTest("%s\n", szStatBuf);
|
||||
ASSERT_EQ(readLen, strlen(szStatBuf));
|
||||
|
||||
char *res = strstr(szStatBuf, "procfs");
|
||||
ASSERT_NE(res, nullptr);
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
64
testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
Normal file
64
testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
static std::string gen_proc_pid_meminfo_path(int pid)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid << "/meminfo";
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
static void operPidMemInfo(std::string strFile)
|
||||
{
|
||||
const int FILE_LEN = 1024;
|
||||
char szStatBuf[FILE_LEN];
|
||||
FILE *fp = fopen(strFile.c_str(), "rb");
|
||||
ASSERT_NE(fp, nullptr);
|
||||
|
||||
(void)memset_s(szStatBuf, FILE_LEN, 0, FILE_LEN);
|
||||
int ret = fread(szStatBuf, 1, FILE_LEN, fp);
|
||||
PrintTest("cat %s\n", strFile.c_str());
|
||||
PrintTest("%s\n", szStatBuf);
|
||||
ASSERT_EQ(ret, strlen(szStatBuf));
|
||||
|
||||
char *res = strstr(szStatBuf, "VMSpaceSize");
|
||||
ASSERT_NE(res, nullptr);
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
|
||||
void ItProcessFs004(void)
|
||||
{
|
||||
auto path = gen_proc_pid_meminfo_path(getpid());
|
||||
operPidMemInfo(path);
|
||||
}
|
||||
65
testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
Normal file
65
testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static std::string gen_proc_pid_cpup_path(int pid)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid << "/cpup";
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
static void operPidCpup(std::string strFile)
|
||||
{
|
||||
const int PUP_LEN = 1024;
|
||||
char szStatBuf[PUP_LEN];
|
||||
FILE *fp = fopen(strFile.c_str(), "rb");
|
||||
ASSERT_NE(fp, nullptr);
|
||||
|
||||
(void)memset_s(szStatBuf, PUP_LEN, 0, PUP_LEN);
|
||||
int ret = fread(szStatBuf, 1, PUP_LEN, fp);
|
||||
PrintTest("cat %s\n", strFile.c_str());
|
||||
|
||||
PrintTest("%s\n", szStatBuf);
|
||||
ASSERT_EQ(ret, strlen(szStatBuf));
|
||||
|
||||
char *res = strstr(szStatBuf, "TotalRunningTime");
|
||||
ASSERT_NE(res, nullptr);
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
|
||||
void ItProcessFs005(void)
|
||||
{
|
||||
auto path = gen_proc_pid_cpup_path(getpid());
|
||||
operPidCpup(path);
|
||||
}
|
||||
124
testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
Normal file
124
testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const maxContainerNum = 5;
|
||||
static int const configLen = 16;
|
||||
static int nInitArry[maxContainerNum] = {61, 54, 49, 44, 41};
|
||||
|
||||
static std::string arryEntries[maxContainerNum] = {
|
||||
"max_mnt_container",
|
||||
"max_pid_container",
|
||||
"max_user_container",
|
||||
"max_net_container",
|
||||
"max_uts_container"
|
||||
};
|
||||
|
||||
static void WriteContainer(const char *filepath, int value)
|
||||
{
|
||||
PrintTest("writeproc %d >> %s\n", value, filepath);
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
ASSERT_EQ(fd, -1);
|
||||
char buf[configLen];
|
||||
size_t twd = sprintf_s(buf, configLen, "%d", value);
|
||||
ASSERT_GT(twd, 0);
|
||||
twd = write(fd, buf, (strlen(buf)+1));
|
||||
ASSERT_EQ(twd, -1);
|
||||
(void)close(fd);
|
||||
}
|
||||
|
||||
static void ReadContainer(std::string strFile, int value)
|
||||
{
|
||||
char szStatBuf[configLen];
|
||||
FILE *fp = fopen(strFile.c_str(), "rb");
|
||||
ASSERT_NE(fp, nullptr);
|
||||
|
||||
int ret;
|
||||
(void)memset_s(szStatBuf, configLen, 0, configLen);
|
||||
ret = fread(szStatBuf, 1, configLen, fp);
|
||||
ASSERT_NE(ret, 0);
|
||||
PrintTest("cat %s\n", strFile.c_str());
|
||||
|
||||
PrintTest("%s\n", szStatBuf);
|
||||
ret = atoi(szStatBuf);
|
||||
ASSERT_EQ(ret, value);
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
|
||||
static void ErrWriteContainer0(const char *filepath)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
ASSERT_EQ(fd, -1);
|
||||
char buf[configLen];
|
||||
int invalidNum = 0;
|
||||
size_t twd1 = sprintf_s(buf, configLen, "%d", invalidNum);
|
||||
ASSERT_GT(twd1, 0);
|
||||
PrintTest("writeproc %d >> %s\n", invalidNum, filepath);
|
||||
twd1 = write(fd, buf, (strlen(buf)+1));
|
||||
(void)close(fd);
|
||||
ASSERT_EQ(twd1, -1);
|
||||
}
|
||||
|
||||
static void ErrWriteContainer65(const char *filepath)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
ASSERT_EQ(fd, -1);
|
||||
char buf[configLen];
|
||||
int invalidNum = 65;
|
||||
size_t twd2 = sprintf_s(buf, configLen, "%d", invalidNum);
|
||||
ASSERT_GT(twd2, 0);
|
||||
PrintTest("writeproc %d >> %s\n", invalidNum, filepath);
|
||||
twd2 = write(fd, buf, (strlen(buf)+1));
|
||||
(void)close(fd);
|
||||
ASSERT_EQ(twd2, -1);
|
||||
}
|
||||
|
||||
void ItProcessFs006(void)
|
||||
{
|
||||
const int CONFIG_FILE_LEN = 1024;
|
||||
char szFile[CONFIG_FILE_LEN] = {0};
|
||||
for (int i = 0; i < maxContainerNum; i++) {
|
||||
size_t count = sprintf_s(szFile, CONFIG_FILE_LEN, "/proc/sys/user/%s", arryEntries[i].c_str());
|
||||
ASSERT_GT(count, 0);
|
||||
WriteContainer(szFile, nInitArry[i]);
|
||||
ReadContainer(szFile, nInitArry[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxContainerNum; i++) {
|
||||
size_t count = sprintf_s(szFile, CONFIG_FILE_LEN, "/proc/sys/user/%s", arryEntries[i].c_str());
|
||||
ASSERT_GT(count, 0);
|
||||
ErrWriteContainer0(szFile);
|
||||
|
||||
ErrWriteContainer65(szFile);
|
||||
}
|
||||
}
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_007.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 ItProcessFs007(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "uts");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'uts:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_008.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 ItProcessFs008(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "mnt");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'mnt:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_009.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 ItProcessFs009(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "user");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'user:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_010.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 ItProcessFs010(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "pid");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'pid:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
49
testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
Normal file
49
testsuites/unittest/process/fs/smoke/It_process_fs_011.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 ItProcessFs011(void)
|
||||
{
|
||||
auto path = GenProcPidContainerPath(getpid(), "net");
|
||||
std::vector<char> buf(PATH_MAX);
|
||||
auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
|
||||
ASSERT_NE(nbytes, -1);
|
||||
|
||||
std::regex reg("'net:\\[[0-9]+\\]'");
|
||||
bool ret = std::regex_match(buf.data(), reg);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
79
testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
Normal file
79
testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <climits>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
static const int STACK_SIZE = 1024 * 1024;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
|
||||
static int child_process(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
pid_t pid = getpid();
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid;
|
||||
DIR *dirp = opendir(buf.str().data());
|
||||
if (dirp == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
(void)closedir(dirp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItProcessFs012(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int status;
|
||||
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;
|
||||
int arg = CHILD_FUNC_ARG;
|
||||
pid_t pid = clone(child_process, stackTop, SIGCHLD, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
|
||||
ret = WIFEXITED(status);
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
|
||||
std::ostringstream buf;
|
||||
buf << "/proc/" << pid;
|
||||
DIR *dirp = opendir(buf.str().data());
|
||||
ASSERT_EQ(dirp, nullptr);
|
||||
}
|
||||
48
testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
Normal file
48
testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
static const int ini_process_max = 3;
|
||||
|
||||
void ItProcessFs013(void)
|
||||
{
|
||||
std::string path;
|
||||
DIR *dirp = nullptr;
|
||||
for (int i = 1; i <= ini_process_max; i++) {
|
||||
if (i != 2) { /* 2: skip kernel process */
|
||||
path = GenProcPidPath(i);
|
||||
printf("path: %s\n", path.c_str());
|
||||
dirp = opendir(path.data());
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
(void)closedir(dirp);
|
||||
};
|
||||
}
|
||||
}
|
||||
39
testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
Normal file
39
testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
void ItProcessFs014(void)
|
||||
{
|
||||
std::string path = "/proc/100000";
|
||||
DIR *dirp = nullptr;
|
||||
dirp = opendir(path.c_str());
|
||||
ASSERT_EQ(dirp, nullptr);
|
||||
}
|
||||
41
testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
Normal file
41
testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include "It_process_fs_test.h"
|
||||
|
||||
void ItProcessFs015(void)
|
||||
{
|
||||
std::string path = "/proc/power";
|
||||
DIR *dirp = nullptr;
|
||||
dirp = opendir(path.c_str());
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
|
||||
(void)closedir(dirp);
|
||||
}
|
||||
76
testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
Normal file
76
testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static int const invalidNum = 2;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
const int STACK_SIZE = (1024 * 1024);
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
char buf[configLen];
|
||||
(void)sprintf(buf, "%d", invalidNum);
|
||||
size_t 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,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
|
||||
ASSERT_EQ(pid, -1);
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
77
testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
Normal file
77
testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static int const invalidNum = 2;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
const int STACK_SIZE = (1024 * 1024);
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
char buf[configLen];
|
||||
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,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
|
||||
ASSERT_EQ(pid, -1);
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
77
testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
Normal file
77
testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static int const invalidNum = 2;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
const int STACK_SIZE = (1024 * 1024);
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
char buf[configLen];
|
||||
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,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
|
||||
ASSERT_EQ(pid, -1);
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
77
testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
Normal file
77
testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static int const invalidNum = 2;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
const int STACK_SIZE = (1024 * 1024);
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
char buf[configLen];
|
||||
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,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
|
||||
ASSERT_EQ(pid, -1);
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
77
testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
Normal file
77
testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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_process_fs_test.h"
|
||||
|
||||
static int const configLen = 16;
|
||||
static int const invalidNum = 2;
|
||||
static const int CHILD_FUNC_ARG = 0x2088;
|
||||
const int STACK_SIZE = (1024 * 1024);
|
||||
|
||||
static int childFunc(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
sleep(2); /* 2: delay 2s */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
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,
|
||||
-1, 0);
|
||||
ASSERT_NE(stack, NULL);
|
||||
char *stackTop = stack + STACK_SIZE;
|
||||
|
||||
auto pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
|
||||
ASSERT_NE(pid, -1);
|
||||
|
||||
pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
|
||||
ASSERT_EQ(pid, -1);
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
Reference in New Issue
Block a user