xref: /aosp_15_r20/external/perfetto/src/trace_config_utils/pb_to_txt_unittest.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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_config_utils/pb_to_txt.h"
18 
19 #include "protos/perfetto/config/trace_config.gen.h"
20 #include "test/gtest_and_gmock.h"
21 
22 namespace perfetto {
23 namespace {
24 
25 using protos::gen::TraceConfig;
26 
TEST(PbToTxtTest,EmptyTraceConfig)27 TEST(PbToTxtTest, EmptyTraceConfig) {
28   TraceConfig tc;
29   std::vector<uint8_t> data = tc.SerializeAsArray();
30   std::string txt = TraceConfigPbToTxt(data.data(), data.size());
31   EXPECT_EQ(txt, "");
32 }
33 
TEST(PbToTxtTest,ValidTraceConfig)34 TEST(PbToTxtTest, ValidTraceConfig) {
35   TraceConfig tc;
36   tc.set_duration_ms(1234);
37   tc.set_trace_uuid_lsb(INT64_MAX);
38   tc.set_trace_uuid_msb(1234567890124LL);
39   auto* buf = tc.add_buffers();
40   buf->set_size_kb(4096);
41   buf->set_fill_policy(TraceConfig::BufferConfig::RING_BUFFER);
42   tc.set_write_into_file(true);
43 
44   std::vector<uint8_t> data = tc.SerializeAsArray();
45   std::string txt = TraceConfigPbToTxt(data.data(), data.size());
46   EXPECT_EQ(txt, R"(buffers {
47   size_kb: 4096
48   fill_policy: RING_BUFFER
49 }
50 duration_ms: 1234
51 write_into_file: true
52 trace_uuid_msb: 1234567890124
53 trace_uuid_lsb: 9223372036854775807)");
54 }
55 
56 }  // namespace
57 }  // namespace perfetto
58