• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #undef LOG_TAG
18 #define LOG_TAG "LibSurfaceFlingerUnittests"
19 
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include <log/log.h>
23 #include <utils/Errors.h>
24 
25 #include "AsyncCallRecorder.h"
26 #include "Scheduler/EventThread.h"
27 #include "Scheduler/HwcStrongTypes.h"
28 
29 using namespace std::chrono_literals;
30 using namespace std::placeholders;
31 
32 using testing::_;
33 using testing::Invoke;
34 
35 namespace android {
36 
37 namespace {
38 
39 constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID = 111;
40 constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID = 222;
41 constexpr PhysicalDisplayId DISPLAY_ID_64BIT = 0xabcd12349876fedcULL;
42 
43 class MockVSyncSource : public VSyncSource {
44 public:
getName() const45     const char* getName() const override { return "test"; }
46 
47     MOCK_METHOD1(setVSyncEnabled, void(bool));
48     MOCK_METHOD1(setCallback, void(VSyncSource::Callback*));
49     MOCK_METHOD1(setPhaseOffset, void(nsecs_t));
50     MOCK_METHOD1(pauseVsyncCallback, void(bool));
51     MOCK_CONST_METHOD1(dump, void(std::string&));
52 };
53 
54 } // namespace
55 
56 class EventThreadTest : public testing::Test {
57 protected:
58     class MockEventThreadConnection : public EventThreadConnection {
59     public:
MockEventThreadConnection(impl::EventThread * eventThread,ResyncCallback && resyncCallback,ISurfaceComposer::ConfigChanged configChanged)60         MockEventThreadConnection(impl::EventThread* eventThread, ResyncCallback&& resyncCallback,
61                                   ISurfaceComposer::ConfigChanged configChanged)
62               : EventThreadConnection(eventThread, std::move(resyncCallback), configChanged) {}
63         MOCK_METHOD1(postEvent, status_t(const DisplayEventReceiver::Event& event));
64     };
65 
66     using ConnectionEventRecorder =
67             AsyncCallRecorderWithCannedReturn<status_t (*)(const DisplayEventReceiver::Event&)>;
68 
69     EventThreadTest();
70     ~EventThreadTest() override;
71 
72     void createThread(std::unique_ptr<VSyncSource>);
73     sp<MockEventThreadConnection> createConnection(ConnectionEventRecorder& recorder,
74                                                    ISurfaceComposer::ConfigChanged configChanged);
75 
76     void expectVSyncSetEnabledCallReceived(bool expectedState);
77     void expectVSyncSetPhaseOffsetCallReceived(nsecs_t expectedPhaseOffset);
78     VSyncSource::Callback* expectVSyncSetCallbackCallReceived();
79     void expectInterceptCallReceived(nsecs_t expectedTimestamp);
80     void expectVsyncEventReceivedByConnection(const char* name,
81                                               ConnectionEventRecorder& connectionEventRecorder,
82                                               nsecs_t expectedTimestamp, unsigned expectedCount);
83     void expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, unsigned expectedCount);
84     void expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
85                                                 bool expectedConnected);
86     void expectConfigChangedEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
87                                                       int32_t expectedConfigId,
88                                                       nsecs_t expectedVsyncPeriod);
89 
90     AsyncCallRecorder<void (*)(bool)> mVSyncSetEnabledCallRecorder;
91     AsyncCallRecorder<void (*)(VSyncSource::Callback*)> mVSyncSetCallbackCallRecorder;
92     AsyncCallRecorder<void (*)(nsecs_t)> mVSyncSetPhaseOffsetCallRecorder;
93     AsyncCallRecorder<void (*)()> mResyncCallRecorder;
94     AsyncCallRecorder<void (*)(nsecs_t)> mInterceptVSyncCallRecorder;
95     ConnectionEventRecorder mConnectionEventCallRecorder{0};
96 
97     MockVSyncSource* mVSyncSource;
98     VSyncSource::Callback* mCallback = nullptr;
99     std::unique_ptr<impl::EventThread> mThread;
100     sp<MockEventThreadConnection> mConnection;
101 };
102 
EventThreadTest()103 EventThreadTest::EventThreadTest() {
104     const ::testing::TestInfo* const test_info =
105             ::testing::UnitTest::GetInstance()->current_test_info();
106     ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
107 
108     auto vsyncSource = std::make_unique<MockVSyncSource>();
109     mVSyncSource = vsyncSource.get();
110 
111     EXPECT_CALL(*mVSyncSource, setVSyncEnabled(_))
112             .WillRepeatedly(Invoke(mVSyncSetEnabledCallRecorder.getInvocable()));
113 
114     EXPECT_CALL(*mVSyncSource, setCallback(_))
115             .WillRepeatedly(Invoke(mVSyncSetCallbackCallRecorder.getInvocable()));
116 
117     EXPECT_CALL(*mVSyncSource, setPhaseOffset(_))
118             .WillRepeatedly(Invoke(mVSyncSetPhaseOffsetCallRecorder.getInvocable()));
119 
120     createThread(std::move(vsyncSource));
121     mConnection = createConnection(mConnectionEventCallRecorder,
122                                    ISurfaceComposer::eConfigChangedDispatch);
123 
124     // A display must be connected for VSYNC events to be delivered.
125     mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true);
126     expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true);
127 }
128 
~EventThreadTest()129 EventThreadTest::~EventThreadTest() {
130     const ::testing::TestInfo* const test_info =
131             ::testing::UnitTest::GetInstance()->current_test_info();
132     ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
133 
134     // EventThread should unregister itself as VSyncSource callback.
135     EXPECT_TRUE(!mVSyncSetCallbackCallRecorder.waitForUnexpectedCall().has_value());
136 }
137 
createThread(std::unique_ptr<VSyncSource> source)138 void EventThreadTest::createThread(std::unique_ptr<VSyncSource> source) {
139     mThread = std::make_unique<impl::EventThread>(std::move(source),
140                                                   mInterceptVSyncCallRecorder.getInvocable());
141 
142     // EventThread should register itself as VSyncSource callback.
143     mCallback = expectVSyncSetCallbackCallReceived();
144     ASSERT_TRUE(mCallback);
145 }
146 
createConnection(ConnectionEventRecorder & recorder,ISurfaceComposer::ConfigChanged configChanged)147 sp<EventThreadTest::MockEventThreadConnection> EventThreadTest::createConnection(
148         ConnectionEventRecorder& recorder, ISurfaceComposer::ConfigChanged configChanged) {
149     sp<MockEventThreadConnection> connection =
150             new MockEventThreadConnection(mThread.get(), mResyncCallRecorder.getInvocable(),
151                                           configChanged);
152     EXPECT_CALL(*connection, postEvent(_)).WillRepeatedly(Invoke(recorder.getInvocable()));
153     return connection;
154 }
155 
expectVSyncSetEnabledCallReceived(bool expectedState)156 void EventThreadTest::expectVSyncSetEnabledCallReceived(bool expectedState) {
157     auto args = mVSyncSetEnabledCallRecorder.waitForCall();
158     ASSERT_TRUE(args.has_value());
159     EXPECT_EQ(expectedState, std::get<0>(args.value()));
160 }
161 
expectVSyncSetPhaseOffsetCallReceived(nsecs_t expectedPhaseOffset)162 void EventThreadTest::expectVSyncSetPhaseOffsetCallReceived(nsecs_t expectedPhaseOffset) {
163     auto args = mVSyncSetPhaseOffsetCallRecorder.waitForCall();
164     ASSERT_TRUE(args.has_value());
165     EXPECT_EQ(expectedPhaseOffset, std::get<0>(args.value()));
166 }
167 
expectVSyncSetCallbackCallReceived()168 VSyncSource::Callback* EventThreadTest::expectVSyncSetCallbackCallReceived() {
169     auto callbackSet = mVSyncSetCallbackCallRecorder.waitForCall();
170     return callbackSet.has_value() ? std::get<0>(callbackSet.value()) : nullptr;
171 }
172 
expectInterceptCallReceived(nsecs_t expectedTimestamp)173 void EventThreadTest::expectInterceptCallReceived(nsecs_t expectedTimestamp) {
174     auto args = mInterceptVSyncCallRecorder.waitForCall();
175     ASSERT_TRUE(args.has_value());
176     EXPECT_EQ(expectedTimestamp, std::get<0>(args.value()));
177 }
178 
expectVsyncEventReceivedByConnection(const char * name,ConnectionEventRecorder & connectionEventRecorder,nsecs_t expectedTimestamp,unsigned expectedCount)179 void EventThreadTest::expectVsyncEventReceivedByConnection(
180         const char* name, ConnectionEventRecorder& connectionEventRecorder,
181         nsecs_t expectedTimestamp, unsigned expectedCount) {
182     auto args = connectionEventRecorder.waitForCall();
183     ASSERT_TRUE(args.has_value()) << name << " did not receive an event for timestamp "
184                                   << expectedTimestamp;
185     const auto& event = std::get<0>(args.value());
186     EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_VSYNC, event.header.type)
187             << name << " did not get the correct event for timestamp " << expectedTimestamp;
188     EXPECT_EQ(expectedTimestamp, event.header.timestamp)
189             << name << " did not get the expected timestamp for timestamp " << expectedTimestamp;
190     EXPECT_EQ(expectedCount, event.vsync.count)
191             << name << " did not get the expected count for timestamp " << expectedTimestamp;
192 }
193 
expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp,unsigned expectedCount)194 void EventThreadTest::expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp,
195                                                            unsigned expectedCount) {
196     expectVsyncEventReceivedByConnection("mConnectionEventCallRecorder",
197                                          mConnectionEventCallRecorder, expectedTimestamp,
198                                          expectedCount);
199 }
200 
expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,bool expectedConnected)201 void EventThreadTest::expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
202                                                              bool expectedConnected) {
203     auto args = mConnectionEventCallRecorder.waitForCall();
204     ASSERT_TRUE(args.has_value());
205     const auto& event = std::get<0>(args.value());
206     EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, event.header.type);
207     EXPECT_EQ(expectedDisplayId, event.header.displayId);
208     EXPECT_EQ(expectedConnected, event.hotplug.connected);
209 }
210 
expectConfigChangedEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,int32_t expectedConfigId,nsecs_t expectedVsyncPeriod)211 void EventThreadTest::expectConfigChangedEventReceivedByConnection(
212         PhysicalDisplayId expectedDisplayId, int32_t expectedConfigId,
213         nsecs_t expectedVsyncPeriod) {
214     auto args = mConnectionEventCallRecorder.waitForCall();
215     ASSERT_TRUE(args.has_value());
216     const auto& event = std::get<0>(args.value());
217     EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, event.header.type);
218     EXPECT_EQ(expectedDisplayId, event.header.displayId);
219     EXPECT_EQ(expectedConfigId, event.config.configId);
220     EXPECT_EQ(expectedVsyncPeriod, event.config.vsyncPeriod);
221 }
222 
223 namespace {
224 
225 /* ------------------------------------------------------------------------
226  * Test cases
227  */
228 
TEST_F(EventThreadTest,canCreateAndDestroyThreadWithNoEventsSent)229 TEST_F(EventThreadTest, canCreateAndDestroyThreadWithNoEventsSent) {
230     EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
231     EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value());
232     EXPECT_FALSE(mVSyncSetPhaseOffsetCallRecorder.waitForCall(0us).has_value());
233     EXPECT_FALSE(mResyncCallRecorder.waitForCall(0us).has_value());
234     EXPECT_FALSE(mInterceptVSyncCallRecorder.waitForCall(0us).has_value());
235     EXPECT_FALSE(mConnectionEventCallRecorder.waitForCall(0us).has_value());
236 }
237 
TEST_F(EventThreadTest,vsyncRequestIsIgnoredIfDisplayIsDisconnected)238 TEST_F(EventThreadTest, vsyncRequestIsIgnoredIfDisplayIsDisconnected) {
239     mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false);
240     expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false);
241 
242     // Signal that we want the next vsync event to be posted to the connection.
243     mThread->requestNextVsync(mConnection);
244 
245     // EventThread should not enable vsync callbacks.
246     EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
247 }
248 
TEST_F(EventThreadTest,requestNextVsyncPostsASingleVSyncEventToTheConnection)249 TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) {
250     // Signal that we want the next vsync event to be posted to the connection
251     mThread->requestNextVsync(mConnection);
252 
253     // EventThread should immediately request a resync.
254     EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value());
255 
256     // EventThread should enable vsync callbacks.
257     expectVSyncSetEnabledCallReceived(true);
258 
259     // Use the received callback to signal a first vsync event.
260     // The interceptor should receive the event, as well as the connection.
261     mCallback->onVSyncEvent(123, 456);
262     expectInterceptCallReceived(123);
263     expectVsyncEventReceivedByConnection(123, 1u);
264 
265     // Use the received callback to signal a second vsync event.
266     // The interceptor should receive the event, but the the connection should
267     // not as it was only interested in the first.
268     mCallback->onVSyncEvent(456, 123);
269     expectInterceptCallReceived(456);
270     EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
271 
272     // EventThread should also detect that at this point that it does not need
273     // any more vsync events, and should disable their generation.
274     expectVSyncSetEnabledCallReceived(false);
275 }
276 
TEST_F(EventThreadTest,setVsyncRateZeroPostsNoVSyncEventsToThatConnection)277 TEST_F(EventThreadTest, setVsyncRateZeroPostsNoVSyncEventsToThatConnection) {
278     // Create a first connection, register it, and request a vsync rate of zero.
279     ConnectionEventRecorder firstConnectionEventRecorder{0};
280     sp<MockEventThreadConnection> firstConnection =
281             createConnection(firstConnectionEventRecorder,
282                              ISurfaceComposer::eConfigChangedSuppress);
283     mThread->setVsyncRate(0, firstConnection);
284 
285     // By itself, this should not enable vsync events
286     EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
287     EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value());
288 
289     // However if there is another connection which wants events at a nonzero rate.....
290     ConnectionEventRecorder secondConnectionEventRecorder{0};
291     sp<MockEventThreadConnection> secondConnection =
292             createConnection(secondConnectionEventRecorder,
293                              ISurfaceComposer::eConfigChangedSuppress);
294     mThread->setVsyncRate(1, secondConnection);
295 
296     // EventThread should enable vsync callbacks.
297     expectVSyncSetEnabledCallReceived(true);
298 
299     // Send a vsync event. EventThread should then make a call to the
300     // interceptor, and the second connection. The first connection should not
301     // get the event.
302     mCallback->onVSyncEvent(123, 456);
303     expectInterceptCallReceived(123);
304     EXPECT_FALSE(firstConnectionEventRecorder.waitForUnexpectedCall().has_value());
305     expectVsyncEventReceivedByConnection("secondConnection", secondConnectionEventRecorder, 123,
306                                          1u);
307 }
308 
TEST_F(EventThreadTest,setVsyncRateOnePostsAllEventsToThatConnection)309 TEST_F(EventThreadTest, setVsyncRateOnePostsAllEventsToThatConnection) {
310     mThread->setVsyncRate(1, mConnection);
311 
312     // EventThread should enable vsync callbacks.
313     expectVSyncSetEnabledCallReceived(true);
314 
315     // Send a vsync event. EventThread should then make a call to the
316     // interceptor, and the connection.
317     mCallback->onVSyncEvent(123, 456);
318     expectInterceptCallReceived(123);
319     expectVsyncEventReceivedByConnection(123, 1u);
320 
321     // A second event should go to the same places.
322     mCallback->onVSyncEvent(456, 123);
323     expectInterceptCallReceived(456);
324     expectVsyncEventReceivedByConnection(456, 2u);
325 
326     // A third event should go to the same places.
327     mCallback->onVSyncEvent(789, 777);
328     expectInterceptCallReceived(789);
329     expectVsyncEventReceivedByConnection(789, 3u);
330 }
331 
TEST_F(EventThreadTest,setVsyncRateTwoPostsEveryOtherEventToThatConnection)332 TEST_F(EventThreadTest, setVsyncRateTwoPostsEveryOtherEventToThatConnection) {
333     mThread->setVsyncRate(2, mConnection);
334 
335     // EventThread should enable vsync callbacks.
336     expectVSyncSetEnabledCallReceived(true);
337 
338     // The first event will be seen by the interceptor, and not the connection.
339     mCallback->onVSyncEvent(123, 456);
340     expectInterceptCallReceived(123);
341     EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
342 
343     // The second event will be seen by the interceptor and the connection.
344     mCallback->onVSyncEvent(456, 123);
345     expectInterceptCallReceived(456);
346     expectVsyncEventReceivedByConnection(456, 2u);
347 
348     // The third event will be seen by the interceptor, and not the connection.
349     mCallback->onVSyncEvent(789, 777);
350     expectInterceptCallReceived(789);
351     EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
352 
353     // The fourth event will be seen by the interceptor and the connection.
354     mCallback->onVSyncEvent(101112, 7847);
355     expectInterceptCallReceived(101112);
356     expectVsyncEventReceivedByConnection(101112, 4u);
357 }
358 
TEST_F(EventThreadTest,connectionsRemovedIfInstanceDestroyed)359 TEST_F(EventThreadTest, connectionsRemovedIfInstanceDestroyed) {
360     mThread->setVsyncRate(1, mConnection);
361 
362     // EventThread should enable vsync callbacks.
363     expectVSyncSetEnabledCallReceived(true);
364 
365     // Destroy the only (strong) reference to the connection.
366     mConnection = nullptr;
367 
368     // The first event will be seen by the interceptor, and not the connection.
369     mCallback->onVSyncEvent(123, 456);
370     expectInterceptCallReceived(123);
371     EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
372 
373     // EventThread should disable vsync callbacks
374     expectVSyncSetEnabledCallReceived(false);
375 }
376 
TEST_F(EventThreadTest,connectionsRemovedIfEventDeliveryError)377 TEST_F(EventThreadTest, connectionsRemovedIfEventDeliveryError) {
378     ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY};
379     sp<MockEventThreadConnection> errorConnection =
380             createConnection(errorConnectionEventRecorder,
381                              ISurfaceComposer::eConfigChangedSuppress);
382     mThread->setVsyncRate(1, errorConnection);
383 
384     // EventThread should enable vsync callbacks.
385     expectVSyncSetEnabledCallReceived(true);
386 
387     // The first event will be seen by the interceptor, and by the connection,
388     // which then returns an error.
389     mCallback->onVSyncEvent(123, 456);
390     expectInterceptCallReceived(123);
391     expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
392 
393     // A subsequent event will be seen by the interceptor and not by the
394     // connection.
395     mCallback->onVSyncEvent(456, 123);
396     expectInterceptCallReceived(456);
397     EXPECT_FALSE(errorConnectionEventRecorder.waitForUnexpectedCall().has_value());
398 
399     // EventThread should disable vsync callbacks with the second event
400     expectVSyncSetEnabledCallReceived(false);
401 }
402 
TEST_F(EventThreadTest,tracksEventConnections)403 TEST_F(EventThreadTest, tracksEventConnections) {
404     EXPECT_EQ(1, mThread->getEventThreadConnectionCount());
405     ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY};
406     sp<MockEventThreadConnection> errorConnection =
407             createConnection(errorConnectionEventRecorder,
408                              ISurfaceComposer::eConfigChangedSuppress);
409     mThread->setVsyncRate(1, errorConnection);
410     EXPECT_EQ(2, mThread->getEventThreadConnectionCount());
411     ConnectionEventRecorder secondConnectionEventRecorder{0};
412     sp<MockEventThreadConnection> secondConnection =
413             createConnection(secondConnectionEventRecorder,
414                              ISurfaceComposer::eConfigChangedSuppress);
415     mThread->setVsyncRate(1, secondConnection);
416     EXPECT_EQ(3, mThread->getEventThreadConnectionCount());
417 
418     // EventThread should enable vsync callbacks.
419     expectVSyncSetEnabledCallReceived(true);
420 
421     // The first event will be seen by the interceptor, and by the connection,
422     // which then returns an error.
423     mCallback->onVSyncEvent(123, 456);
424     expectInterceptCallReceived(123);
425     expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
426     expectVsyncEventReceivedByConnection("successConnection", secondConnectionEventRecorder, 123,
427                                          1u);
428     EXPECT_EQ(2, mThread->getEventThreadConnectionCount());
429 }
430 
TEST_F(EventThreadTest,eventsDroppedIfNonfatalEventDeliveryError)431 TEST_F(EventThreadTest, eventsDroppedIfNonfatalEventDeliveryError) {
432     ConnectionEventRecorder errorConnectionEventRecorder{WOULD_BLOCK};
433     sp<MockEventThreadConnection> errorConnection =
434             createConnection(errorConnectionEventRecorder,
435                              ISurfaceComposer::eConfigChangedSuppress);
436     mThread->setVsyncRate(1, errorConnection);
437 
438     // EventThread should enable vsync callbacks.
439     expectVSyncSetEnabledCallReceived(true);
440 
441     // The first event will be seen by the interceptor, and by the connection,
442     // which then returns an non-fatal error.
443     mCallback->onVSyncEvent(123, 456);
444     expectInterceptCallReceived(123);
445     expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
446 
447     // A subsequent event will be seen by the interceptor, and by the connection,
448     // which still then returns an non-fatal error.
449     mCallback->onVSyncEvent(456, 123);
450     expectInterceptCallReceived(456);
451     expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 456, 2u);
452 
453     // EventThread will not disable vsync callbacks as the errors are non-fatal.
454     EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
455 }
456 
TEST_F(EventThreadTest,setPhaseOffsetForwardsToVSyncSource)457 TEST_F(EventThreadTest, setPhaseOffsetForwardsToVSyncSource) {
458     mThread->setPhaseOffset(321);
459     expectVSyncSetPhaseOffsetCallReceived(321);
460 }
461 
TEST_F(EventThreadTest,postHotplugInternalDisconnect)462 TEST_F(EventThreadTest, postHotplugInternalDisconnect) {
463     mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false);
464     expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false);
465 }
466 
TEST_F(EventThreadTest,postHotplugInternalConnect)467 TEST_F(EventThreadTest, postHotplugInternalConnect) {
468     mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true);
469     expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true);
470 }
471 
TEST_F(EventThreadTest,postHotplugExternalDisconnect)472 TEST_F(EventThreadTest, postHotplugExternalDisconnect) {
473     mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, false);
474     expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, false);
475 }
476 
TEST_F(EventThreadTest,postHotplugExternalConnect)477 TEST_F(EventThreadTest, postHotplugExternalConnect) {
478     mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, true);
479     expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, true);
480 }
481 
TEST_F(EventThreadTest,postConfigChangedPrimary)482 TEST_F(EventThreadTest, postConfigChangedPrimary) {
483     mThread->onConfigChanged(INTERNAL_DISPLAY_ID, HwcConfigIndexType(7), 16666666);
484     expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 7, 16666666);
485 }
486 
TEST_F(EventThreadTest,postConfigChangedExternal)487 TEST_F(EventThreadTest, postConfigChangedExternal) {
488     mThread->onConfigChanged(EXTERNAL_DISPLAY_ID, HwcConfigIndexType(5), 16666666);
489     expectConfigChangedEventReceivedByConnection(EXTERNAL_DISPLAY_ID, 5, 16666666);
490 }
491 
TEST_F(EventThreadTest,postConfigChangedPrimary64bit)492 TEST_F(EventThreadTest, postConfigChangedPrimary64bit) {
493     mThread->onConfigChanged(DISPLAY_ID_64BIT, HwcConfigIndexType(7), 16666666);
494     expectConfigChangedEventReceivedByConnection(DISPLAY_ID_64BIT, 7, 16666666);
495 }
496 
TEST_F(EventThreadTest,suppressConfigChanged)497 TEST_F(EventThreadTest, suppressConfigChanged) {
498     ConnectionEventRecorder suppressConnectionEventRecorder{0};
499     sp<MockEventThreadConnection> suppressConnection =
500             createConnection(suppressConnectionEventRecorder,
501                              ISurfaceComposer::eConfigChangedSuppress);
502 
503     mThread->onConfigChanged(INTERNAL_DISPLAY_ID, HwcConfigIndexType(9), 16666666);
504     expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 9, 16666666);
505 
506     auto args = suppressConnectionEventRecorder.waitForCall();
507     ASSERT_FALSE(args.has_value());
508 }
509 
510 } // namespace
511 } // namespace android
512