2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
19 #include <base/stringprintf.h>
22 #include "test_util.h"
24 static std::unique_ptr<Command> StatCmd() {
25 return CreateCommandInstance("stat");
28 TEST(stat_cmd, no_options) {
29 ASSERT_TRUE(StatCmd()->Run({"sleep", "1"}));
32 TEST(stat_cmd, event_option) {
33 ASSERT_TRUE(StatCmd()->Run({"-e", "cpu-clock,task-clock", "sleep", "1"}));
36 TEST(stat_cmd, system_wide_option) {
37 ASSERT_TRUE(StatCmd()->Run({"-a", "sleep", "1"}));
40 TEST(stat_cmd, verbose_option) {
41 ASSERT_TRUE(StatCmd()->Run({"--verbose", "sleep", "1"}));
44 TEST(stat_cmd, tracepoint_event) {
45 ASSERT_TRUE(StatCmd()->Run({"-a", "-e", "sched:sched_switch", "sleep", "1"}));
48 TEST(stat_cmd, event_modifier) {
49 ASSERT_TRUE(StatCmd()->Run({"-e", "cpu-cycles:u,sched:sched_switch:k", "sleep", "1"}));
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}));
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}));
69 TEST(stat_cmd, no_monitored_threads) {
70 ASSERT_FALSE(StatCmd()->Run({""}));