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 "src/trace_processor/importers/systrace/systrace_parser.h"
18
19 #include "test/gtest_and_gmock.h"
20
21 namespace perfetto {
22 namespace trace_processor {
23 namespace systrace_utils {
24 namespace {
25
26 using Result = SystraceParseResult;
27
TEST(SystraceParserTest,SystraceEvent)28 TEST(SystraceParserTest, SystraceEvent) {
29 SystraceTracePoint result{};
30 ASSERT_EQ(ParseSystraceTracePoint("", &result), Result::kFailure);
31 ASSERT_EQ(ParseSystraceTracePoint("abcdef", &result), Result::kFailure);
32 ASSERT_EQ(ParseSystraceTracePoint(" ", &result), Result::kFailure);
33 ASSERT_EQ(ParseSystraceTracePoint("|", &result), Result::kFailure);
34 ASSERT_EQ(ParseSystraceTracePoint("||", &result), Result::kFailure);
35 ASSERT_EQ(ParseSystraceTracePoint("|||", &result), Result::kFailure);
36 ASSERT_EQ(ParseSystraceTracePoint("\n", &result), Result::kFailure);
37 ASSERT_EQ(ParseSystraceTracePoint("|\n", &result), Result::kFailure);
38 ASSERT_EQ(ParseSystraceTracePoint("||\n", &result), Result::kFailure);
39 ASSERT_EQ(ParseSystraceTracePoint("||\n", &result), Result::kFailure);
40 ASSERT_EQ(ParseSystraceTracePoint("B", &result), Result::kFailure);
41 ASSERT_EQ(ParseSystraceTracePoint("C", &result), Result::kFailure);
42 ASSERT_EQ(ParseSystraceTracePoint("S", &result), Result::kFailure);
43 ASSERT_EQ(ParseSystraceTracePoint("F", &result), Result::kFailure);
44
45 ASSERT_EQ(ParseSystraceTracePoint("B|42|\n", &result), Result::kSuccess);
46 EXPECT_EQ(result, SystraceTracePoint::B(42, "[empty slice name]"));
47
48 ASSERT_EQ(ParseSystraceTracePoint("B|1|foo", &result), Result::kSuccess);
49 EXPECT_EQ(result, SystraceTracePoint::B(1, "foo"));
50
51 ASSERT_EQ(ParseSystraceTracePoint("B|42|Bar\n", &result), Result::kSuccess);
52 EXPECT_EQ(result, SystraceTracePoint::B(42, "Bar"));
53
54 ASSERT_EQ(ParseSystraceTracePoint("E\n", &result), Result::kSuccess);
55 EXPECT_EQ(result, SystraceTracePoint::E(0));
56
57 ASSERT_EQ(ParseSystraceTracePoint("E", &result), Result::kSuccess);
58 EXPECT_EQ(result, SystraceTracePoint::E(0));
59
60 ASSERT_EQ(ParseSystraceTracePoint("E|42\n", &result), Result::kSuccess);
61 EXPECT_EQ(result, SystraceTracePoint::E(42));
62
63 ASSERT_EQ(ParseSystraceTracePoint("E|42", &result), Result::kSuccess);
64 EXPECT_EQ(result, SystraceTracePoint::E(42));
65
66 ASSERT_EQ(ParseSystraceTracePoint("C|543|foo|", &result), Result::kFailure);
67 ASSERT_EQ(ParseSystraceTracePoint("C|543|foo|8", &result), Result::kSuccess);
68 EXPECT_EQ(result, SystraceTracePoint::C(543, "foo", 8));
69
70 ASSERT_EQ(ParseSystraceTracePoint("C|543|foo|8|", &result), Result::kFailure);
71 ASSERT_EQ(ParseSystraceTracePoint("C|543|foo|8|group", &result),
72 Result::kSuccess);
73 EXPECT_EQ(result, SystraceTracePoint::C(543, "foo", 8, "group"));
74
75 ASSERT_EQ(ParseSystraceTracePoint("S|", &result), Result::kFailure);
76
77 ASSERT_EQ(ParseSystraceTracePoint("S|123|foo|456", &result),
78 Result::kSuccess);
79 EXPECT_EQ(result, SystraceTracePoint::S(123, "foo", 456));
80
81 ASSERT_EQ(ParseSystraceTracePoint("F|123|foo|456", &result),
82 Result::kSuccess);
83 EXPECT_EQ(result, SystraceTracePoint::F(123, "foo", 456));
84
85 ASSERT_EQ(ParseSystraceTracePoint("trace_event_clock_sync: parent_ts=0.123\n",
86 &result),
87 Result::kUnsupported);
88 ASSERT_EQ(ParseSystraceTracePoint("trace_event_clock_sync: realtime_ts=123\n",
89 &result),
90 Result::kUnsupported);
91 }
92
93 } // namespace
94 } // namespace systrace_utils
95 } // namespace trace_processor
96 } // namespace perfetto
97