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 "perfetto/ext/base/scoped_file.h"
18 #include "perfetto/ext/base/utils.h"
19 #include "perfetto/trace_processor/read_trace.h"
20 
21 #include "src/base/test/utils.h"
22 #include "test/gtest_and_gmock.h"
23 
24 #include "protos/perfetto/trace/trace.pbzero.h"
25 #include "protos/perfetto/trace/trace_packet.pbzero.h"
26 
27 namespace perfetto {
28 namespace trace_processor {
29 namespace {
30 
TEST(ReadTraceIntegrationTest,CompressedTrace)31 TEST(ReadTraceIntegrationTest, CompressedTrace) {
32   base::ScopedFstream f(fopen(
33       base::GetTestDataPath(std::string("test/data/compressed.pb")).c_str(),
34       "rb"));
35   std::vector<uint8_t> raw_trace;
36   while (!feof(*f)) {
37     uint8_t buf[4096];
38     auto rsize =
39         fread(reinterpret_cast<char*>(buf), 1, base::ArraySize(buf), *f);
40     raw_trace.insert(raw_trace.end(), buf, buf + rsize);
41   }
42 
43   std::vector<uint8_t> decompressed;
44   decompressed.reserve(raw_trace.size());
45 
46   util::Status status = trace_processor::DecompressTrace(
47       raw_trace.data(), raw_trace.size(), &decompressed);
48   ASSERT_TRUE(status.ok());
49 
50   protos::pbzero::Trace::Decoder decoder(decompressed.data(),
51                                          decompressed.size());
52   uint32_t packet_count = 0;
53   for (auto it = decoder.packet(); it; ++it) {
54     protos::pbzero::TracePacket::Decoder packet(*it);
55     ASSERT_FALSE(packet.has_compressed_packets());
56     ++packet_count;
57   }
58   ASSERT_EQ(packet_count, 2412u);
59 }
60 
61 }  // namespace
62 }  // namespace trace_processor
63 }  // namespace perfetto
64