OSDN Git Service

am b89e81dc: fs_config: align with new explicit fs_config target_out parameter
[android-x86/system-extras.git] / simpleperf / cmd_stat_test.cpp
1 /*
2  * Copyright (C) 2015 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 <base/stringprintf.h>
20
21 #include "command.h"
22 #include "test_util.h"
23
24 static std::unique_ptr<Command> StatCmd() {
25   return CreateCommandInstance("stat");
26 }
27
28 TEST(stat_cmd, no_options) {
29   ASSERT_TRUE(StatCmd()->Run({"sleep", "1"}));
30 }
31
32 TEST(stat_cmd, event_option) {
33   ASSERT_TRUE(StatCmd()->Run({"-e", "cpu-clock,task-clock", "sleep", "1"}));
34 }
35
36 TEST(stat_cmd, system_wide_option) {
37   ASSERT_TRUE(StatCmd()->Run({"-a", "sleep", "1"}));
38 }
39
40 TEST(stat_cmd, verbose_option) {
41   ASSERT_TRUE(StatCmd()->Run({"--verbose", "sleep", "1"}));
42 }
43
44 TEST(stat_cmd, tracepoint_event) {
45   ASSERT_TRUE(StatCmd()->Run({"-a", "-e", "sched:sched_switch", "sleep", "1"}));
46 }
47
48 TEST(stat_cmd, event_modifier) {
49   ASSERT_TRUE(StatCmd()->Run({"-e", "cpu-cycles:u,sched:sched_switch:k", "sleep", "1"}));
50 }
51
52 TEST(stat_cmd, existing_processes) {
53   std::vector<std::unique_ptr<Workload>> workloads;
54   CreateProcesses(2, &workloads);
55   std::string pid_list =
56       android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid());
57   ASSERT_TRUE(StatCmd()->Run({"-p", pid_list}));
58 }
59
60 TEST(stat_cmd, existing_threads) {
61   std::vector<std::unique_ptr<Workload>> workloads;
62   CreateProcesses(2, &workloads);
63   // Process id can be used as thread id in linux.
64   std::string tid_list =
65       android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid());
66   ASSERT_TRUE(StatCmd()->Run({"-t", tid_list}));
67 }
68
69 TEST(stat_cmd, no_monitored_threads) {
70   ASSERT_FALSE(StatCmd()->Run({""}));
71 }