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
TEST(trace_sched_cmd,smoke)46 TEST(trace_sched_cmd, smoke) {
47 TEST_IN_ROOT({ ASSERT_TRUE(TraceSchedCmd()->Run({"--duration", "1"})); });
48 }
49
TEST(trace_sched_cmd,report_smoke)50 TEST(trace_sched_cmd, report_smoke) {
51 CaptureStdout capture;
52 ASSERT_TRUE(capture.Start());
53 ASSERT_TRUE(TraceSchedCmd()->Run(
54 {"--record-file", GetTestData(PERF_DATA_SCHED_STAT_RUNTIME), "--show-threads"}));
55 std::string data = capture.Finish();
56 ASSERT_NE(data.find("Process 3845.961 ms 94.90% 8603 examplepurejava"),
57 std::string::npos);
58 ASSERT_NE(data.find("Thread 3845.961 ms 94.90% 8615 BusyThread"), std::string::npos);
59 ASSERT_NE(data.find("Detect 3 spin loops in process examplepurejava (8603) thread "
60 "BusyThread (8615),\nmax rate at [326962.439095 s - 326963.442418 s], "
61 "taken 997.813 ms / 1003.323 ms (99.45%)."),
62 std::string::npos);
63 }
64