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