10d163575Sopenharmony_ci/* 20d163575Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. 30d163575Sopenharmony_ci * 40d163575Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 50d163575Sopenharmony_ci * are permitted provided that the following conditions are met: 60d163575Sopenharmony_ci * 70d163575Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 80d163575Sopenharmony_ci * conditions and the following disclaimer. 90d163575Sopenharmony_ci * 100d163575Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 110d163575Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 120d163575Sopenharmony_ci * provided with the distribution. 130d163575Sopenharmony_ci * 140d163575Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 150d163575Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 160d163575Sopenharmony_ci * permission. 170d163575Sopenharmony_ci * 180d163575Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 190d163575Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 200d163575Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 210d163575Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 220d163575Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 230d163575Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 240d163575Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 250d163575Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 260d163575Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 270d163575Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 280d163575Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 290d163575Sopenharmony_ci */ 300d163575Sopenharmony_ci#ifndef _IT_PROCESS_PLIMITS_H 310d163575Sopenharmony_ci#define _IT_PROCESS_PLIMITS_H 320d163575Sopenharmony_ci 330d163575Sopenharmony_ci#include <string> 340d163575Sopenharmony_ci#include <vector> 350d163575Sopenharmony_ci#include <iostream> 360d163575Sopenharmony_ci#include <sstream> 370d163575Sopenharmony_ci#include <regex> 380d163575Sopenharmony_ci#include <fcntl.h> 390d163575Sopenharmony_ci#include <iostream> 400d163575Sopenharmony_ci#include <cstring> 410d163575Sopenharmony_ci#include <fstream> 420d163575Sopenharmony_ci#include <regex> 430d163575Sopenharmony_ci#include <sstream> 440d163575Sopenharmony_ci#include <numeric> 450d163575Sopenharmony_ci#include "osTest.h" 460d163575Sopenharmony_ci 470d163575Sopenharmony_ci#define MEM_PAGE_SIZE 4096 480d163575Sopenharmony_ci#define MEM_SLEEP_TIME 5 490d163575Sopenharmony_ci#define MEM_RESERVED_PAGE 2 500d163575Sopenharmony_ci#define CHILD_FUNC_ARG (0x2088) 510d163575Sopenharmony_ci#define STACK_SIZE (1024 * 1024) 520d163575Sopenharmony_ci#define PROCESS_LIMIT_AMOUNT (64) 530d163575Sopenharmony_ci#define TEST_BUFFER_SIZE (512) 540d163575Sopenharmony_ci#define CPUP10S_INDEX (11) 550d163575Sopenharmony_ci#define CPUP1S_INDEX (12) 560d163575Sopenharmony_ci#define WAIT_CPUP_STABLE (7) 570d163575Sopenharmony_ci#define WAIT_CPUP_STABLE_FOR_100 (17) 580d163575Sopenharmony_ci#define STATISTIC_TIMES (11) 590d163575Sopenharmony_ci#define PERIOD_10_SEC_IN_US (10 * 1000 * 1000) 600d163575Sopenharmony_ci#define QUOTA_2_SEC_IN_US (2 * 1000 * 1000) 610d163575Sopenharmony_ci#define QUOTA_5_SEC_IN_US (5 * 1000 * 1000) 620d163575Sopenharmony_ci#define QUOTA_6_SEC_IN_US (6 * 1000 * 1000) 630d163575Sopenharmony_ci#define QUOTA_7_SEC_IN_US (7 * 1000 * 1000) 640d163575Sopenharmony_ci#define QUOTA_10_SEC_IN_US (10 * 1000 * 1000) 650d163575Sopenharmony_ci#define QUOTA_PERCENT_20 (20) 660d163575Sopenharmony_ci#define QUOTA_PERCENT_50 (50) 670d163575Sopenharmony_ci#define QUOTA_PERCENT_60 (60) 680d163575Sopenharmony_ci#define QUOTA_PERCENT_70 (70) 690d163575Sopenharmony_ci#define QUOTA_PERCENT_100 (100) 700d163575Sopenharmony_ci#define HARDWARE_CORE_AMOUNT (2) 710d163575Sopenharmony_ci#define TOLERANCE_ERROR (5) 720d163575Sopenharmony_ci 730d163575Sopenharmony_ciint WriteFile(const char *filepath, const char *buf); 740d163575Sopenharmony_ciint RmdirLimiterFile(std::string path); 750d163575Sopenharmony_ciint RmdirControlFile(std::string path); 760d163575Sopenharmony_ciint ReadFile(const char *filepath, char *buf); 770d163575Sopenharmony_ciint GetLine(char *buf, int count, int maxLen, char **array); 780d163575Sopenharmony_ciint RmdirTest (std::string path); 790d163575Sopenharmony_ciextern UINT32 LosCurTaskIDGet(); 800d163575Sopenharmony_ci 810d163575Sopenharmony_ciint ForkChilds(int num, int *pidArray); 820d163575Sopenharmony_ciint CreatePlimitGroup(const char* groupName, char *childPidFiles, 830d163575Sopenharmony_ci unsigned long long periodUs, unsigned long long quotaUs); 840d163575Sopenharmony_ciint AddPidIntoSchedLimiters(int num, int *pidArray, const char *procspath); 850d163575Sopenharmony_ciint WaitForCpupStable(int expectedCpupPercent); 860d163575Sopenharmony_cidouble CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent); 870d163575Sopenharmony_cidouble CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent); 880d163575Sopenharmony_ciint TerminateChildProcess(int *childPidArray, int childAmount, int sig); 890d163575Sopenharmony_cidouble TestCpupInPlimit(int childAmount, const char* groupName, 900d163575Sopenharmony_ci unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent); 910d163575Sopenharmony_cidouble TestCpupWithoutLimit(int childAmount, const char* groupName, int expectedCpupPercent); 920d163575Sopenharmony_ci 930d163575Sopenharmony_ci#if defined(LOSCFG_USER_TEST_SMOKE) 940d163575Sopenharmony_civoid ItProcessPlimits001(void); 950d163575Sopenharmony_civoid ItProcessPlimits002(void); 960d163575Sopenharmony_civoid ItProcessPlimits003(void); 970d163575Sopenharmony_civoid ItProcessPlimits004(void); 980d163575Sopenharmony_civoid ItProcessPlimits005(void); 990d163575Sopenharmony_civoid ItProcessPlimits006(void); 1000d163575Sopenharmony_civoid ItProcessPlimits007(void); 1010d163575Sopenharmony_civoid ItProcessPlimits008(void); 1020d163575Sopenharmony_civoid ItProcessPlimitsMemory001(void); 1030d163575Sopenharmony_civoid ItProcessPlimitsMemory002(void); 1040d163575Sopenharmony_civoid ItProcessPlimitsPid001(void); 1050d163575Sopenharmony_civoid ItProcessPlimitsPid002(void); 1060d163575Sopenharmony_civoid ItProcessPlimitsPid003(void); 1070d163575Sopenharmony_civoid ItProcessPlimitsPid004(void); 1080d163575Sopenharmony_civoid ItProcessPlimitsPid005(void); 1090d163575Sopenharmony_civoid ItProcessPlimitsPid006(void); 1100d163575Sopenharmony_civoid ItProcessPlimitsSched001(VOID); 1110d163575Sopenharmony_civoid ItProcessPlimitsSched002(VOID); 1120d163575Sopenharmony_civoid ItProcessPlimitsSched003(VOID); 1130d163575Sopenharmony_civoid ItProcessPlimitsSched004(VOID); 1140d163575Sopenharmony_civoid ItProcessPlimitsDevices001(void); 1150d163575Sopenharmony_civoid ItProcessPlimitsDevices002(void); 1160d163575Sopenharmony_civoid ItProcessPlimitsDevices003(void); 1170d163575Sopenharmony_civoid ItProcessPlimitsDevices004(void); 1180d163575Sopenharmony_civoid ItProcessPlimitsDevices005(void); 1190d163575Sopenharmony_civoid ItProcessPlimitsDevices006(void); 1200d163575Sopenharmony_civoid ItProcessPlimitsDevices007(void); 1210d163575Sopenharmony_civoid ItProcessPlimitsDevices008(void); 1220d163575Sopenharmony_civoid ItProcessPlimitsDevices009(void); 1230d163575Sopenharmony_civoid ItProcessPlimitsIpc002(void); 1240d163575Sopenharmony_civoid ItProcessPlimitsIpc003(void); 1250d163575Sopenharmony_civoid ItProcessPlimitsIpc004(void); 1260d163575Sopenharmony_civoid ItProcessPlimitsIpc005(void); 1270d163575Sopenharmony_civoid ItProcessPlimitsIpc006(void); 1280d163575Sopenharmony_civoid ItProcessPlimitsIpc007(void); 1290d163575Sopenharmony_civoid ItProcessPlimitsIpc008(void); 1300d163575Sopenharmony_civoid ItProcessPlimitsIpc009(void); 1310d163575Sopenharmony_civoid ItProcessPlimitsIpc010(void); 1320d163575Sopenharmony_civoid ItProcessPlimitsIpc011(void); 1330d163575Sopenharmony_civoid ItProcessPlimitsIpc012(void); 1340d163575Sopenharmony_civoid ItProcessPlimitsIpc013(void); 1350d163575Sopenharmony_ci#endif 1360d163575Sopenharmony_ci#endif /* _IT_PROCESS_PLIMITS_H */ 137