#include "src/trace_processor/util/protozero_to_json.h"
#include "perfetto/ext/base/string_utils.h"
#include "perfetto/protozero/scattered_heap_buffer.h"
#include "src/protozero/test/example_proto/test_messages.pbzero.h"
#include "src/trace_processor/importers/proto/track_event.descriptor.h"
#include "src/trace_processor/test_messages.descriptor.h"
#include "src/trace_processor/util/descriptors.h"
#include "test/gtest_and_gmock.h"
#include "protos/perfetto/trace/track_event/chrome_compositor_scheduler_state.pbzero.h"
#include "protos/perfetto/trace/track_event/track_event.pbzero.h"
#if PERFETTO_BUILDFLAG(PERFETTO_STANDALONE_BUILD)
#include "protos/perfetto/metrics/chrome/all_chrome_metrics.pb.h"
#include "src/trace_processor/metrics/all_chrome_metrics.descriptor.h"
#endif
namespace perfetto {
namespace trace_processor {
namespace protozero_to_json {
namespace {
constexpr size_t kChunkSize = …;
using ::protozero::test::protos::pbzero::EveryField;
using ::protozero::test::protos::pbzero::PackedRepeatedFields;
_;
ElementsAre;
Eq;
StartsWith;
TEST(ProtozeroToJsonTest, CustomDescriptorPoolEmpty) { … }
TEST(ProtozeroToJsonTest, CustomDescriptorPoolBasic) { … }
TEST(ProtozeroToJsonTest, CustomDescriptorPoolNestedMsg) { … }
#if PERFETTO_BUILDFLAG(PERFETTO_STANDALONE_BUILD)
TEST(ProtozeroToJsonTest, CustomDescriptorPoolAnnotations) {
using perfetto::protos::TestChromeMetric;
TestChromeMetric msg;
msg.set_test_value(1);
auto binary_proto = msg.SerializeAsString();
protozero::ConstBytes binary_proto_bytes{
reinterpret_cast<const uint8_t*>(binary_proto.data()),
binary_proto.size()};
DescriptorPool pool;
auto status = pool.AddFromFileDescriptorSet(
kAllChromeMetricsDescriptor.data(), kAllChromeMetricsDescriptor.size());
ASSERT_TRUE(status.ok());
EXPECT_EQ(R"({
"test_value": 1,
"__annotations": {
"test_value": {
"__field_options": {
"unit": "count_smallerIsBetter"
}
}
}
})",
ProtozeroToJson(pool, ".perfetto.protos.TestChromeMetric",
binary_proto_bytes, kPretty | kInlineAnnotations));
}
#endif
class ProtozeroToJsonTestMessageTest : public testing::Test { … };
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntInt32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntSint32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntUint32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntInt64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntSint64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntBool) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntSmallEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntSignedEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntBigEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntEnumUnknown) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntUnknown) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntMismatch) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldVarIntForPacked) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed32Signed) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed32Unsigned) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed32Float) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed32Unknown) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed32Mismatch) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed64Signed) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed64Unsigned) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed64Double) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed64Unknown) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldFixed64Mismatch) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedString) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedBadString) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedUnicodeString) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedBytes) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedUnknown) { … }
TEST_F(ProtozeroToJsonTestMessageTest, RepeatedInt32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, RepeatedFixed64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, RepeatedSignedFixed32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, RepeatedString) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedBool) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedForNonPacked) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntInt32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntInt64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntUint32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntUint64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed32Uint32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed32Int32) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed32Float) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed64Uint64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed64Int64) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixed64Double) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedSmallEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedSignedEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedBigEnum) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixedErrShort) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedFixedGarbage) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntShort) { … }
TEST_F(ProtozeroToJsonTestMessageTest, FieldLengthLimitedPackedVarIntGarbage) { … }
TEST_F(ProtozeroToJsonTestMessageTest, NestedBackToBack) { … }
TEST_F(ProtozeroToJsonTestMessageTest, ExtraBytes) { … }
TEST_F(ProtozeroToJsonTestMessageTest, NonExistingType) { … }
}
}
}
}