feat: 添加cgroups测试用例
Close #I6H2AR Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I31a432b69ea5fbad137aa1bb947fff4b6fc307df
This commit is contained in:
58
testsuites/unittest/process/plimits/BUILD.gn
Normal file
58
testsuites/unittest/process/plimits/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_plimits_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_plimits_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" ]
|
||||
}
|
||||
}
|
||||
136
testsuites/unittest/process/plimits/It_process_plimits.h
Normal file
136
testsuites/unittest/process/plimits/It_process_plimits.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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_PLIMITS_H
|
||||
#define _IT_PROCESS_PLIMITS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <numeric>
|
||||
#include "osTest.h"
|
||||
|
||||
#define MEM_PAGE_SIZE 4096
|
||||
#define MEM_SLEEP_TIME 5
|
||||
#define MEM_RESERVED_PAGE 2
|
||||
#define CHILD_FUNC_ARG (0x2088)
|
||||
#define STACK_SIZE (1024 * 1024)
|
||||
#define PROCESS_LIMIT_AMOUNT (64)
|
||||
#define TEST_BUFFER_SIZE (512)
|
||||
#define CPUP10S_INDEX (11)
|
||||
#define CPUP1S_INDEX (12)
|
||||
#define WAIT_CPUP_STABLE (7)
|
||||
#define WAIT_CPUP_STABLE_FOR_100 (17)
|
||||
#define STATISTIC_TIMES (11)
|
||||
#define PERIOD_10_SEC_IN_US (10 * 1000 * 1000)
|
||||
#define QUOTA_2_SEC_IN_US (2 * 1000 * 1000)
|
||||
#define QUOTA_5_SEC_IN_US (5 * 1000 * 1000)
|
||||
#define QUOTA_6_SEC_IN_US (6 * 1000 * 1000)
|
||||
#define QUOTA_7_SEC_IN_US (7 * 1000 * 1000)
|
||||
#define QUOTA_10_SEC_IN_US (10 * 1000 * 1000)
|
||||
#define QUOTA_PERCENT_20 (20)
|
||||
#define QUOTA_PERCENT_50 (50)
|
||||
#define QUOTA_PERCENT_60 (60)
|
||||
#define QUOTA_PERCENT_70 (70)
|
||||
#define QUOTA_PERCENT_100 (100)
|
||||
#define HARDWARE_CORE_AMOUNT (2)
|
||||
#define TOLERANCE_ERROR (5)
|
||||
|
||||
int WriteFile(const char *filepath, const char *buf);
|
||||
int RmdirLimiterFile(std::string path);
|
||||
int RmdirControlFile(std::string path);
|
||||
int ReadFile(const char *filepath, char *buf);
|
||||
int GetLine(char *buf, int count, int maxLen, char **array);
|
||||
int RmdirTest (std::string path);
|
||||
extern UINT32 LosCurTaskIDGet();
|
||||
|
||||
int ForkChilds(int num, int *pidArray);
|
||||
int CreatePlimitGroup(const char* groupName, char *childPidFiles,
|
||||
unsigned long long periodUs, unsigned long long quotaUs);
|
||||
int AddPidIntoSchedLimiters(int num, int *pidArray, const char *procspath);
|
||||
int WaitForCpupStable(int expectedCpupPercent);
|
||||
double CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent);
|
||||
double CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent);
|
||||
int TerminateChildProcess(int *childPidArray, int childAmount, int sig);
|
||||
double TestCpupInPlimit(int childAmount, const char* groupName,
|
||||
unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent);
|
||||
double TestCpupWithoutLimit(int childAmount, const char* groupName, int expectedCpupPercent);
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
void ItProcessPlimits001(void);
|
||||
void ItProcessPlimits002(void);
|
||||
void ItProcessPlimits003(void);
|
||||
void ItProcessPlimits004(void);
|
||||
void ItProcessPlimits005(void);
|
||||
void ItProcessPlimits006(void);
|
||||
void ItProcessPlimits007(void);
|
||||
void ItProcessPlimits008(void);
|
||||
void ItProcessPlimitsMemory001(void);
|
||||
void ItProcessPlimitsMemory002(void);
|
||||
void ItProcessPlimitsPid001(void);
|
||||
void ItProcessPlimitsPid002(void);
|
||||
void ItProcessPlimitsPid003(void);
|
||||
void ItProcessPlimitsPid004(void);
|
||||
void ItProcessPlimitsPid005(void);
|
||||
void ItProcessPlimitsPid006(void);
|
||||
void ItProcessPlimitsSched001(VOID);
|
||||
void ItProcessPlimitsSched002(VOID);
|
||||
void ItProcessPlimitsSched003(VOID);
|
||||
void ItProcessPlimitsSched004(VOID);
|
||||
void ItProcessPlimitsDevices001(void);
|
||||
void ItProcessPlimitsDevices002(void);
|
||||
void ItProcessPlimitsDevices003(void);
|
||||
void ItProcessPlimitsDevices004(void);
|
||||
void ItProcessPlimitsDevices005(void);
|
||||
void ItProcessPlimitsDevices006(void);
|
||||
void ItProcessPlimitsDevices007(void);
|
||||
void ItProcessPlimitsDevices008(void);
|
||||
void ItProcessPlimitsDevices009(void);
|
||||
void ItProcessPlimitsIpc002(void);
|
||||
void ItProcessPlimitsIpc003(void);
|
||||
void ItProcessPlimitsIpc004(void);
|
||||
void ItProcessPlimitsIpc005(void);
|
||||
void ItProcessPlimitsIpc006(void);
|
||||
void ItProcessPlimitsIpc007(void);
|
||||
void ItProcessPlimitsIpc008(void);
|
||||
void ItProcessPlimitsIpc009(void);
|
||||
void ItProcessPlimitsIpc010(void);
|
||||
void ItProcessPlimitsIpc011(void);
|
||||
void ItProcessPlimitsIpc012(void);
|
||||
void ItProcessPlimitsIpc013(void);
|
||||
#endif
|
||||
#endif /* _IT_PROCESS_PLIMITS_H */
|
||||
100
testsuites/unittest/process/plimits/config.gni
Normal file
100
testsuites/unittest/process/plimits/config.gni
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.
|
||||
|
||||
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_plimits_include_dirs = [ "$TEST_UNITTEST_DIR/process/plimits" ]
|
||||
|
||||
process_plimits_sources_entry =
|
||||
[ "$TEST_UNITTEST_DIR/process/plimits/process_plimits_test.cpp" ]
|
||||
|
||||
process_plimits_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_001.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_002.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_003.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_004.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_005.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_006.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_007.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_008.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_009.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_010.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_011.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_012.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_013.cpp",
|
||||
]
|
||||
|
||||
process_plimits_sources_full = []
|
||||
|
||||
# plimits module
|
||||
if (LOSCFG_USER_TEST_PROCESS == true) {
|
||||
common_include_dirs += process_plimits_include_dirs
|
||||
sources_entry += process_plimits_sources_entry
|
||||
sources_smoke += process_plimits_sources_smoke
|
||||
sources_full += process_plimits_sources_full
|
||||
}
|
||||
901
testsuites/unittest/process/plimits/process_plimits_test.cpp
Normal file
901
testsuites/unittest/process/plimits/process_plimits_test.cpp
Normal file
@@ -0,0 +1,901 @@
|
||||
/*
|
||||
|
||||
* 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 <climits>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ProcessPlimitsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
|
||||
protected:
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
private:
|
||||
inline bool IsFile(const std::string &file);
|
||||
inline bool IsDir(const std::string &path);
|
||||
inline bool IsSpecialDir(const std::string &path);
|
||||
};
|
||||
|
||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||
/**
|
||||
* @tc.name: plimits_Test_001
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits001, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_002
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_003
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits003, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_004
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits004, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_005
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits005, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_006
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits006, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_007
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits007, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Test_008
|
||||
* @tc.desc: plimits function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimits008, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimits008();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_001
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid001, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_002
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_003
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid003, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_004
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid004, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_005
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid005, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_pid_Test_006
|
||||
* @tc.desc: pid plimit function test case
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid006, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsPid006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Mem_Test_001
|
||||
* @tc.desc: mem plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsMemory001, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsMemory001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Mem_Test_002
|
||||
* @tc.desc: mem plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsMemory002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsMemory002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_001
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices001, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_002
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_003
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices003, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_004
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices004, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_005
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices005, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_006
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices006, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_007
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices007, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_008
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices008, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices008();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Dev_Test_009
|
||||
* @tc.desc: devices plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices009, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsDevices009();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_002
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_003
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc003, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_004
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc004, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_005
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc005, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_006
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc006, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc006();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_007
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc007, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc007();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_008
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc008, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc008();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_009
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc009, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc009();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_010
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc010, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc010();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_011
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc011, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc011();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_012
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc012, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc012();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Ipc_Test_013
|
||||
* @tc.desc: ipc plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc013, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsIpc013();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Sched_Test_001
|
||||
* @tc.desc: sched plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched001, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsSched001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Sched_Test_002
|
||||
* @tc.desc: sched plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched002, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsSched002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Sched_Test_003
|
||||
* @tc.desc: sched plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched003, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsSched003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: plimits_Sched_Test_004
|
||||
* @tc.desc: sched plimit function test case
|
||||
* @tc.require: issueI6GVPL
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched004, TestSize.Level0)
|
||||
{
|
||||
ItProcessPlimitsSched004();
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
void ProcessPlimitsTest::SetUp()
|
||||
{
|
||||
(void)rmdir("/proc/plimits/test");
|
||||
}
|
||||
|
||||
void ProcessPlimitsTest::TearDown()
|
||||
{
|
||||
(void)rmdir("/proc/plimits/test");
|
||||
}
|
||||
|
||||
bool ProcessPlimitsTest::IsFile(const std::string &file)
|
||||
{
|
||||
struct stat statbuf;
|
||||
return (lstat(file.c_str(), &statbuf) == 0) && S_ISREG(statbuf.st_mode);
|
||||
}
|
||||
|
||||
bool ProcessPlimitsTest::IsDir(const std::string &path)
|
||||
{
|
||||
struct stat statbuf;
|
||||
return (lstat(path.c_str(), &statbuf) == 0) && S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
|
||||
bool ProcessPlimitsTest::IsSpecialDir(const std::string &path)
|
||||
{
|
||||
return strcmp(path.c_str(), ".") == 0 || strcmp(path.c_str(), "..") == 0;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int RmdirTest(std::string path)
|
||||
{
|
||||
int ret;
|
||||
RmdirControlFile(path);
|
||||
ret = rmdir(path.c_str());
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WaitForCpupStable(int expectedCpupPercent)
|
||||
{
|
||||
int sleepTime;
|
||||
if (expectedCpupPercent >= QUOTA_PERCENT_100) {
|
||||
sleepTime = WAIT_CPUP_STABLE_FOR_100;
|
||||
} else {
|
||||
sleepTime = WAIT_CPUP_STABLE;
|
||||
}
|
||||
return sleep(sleepTime);
|
||||
}
|
||||
|
||||
static int SampleRound(void)
|
||||
{
|
||||
return STATISTIC_TIMES;
|
||||
}
|
||||
|
||||
static vector<string> GetProcessInfo(pid_t pid)
|
||||
{
|
||||
vector<string> contentArr;
|
||||
char buf[TEST_BUFFER_SIZE + 1] = {0};
|
||||
string strpid = to_string(pid);
|
||||
|
||||
ifstream infile;
|
||||
infile.open("/proc/process");
|
||||
while (!infile.eof()) {
|
||||
infile.getline(buf, TEST_BUFFER_SIZE);
|
||||
regex e("^\\s+"+strpid);
|
||||
int matchResult = regex_search(buf, e);
|
||||
if (matchResult == 1) {
|
||||
istringstream str(buf);
|
||||
string out;
|
||||
while (str >> out) {
|
||||
contentArr.push_back(out);
|
||||
}
|
||||
break;
|
||||
}
|
||||
(void)memset_s(buf, TEST_BUFFER_SIZE, 0, TEST_BUFFER_SIZE);
|
||||
}
|
||||
infile.close();
|
||||
(void)memset_s(buf, TEST_BUFFER_SIZE, 0, TEST_BUFFER_SIZE);
|
||||
return contentArr;
|
||||
}
|
||||
|
||||
|
||||
static void SigQuit(int s)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int ChildRunCpup()
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_handler = SigQuit;
|
||||
(void)sigaction(SIGUSR1, &act, NULL);
|
||||
|
||||
unsigned long x = 1;
|
||||
unsigned long y = 1;
|
||||
while (1) {
|
||||
y++;
|
||||
x *= y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ForkChilds(int num, int *pidArray)
|
||||
{
|
||||
pid_t childPid;
|
||||
pid_t pidArrayLocal[PROCESS_LIMIT_AMOUNT];
|
||||
|
||||
for (int idx = 0; idx < num; idx++) {
|
||||
childPid = fork();
|
||||
if (childPid == 0) {
|
||||
(void)ChildRunCpup();
|
||||
} else if (childPid > 0) {
|
||||
pidArrayLocal[idx] = childPid;
|
||||
*pidArray = childPid;
|
||||
pidArray++;
|
||||
} else {
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double GetCpup(pid_t pid)
|
||||
{
|
||||
auto content = GetProcessInfo(pid);
|
||||
double cpup10s = atof(content[CPUP10S_INDEX].c_str());
|
||||
return cpup10s;
|
||||
}
|
||||
|
||||
static int CollectCpupData(int childAmount, int sampleSeconds, int *pidArray, vector<vector<double>> &cpupValuesArray)
|
||||
{
|
||||
double cpup10s;
|
||||
for (int i = 0; i < sampleSeconds; i++) {
|
||||
for (int j = 0; j < childAmount;j++) {
|
||||
cpup10s = GetCpup(pidArray[j]);
|
||||
cpupValuesArray[j].push_back(cpup10s);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CalcAverageCpup(int num, vector<vector<double>> &cpupValuesArray, double *cpupAverageArray)
|
||||
{
|
||||
double cpup10sAverage;
|
||||
for (int idx = 0; idx < num; idx++) {
|
||||
auto size = cpupValuesArray[idx].size();
|
||||
cpup10sAverage = std::accumulate(cpupValuesArray[idx].begin(), cpupValuesArray[idx].end(), 0.0) / size;
|
||||
cpupAverageArray[idx] = cpup10sAverage;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreatePlimitGroup(const char* groupName, char *childPidFiles,
|
||||
unsigned long long periodUs, unsigned long long quotaUs)
|
||||
{
|
||||
int ret;
|
||||
mode_t mode = 0777;
|
||||
char dirpath[TEST_BUFFER_SIZE];
|
||||
char procspath[TEST_BUFFER_SIZE];
|
||||
char periodpath[TEST_BUFFER_SIZE];
|
||||
char quotapath[TEST_BUFFER_SIZE];
|
||||
char periodValue[TEST_BUFFER_SIZE];
|
||||
char quotaValue[TEST_BUFFER_SIZE];
|
||||
|
||||
if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sprintf_s(procspath, TEST_BUFFER_SIZE, "%s/plimits.procs", dirpath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sprintf_s(periodpath, TEST_BUFFER_SIZE, "%s/sched.period", dirpath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sprintf_s(quotapath, TEST_BUFFER_SIZE, "%s/sched.quota", dirpath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = access(dirpath, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
|
||||
ret = mkdir(dirpath, mode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
if (sprintf_s(periodValue, TEST_BUFFER_SIZE, "%llu", periodUs) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sprintf_s(quotaValue, TEST_BUFFER_SIZE, "%llu", quotaUs) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ret = WriteFile(periodpath, periodValue);
|
||||
if (ret < 0) {
|
||||
printf("%s %d\n", __FUNCTION__, __LINE__);
|
||||
return ret;
|
||||
}
|
||||
ret = WriteFile(quotapath, quotaValue);
|
||||
if (ret < 0) {
|
||||
printf("%s %d\n", __FUNCTION__, __LINE__);
|
||||
return ret;
|
||||
}
|
||||
if (sprintf_s(childPidFiles, TEST_BUFFER_SIZE, "%s", procspath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreatePlimitGroupWithoutLimit(const char* groupName, char *childPidFiles)
|
||||
{
|
||||
int ret;
|
||||
mode_t mode = 0777;
|
||||
char dirpath[TEST_BUFFER_SIZE];
|
||||
char procspath[TEST_BUFFER_SIZE];
|
||||
|
||||
if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sprintf_s(procspath, TEST_BUFFER_SIZE, "%s/plimits.procs", dirpath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = access(dirpath, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ret = mkdir(dirpath, mode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
if (sprintf_s(childPidFiles, TEST_BUFFER_SIZE, "%s", procspath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TerminateChildProcess(int *childPidArray, int childAmount, int sig)
|
||||
{
|
||||
int idx;
|
||||
for (idx = 0; idx < childAmount; idx++) {
|
||||
(void)kill(childPidArray[idx], SIGUSR1);
|
||||
|
||||
int status;
|
||||
(void)waitpid(childPidArray[idx], &status, 0);
|
||||
}
|
||||
|
||||
(void)signal(SIGUSR1, SIG_DFL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent)
|
||||
{
|
||||
int idx;
|
||||
int sampleSeconds = SampleRound();
|
||||
vector<vector<double>> cpupValuesArray(PROCESS_LIMIT_AMOUNT);
|
||||
(void)CollectCpupData(childAmount, sampleSeconds, &childPidArray[0], cpupValuesArray);
|
||||
|
||||
double actualCpup10sArray[PROCESS_LIMIT_AMOUNT];
|
||||
(void)CalcAverageCpup(childAmount, cpupValuesArray, &actualCpup10sArray[0]);
|
||||
|
||||
double sumAllChildsCpup = 0;
|
||||
for (idx = 0; idx < childAmount; idx++) {
|
||||
sumAllChildsCpup += actualCpup10sArray[idx];
|
||||
}
|
||||
return sumAllChildsCpup;
|
||||
}
|
||||
|
||||
double CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent)
|
||||
{
|
||||
if (expectedCpupPercent <= 0.0) {
|
||||
return 500.0; /* 500.0: errno */
|
||||
}
|
||||
double errorRate = fabs(sumAllChildsCpup / expectedCpupPercent - 1.0);
|
||||
return errorRate;
|
||||
}
|
||||
|
||||
int checkCpupUsageGreaterThan(double sumAllChildsCpup, int expectedCpupPercent)
|
||||
{
|
||||
if (sumAllChildsCpup > expectedCpupPercent) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
double TestCpupInPlimit(int childAmount, const char* groupName,
|
||||
unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent)
|
||||
{
|
||||
char dirpath[TEST_BUFFER_SIZE];
|
||||
pid_t childPidArray[PROCESS_LIMIT_AMOUNT];
|
||||
char procspath[TEST_BUFFER_SIZE];
|
||||
double sumAllChildsCpup = 0;
|
||||
|
||||
int ret = CreatePlimitGroup(groupName, procspath, periodUs, quotaUs);
|
||||
if (ret < 0) {
|
||||
printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, ret);
|
||||
return 100.0; /* 100.0: errno */
|
||||
}
|
||||
ret = ForkChilds(childAmount, &childPidArray[0]);
|
||||
if (ret != 0) {
|
||||
printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, ret);
|
||||
return 200.0; /* 200.0: errno */
|
||||
}
|
||||
(void)WaitForCpupStable(expectedCpupPercent);
|
||||
sumAllChildsCpup = CalcCpupUsage(childAmount, &childPidArray[0], 0);
|
||||
double errorRate = CheckCpupUsage(sumAllChildsCpup, expectedCpupPercent);
|
||||
|
||||
(void)TerminateChildProcess(&childPidArray[0], childAmount, SIGUSR1);
|
||||
|
||||
if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) {
|
||||
return 300.0; /* 300.0: errno */
|
||||
}
|
||||
ret = rmdir(dirpath);
|
||||
if (ret != 0) {
|
||||
printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, errno);
|
||||
return 400.0; /* 400.0: errno */
|
||||
}
|
||||
return errorRate;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
#include <sys/types.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <dirent.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits001(void)
|
||||
{
|
||||
DIR *dirp = opendir("/proc/plimits");
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
(void)closedir(dirp);
|
||||
|
||||
int ret;
|
||||
std::string path = "/proc/plimits/test1";
|
||||
ret = mkdir(path.c_str(), S_IRWXU); // create directory
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits002(void)
|
||||
{
|
||||
(void)rmdir("/proc/plimits");
|
||||
DIR *dirp = opendir("/proc/plimits/");
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
(void)closedir(dirp);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits003(void)
|
||||
{
|
||||
int ret;
|
||||
const char *path = "/proc/text.txt";
|
||||
ret = open(path, O_CREAT);
|
||||
ASSERT_EQ(ret, -1);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <regex>
|
||||
#include <fstream>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits004(void)
|
||||
{
|
||||
int ret, matchResult;
|
||||
const size_t BUFFER_SIZE = 512;
|
||||
char buf[BUFFER_SIZE + 1] = {0};
|
||||
std::string path = "/proc/plimits/test";
|
||||
mode_t mode;
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)ReadFile("/proc/plimits/test/plimits.limiters", buf);
|
||||
printf("/proc/plimits/test/plimits.limiters: %s\n", buf);
|
||||
matchResult = strncmp(buf, "pids memory ipc devices sched", 29); /* 29: buf len */
|
||||
ASSERT_EQ(matchResult, 0);
|
||||
|
||||
ret = rmdir("/proc/plimits/test");
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits005(void)
|
||||
{
|
||||
int ret;
|
||||
const char *path = "/proc/plimits/text.txt";
|
||||
ret = open(path, O_CREAT);
|
||||
ASSERT_EQ(ret, -1);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits006(void)
|
||||
{
|
||||
int ret;
|
||||
const char *path3 = "/proc/plimits/plimits.procs";
|
||||
ret = remove(path3);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path4 = "/proc/plimits/pids.max";
|
||||
ret = remove(path4);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path5 = "/proc/plimits/pids.priority";
|
||||
ret = remove(path5);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path6 = "/proc/plimits/sched.period";
|
||||
ret = remove(path6);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path7 = "/proc/plimits/sched.quota";
|
||||
ret = remove(path7);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path8 = "/proc/plimits/sched.stat";
|
||||
ret = remove(path8);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path9 = "/proc/plimits/memory.limit";
|
||||
ret = remove(path9);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path10 = "/proc/plimits/memory.stat";
|
||||
ret = remove(path10);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path11 = "/proc/plimits/ipc.mq_limit";
|
||||
ret = remove(path11);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path12 = "/proc/plimits/ipc.shm_limit";
|
||||
ret = remove(path12);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path13 = "/proc/plimits/ipc.stat";
|
||||
ret = remove(path13);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path14 = "/proc/plimits/devices.list";
|
||||
ret = remove(path14);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path15 = "/proc/plimits/devices.deny";
|
||||
ret = remove(path15);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path16 = "/proc/plimits/devices.allow";
|
||||
ret = remove(path16);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
const char *path17 = "/proc/plimits/limiters";
|
||||
ret = remove(path17);
|
||||
ASSERT_EQ(ret, -1);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <climits>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimits007(void)
|
||||
{
|
||||
mode_t mode = S_IRWXU;
|
||||
std::string path0 = "/proc/plimits/test";
|
||||
std::string path1 = "/proc/plimits/test/subtest";
|
||||
std::string path2 = "/proc/plimits/test/subtest/subtest";
|
||||
std::string path3 = "/proc/plimits/test/subtest/subtest/subtest";
|
||||
std::string path4 = "/proc/plimits/test/subtest/subtest/subtest/subtest";
|
||||
int ret = mkdir(path0.c_str(), mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = mkdir(path1.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = mkdir(path2.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = mkdir(path3.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = mkdir(path4.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = rmdir(path0.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <climits>
|
||||
#include <sys/types.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static std::string GetFileMode(const char* filePath)
|
||||
{
|
||||
const int MODE_COUNT = 11;
|
||||
char fileProperty[MODE_COUNT] = "----------";
|
||||
char fileMode[MODE_COUNT] = "-rwxrwxrwx";
|
||||
struct stat buf;
|
||||
stat(filePath, &buf);
|
||||
unsigned int off = 256;
|
||||
const int LOOP_VARY = 10;
|
||||
for (int i = 1; i < LOOP_VARY; i++) {
|
||||
if (buf.st_mode & (off >> (i - 1))) {
|
||||
fileProperty[i] = fileMode[i];
|
||||
}
|
||||
}
|
||||
return fileProperty;
|
||||
}
|
||||
|
||||
static int IsFilePropertyR1(const char* filePath)
|
||||
{
|
||||
std::string fileOrg = "-r--r--r--";
|
||||
std::string fileProperty = GetFileMode(filePath);
|
||||
return strcmp(fileProperty.c_str(), fileOrg.c_str());
|
||||
}
|
||||
|
||||
void ItProcessPlimits008(void)
|
||||
{
|
||||
std::string filePath = "/proc/plimits/";
|
||||
std::vector<std::string> fileName;
|
||||
fileName.push_back("plimits.procs");
|
||||
fileName.push_back("plimits.limiters");
|
||||
fileName.push_back("pids.max");
|
||||
fileName.push_back("sched.period");
|
||||
fileName.push_back("sched.quota");
|
||||
fileName.push_back("sched.stat");
|
||||
fileName.push_back("memory.failcnt");
|
||||
fileName.push_back("memory.limit");
|
||||
fileName.push_back("memory.peak");
|
||||
fileName.push_back("memory.usage");
|
||||
fileName.push_back("memory.stat");
|
||||
|
||||
for (auto iter = fileName.begin(); iter != fileName.end(); ++iter) {
|
||||
std::string fileFullPath = filePath + *iter;
|
||||
int ret = IsFilePropertyR1(fileFullPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices001(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
char writeBuf[8];
|
||||
std::string test_dev = "/dev/hi_mipi";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string procsTestPath = "/proc/plimits/test/plimits.procs";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
|
||||
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", getpid());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = WriteFile(procsTestPath.c_str(), writeBuf);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDWR|O_CREAT);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices002(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/hi_mipi";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_a_r = "a * r";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_a_r.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDWR|O_CREAT);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices003(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/hi_mipi";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_a_w = "a * w";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_a_w.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDWR|O_CREAT);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices004(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/hi_mipi";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_a_m = "a * m";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_a_m.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_CREAT);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices005(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/mem";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_c = "c * rwm";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_c.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDWR|O_CREAT);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices006(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/mem";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_c_r = "c * r";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_c_r.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices007(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/mem";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_c_w = "c * w";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_c_w.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices008(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/mem";
|
||||
std::string device_a = "a * rwm";
|
||||
std::string device_c_m = "c * rm";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
std::string devicesAllowPath = "/proc/plimits/test/devices.allow";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = WriteFile(devicesAllowPath.c_str(), device_c_m.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_CREAT, O_RDONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsDevices009(void)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
mode_t mode;
|
||||
std::string test_dev = "/dev/hi_mipi";
|
||||
std::string device_a = "a";
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string devicesDenyPath = "/proc/plimits/test/devices.deny";
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
fd = open(test_dev.c_str(), O_RDONLY|O_CREAT);
|
||||
ASSERT_EQ(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
fd = open(test_dev.c_str(), O_WRONLY|O_CREAT);
|
||||
ASSERT_EQ(fd, -1);
|
||||
(void)close(fd);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc002(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
int fd;
|
||||
std::string plimitsRootPath = "/proc/plimits/";
|
||||
std::vector<std::string> ipcConfFileName;
|
||||
ipcConfFileName.push_back("ipc.mq_limit");
|
||||
ipcConfFileName.push_back("ipc.shm_limit");
|
||||
ipcConfFileName.push_back("ipc.stat");
|
||||
|
||||
for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) {
|
||||
std::string fullPath = plimitsRootPath + *iter;
|
||||
fd = access(fullPath.c_str(), W_OK | X_OK);
|
||||
ASSERT_EQ(fd, -1);
|
||||
fd = access(fullPath.c_str(), F_OK | R_OK);
|
||||
ASSERT_EQ(fd, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc003(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit";
|
||||
std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit";
|
||||
std::string configFileStat = "/proc/plimits/test/ipc.stat";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
int fd = access(configFileMqCount.c_str(), F_OK | W_OK | R_OK);
|
||||
ASSERT_EQ(fd, 0);
|
||||
|
||||
fd = access(configFileShmSize.c_str(), F_OK | W_OK | R_OK);
|
||||
ASSERT_EQ(fd, 0);
|
||||
|
||||
fd = access(configFileStat.c_str(), F_OK | R_OK);
|
||||
ASSERT_EQ(fd, 0);
|
||||
|
||||
fd = access(configFileStat.c_str(), W_OK | X_OK);
|
||||
ASSERT_EQ(fd, -1);
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc004(void)
|
||||
{
|
||||
mode_t mode;
|
||||
mode_t chmodMode = 0777;
|
||||
int ret;
|
||||
int fd;
|
||||
std::string rootplimitsPath = "/proc/plimits";
|
||||
std::string subPlimitsPath = "/proc/plimits/test";
|
||||
|
||||
std::vector<std::string> ipcConfFileName;
|
||||
ipcConfFileName.push_back("ipc.mq_limit");
|
||||
ipcConfFileName.push_back("ipc.shm_limit");
|
||||
ipcConfFileName.push_back("ipc.stat");
|
||||
|
||||
ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) {
|
||||
std::string fullPath = rootplimitsPath + "/" + *iter;
|
||||
ret = chmod(fullPath.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
}
|
||||
|
||||
for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) {
|
||||
std::string fullPath = subPlimitsPath + "/" + *iter;
|
||||
ret = chmod(fullPath.c_str(), mode);
|
||||
ASSERT_EQ(ret, -1);
|
||||
}
|
||||
|
||||
ret = rmdir(subPlimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <mqueue.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int MQ_MAX_PER_PROCESS_COUNT = 255;
|
||||
static const int MQUEUE_STANDARD_NAME_LENGTH = 50;
|
||||
|
||||
void ItProcessPlimitsIpc005(void)
|
||||
{
|
||||
INT32 ret;
|
||||
mode_t mode;
|
||||
char buf[g_buffSize] = { 0 };
|
||||
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
mqd_t mqueue[MQ_MAX_PER_PROCESS_COUNT];
|
||||
struct mq_attr attr = { 0 };
|
||||
int index = 0;
|
||||
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
|
||||
attr.mq_maxmsg = 1;
|
||||
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/ipc.mq_limit", buf);
|
||||
ASSERT_STREQ(buf, "1024\n");
|
||||
|
||||
for (index = 0; index < MQ_MAX_PER_PROCESS_COUNT; ++index) {
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_005_%d_%d",
|
||||
index, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ASSERT_NE(mqueue[index], (mqd_t)-1);
|
||||
}
|
||||
for (int k = 0; k < MQ_MAX_PER_PROCESS_COUNT; ++k) {
|
||||
ret = mq_close(mqueue[k]);
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_005_%d_%d", k, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = mq_unlink(mqname);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <mqueue.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static const int MQUEUE_STANDARD_NAME_LENGTH = 50;
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
static const int MQ_MAX_LIMIT_COUNT = 10;
|
||||
|
||||
static int FreeResource(mqd_t *mqueue, int index, char *mqname)
|
||||
{
|
||||
int ret = -1;
|
||||
for (int k = 0; k < index; ++k) {
|
||||
if (snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d",
|
||||
k, LosCurTaskIDGet()) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ret = mq_close(mqueue[k]);
|
||||
if (ret != 0) {
|
||||
return -2; /* 2: errno */
|
||||
}
|
||||
ret = mq_unlink(mqname);
|
||||
if (ret != 0) {
|
||||
return -3; /* 3: errno */
|
||||
}
|
||||
(void)memset_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, 0, MQUEUE_STANDARD_NAME_LENGTH);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// plimits_ipc_07, plimits_ipc_14, plimits_ipc_17
|
||||
void ItProcessPlimitsIpc006(void)
|
||||
{
|
||||
INT32 ret;
|
||||
mode_t mode;
|
||||
char buf[g_buffSize] = { 0 };
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
int mqSuccessCount = -1, mqFailedCount = -1;
|
||||
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
mqd_t mqueue[g_readLen];
|
||||
std::string subPlimitsPath = "/proc/plimits/test";
|
||||
std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit";
|
||||
std::string limitMqCount = "10";
|
||||
struct mq_attr attr = { 0 };
|
||||
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
|
||||
attr.mq_maxmsg = 1;
|
||||
int index = 0;
|
||||
|
||||
ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), limitMqCount.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
for (index = 0; index < MQ_MAX_LIMIT_COUNT; ++index) {
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d",
|
||||
index, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ASSERT_NE(mqueue[index], (mqd_t)-1);
|
||||
(void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname));
|
||||
}
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", index, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ASSERT_EQ(mqueue[index], (mqd_t)-1);
|
||||
(void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname));
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/ipc.stat", buf);
|
||||
printf("/proc/plimits/test/ipc.stat: %s\n", buf);
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
mqSuccessCount = atoi(array[0] + strlen("mq count: "));
|
||||
mqFailedCount = atoi((array[1] + strlen("mq failed count: ")));
|
||||
ASSERT_EQ(mqSuccessCount, MQ_MAX_LIMIT_COUNT);
|
||||
ASSERT_EQ(mqFailedCount, 1);
|
||||
ret = FreeResource(mqueue, index, mqname);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = rmdir(subPlimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc007(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit";
|
||||
std::string mqLimitCount = "0123";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc008(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit";
|
||||
std::string mqLimitCount_0 = "111*";
|
||||
std::string mqLimitCount_1 = "123abc";
|
||||
std::string mqLimitCount_2 = "\"123 456\"";
|
||||
std::string mqLimitCount_3 = "\123";
|
||||
std::string mqLimitCount_4 = "10000000000000000000000000000000001";
|
||||
std::string mqLimitCount_5 = "\1\2\3";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_0.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_1.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_2.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_3.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_4.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_5.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <sys/shm.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
void ItProcessPlimitsIpc009(void)
|
||||
{
|
||||
mode_t mode;
|
||||
char buf[g_buffSize] = { 0 };
|
||||
int ret;
|
||||
int shmid;
|
||||
void *shared = nullptr;
|
||||
mode_t acessMode = 0666;
|
||||
std::string subPlimitsPath = "/proc/plimits/test";
|
||||
|
||||
ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/ipc.shm_limit", buf);
|
||||
ASSERT_STREQ(buf, "104857600\n");
|
||||
|
||||
shmid = shmget(IPC_PRIVATE, PAGE_SIZE, acessMode | IPC_CREAT);
|
||||
ASSERT_NE(shmid, -1);
|
||||
shared = shmat(shmid, nullptr, 0);
|
||||
ASSERT_NE(shared, (void *)-1);
|
||||
ret = shmdt(shared);
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = shmctl(shmid, IPC_RMID, nullptr);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = rmdir(subPlimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <sys/shm.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static const int g_buffSize = 512;
|
||||
static const int g_arryLen = 4;
|
||||
static const int g_readLen = 254;
|
||||
|
||||
void ItProcessPlimitsIpc010(void)
|
||||
{
|
||||
mode_t mode;
|
||||
mode_t shmAcess = 0666;
|
||||
char buf[g_buffSize] = { 0 };
|
||||
char *array[g_arryLen] = { nullptr };
|
||||
int mqSuccessCount;
|
||||
int mqFailedCount;
|
||||
int shmSuccessSize;
|
||||
int shmFailedCount;
|
||||
int shmid = -1;
|
||||
int shmid_1 = -1;
|
||||
int index = 0;
|
||||
int shmCkeckSize = PAGE_SIZE * 9;
|
||||
void *shared = nullptr;
|
||||
size_t shmSize = PAGE_SIZE * 9;
|
||||
std::string subPlimitsPath = "/proc/plimits/test";
|
||||
std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit";
|
||||
char shmemLimit[6] = "40960";
|
||||
|
||||
int ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmemLimit);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
shmid = shmget(IPC_PRIVATE, shmSize, shmAcess | IPC_CREAT);
|
||||
ASSERT_NE(shmid, -1);
|
||||
shmid_1 = shmget(IPC_PRIVATE, 2 * PAGE_SIZE, shmAcess | IPC_CREAT); /* 2: PAGE num */
|
||||
ASSERT_EQ(shmid_1, -1);
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/ipc.stat", buf);
|
||||
GetLine(buf, g_arryLen, g_readLen, array);
|
||||
mqSuccessCount = atoi(array[index++] + strlen("mq count: "));
|
||||
mqFailedCount = atoi(array[index++] + strlen("mq failed count: "));
|
||||
shmSuccessSize = atoi(array[index++] + strlen("shm size: "));
|
||||
shmFailedCount = atoi(array[index++] + strlen("shm failed count: "));
|
||||
|
||||
ASSERT_EQ(shmSuccessSize, shmCkeckSize);
|
||||
ASSERT_EQ(shmFailedCount, 1);
|
||||
|
||||
shared = shmat(shmid, nullptr, 0);
|
||||
ASSERT_NE(shared, (void *)-1);
|
||||
|
||||
ret = shmdt(shared);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = shmctl(shmid, IPC_RMID, nullptr);
|
||||
ASSERT_NE(ret, -1);
|
||||
shmctl(shmid_1, IPC_RMID, nullptr);
|
||||
shmctl(shmid, IPC_RMID, nullptr);
|
||||
|
||||
ret = rmdir(subPlimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc011(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
char buf[512] = { 0 };
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit";
|
||||
std::string shmLimitSize = "0123";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsIpc012(void)
|
||||
{
|
||||
mode_t mode;
|
||||
int ret;
|
||||
std::string plimitsPath = "/proc/plimits/test";
|
||||
std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit";
|
||||
std::string shmLimitSize_0 = "111*";
|
||||
std::string shmLimitSize_1 = "123abc";
|
||||
std::string shmLimitSize_2 = "\"123 456\"";
|
||||
std::string shmLimitSize_3 = "\123";
|
||||
std::string shmLimitSize_4 = "10000000000000000000000000000000001";
|
||||
std::string shmLimitSize_5 = "\1\2\3";
|
||||
|
||||
ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_0.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_1.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_2.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_3.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_4.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_5.c_str());
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = rmdir(plimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <mqueue.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static const int MQUEUE_STANDARD_NAME_LENGTH = 50;
|
||||
static const int MQUEUE_STANDARD_NAME_LENGTH_MAX = 102500;
|
||||
static const int g_buff = 512;
|
||||
static const int MQ_MAX_LIMIT_COUNT = 10;
|
||||
|
||||
static int FreeResource(mqd_t *mqueue, int index, char *mqname)
|
||||
{
|
||||
int ret = -1;
|
||||
for (int k = 0; k < index; ++k) {
|
||||
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d",
|
||||
k, LosCurTaskIDGet());
|
||||
if (ret < 0) {
|
||||
return -1; /* 1: errno */
|
||||
}
|
||||
ret = mq_close(mqueue[k]);
|
||||
if (ret < 0) {
|
||||
return -2; /* 2: errno */
|
||||
}
|
||||
ret = mq_unlink(mqname);
|
||||
if (ret < 0) {
|
||||
return -3; /* 3: errno */
|
||||
}
|
||||
(void)memset_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, 0, MQUEUE_STANDARD_NAME_LENGTH);
|
||||
}
|
||||
return ret ;
|
||||
}
|
||||
|
||||
void ItProcessPlimitsIpc013(void)
|
||||
{
|
||||
INT32 ret;
|
||||
mode_t mode;
|
||||
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
mqd_t mqueue[g_buff];
|
||||
std::string subPlimitsPath = "/proc/plimits/test";
|
||||
std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit";
|
||||
std::string limitMqCount = "11";
|
||||
struct mq_attr attr = { 0 };
|
||||
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
|
||||
attr.mq_maxmsg = 1;
|
||||
struct mq_attr attr_err = { 0 };
|
||||
attr_err.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH_MAX;
|
||||
attr_err.mq_maxmsg = 1;
|
||||
int index = 0;
|
||||
|
||||
ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = WriteFile(configFileMqCount.c_str(), limitMqCount.c_str());
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
for (index = 0; index < MQ_MAX_LIMIT_COUNT; ++index) {
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d",
|
||||
index, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ASSERT_NE(mqueue[index], (mqd_t)-1);
|
||||
(void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname));
|
||||
}
|
||||
|
||||
ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", index, LosCurTaskIDGet());
|
||||
ASSERT_NE(ret, -1);
|
||||
mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr_err);
|
||||
ASSERT_EQ(mqueue[index], (mqd_t)-1);
|
||||
(void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname));
|
||||
ret = FreeResource(mqueue, index, mqname);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = rmdir(subPlimitsPath.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static char *testStr1 = nullptr;
|
||||
|
||||
static int limitWrite(const char *filepath, const char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
size_t ret = write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int CloneOne(void *arg)
|
||||
{
|
||||
const unsigned int testSize = 11534336;
|
||||
|
||||
testStr1 = (char *)malloc(testSize);
|
||||
EXPECT_STRNE(testStr1, NULL);
|
||||
|
||||
(void)memset_s(testStr1, testSize, 1, testSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItProcessPlimitsMemory001(void)
|
||||
{
|
||||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
int ret, pid, status;
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string limitTestPath = "/proc/plimits/test/memory.limit";
|
||||
std::string usageTestPath = "/proc/plimits/test/memory.stat";
|
||||
const char *buffer = "10485760";
|
||||
char buf[512];
|
||||
int twoM = 2 * 1024 * 1024;
|
||||
|
||||
char *stack = (char *)mmap(NULL, twoM, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||
EXPECT_STRNE(stack, NULL);
|
||||
ret = access(path.c_str(), 0);
|
||||
EXPECT_EQ(ret, -1);
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = limitWrite(limitTestPath.c_str(), buffer);
|
||||
EXPECT_NE(ret, -1);
|
||||
pid = clone(CloneOne, stack, 0, NULL);
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
||||
ret = ReadFile(usageTestPath.c_str(), buf);
|
||||
EXPECT_NE(ret, -1);
|
||||
printf("%s: %s\n", usageTestPath.c_str(), buf);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static char *testStr1 = nullptr;
|
||||
|
||||
static int limitWrite(const char *filepath, const char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
size_t ret = write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int CloneOne(void *arg)
|
||||
{
|
||||
const unsigned int testSize = 1153;
|
||||
|
||||
testStr1 = (char *)malloc(testSize);
|
||||
EXPECT_STRNE(testStr1, NULL);
|
||||
|
||||
(void)memset_s(testStr1, testSize, 1, testSize);
|
||||
free(testStr1);
|
||||
testStr1 = nullptr;
|
||||
return 0;
|
||||
}
|
||||
void ItProcessPlimitsMemory002(void)
|
||||
{
|
||||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
int ret, pid, status;
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string limitTestPath = "/proc/plimits/test/memory.limit";
|
||||
std::string usageTestPath = "/proc/plimits/test/memory.stat";
|
||||
char buf[512];
|
||||
const char *buffer = "10485760";
|
||||
int twoM = 2 * 1024 * 1024;
|
||||
|
||||
char *stack = (char *)mmap(NULL, twoM, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||
EXPECT_STRNE(stack, NULL);
|
||||
ret = access(path.c_str(), 0);
|
||||
EXPECT_EQ(ret, -1);
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = limitWrite(limitTestPath.c_str(), buffer);
|
||||
EXPECT_NE(ret, -1);
|
||||
pid = clone(CloneOne, stack, 0, NULL);
|
||||
ret = waitpid(pid, &status, 0);
|
||||
ASSERT_EQ(ret, pid);
|
||||
ret = WIFEXITED(status);
|
||||
ASSERT_NE(ret, 0);
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
ASSERT_EQ(exitCode, 0);
|
||||
|
||||
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
||||
ret = ReadFile(usageTestPath.c_str(), buf);
|
||||
EXPECT_NE(ret, -1);
|
||||
printf("%s: %s\n", usageTestPath.c_str(), buf);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <sys/wait.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static int g_pidGroup[10] = {0};
|
||||
static int g_index = 0;
|
||||
static int g_sleepTime = 5;
|
||||
|
||||
static int PidWrite(const char *filepath, char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
if (fd <= 0) {
|
||||
return 2; /* 2: errno */
|
||||
}
|
||||
size_t ret = write(fd, buf, strlen(buf));
|
||||
if (ret < 0) {
|
||||
printf("filepath: %s buf: %s, errno=%d\n", filepath, buf, errno);
|
||||
}
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int PidFork(const char *filepath, int index)
|
||||
{
|
||||
pid_t fpid = fork();
|
||||
if (fpid == 0) { // children proc
|
||||
sleep(g_sleepTime);
|
||||
exit(0);
|
||||
} else if (fpid > 0) {
|
||||
g_pidGroup[index] = fpid;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ItProcessPlimitsPid001(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
int status;
|
||||
const char *pidMaxPath = "/proc/plimits/test/pids.max";
|
||||
const char *procsPath = "/proc/plimits/test/plimits.procs";
|
||||
std::string path = "/proc/plimits/test";
|
||||
char writeBuf[3];
|
||||
int i = 0;
|
||||
int pidnum = 5;
|
||||
int mainpid = getpid();
|
||||
int ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
|
||||
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum);
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = PidWrite(pidMaxPath, writeBuf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
for (i = g_index; i < pidnum; i++) {
|
||||
ret = PidFork(procsPath, i);
|
||||
if (i != (pidnum - 1)) {
|
||||
ASSERT_EQ(ret, 0);
|
||||
} else {
|
||||
ASSERT_EQ(ret, -1);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < pidnum - 1; ++i) {
|
||||
pid_t pid = waitpid(g_pidGroup[i], &status, 0);
|
||||
ASSERT_EQ(pid, g_pidGroup[i]);
|
||||
ASSERT_EQ(WEXITSTATUS(status), 0);
|
||||
}
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <sys/wait.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static int g_pidGroup[10] = {0};
|
||||
static int g_index = 0;
|
||||
static int g_sleepTime = 5;
|
||||
|
||||
static int PidWrite(const char *filepath, char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
size_t ret = write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void PidFork(int index)
|
||||
{
|
||||
pid_t fpid = fork();
|
||||
if (fpid == 0) { // children proc
|
||||
sleep(g_sleepTime);
|
||||
exit(0);
|
||||
} else if (fpid > 0) {
|
||||
g_pidGroup[index] = fpid;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ItProcessPlimitsPid002(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
int status;
|
||||
const char *pidMaxPath = "/proc/plimits/test/pids.max";
|
||||
const char *procsPath = "/proc/plimits/test/plimits.procs";
|
||||
std::string path = "/proc/plimits/test";
|
||||
char writeBuf[3];
|
||||
int num = 4;
|
||||
int i = 0;
|
||||
pid_t fpid;
|
||||
int pidnum = 5;
|
||||
int ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
|
||||
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum);
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = PidWrite(pidMaxPath, writeBuf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
|
||||
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", getpid());
|
||||
ASSERT_NE(ret, -1);
|
||||
ret = PidWrite(procsPath, writeBuf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
for (i = g_index; i < num; ++i) {
|
||||
PidFork(i);
|
||||
}
|
||||
g_index = i;
|
||||
fpid = fork();
|
||||
if (fpid == 0) {
|
||||
exit(0);
|
||||
} else if (fpid > 0) {
|
||||
waitpid(fpid, &status, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < g_index; ++i) {
|
||||
waitpid(g_pidGroup[i], &status, 0);
|
||||
ASSERT_EQ(WEXITSTATUS(status), 0);
|
||||
}
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <sys/wait.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static int PidWrite(const char *filepath, char *buf)
|
||||
{
|
||||
int fd = open(filepath, O_WRONLY);
|
||||
size_t ret = write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ItProcessPlimitsPid003(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
int status;
|
||||
struct sched_param param = { 0 };
|
||||
const char *pidMaxPath = "/proc/plimits/test/pids.priority";
|
||||
std::string path = "/proc/plimits/test";
|
||||
char writeBuf[3];
|
||||
int pidnum = 15; /* 15: priority limit */
|
||||
int ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
|
||||
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
ret = PidWrite(pidMaxPath, writeBuf);
|
||||
ASSERT_NE(ret, -1);
|
||||
|
||||
int currProcessPri = getpriority(PRIO_PROCESS, getpid());
|
||||
|
||||
param.sched_priority = pidnum - 1;
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR, ¶m);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), param.sched_priority);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
param.sched_priority = currProcessPri + 1;
|
||||
ret = sched_setscheduler(getpid(), SCHED_RR, ¶m);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
param.sched_priority++;
|
||||
ret = setpriority(PRIO_PROCESS, getpid(), param.sched_priority);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
param.sched_priority++;
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsPid004(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
int ret;
|
||||
const char *res = nullptr;
|
||||
const size_t BUFFER_SIZE = 512;
|
||||
std::string path = "/proc/plimits/test";
|
||||
DIR *dirp = opendir("/proc/plimits");
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
closedir(dirp);
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
char buff[BUFFER_SIZE] = {0};
|
||||
ret = ReadFile("/proc/plimits/pids.max", buff);
|
||||
res = strstr(buff, "64");
|
||||
ASSERT_STRNE(res, nullptr);
|
||||
(void)memset_s(buff, BUFFER_SIZE, 0, BUFFER_SIZE);
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/pids.max", buff);
|
||||
res = strstr(buff, "64");
|
||||
ASSERT_STRNE(res, nullptr);
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
#include <sys/types.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <dirent.h>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
static int g_processOs = 8;
|
||||
|
||||
void ItProcessPlimitsPid005(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
std::string path = "/proc/plimits/test";
|
||||
std::string filepath = "/proc/plimits/test/plimits.procs";
|
||||
int pid = getpid();
|
||||
int vprocessId = 90;
|
||||
std::string missPid = std::to_string(vprocessId);
|
||||
std::string runPid = std::to_string(pid);
|
||||
|
||||
int ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
int fd = open(filepath.c_str(), O_WRONLY);
|
||||
ASSERT_NE(fd, -1);
|
||||
|
||||
for (int i = 1; i <= g_processOs; i++) {
|
||||
std::string fWrite = std::to_string(i);
|
||||
ret = write(fd, fWrite.c_str(), (fWrite.length()));
|
||||
ASSERT_EQ(ret, -1);
|
||||
}
|
||||
|
||||
ret = write(fd, missPid.c_str(), (missPid.length()));
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = write(fd, path.c_str(), (path.length()));
|
||||
ASSERT_EQ(ret, -1);
|
||||
|
||||
ret = write(fd, runPid.c_str(), (runPid.length()));
|
||||
ASSERT_NE(ret, -1);
|
||||
close(fd);
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
void ItProcessPlimitsPid006(void)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
int ret;
|
||||
const char *res = nullptr;
|
||||
const size_t BUFFER_SIZE = 512;
|
||||
std::string path = "/proc/plimits/test";
|
||||
DIR *dirp = opendir("/proc/plimits");
|
||||
ASSERT_NE(dirp, nullptr);
|
||||
closedir(dirp);
|
||||
|
||||
ret = mkdir(path.c_str(), S_IFDIR | mode);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
char buff[BUFFER_SIZE] = {0};
|
||||
ret = ReadFile("/proc/plimits/pids.max", buff);
|
||||
res = strstr(buff, "64");
|
||||
ASSERT_STRNE(res, nullptr);
|
||||
(void)memset_s(buff, BUFFER_SIZE, 0, BUFFER_SIZE);
|
||||
|
||||
ret = ReadFile("/proc/plimits/test/pids.max", buff);
|
||||
res = strstr(buff, "64");
|
||||
ASSERT_STRNE(res, nullptr);
|
||||
ret = rmdir(path.c_str());
|
||||
ASSERT_EQ(ret, 0);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VOID ItProcessPlimitsSched001(void)
|
||||
{
|
||||
const int childAmount = 1;
|
||||
double errorRate = TestCpupInPlimit(childAmount, "testcpup101", PERIOD_10_SEC_IN_US,
|
||||
QUOTA_2_SEC_IN_US, QUOTA_PERCENT_20);
|
||||
ASSERT_GE(errorRate, 0);
|
||||
ASSERT_LE(errorRate, TOLERANCE_ERROR);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "It_process_plimits.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VOID ItProcessPlimitsSched002(void)
|
||||
{
|
||||
const int childAmount = 1;
|
||||
double errorRate = TestCpupInPlimit(childAmount, "testcpup102", PERIOD_10_SEC_IN_US,
|
||||
QUOTA_6_SEC_IN_US, QUOTA_PERCENT_60);
|
||||
ASSERT_GE(errorRate, 0);
|
||||
ASSERT_LE(errorRate, TOLERANCE_ERROR);
|
||||
}
|
||||
|
||||
@@ -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 "It_process_plimits.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VOID ItProcessPlimitsSched003(void)
|
||||
{
|
||||
const int childAmount = 1;
|
||||
double errorRate = TestCpupInPlimit(childAmount, "testcpup104", PERIOD_10_SEC_IN_US,
|
||||
QUOTA_10_SEC_IN_US, QUOTA_PERCENT_100);
|
||||
ASSERT_GE(errorRate, 0);
|
||||
ASSERT_LE(errorRate, TOLERANCE_ERROR);
|
||||
}
|
||||
@@ -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 "It_process_plimits.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VOID ItProcessPlimitsSched004(void)
|
||||
{
|
||||
const int childAmount = 2;
|
||||
double errorRate = TestCpupInPlimit(childAmount, "testcpup105", PERIOD_10_SEC_IN_US,
|
||||
QUOTA_10_SEC_IN_US, QUOTA_PERCENT_100);
|
||||
ASSERT_GE(errorRate, 0);
|
||||
ASSERT_LE(errorRate, TOLERANCE_ERROR);
|
||||
}
|
||||
Reference in New Issue
Block a user