1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TEST_UTIL_H 17 #define TEST_UTIL_H 18 19 #include <string> 20 #include <list> 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 25 typedef enum CmdType { 26 CLEAR_DIR, 27 KILL_ALL, 28 PID_OF, 29 } CmdType; 30 31 class TestUtil { 32 public: 33 static bool FileExists(const std::string &path); 34 static std::string GetSmapsPath(const std::string &processName); 35 static std::string GetSampleFile(const std::string &processName); 36 static void KillProcess(const std::string &name); 37 static void ClearDir(std::string name); 38 static std::string BuildCommand(CmdType type, const std::string &target); 39 static bool IsLeakingProcessAlive(); 40 static bool GetStatm(uint64_t &rss); 41 static bool GetSelfStatm(uint64_t &rss); 42 static bool RestartProcess(const std::string &name); 43 static void CopyFile(const std::string &srcFile, const std::string &dstFile); 44 static void WriteFile(const std::string &file, const std::string &line); 45 static void DeleteFile(const std::string &file); 46 static bool IsSelfOverLimit(int leakTarget); 47 48 private: 49 static std::string ExecCmd(CmdType type, const std::string &target); 50 static std::string GetPidByProcess(const std::string &name); 51 static bool IsValidTarget(const std::string &target); 52 static std::list<std::string> GetDightStrArr(const std::string &target); 53 static pid_t leakProcessPid_; 54 }; 55 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 59 #endif // TEST_UTIL_H 60