1 /* 2 * Copyright (C) 2021 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 #include <gtest/gtest.h> 16 #include <iostream> 17 #include <sstream> 18 #include <thread> 19 #include "unistd.h" 20 #include "sp_utils.h" 21 #include "ByTrace.h" 22 23 using namespace testing::ext; 24 using namespace std; 25 26 namespace OHOS { 27 namespace SmartPerf { 28 class ByTraceTest : public testing::Test { 29 public: SetUpTestCase()30 static void SetUpTestCase() {} TearDownTestCase()31 static void TearDownTestCase() {} 32 SetUp()33 void SetUp() {} TearDown()34 void TearDown() {} 35 }; 36 37 HWTEST_F(ByTraceTest, ThreadGetTraceTest, TestSize.Level1) 38 { 39 ByTrace &byTrace = ByTrace::GetInstance(); 40 std::string result; 41 std::string cmdString; 42 if (SPUtils::IsHmKernel()) { 43 cmdString = "hitrace --trace_clock mono -t 10 -b 102400 --overwrite idle ace app ohos ability graphic nweb "; 44 } else { 45 cmdString = "hitrace --trace_clock mono -t 10 -b 204800 --overwrite idle ace app ohos ability graphic nweb "; 46 } 47 std::string cmdStringEnd = "sched freq sync workq multimodalinput > "; 48 std::string file = "/data/local/tmp/sptrace_"; 49 std::string time = std::to_string(SPUtils::GetCurTime()); 50 std::string traceFile = file + time + ".ftrace"; 51 std::string traceCmdExe = cmdString + cmdStringEnd + traceFile; 52 auto ret = SPUtils::LoadCmd(traceCmdExe, result); 53 byTrace.ThreadGetTrace(); 54 55 EXPECT_EQ(ret, true); 56 } 57 58 HWTEST_F(ByTraceTest, CheckFpsJittersTest, TestSize.Level1) 59 { 60 ByTrace &byTrace = ByTrace::GetInstance(); 61 std::vector<long long> jitters = {1000000, 2000000, 3000000}; 62 int cfps = 30; 63 TraceStatus result = byTrace.CheckFpsJitters(jitters, cfps); 64 65 EXPECT_EQ(result, TraceStatus::TRACE_FINISH); 66 } 67 68 HWTEST_F(ByTraceTest, CheckHitraceIdTest, TestSize.Level1) 69 { 70 ByTrace &byTrace = ByTrace::GetInstance(); 71 std::string result; 72 std::string cmd = "ps -ef |grep hitrace |grep -v grep"; 73 SPUtils::LoadCmd(cmd, result); 74 bool resultCheck = byTrace.CheckHitraceId(); 75 76 ASSERT_FALSE(resultCheck); 77 } 78 } 79 }