1 /*
2  * Copyright 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 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
20 #pragma clang diagnostic ignored "-Wextra"
21 
22 #undef LOG_TAG
23 #define LOG_TAG "LibSurfaceFlingerUnittests"
24 
25 #include <FrameTracer/FrameTracer.h>
26 #include <gmock/gmock.h>
27 #include <gtest/gtest.h>
28 #include <log/log.h>
29 #include <perfetto/trace/trace.pb.h>
30 
31 #include "libsurfaceflinger_unittest_main.h"
32 
33 using namespace google::protobuf;
34 
35 namespace android {
36 namespace {
37 
38 class FrameTracerTest : public testing::Test {
39 public:
FrameTracerTest()40     FrameTracerTest() {
41         const ::testing::TestInfo* const test_info =
42                 ::testing::UnitTest::GetInstance()->current_test_info();
43         ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
44 
45         // Need to initialize tracing in process for testing, and only once per test suite.
46         static bool wasInitialized = false;
47         if (!wasInitialized) {
48             perfetto::TracingInitArgs args;
49             args.backends = perfetto::kInProcessBackend;
50             perfetto::Tracing::Initialize(args);
51             wasInitialized = true;
52         }
53     }
54 
~FrameTracerTest()55     ~FrameTracerTest() {
56         const ::testing::TestInfo* const test_info =
57                 ::testing::UnitTest::GetInstance()->current_test_info();
58         ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
59     }
60 
SetUp()61     void SetUp() override {
62         mFrameTracer = std::make_unique<FrameTracer>();
63         mFrameTracer->registerDataSource();
64     }
65 
TearDown()66     void TearDown() override { mFrameTracer.reset(); }
67 
68     // Each tracing session can be used for a single block of Start -> Stop.
getTracingSessionForTest()69     static std::unique_ptr<perfetto::TracingSession> getTracingSessionForTest() {
70         perfetto::TraceConfig cfg;
71         cfg.set_duration_ms(500);
72         cfg.add_buffers()->set_size_kb(1024);
73         auto* ds_cfg = cfg.add_data_sources()->mutable_config();
74         ds_cfg->set_name(FrameTracer::kFrameTracerDataSource);
75 
76         auto tracingSession = perfetto::Tracing::NewTrace(perfetto::kInProcessBackend);
77         tracingSession->Setup(cfg);
78         return tracingSession;
79     }
80 
readGraphicsFramePacketsBlocking(perfetto::TracingSession * tracingSession)81     std::vector<perfetto::protos::TracePacket> readGraphicsFramePacketsBlocking(
82             perfetto::TracingSession* tracingSession) {
83         std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
84         perfetto::protos::Trace trace;
85         EXPECT_TRUE(trace.ParseFromArray(raw_trace.data(), int(raw_trace.size())));
86 
87         std::vector<perfetto::protos::TracePacket> packets;
88         for (const auto& packet : trace.packet()) {
89             if (!packet.has_graphics_frame_event()) {
90                 continue;
91             }
92             packets.emplace_back(packet);
93         }
94         return packets;
95     }
96 
97     std::unique_ptr<FrameTracer> mFrameTracer;
98     FenceToFenceTimeMap fenceFactory;
99 };
100 
TEST_F(FrameTracerTest,traceNewLayerStartsTrackingLayerWhenTracing)101 TEST_F(FrameTracerTest, traceNewLayerStartsTrackingLayerWhenTracing) {
102     EXPECT_EQ(mFrameTracer->miniDump(),
103               "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
104 
105     const std::string layerName = "co.layername#0";
106     const int32_t layerId = 5;
107     mFrameTracer->traceNewLayer(layerId, layerName);
108 
109     EXPECT_EQ(mFrameTracer->miniDump(),
110               "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
111 
112     auto tracingSession = getTracingSessionForTest();
113     tracingSession->StartBlocking();
114     EXPECT_EQ(mFrameTracer->miniDump(),
115               "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
116     mFrameTracer->traceNewLayer(layerId, layerName);
117     EXPECT_EQ(mFrameTracer->miniDump(),
118               "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
119     tracingSession->StopBlocking();
120 }
121 
TEST_F(FrameTracerTest,onDestroyRemovesTheTrackedLayer)122 TEST_F(FrameTracerTest, onDestroyRemovesTheTrackedLayer) {
123     EXPECT_EQ(mFrameTracer->miniDump(),
124               "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
125 
126     const std::string layerName = "co.layername#0";
127     const int32_t layerId = 5;
128     const int32_t secondlayerId = 6;
129 
130     auto tracingSession = getTracingSessionForTest();
131     tracingSession->StartBlocking();
132     mFrameTracer->traceNewLayer(layerId, layerName);
133     mFrameTracer->traceNewLayer(secondlayerId, layerName);
134     EXPECT_EQ(mFrameTracer->miniDump(),
135               "FrameTracer miniDump:\nNumber of layers currently being traced is 2\n");
136     tracingSession->StopBlocking();
137 
138     mFrameTracer->onDestroy(layerId);
139     EXPECT_EQ(mFrameTracer->miniDump(),
140               "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
141     mFrameTracer->onDestroy(layerId);
142     EXPECT_EQ(mFrameTracer->miniDump(),
143               "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
144     mFrameTracer->onDestroy(secondlayerId);
145     EXPECT_EQ(mFrameTracer->miniDump(),
146               "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
147 }
148 
TEST_F(FrameTracerTest,canTraceAfterAddingLayer)149 TEST_F(FrameTracerTest, canTraceAfterAddingLayer) {
150     const std::string layerName = "co.layername#0";
151     const int32_t layerId = 1;
152     const uint32_t bufferID = 2;
153     const uint64_t frameNumber = 3;
154     const nsecs_t timestamp = 4;
155     const nsecs_t duration = 5;
156     const auto type = FrameTracer::FrameEvent::POST;
157 
158     {
159         auto tracingSession = getTracingSessionForTest();
160 
161         tracingSession->StartBlocking();
162         mFrameTracer->traceTimestamp(layerId, bufferID, frameNumber, timestamp, type, duration);
163         // Create second trace packet to finalize the previous one.
164         mFrameTracer->traceTimestamp(layerId, 0, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
165         tracingSession->StopBlocking();
166 
167         auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
168         EXPECT_EQ(packets.size(), 0);
169     }
170 
171     {
172         auto tracingSession = getTracingSessionForTest();
173 
174         tracingSession->StartBlocking();
175         mFrameTracer->traceNewLayer(layerId, layerName);
176         mFrameTracer->traceTimestamp(layerId, bufferID, frameNumber, timestamp, type, duration);
177         // Create second trace packet to finalize the previous one.
178         mFrameTracer->traceTimestamp(layerId, 0, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
179         tracingSession->StopBlocking();
180 
181         auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
182         ASSERT_EQ(packets.size(), 2);
183 
184         const auto& packet1 = packets[0];
185         ASSERT_TRUE(packet1.has_timestamp());
186         EXPECT_EQ(packet1.timestamp(), timestamp);
187         ASSERT_TRUE(packet1.has_graphics_frame_event());
188         const auto& frame_event1 = packet1.graphics_frame_event();
189         ASSERT_TRUE(frame_event1.has_buffer_event());
190         const auto& buffer_event1 = frame_event1.buffer_event();
191         ASSERT_TRUE(buffer_event1.has_buffer_id());
192         EXPECT_EQ(buffer_event1.buffer_id(), bufferID);
193         ASSERT_TRUE(buffer_event1.has_frame_number());
194         EXPECT_EQ(buffer_event1.frame_number(), frameNumber);
195         ASSERT_TRUE(buffer_event1.has_type());
196         EXPECT_EQ(buffer_event1.type(), perfetto::protos::GraphicsFrameEvent_BufferEventType(type));
197         ASSERT_TRUE(buffer_event1.has_duration_ns());
198         EXPECT_EQ(buffer_event1.duration_ns(), duration);
199 
200         const auto& packet2 = packets[1];
201         ASSERT_TRUE(packet2.has_timestamp());
202         EXPECT_EQ(packet2.timestamp(), 0);
203         ASSERT_TRUE(packet2.has_graphics_frame_event());
204         const auto& frame_event2 = packet2.graphics_frame_event();
205         ASSERT_TRUE(frame_event2.has_buffer_event());
206         const auto& buffer_event2 = frame_event2.buffer_event();
207         ASSERT_TRUE(buffer_event2.has_type());
208         EXPECT_EQ(buffer_event2.type(),
209                   perfetto::protos::GraphicsFrameEvent_BufferEventType(
210                           FrameTracer::FrameEvent::UNSPECIFIED));
211     }
212 }
213 
TEST_F(FrameTracerTest,traceFenceTriggersOnNextTraceAfterFenceFired)214 TEST_F(FrameTracerTest, traceFenceTriggersOnNextTraceAfterFenceFired) {
215     const std::string layerName = "co.layername#0";
216     const int32_t layerId = 5;
217     const uint32_t bufferID = 4;
218     const uint64_t frameNumber = 3;
219     const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
220 
221     {
222         auto fenceTime = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
223         fenceFactory.signalAllForTest(Fence::NO_FENCE, Fence::SIGNAL_TIME_PENDING);
224         auto tracingSession = getTracingSessionForTest();
225         tracingSession->StartBlocking();
226         // Trace.
227         mFrameTracer->traceNewLayer(layerId, layerName);
228         mFrameTracer->traceFence(layerId, bufferID, frameNumber, fenceTime, type);
229         // Create extra trace packet to (hopefully not) trigger and finalize the fence packet.
230         mFrameTracer->traceTimestamp(layerId, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
231         tracingSession->StopBlocking();
232 
233         auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
234         ASSERT_EQ(packets.size(), 1);
235         const auto& packet = packets[0];
236         ASSERT_TRUE(packet.has_timestamp());
237         EXPECT_EQ(packet.timestamp(), 0);
238         ASSERT_TRUE(packet.has_graphics_frame_event());
239         const auto& frame_event = packet.graphics_frame_event();
240         ASSERT_TRUE(frame_event.has_buffer_event());
241         const auto& buffer_event = frame_event.buffer_event();
242         ASSERT_TRUE(buffer_event.has_type());
243         EXPECT_EQ(buffer_event.type(),
244                   perfetto::protos::GraphicsFrameEvent_BufferEventType(
245                           FrameTracer::FrameEvent::UNSPECIFIED));
246     }
247 
248     {
249         auto fenceTime = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
250         auto tracingSession = getTracingSessionForTest();
251         tracingSession->StartBlocking();
252         mFrameTracer->traceNewLayer(layerId, layerName);
253         mFrameTracer->traceFence(layerId, bufferID, frameNumber, fenceTime, type);
254         const nsecs_t timestamp = systemTime();
255         fenceFactory.signalAllForTest(Fence::NO_FENCE, timestamp);
256         // Create extra trace packet to trigger and finalize fence trace packets.
257         mFrameTracer->traceTimestamp(layerId, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
258         tracingSession->StopBlocking();
259 
260         auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
261         ASSERT_EQ(packets.size(), 3);
262 
263         const auto& packet1 = packets[0];
264         ASSERT_TRUE(packet1.has_timestamp());
265         EXPECT_EQ(packet1.timestamp(), timestamp);
266         ASSERT_TRUE(packet1.has_graphics_frame_event());
267         const auto& frame_event1 = packet1.graphics_frame_event();
268         ASSERT_TRUE(frame_event1.has_buffer_event());
269         const auto& buffer_event1 = frame_event1.buffer_event();
270         ASSERT_TRUE(buffer_event1.has_buffer_id());
271         EXPECT_EQ(buffer_event1.buffer_id(), bufferID);
272         ASSERT_TRUE(buffer_event1.has_frame_number());
273         EXPECT_EQ(buffer_event1.frame_number(), frameNumber);
274         ASSERT_TRUE(buffer_event1.has_type());
275         EXPECT_EQ(buffer_event1.type(),
276                   perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
277         EXPECT_FALSE(buffer_event1.has_duration_ns());
278 
279         const auto& packet2 = packets[1];
280         ASSERT_TRUE(packet2.has_timestamp());
281         EXPECT_EQ(packet2.timestamp(), timestamp);
282         ASSERT_TRUE(packet2.has_graphics_frame_event());
283         const auto& frame_event2 = packet2.graphics_frame_event();
284         ASSERT_TRUE(frame_event2.has_buffer_event());
285         const auto& buffer_event2 = frame_event2.buffer_event();
286         ASSERT_TRUE(buffer_event2.has_buffer_id());
287         EXPECT_EQ(buffer_event2.buffer_id(), bufferID);
288         ASSERT_TRUE(buffer_event2.has_frame_number());
289         EXPECT_EQ(buffer_event2.frame_number(), frameNumber);
290         ASSERT_TRUE(buffer_event2.has_type());
291         EXPECT_EQ(buffer_event2.type(),
292                   perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
293         EXPECT_FALSE(buffer_event2.has_duration_ns());
294 
295         const auto& packet3 = packets[2];
296         ASSERT_TRUE(packet3.has_timestamp());
297         EXPECT_EQ(packet3.timestamp(), 0);
298         ASSERT_TRUE(packet3.has_graphics_frame_event());
299         const auto& frame_event3 = packet3.graphics_frame_event();
300         ASSERT_TRUE(frame_event3.has_buffer_event());
301         const auto& buffer_event3 = frame_event3.buffer_event();
302         ASSERT_TRUE(buffer_event3.has_buffer_id());
303         EXPECT_EQ(buffer_event3.buffer_id(), bufferID);
304         ASSERT_TRUE(buffer_event3.has_frame_number());
305         EXPECT_EQ(buffer_event3.frame_number(), 0);
306         ASSERT_TRUE(buffer_event3.has_type());
307         EXPECT_EQ(buffer_event3.type(),
308                   perfetto::protos::GraphicsFrameEvent::BufferEventType(
309                           FrameTracer::FrameEvent::UNSPECIFIED));
310         EXPECT_FALSE(buffer_event3.has_duration_ns());
311     }
312 }
313 
TEST_F(FrameTracerTest,traceFenceWithStartTimeAfterSignalTime_ShouldHaveNoDuration)314 TEST_F(FrameTracerTest, traceFenceWithStartTimeAfterSignalTime_ShouldHaveNoDuration) {
315     const std::string layerName = "co.layername#0";
316     const int32_t layerId = 5;
317     const uint32_t bufferID = 4;
318     const uint64_t frameNumber = 3;
319     const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
320 
321     auto tracingSession = getTracingSessionForTest();
322 
323     tracingSession->StartBlocking();
324     mFrameTracer->traceNewLayer(layerId, layerName);
325 
326     // traceFence called after fence signalled.
327     const nsecs_t signalTime1 = systemTime();
328     const nsecs_t startTime1 = signalTime1 + 100000;
329     auto fence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
330     fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime1);
331     mFrameTracer->traceFence(layerId, bufferID, frameNumber, fence1, type, startTime1);
332 
333     // traceFence called before fence signalled.
334     const nsecs_t signalTime2 = systemTime();
335     const nsecs_t startTime2 = signalTime2 + 100000;
336     auto fence2 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
337     mFrameTracer->traceFence(layerId, bufferID, frameNumber, fence2, type, startTime2);
338     fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime2);
339 
340     // Create extra trace packet to trigger and finalize fence trace packets.
341     mFrameTracer->traceTimestamp(layerId, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
342     tracingSession->StopBlocking();
343 
344     auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
345     ASSERT_EQ(packets.size(), 3);
346 
347     const auto& packet1 = packets[0];
348     ASSERT_TRUE(packet1.has_timestamp());
349     EXPECT_EQ(packet1.timestamp(), signalTime1);
350     ASSERT_TRUE(packet1.has_graphics_frame_event());
351     ASSERT_TRUE(packet1.graphics_frame_event().has_buffer_event());
352     ASSERT_FALSE(packet1.graphics_frame_event().buffer_event().has_duration_ns());
353     EXPECT_EQ(packet1.graphics_frame_event().buffer_event().type(),
354               perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
355 
356     const auto& packet2 = packets[1];
357     ASSERT_TRUE(packet2.has_timestamp());
358     EXPECT_EQ(packet2.timestamp(), signalTime2);
359     ASSERT_TRUE(packet2.has_graphics_frame_event());
360     ASSERT_TRUE(packet2.graphics_frame_event().has_buffer_event());
361     ASSERT_FALSE(packet2.graphics_frame_event().buffer_event().has_duration_ns());
362     EXPECT_EQ(packet2.graphics_frame_event().buffer_event().type(),
363               perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
364 
365     const auto& packet3 = packets[2];
366     ASSERT_TRUE(packet3.has_timestamp());
367     EXPECT_EQ(packet3.timestamp(), 0);
368     ASSERT_TRUE(packet3.has_graphics_frame_event());
369     ASSERT_TRUE(packet3.graphics_frame_event().has_buffer_event());
370     EXPECT_EQ(packet3.graphics_frame_event().buffer_event().type(),
371               perfetto::protos::GraphicsFrameEvent::BufferEventType(
372                       FrameTracer::FrameEvent::UNSPECIFIED));
373 }
374 
TEST_F(FrameTracerTest,traceFenceOlderThanDeadline_ShouldBeIgnored)375 TEST_F(FrameTracerTest, traceFenceOlderThanDeadline_ShouldBeIgnored) {
376     const std::string layerName = "co.layername#0";
377     const int32_t layerId = 5;
378     const uint32_t bufferID = 4;
379     const uint64_t frameNumber = 3;
380     const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
381     const nsecs_t signalTime = systemTime() - FrameTracer::kFenceSignallingDeadline;
382 
383     auto tracingSession = getTracingSessionForTest();
384     auto fence = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
385 
386     tracingSession->StartBlocking();
387     mFrameTracer->traceNewLayer(layerId, layerName);
388     mFrameTracer->traceFence(layerId, bufferID, frameNumber, fence, type);
389     fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime);
390     // Create extra trace packet to trigger and finalize any previous fence packets.
391     mFrameTracer->traceTimestamp(layerId, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
392     tracingSession->StopBlocking();
393 
394     auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
395     ASSERT_EQ(packets.size(), 1);
396     const auto& packet = packets[0];
397     ASSERT_TRUE(packet.has_timestamp());
398     EXPECT_EQ(packet.timestamp(), 0);
399     ASSERT_TRUE(packet.has_graphics_frame_event());
400     ASSERT_TRUE(packet.graphics_frame_event().has_buffer_event());
401     EXPECT_EQ(packet.graphics_frame_event().buffer_event().type(),
402               perfetto::protos::GraphicsFrameEvent::BufferEventType(
403                       FrameTracer::FrameEvent::UNSPECIFIED));
404 }
405 
TEST_F(FrameTracerTest,traceFenceWithValidStartTime_ShouldHaveCorrectDuration)406 TEST_F(FrameTracerTest, traceFenceWithValidStartTime_ShouldHaveCorrectDuration) {
407     const std::string layerName = "co.layername#0";
408     const int32_t layerId = 5;
409     const uint32_t bufferID = 4;
410     const uint64_t frameNumber = 3;
411     const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
412     const nsecs_t duration = 1234;
413 
414     auto tracingSession = getTracingSessionForTest();
415 
416     tracingSession->StartBlocking();
417     mFrameTracer->traceNewLayer(layerId, layerName);
418 
419     // traceFence called after fence signalled.
420     const nsecs_t signalTime1 = systemTime();
421     const nsecs_t startTime1 = signalTime1 - duration;
422     auto fence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
423     fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime1);
424     mFrameTracer->traceFence(layerId, bufferID, frameNumber, fence1, type, startTime1);
425 
426     // traceFence called before fence signalled.
427     const nsecs_t signalTime2 = systemTime();
428     const nsecs_t startTime2 = signalTime2 - duration;
429     auto fence2 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
430     mFrameTracer->traceFence(layerId, bufferID, frameNumber, fence2, type, startTime2);
431     fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime2);
432 
433     // Create extra trace packet to trigger and finalize fence trace packets.
434     mFrameTracer->traceTimestamp(layerId, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
435     tracingSession->StopBlocking();
436 
437     auto packets = readGraphicsFramePacketsBlocking(tracingSession.get());
438     ASSERT_EQ(packets.size(), 3);
439 
440     const auto& packet1 = packets[0];
441     ASSERT_TRUE(packet1.has_timestamp());
442     EXPECT_EQ(packet1.timestamp(), startTime1);
443     ASSERT_TRUE(packet1.has_graphics_frame_event());
444     ASSERT_TRUE(packet1.graphics_frame_event().has_buffer_event());
445     ASSERT_TRUE(packet1.graphics_frame_event().buffer_event().has_duration_ns());
446     const auto& buffer_event1 = packet1.graphics_frame_event().buffer_event();
447     EXPECT_EQ(buffer_event1.duration_ns(), duration);
448     EXPECT_EQ(buffer_event1.type(), perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
449 
450     const auto& packet2 = packets[1];
451     ASSERT_TRUE(packet2.has_timestamp());
452     EXPECT_EQ(packet2.timestamp(), startTime2);
453     ASSERT_TRUE(packet2.has_graphics_frame_event());
454     ASSERT_TRUE(packet2.graphics_frame_event().has_buffer_event());
455     ASSERT_TRUE(packet2.graphics_frame_event().buffer_event().has_duration_ns());
456     const auto& buffer_event2 = packet2.graphics_frame_event().buffer_event();
457     EXPECT_EQ(buffer_event2.duration_ns(), duration);
458     EXPECT_EQ(buffer_event2.type(), perfetto::protos::GraphicsFrameEvent::BufferEventType(type));
459 
460     const auto& packet3 = packets[2];
461     ASSERT_TRUE(packet3.has_timestamp());
462     EXPECT_EQ(packet3.timestamp(), 0);
463     ASSERT_TRUE(packet3.has_graphics_frame_event());
464     ASSERT_TRUE(packet3.graphics_frame_event().has_buffer_event());
465     const auto& buffer_event3 = packet3.graphics_frame_event().buffer_event();
466     EXPECT_EQ(buffer_event3.type(),
467               perfetto::protos::GraphicsFrameEvent::BufferEventType(
468                       FrameTracer::FrameEvent::UNSPECIFIED));
469 }
470 
471 } // namespace
472 } // namespace android
473 
474 // TODO(b/129481165): remove the #pragma below and fix conversion issues
475 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
476