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/forwarding_trace_parser.h"
18
19 #include "test/gtest_and_gmock.h"
20
21 namespace perfetto {
22 namespace trace_processor {
23 namespace {
24
TEST(TraceProcessorImplTest,GuessTraceType_Empty)25 TEST(TraceProcessorImplTest, GuessTraceType_Empty) {
26 const uint8_t prefix[] = "";
27 EXPECT_EQ(kUnknownTraceType, GuessTraceType(prefix, 0));
28 }
29
TEST(TraceProcessorImplTest,GuessTraceType_Json)30 TEST(TraceProcessorImplTest, GuessTraceType_Json) {
31 const uint8_t prefix[] = "{\"traceEvents\":[";
32 EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
33 }
34
TEST(TraceProcessorImplTest,GuessTraceType_Ninja)35 TEST(TraceProcessorImplTest, GuessTraceType_Ninja) {
36 const uint8_t prefix[] = "# ninja log v5\n";
37 EXPECT_EQ(kNinjaLogTraceType, GuessTraceType(prefix, sizeof(prefix)));
38 }
39
TEST(TraceProcessorImplTest,GuessTraceType_JsonWithSpaces)40 TEST(TraceProcessorImplTest, GuessTraceType_JsonWithSpaces) {
41 const uint8_t prefix[] = "\n{ \"traceEvents\": [";
42 EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
43 }
44
45 // Some Android build traces do not contain the wrapper. See b/118826940
TEST(TraceProcessorImplTest,GuessTraceType_JsonMissingTraceEvents)46 TEST(TraceProcessorImplTest, GuessTraceType_JsonMissingTraceEvents) {
47 const uint8_t prefix[] = "[{";
48 EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
49 }
50
TEST(TraceProcessorImplTest,GuessTraceType_Proto)51 TEST(TraceProcessorImplTest, GuessTraceType_Proto) {
52 const uint8_t prefix[] = {0x0a, 0x00}; // An empty TracePacket.
53 EXPECT_EQ(kProtoTraceType, GuessTraceType(prefix, sizeof(prefix)));
54 }
55
TEST(TraceProcessorImplTest,GuessTraceType_Fuchsia)56 TEST(TraceProcessorImplTest, GuessTraceType_Fuchsia) {
57 const uint8_t prefix[] = {0x10, 0x00, 0x04, 0x46, 0x78, 0x54, 0x16, 0x00};
58 EXPECT_EQ(kFuchsiaTraceType, GuessTraceType(prefix, sizeof(prefix)));
59 }
60
TEST(TraceProcessorImplTest,GuessTraceType_Bmp)61 TEST(TraceProcessorImplTest, GuessTraceType_Bmp) {
62 const uint8_t prefix[] = {0x42, 0x4d, 0x1e, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00,
64 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00};
65 EXPECT_EQ(kUnknownTraceType, GuessTraceType(prefix, sizeof(prefix)));
66 }
67
68 } // namespace
69 } // namespace trace_processor
70 } // namespace perfetto
71