1 /*
2 * Copyright (C) 2019 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 "src/trace_processor/ftrace_utils.h"
18
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21
22 namespace perfetto {
23 namespace trace_processor {
24 namespace ftrace_utils {
25 namespace {
26
27 using ::testing::ElementsAre;
28
TEST(TaskStateUnittest,Invalid)29 TEST(TaskStateUnittest, Invalid) {
30 TaskState state;
31 ASSERT_FALSE(state.is_valid());
32 }
33
TEST(TaskStateUnittest,Smoke)34 TEST(TaskStateUnittest, Smoke) {
35 auto state = TaskState(static_cast<uint16_t>(0u));
36 ASSERT_TRUE(state.is_valid());
37
38 ASSERT_STREQ(state.ToString().data(), "R");
39 ASSERT_STREQ(TaskState(1).ToString().data(), "S");
40 ASSERT_STREQ(TaskState(2).ToString().data(), "D");
41 ASSERT_STREQ(TaskState(4).ToString().data(), "T");
42 ASSERT_STREQ(TaskState(8).ToString().data(), "t");
43 ASSERT_STREQ(TaskState(16).ToString().data(), "X");
44 ASSERT_STREQ(TaskState(32).ToString().data(), "Z");
45 ASSERT_STREQ(TaskState(64).ToString().data(), "x");
46 ASSERT_STREQ(TaskState(128).ToString().data(), "K");
47 ASSERT_STREQ(TaskState(256).ToString().data(), "W");
48 ASSERT_STREQ(TaskState(512).ToString().data(), "P");
49 ASSERT_STREQ(TaskState(1024).ToString().data(), "N");
50 }
51
TEST(TaskStateUnittest,MultipleState)52 TEST(TaskStateUnittest, MultipleState) {
53 ASSERT_STREQ(TaskState(2048).ToString().data(), "R+");
54 ASSERT_STREQ(TaskState(4096).ToString().data(), "R+");
55 ASSERT_STREQ(TaskState(130).ToString().data(), "DK");
56 ASSERT_STREQ(TaskState(258).ToString().data(), "DW");
57 }
58
59 } // namespace
60 } // namespace ftrace_utils
61 } // namespace trace_processor
62 } // namespace perfetto
63