xref: /aosp_15_r20/system/extras/simpleperf/cmd_trace_sched_test.cpp (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 
23 #include <android-base/file.h>
24 #include <android-base/stringprintf.h>
25 
26 #include <map>
27 #include <memory>
28 #include <thread>
29 
30 #include "command.h"
31 #include "environment.h"
32 #include "event_selection_set.h"
33 #include "get_test_data.h"
34 #include "record.h"
35 #include "record_file.h"
36 #include "test_util.h"
37 #include "thread_tree.h"
38 
39 using namespace simpleperf;
40 using namespace PerfFileFormat;
41 
TraceSchedCmd()42 static std::unique_ptr<Command> TraceSchedCmd() {
43   return CreateCommandInstance("trace-sched");
44 }
45 
46 // @CddTest = 6.1/C-0-2
TEST(trace_sched_cmd,smoke)47 TEST(trace_sched_cmd, smoke) {
48   TEST_IN_ROOT({ ASSERT_TRUE(TraceSchedCmd()->Run({"--duration", "1"})); });
49 }
50 
51 // @CddTest = 6.1/C-0-2
TEST(trace_sched_cmd,report_smoke)52 TEST(trace_sched_cmd, report_smoke) {
53   CaptureStdout capture;
54   ASSERT_TRUE(capture.Start());
55   ASSERT_TRUE(TraceSchedCmd()->Run(
56       {"--record-file", GetTestData(PERF_DATA_SCHED_STAT_RUNTIME), "--show-threads"}));
57   std::string data = capture.Finish();
58   ASSERT_NE(data.find("Process  3845.961 ms  94.90%      8603  examplepurejava"),
59             std::string::npos);
60   ASSERT_NE(data.find("Thread   3845.961 ms  94.90%      8615  BusyThread"), std::string::npos);
61   ASSERT_NE(data.find("Detect 3 spin loops in process examplepurejava (8603) thread "
62                       "BusyThread (8615),\nmax rate at [326962.439095 s - 326963.442418 s], "
63                       "taken 997.813 ms / 1003.323 ms (99.45%)."),
64             std::string::npos);
65 }
66