blob: cb690aa0e4a9ce639174bf282d0631360501a698 [file] [log] [blame]
Lloyd Pique24b0a482018-03-09 18:52:26 -08001/*
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
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Lloyd Pique24b0a482018-03-09 18:52:26 -080021#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
Lloyd Pique24b0a482018-03-09 18:52:26 -080026#include <log/log.h>
Lloyd Pique24b0a482018-03-09 18:52:26 -080027#include <utils/Errors.h>
28
29#include "AsyncCallRecorder.h"
Marin Shalamanov23c44202020-12-22 19:09:20 +010030#include "DisplayHardware/DisplayMode.h"
Rachel Lee3f028662021-11-04 19:32:24 +000031#include "FrameTimeline.h"
Ana Krulecfefcb582018-08-07 14:22:37 -070032#include "Scheduler/EventThread.h"
Lloyd Pique24b0a482018-03-09 18:52:26 -080033
34using namespace std::chrono_literals;
35using namespace std::placeholders;
36
Ady Abraham62f216c2020-10-13 19:07:23 -070037using namespace android::flag_operators;
Lloyd Pique24b0a482018-03-09 18:52:26 -080038using testing::_;
39using testing::Invoke;
40
41namespace android {
Ady Abraham2139f732019-11-13 18:56:40 -080042
Lloyd Pique24b0a482018-03-09 18:52:26 -080043namespace {
44
Dominik Laskowskif1833852021-03-23 15:06:50 -070045constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID = PhysicalDisplayId::fromPort(111u);
46constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID = PhysicalDisplayId::fromPort(222u);
47constexpr PhysicalDisplayId DISPLAY_ID_64BIT =
48 PhysicalDisplayId::fromEdid(0xffu, 0xffffu, 0xffff'ffffu);
49
Jorim Jaggic0086af2021-02-12 18:18:11 +010050constexpr std::chrono::duration VSYNC_PERIOD(16ms);
Dominik Laskowskif1833852021-03-23 15:06:50 -070051
Lloyd Pique24b0a482018-03-09 18:52:26 -080052class MockVSyncSource : public VSyncSource {
53public:
Dominik Laskowski6505f792019-09-18 11:10:05 -070054 const char* getName() const override { return "test"; }
55
Lloyd Pique24b0a482018-03-09 18:52:26 -080056 MOCK_METHOD1(setVSyncEnabled, void(bool));
57 MOCK_METHOD1(setCallback, void(VSyncSource::Callback*));
Ady Abraham9c53ee72020-07-22 21:16:18 -070058 MOCK_METHOD2(setDuration,
59 void(std::chrono::nanoseconds workDuration,
60 std::chrono::nanoseconds readyDuration));
Ady Abrahamb838aed2019-02-12 15:30:16 -080061 MOCK_METHOD1(pauseVsyncCallback, void(bool));
Ady Abraham5e7371c2020-03-24 14:47:24 -070062 MOCK_CONST_METHOD1(dump, void(std::string&));
Lloyd Pique24b0a482018-03-09 18:52:26 -080063};
64
65} // namespace
66
67class EventThreadTest : public testing::Test {
68protected:
Dominik Laskowskif654d572018-12-20 11:03:06 -080069 class MockEventThreadConnection : public EventThreadConnection {
Lloyd Pique24b0a482018-03-09 18:52:26 -080070 public:
Ady Abraham0bb6a472020-10-12 10:22:13 -070071 MockEventThreadConnection(impl::EventThread* eventThread, uid_t callingUid,
72 ResyncCallback&& resyncCallback,
Ady Abraham62f216c2020-10-13 19:07:23 -070073 ISurfaceComposer::EventRegistrationFlags eventRegistration)
Ady Abraham0bb6a472020-10-12 10:22:13 -070074 : EventThreadConnection(eventThread, callingUid, std::move(resyncCallback),
Ady Abraham62f216c2020-10-13 19:07:23 -070075 eventRegistration) {}
Lloyd Pique24b0a482018-03-09 18:52:26 -080076 MOCK_METHOD1(postEvent, status_t(const DisplayEventReceiver::Event& event));
77 };
78
79 using ConnectionEventRecorder =
80 AsyncCallRecorderWithCannedReturn<status_t (*)(const DisplayEventReceiver::Event&)>;
81
82 EventThreadTest();
83 ~EventThreadTest() override;
84
Dominik Laskowski6505f792019-09-18 11:10:05 -070085 void createThread(std::unique_ptr<VSyncSource>);
Ady Abraham62f216c2020-10-13 19:07:23 -070086 sp<MockEventThreadConnection> createConnection(
87 ConnectionEventRecorder& recorder,
88 ISurfaceComposer::EventRegistrationFlags eventRegistration = {},
89 uid_t ownerUid = mConnectionUid);
Lloyd Pique24b0a482018-03-09 18:52:26 -080090
91 void expectVSyncSetEnabledCallReceived(bool expectedState);
Ady Abraham9c53ee72020-07-22 21:16:18 -070092 void expectVSyncSetDurationCallReceived(std::chrono::nanoseconds expectedDuration,
93 std::chrono::nanoseconds expectedReadyDuration);
Lloyd Pique24b0a482018-03-09 18:52:26 -080094 VSyncSource::Callback* expectVSyncSetCallbackCallReceived();
95 void expectInterceptCallReceived(nsecs_t expectedTimestamp);
96 void expectVsyncEventReceivedByConnection(const char* name,
97 ConnectionEventRecorder& connectionEventRecorder,
98 nsecs_t expectedTimestamp, unsigned expectedCount);
99 void expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, unsigned expectedCount);
Rachel Lee3f028662021-11-04 19:32:24 +0000100 void expectVsyncEventFrameTimelinesCorrect(nsecs_t expectedTimestamp,
101 nsecs_t preferredDeadline);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800102 void expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
Dominik Laskowski00a6fa22018-06-06 16:42:02 -0700103 bool expectedConnected);
Ady Abraham447052e2019-02-13 16:07:27 -0800104 void expectConfigChangedEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
Alec Mouri60aee1c2019-10-28 16:18:59 -0700105 int32_t expectedConfigId,
106 nsecs_t expectedVsyncPeriod);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700107 void expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t);
Ady Abraham62f216c2020-10-13 19:07:23 -0700108 void expectUidFrameRateMappingEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
109 std::vector<FrameRateOverride>);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800110
111 AsyncCallRecorder<void (*)(bool)> mVSyncSetEnabledCallRecorder;
112 AsyncCallRecorder<void (*)(VSyncSource::Callback*)> mVSyncSetCallbackCallRecorder;
Ady Abraham9c53ee72020-07-22 21:16:18 -0700113 AsyncCallRecorder<void (*)(std::chrono::nanoseconds, std::chrono::nanoseconds)>
114 mVSyncSetDurationCallRecorder;
Lloyd Pique24b0a482018-03-09 18:52:26 -0800115 AsyncCallRecorder<void (*)()> mResyncCallRecorder;
116 AsyncCallRecorder<void (*)(nsecs_t)> mInterceptVSyncCallRecorder;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700117 AsyncCallRecorder<void (*)(nsecs_t, uid_t)> mThrottleVsyncCallRecorder;
Lloyd Pique24b0a482018-03-09 18:52:26 -0800118 ConnectionEventRecorder mConnectionEventCallRecorder{0};
Ady Abraham0bb6a472020-10-12 10:22:13 -0700119 ConnectionEventRecorder mThrottledConnectionEventCallRecorder{0};
Lloyd Pique24b0a482018-03-09 18:52:26 -0800120
Dominik Laskowski6505f792019-09-18 11:10:05 -0700121 MockVSyncSource* mVSyncSource;
Dominik Laskowski029cc122019-01-23 19:52:06 -0800122 VSyncSource::Callback* mCallback = nullptr;
Dominik Laskowski6505f792019-09-18 11:10:05 -0700123 std::unique_ptr<impl::EventThread> mThread;
Lloyd Pique24b0a482018-03-09 18:52:26 -0800124 sp<MockEventThreadConnection> mConnection;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700125 sp<MockEventThreadConnection> mThrottledConnection;
Rachel Lee3f028662021-11-04 19:32:24 +0000126 std::unique_ptr<frametimeline::impl::TokenManager> mTokenManager;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700127
128 static constexpr uid_t mConnectionUid = 443;
129 static constexpr uid_t mThrottledConnectionUid = 177;
Lloyd Pique24b0a482018-03-09 18:52:26 -0800130};
131
132EventThreadTest::EventThreadTest() {
133 const ::testing::TestInfo* const test_info =
134 ::testing::UnitTest::GetInstance()->current_test_info();
135 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
136
Dominik Laskowski6505f792019-09-18 11:10:05 -0700137 auto vsyncSource = std::make_unique<MockVSyncSource>();
138 mVSyncSource = vsyncSource.get();
139
140 EXPECT_CALL(*mVSyncSource, setVSyncEnabled(_))
Lloyd Pique24b0a482018-03-09 18:52:26 -0800141 .WillRepeatedly(Invoke(mVSyncSetEnabledCallRecorder.getInvocable()));
142
Dominik Laskowski6505f792019-09-18 11:10:05 -0700143 EXPECT_CALL(*mVSyncSource, setCallback(_))
Lloyd Pique24b0a482018-03-09 18:52:26 -0800144 .WillRepeatedly(Invoke(mVSyncSetCallbackCallRecorder.getInvocable()));
145
Ady Abraham9c53ee72020-07-22 21:16:18 -0700146 EXPECT_CALL(*mVSyncSource, setDuration(_, _))
147 .WillRepeatedly(Invoke(mVSyncSetDurationCallRecorder.getInvocable()));
Lloyd Pique24b0a482018-03-09 18:52:26 -0800148
Dominik Laskowski6505f792019-09-18 11:10:05 -0700149 createThread(std::move(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700150 mConnection = createConnection(mConnectionEventCallRecorder,
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100151 ISurfaceComposer::EventRegistration::modeChanged |
Ady Abraham62f216c2020-10-13 19:07:23 -0700152 ISurfaceComposer::EventRegistration::frameRateOverride);
153 mThrottledConnection = createConnection(mThrottledConnectionEventCallRecorder,
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100154 ISurfaceComposer::EventRegistration::modeChanged,
Ady Abraham62f216c2020-10-13 19:07:23 -0700155 mThrottledConnectionUid);
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800156
157 // A display must be connected for VSYNC events to be delivered.
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800158 mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true);
159 expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800160}
161
162EventThreadTest::~EventThreadTest() {
163 const ::testing::TestInfo* const test_info =
164 ::testing::UnitTest::GetInstance()->current_test_info();
165 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
Dominik Laskowski029cc122019-01-23 19:52:06 -0800166
167 // EventThread should unregister itself as VSyncSource callback.
Lloyd Pique0655b8e2019-01-31 18:20:27 -0800168 EXPECT_TRUE(!mVSyncSetCallbackCallRecorder.waitForUnexpectedCall().has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800169}
170
Dominik Laskowski6505f792019-09-18 11:10:05 -0700171void EventThreadTest::createThread(std::unique_ptr<VSyncSource> source) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700172 const auto throttleVsync = [&](nsecs_t expectedVsyncTimestamp, uid_t uid) {
173 mThrottleVsyncCallRecorder.getInvocable()(expectedVsyncTimestamp, uid);
174 return (uid == mThrottledConnectionUid);
175 };
Jorim Jaggic0086af2021-02-12 18:18:11 +0100176 const auto getVsyncPeriod = [](uid_t uid) {
177 return VSYNC_PERIOD.count();
178 };
Ady Abraham0bb6a472020-10-12 10:22:13 -0700179
Rachel Lee3f028662021-11-04 19:32:24 +0000180 mTokenManager = std::make_unique<frametimeline::impl::TokenManager>();
181 mThread = std::make_unique<impl::EventThread>(std::move(source), mTokenManager.get(),
Ady Abraham0bb6a472020-10-12 10:22:13 -0700182 mInterceptVSyncCallRecorder.getInvocable(),
Jorim Jaggic0086af2021-02-12 18:18:11 +0100183 throttleVsync, getVsyncPeriod);
Dominik Laskowski029cc122019-01-23 19:52:06 -0800184
185 // EventThread should register itself as VSyncSource callback.
186 mCallback = expectVSyncSetCallbackCallReceived();
187 ASSERT_TRUE(mCallback);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800188}
189
190sp<EventThreadTest::MockEventThreadConnection> EventThreadTest::createConnection(
Ady Abraham62f216c2020-10-13 19:07:23 -0700191 ConnectionEventRecorder& recorder,
192 ISurfaceComposer::EventRegistrationFlags eventRegistration, uid_t ownerUid) {
Dominik Laskowskif654d572018-12-20 11:03:06 -0800193 sp<MockEventThreadConnection> connection =
Ady Abraham0bb6a472020-10-12 10:22:13 -0700194 new MockEventThreadConnection(mThread.get(), ownerUid,
Ady Abraham62f216c2020-10-13 19:07:23 -0700195 mResyncCallRecorder.getInvocable(), eventRegistration);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800196 EXPECT_CALL(*connection, postEvent(_)).WillRepeatedly(Invoke(recorder.getInvocable()));
197 return connection;
198}
199
200void EventThreadTest::expectVSyncSetEnabledCallReceived(bool expectedState) {
201 auto args = mVSyncSetEnabledCallRecorder.waitForCall();
202 ASSERT_TRUE(args.has_value());
203 EXPECT_EQ(expectedState, std::get<0>(args.value()));
204}
205
Ady Abraham9c53ee72020-07-22 21:16:18 -0700206void EventThreadTest::expectVSyncSetDurationCallReceived(
207 std::chrono::nanoseconds expectedDuration, std::chrono::nanoseconds expectedReadyDuration) {
208 auto args = mVSyncSetDurationCallRecorder.waitForCall();
Lloyd Pique24b0a482018-03-09 18:52:26 -0800209 ASSERT_TRUE(args.has_value());
Ady Abraham9c53ee72020-07-22 21:16:18 -0700210 EXPECT_EQ(expectedDuration, std::get<0>(args.value()));
211 EXPECT_EQ(expectedReadyDuration, std::get<1>(args.value()));
Lloyd Pique24b0a482018-03-09 18:52:26 -0800212}
213
214VSyncSource::Callback* EventThreadTest::expectVSyncSetCallbackCallReceived() {
215 auto callbackSet = mVSyncSetCallbackCallRecorder.waitForCall();
216 return callbackSet.has_value() ? std::get<0>(callbackSet.value()) : nullptr;
217}
218
219void EventThreadTest::expectInterceptCallReceived(nsecs_t expectedTimestamp) {
220 auto args = mInterceptVSyncCallRecorder.waitForCall();
221 ASSERT_TRUE(args.has_value());
222 EXPECT_EQ(expectedTimestamp, std::get<0>(args.value()));
223}
224
Ady Abraham0bb6a472020-10-12 10:22:13 -0700225void EventThreadTest::expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t uid) {
226 auto args = mThrottleVsyncCallRecorder.waitForCall();
227 ASSERT_TRUE(args.has_value());
228 EXPECT_EQ(expectedTimestamp, std::get<0>(args.value()));
229 EXPECT_EQ(uid, std::get<1>(args.value()));
230}
231
Lloyd Pique24b0a482018-03-09 18:52:26 -0800232void EventThreadTest::expectVsyncEventReceivedByConnection(
233 const char* name, ConnectionEventRecorder& connectionEventRecorder,
234 nsecs_t expectedTimestamp, unsigned expectedCount) {
235 auto args = connectionEventRecorder.waitForCall();
236 ASSERT_TRUE(args.has_value()) << name << " did not receive an event for timestamp "
237 << expectedTimestamp;
238 const auto& event = std::get<0>(args.value());
239 EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_VSYNC, event.header.type)
240 << name << " did not get the correct event for timestamp " << expectedTimestamp;
241 EXPECT_EQ(expectedTimestamp, event.header.timestamp)
242 << name << " did not get the expected timestamp for timestamp " << expectedTimestamp;
243 EXPECT_EQ(expectedCount, event.vsync.count)
244 << name << " did not get the expected count for timestamp " << expectedTimestamp;
245}
246
247void EventThreadTest::expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp,
248 unsigned expectedCount) {
249 expectVsyncEventReceivedByConnection("mConnectionEventCallRecorder",
250 mConnectionEventCallRecorder, expectedTimestamp,
251 expectedCount);
252}
253
Rachel Lee3f028662021-11-04 19:32:24 +0000254void EventThreadTest::expectVsyncEventFrameTimelinesCorrect(nsecs_t expectedTimestamp,
255 nsecs_t preferredDeadline) {
256 auto args = mConnectionEventCallRecorder.waitForCall();
257 ASSERT_TRUE(args.has_value()) << " did not receive an event for timestamp "
258 << expectedTimestamp;
259 const auto& event = std::get<0>(args.value());
260 for (int i = 0; i < DisplayEventReceiver::kFrameTimelinesLength; i++) {
261 if (i > 0) {
262 EXPECT_GT(event.vsync.frameTimelines[i].deadlineTimestamp,
263 event.vsync.frameTimelines[i - 1].deadlineTimestamp)
264 << "Deadline timestamp out of order for frame timeline " << i;
265 EXPECT_GT(event.vsync.frameTimelines[i].expectedVSyncTimestamp,
266 event.vsync.frameTimelines[i - 1].expectedVSyncTimestamp)
267 << "Expected vsync timestamp out of order for frame timeline " << i;
268 }
269 if (event.vsync.frameTimelines[i].deadlineTimestamp == preferredDeadline) {
270 EXPECT_EQ(i, event.vsync.preferredFrameTimelineIndex)
271 << "Preferred frame timeline index should be " << i;
272 // For the platform-preferred frame timeline, the vsync ID is 0 because the first frame
273 // timeline is made before the rest.
274 EXPECT_EQ(0, event.vsync.frameTimelines[i].vsyncId)
275 << "Vsync ID incorrect for frame timeline " << i;
276 } else {
277 // Vsync ID 0 is used for the preferred frame timeline.
278 EXPECT_EQ(i + 1, event.vsync.frameTimelines[i].vsyncId)
279 << "Vsync ID incorrect for frame timeline " << i;
280 }
281 }
282}
283
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800284void EventThreadTest::expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
285 bool expectedConnected) {
Lloyd Pique24b0a482018-03-09 18:52:26 -0800286 auto args = mConnectionEventCallRecorder.waitForCall();
287 ASSERT_TRUE(args.has_value());
288 const auto& event = std::get<0>(args.value());
289 EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, event.header.type);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800290 EXPECT_EQ(expectedDisplayId, event.header.displayId);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800291 EXPECT_EQ(expectedConnected, event.hotplug.connected);
292}
293
Ady Abraham447052e2019-02-13 16:07:27 -0800294void EventThreadTest::expectConfigChangedEventReceivedByConnection(
Alec Mouri60aee1c2019-10-28 16:18:59 -0700295 PhysicalDisplayId expectedDisplayId, int32_t expectedConfigId,
296 nsecs_t expectedVsyncPeriod) {
Ady Abraham447052e2019-02-13 16:07:27 -0800297 auto args = mConnectionEventCallRecorder.waitForCall();
298 ASSERT_TRUE(args.has_value());
299 const auto& event = std::get<0>(args.value());
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100300 EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE, event.header.type);
Ady Abraham447052e2019-02-13 16:07:27 -0800301 EXPECT_EQ(expectedDisplayId, event.header.displayId);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100302 EXPECT_EQ(expectedConfigId, event.modeChange.modeId);
303 EXPECT_EQ(expectedVsyncPeriod, event.modeChange.vsyncPeriod);
Ady Abraham447052e2019-02-13 16:07:27 -0800304}
305
Ady Abraham62f216c2020-10-13 19:07:23 -0700306void EventThreadTest::expectUidFrameRateMappingEventReceivedByConnection(
307 PhysicalDisplayId expectedDisplayId, std::vector<FrameRateOverride> expectedOverrides) {
308 for (const auto [uid, frameRateHz] : expectedOverrides) {
309 auto args = mConnectionEventCallRecorder.waitForCall();
310 ASSERT_TRUE(args.has_value());
311 const auto& event = std::get<0>(args.value());
312 EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE, event.header.type);
313 EXPECT_EQ(expectedDisplayId, event.header.displayId);
314 EXPECT_EQ(uid, event.frameRateOverride.uid);
315 EXPECT_EQ(frameRateHz, event.frameRateOverride.frameRateHz);
316 }
317
318 auto args = mConnectionEventCallRecorder.waitForCall();
319 ASSERT_TRUE(args.has_value());
320 const auto& event = std::get<0>(args.value());
321 EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE_FLUSH, event.header.type);
322 EXPECT_EQ(expectedDisplayId, event.header.displayId);
323}
324
Lloyd Pique24b0a482018-03-09 18:52:26 -0800325namespace {
326
327/* ------------------------------------------------------------------------
328 * Test cases
329 */
330
331TEST_F(EventThreadTest, canCreateAndDestroyThreadWithNoEventsSent) {
332 EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
333 EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value());
Ady Abraham9c53ee72020-07-22 21:16:18 -0700334 EXPECT_FALSE(mVSyncSetDurationCallRecorder.waitForCall(0us).has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800335 EXPECT_FALSE(mResyncCallRecorder.waitForCall(0us).has_value());
336 EXPECT_FALSE(mInterceptVSyncCallRecorder.waitForCall(0us).has_value());
337 EXPECT_FALSE(mConnectionEventCallRecorder.waitForCall(0us).has_value());
338}
339
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800340TEST_F(EventThreadTest, vsyncRequestIsIgnoredIfDisplayIsDisconnected) {
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800341 mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false);
342 expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false);
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800343
344 // Signal that we want the next vsync event to be posted to the connection.
Ady Abraham8532d012019-05-08 14:50:56 -0700345 mThread->requestNextVsync(mConnection);
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800346
347 // EventThread should not enable vsync callbacks.
348 EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800349}
350
Lloyd Pique24b0a482018-03-09 18:52:26 -0800351TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) {
352 // Signal that we want the next vsync event to be posted to the connection
Ady Abraham8532d012019-05-08 14:50:56 -0700353 mThread->requestNextVsync(mConnection);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800354
Ady Abraham8532d012019-05-08 14:50:56 -0700355 // EventThread should immediately request a resync.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800356 EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value());
357
Dominik Laskowski029cc122019-01-23 19:52:06 -0800358 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800359 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800360
361 // Use the received callback to signal a first vsync event.
362 // The interceptor should receive the event, as well as the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700363 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800364 expectInterceptCallReceived(123);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700365 expectThrottleVsyncReceived(456, mConnectionUid);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800366 expectVsyncEventReceivedByConnection(123, 1u);
367
368 // Use the received callback to signal a second vsync event.
Ady Abraham0bb6a472020-10-12 10:22:13 -0700369 // The interceptor should receive the event, but the connection should
Lloyd Pique24b0a482018-03-09 18:52:26 -0800370 // not as it was only interested in the first.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700371 mCallback->onVSyncEvent(456, 123, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800372 expectInterceptCallReceived(456);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700373 EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800374 EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
375
376 // EventThread should also detect that at this point that it does not need
377 // any more vsync events, and should disable their generation.
378 expectVSyncSetEnabledCallReceived(false);
379}
380
Rachel Lee3f028662021-11-04 19:32:24 +0000381TEST_F(EventThreadTest, requestNextVsyncEventFrameTimelinesCorrect) {
382 // Signal that we want the next vsync event to be posted to the connection
383 mThread->requestNextVsync(mConnection);
384
385 expectVSyncSetEnabledCallReceived(true);
386
387 // Use the received callback to signal a vsync event.
388 // The interceptor should receive the event, as well as the connection.
389 mCallback->onVSyncEvent(123, 456, 789);
390 expectInterceptCallReceived(123);
391 expectVsyncEventFrameTimelinesCorrect(123, 789);
392}
393
Lloyd Pique24b0a482018-03-09 18:52:26 -0800394TEST_F(EventThreadTest, setVsyncRateZeroPostsNoVSyncEventsToThatConnection) {
395 // Create a first connection, register it, and request a vsync rate of zero.
396 ConnectionEventRecorder firstConnectionEventRecorder{0};
Ady Abraham62f216c2020-10-13 19:07:23 -0700397 sp<MockEventThreadConnection> firstConnection = createConnection(firstConnectionEventRecorder);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800398 mThread->setVsyncRate(0, firstConnection);
399
400 // By itself, this should not enable vsync events
401 EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
402 EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value());
403
404 // However if there is another connection which wants events at a nonzero rate.....
405 ConnectionEventRecorder secondConnectionEventRecorder{0};
406 sp<MockEventThreadConnection> secondConnection =
Ady Abraham62f216c2020-10-13 19:07:23 -0700407 createConnection(secondConnectionEventRecorder);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800408 mThread->setVsyncRate(1, secondConnection);
409
Dominik Laskowski029cc122019-01-23 19:52:06 -0800410 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800411 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800412
413 // Send a vsync event. EventThread should then make a call to the
414 // interceptor, and the second connection. The first connection should not
415 // get the event.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700416 mCallback->onVSyncEvent(123, 456, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800417 expectInterceptCallReceived(123);
418 EXPECT_FALSE(firstConnectionEventRecorder.waitForUnexpectedCall().has_value());
419 expectVsyncEventReceivedByConnection("secondConnection", secondConnectionEventRecorder, 123,
420 1u);
421}
422
423TEST_F(EventThreadTest, setVsyncRateOnePostsAllEventsToThatConnection) {
424 mThread->setVsyncRate(1, mConnection);
425
Dominik Laskowski029cc122019-01-23 19:52:06 -0800426 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800427 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800428
429 // Send a vsync event. EventThread should then make a call to the
430 // interceptor, and the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700431 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800432 expectInterceptCallReceived(123);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700433 expectThrottleVsyncReceived(456, mConnectionUid);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800434 expectVsyncEventReceivedByConnection(123, 1u);
435
436 // A second event should go to the same places.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700437 mCallback->onVSyncEvent(456, 123, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800438 expectInterceptCallReceived(456);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700439 expectThrottleVsyncReceived(123, mConnectionUid);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800440 expectVsyncEventReceivedByConnection(456, 2u);
441
442 // A third event should go to the same places.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700443 mCallback->onVSyncEvent(789, 777, 111);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800444 expectInterceptCallReceived(789);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700445 expectThrottleVsyncReceived(777, mConnectionUid);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800446 expectVsyncEventReceivedByConnection(789, 3u);
447}
448
449TEST_F(EventThreadTest, setVsyncRateTwoPostsEveryOtherEventToThatConnection) {
450 mThread->setVsyncRate(2, mConnection);
451
Dominik Laskowski029cc122019-01-23 19:52:06 -0800452 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800453 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800454
455 // The first event will be seen by the interceptor, and not the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700456 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800457 expectInterceptCallReceived(123);
458 EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
Ady Abraham0bb6a472020-10-12 10:22:13 -0700459 EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800460
461 // The second event will be seen by the interceptor and the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700462 mCallback->onVSyncEvent(456, 123, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800463 expectInterceptCallReceived(456);
464 expectVsyncEventReceivedByConnection(456, 2u);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700465 EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800466
467 // The third event will be seen by the interceptor, and not the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700468 mCallback->onVSyncEvent(789, 777, 744);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800469 expectInterceptCallReceived(789);
470 EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
Ady Abraham0bb6a472020-10-12 10:22:13 -0700471 EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value());
Lloyd Pique24b0a482018-03-09 18:52:26 -0800472
473 // The fourth event will be seen by the interceptor and the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700474 mCallback->onVSyncEvent(101112, 7847, 86);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800475 expectInterceptCallReceived(101112);
476 expectVsyncEventReceivedByConnection(101112, 4u);
477}
478
479TEST_F(EventThreadTest, connectionsRemovedIfInstanceDestroyed) {
480 mThread->setVsyncRate(1, mConnection);
481
Dominik Laskowski029cc122019-01-23 19:52:06 -0800482 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800483 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800484
485 // Destroy the only (strong) reference to the connection.
486 mConnection = nullptr;
487
488 // The first event will be seen by the interceptor, and not the connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700489 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800490 expectInterceptCallReceived(123);
491 EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
492
493 // EventThread should disable vsync callbacks
494 expectVSyncSetEnabledCallReceived(false);
495}
496
497TEST_F(EventThreadTest, connectionsRemovedIfEventDeliveryError) {
498 ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY};
Ady Abraham62f216c2020-10-13 19:07:23 -0700499 sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800500 mThread->setVsyncRate(1, errorConnection);
501
Dominik Laskowski029cc122019-01-23 19:52:06 -0800502 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800503 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800504
505 // The first event will be seen by the interceptor, and by the connection,
506 // which then returns an error.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700507 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800508 expectInterceptCallReceived(123);
509 expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
510
511 // A subsequent event will be seen by the interceptor and not by the
512 // connection.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700513 mCallback->onVSyncEvent(456, 123, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800514 expectInterceptCallReceived(456);
515 EXPECT_FALSE(errorConnectionEventRecorder.waitForUnexpectedCall().has_value());
516
517 // EventThread should disable vsync callbacks with the second event
518 expectVSyncSetEnabledCallReceived(false);
519}
520
Alec Mouri717bcb62020-02-10 17:07:19 -0800521TEST_F(EventThreadTest, tracksEventConnections) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700522 EXPECT_EQ(2, mThread->getEventThreadConnectionCount());
Alec Mouri717bcb62020-02-10 17:07:19 -0800523 ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY};
Ady Abraham62f216c2020-10-13 19:07:23 -0700524 sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder);
Alec Mouri717bcb62020-02-10 17:07:19 -0800525 mThread->setVsyncRate(1, errorConnection);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700526 EXPECT_EQ(3, mThread->getEventThreadConnectionCount());
Alec Mouri717bcb62020-02-10 17:07:19 -0800527 ConnectionEventRecorder secondConnectionEventRecorder{0};
528 sp<MockEventThreadConnection> secondConnection =
Ady Abraham62f216c2020-10-13 19:07:23 -0700529 createConnection(secondConnectionEventRecorder);
Alec Mouri717bcb62020-02-10 17:07:19 -0800530 mThread->setVsyncRate(1, secondConnection);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700531 EXPECT_EQ(4, mThread->getEventThreadConnectionCount());
Alec Mouri717bcb62020-02-10 17:07:19 -0800532
533 // EventThread should enable vsync callbacks.
534 expectVSyncSetEnabledCallReceived(true);
535
536 // The first event will be seen by the interceptor, and by the connection,
537 // which then returns an error.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700538 mCallback->onVSyncEvent(123, 456, 789);
Alec Mouri717bcb62020-02-10 17:07:19 -0800539 expectInterceptCallReceived(123);
540 expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
541 expectVsyncEventReceivedByConnection("successConnection", secondConnectionEventRecorder, 123,
542 1u);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700543 EXPECT_EQ(3, mThread->getEventThreadConnectionCount());
Alec Mouri717bcb62020-02-10 17:07:19 -0800544}
545
Lloyd Pique24b0a482018-03-09 18:52:26 -0800546TEST_F(EventThreadTest, eventsDroppedIfNonfatalEventDeliveryError) {
547 ConnectionEventRecorder errorConnectionEventRecorder{WOULD_BLOCK};
Ady Abraham62f216c2020-10-13 19:07:23 -0700548 sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800549 mThread->setVsyncRate(1, errorConnection);
550
Dominik Laskowski029cc122019-01-23 19:52:06 -0800551 // EventThread should enable vsync callbacks.
Lloyd Pique24b0a482018-03-09 18:52:26 -0800552 expectVSyncSetEnabledCallReceived(true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800553
554 // The first event will be seen by the interceptor, and by the connection,
555 // which then returns an non-fatal error.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700556 mCallback->onVSyncEvent(123, 456, 789);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800557 expectInterceptCallReceived(123);
558 expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u);
559
560 // A subsequent event will be seen by the interceptor, and by the connection,
561 // which still then returns an non-fatal error.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700562 mCallback->onVSyncEvent(456, 123, 0);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800563 expectInterceptCallReceived(456);
564 expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 456, 2u);
565
566 // EventThread will not disable vsync callbacks as the errors are non-fatal.
567 EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
568}
569
570TEST_F(EventThreadTest, setPhaseOffsetForwardsToVSyncSource) {
Ady Abraham9c53ee72020-07-22 21:16:18 -0700571 mThread->setDuration(321ns, 456ns);
572 expectVSyncSetDurationCallReceived(321ns, 456ns);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800573}
574
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800575TEST_F(EventThreadTest, postHotplugInternalDisconnect) {
576 mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false);
577 expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800578}
579
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800580TEST_F(EventThreadTest, postHotplugInternalConnect) {
581 mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true);
582 expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800583}
584
585TEST_F(EventThreadTest, postHotplugExternalDisconnect) {
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800586 mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, false);
587 expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, false);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800588}
589
590TEST_F(EventThreadTest, postHotplugExternalConnect) {
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800591 mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, true);
592 expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, true);
Lloyd Pique24b0a482018-03-09 18:52:26 -0800593}
594
Ady Abraham447052e2019-02-13 16:07:27 -0800595TEST_F(EventThreadTest, postConfigChangedPrimary) {
Ady Abraham690f4612021-07-01 23:24:03 -0700596 const auto mode = DisplayMode::Builder(hal::HWConfigId(0))
597 .setPhysicalDisplayId(INTERNAL_DISPLAY_ID)
598 .setId(DisplayModeId(7))
599 .setVsyncPeriod(16666666)
600 .build();
601
602 mThread->onModeChanged(mode);
Alec Mouri60aee1c2019-10-28 16:18:59 -0700603 expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 7, 16666666);
Ady Abraham447052e2019-02-13 16:07:27 -0800604}
605
606TEST_F(EventThreadTest, postConfigChangedExternal) {
Ady Abraham690f4612021-07-01 23:24:03 -0700607 const auto mode = DisplayMode::Builder(hal::HWConfigId(0))
608 .setPhysicalDisplayId(EXTERNAL_DISPLAY_ID)
609 .setId(DisplayModeId(5))
610 .setVsyncPeriod(16666666)
611 .build();
612
613 mThread->onModeChanged(mode);
Alec Mouri60aee1c2019-10-28 16:18:59 -0700614 expectConfigChangedEventReceivedByConnection(EXTERNAL_DISPLAY_ID, 5, 16666666);
Ady Abraham447052e2019-02-13 16:07:27 -0800615}
616
Ady Abrahamaf0ec272019-03-28 11:38:31 -0700617TEST_F(EventThreadTest, postConfigChangedPrimary64bit) {
Ady Abraham690f4612021-07-01 23:24:03 -0700618 const auto mode = DisplayMode::Builder(hal::HWConfigId(0))
619 .setPhysicalDisplayId(DISPLAY_ID_64BIT)
620 .setId(DisplayModeId(7))
621 .setVsyncPeriod(16666666)
622 .build();
623 mThread->onModeChanged(mode);
Alec Mouri60aee1c2019-10-28 16:18:59 -0700624 expectConfigChangedEventReceivedByConnection(DISPLAY_ID_64BIT, 7, 16666666);
Ady Abrahamaf0ec272019-03-28 11:38:31 -0700625}
626
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700627TEST_F(EventThreadTest, suppressConfigChanged) {
628 ConnectionEventRecorder suppressConnectionEventRecorder{0};
629 sp<MockEventThreadConnection> suppressConnection =
Ady Abraham62f216c2020-10-13 19:07:23 -0700630 createConnection(suppressConnectionEventRecorder);
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700631
Ady Abraham690f4612021-07-01 23:24:03 -0700632 const auto mode = DisplayMode::Builder(hal::HWConfigId(0))
633 .setPhysicalDisplayId(INTERNAL_DISPLAY_ID)
634 .setId(DisplayModeId(9))
635 .setVsyncPeriod(16666666)
636 .build();
637
638 mThread->onModeChanged(mode);
Alec Mouri60aee1c2019-10-28 16:18:59 -0700639 expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 9, 16666666);
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700640
641 auto args = suppressConnectionEventRecorder.waitForCall();
642 ASSERT_FALSE(args.has_value());
643}
644
Ady Abraham62f216c2020-10-13 19:07:23 -0700645TEST_F(EventThreadTest, postUidFrameRateMapping) {
646 const std::vector<FrameRateOverride> overrides = {
647 {.uid = 1, .frameRateHz = 20},
648 {.uid = 3, .frameRateHz = 40},
649 {.uid = 5, .frameRateHz = 60},
650 };
651
652 mThread->onFrameRateOverridesChanged(INTERNAL_DISPLAY_ID, overrides);
653 expectUidFrameRateMappingEventReceivedByConnection(INTERNAL_DISPLAY_ID, overrides);
654}
655
656TEST_F(EventThreadTest, suppressUidFrameRateMapping) {
657 const std::vector<FrameRateOverride> overrides = {
658 {.uid = 1, .frameRateHz = 20},
659 {.uid = 3, .frameRateHz = 40},
660 {.uid = 5, .frameRateHz = 60},
661 };
662
663 ConnectionEventRecorder suppressConnectionEventRecorder{0};
664 sp<MockEventThreadConnection> suppressConnection =
665 createConnection(suppressConnectionEventRecorder);
666
667 mThread->onFrameRateOverridesChanged(INTERNAL_DISPLAY_ID, overrides);
668 expectUidFrameRateMappingEventReceivedByConnection(INTERNAL_DISPLAY_ID, overrides);
669
670 auto args = suppressConnectionEventRecorder.waitForCall();
671 ASSERT_FALSE(args.has_value());
672}
673
Ady Abraham0bb6a472020-10-12 10:22:13 -0700674TEST_F(EventThreadTest, requestNextVsyncWithThrottleVsyncDoesntPostVSync) {
675 // Signal that we want the next vsync event to be posted to the throttled connection
676 mThread->requestNextVsync(mThrottledConnection);
677
678 // EventThread should immediately request a resync.
679 EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value());
680
681 // EventThread should enable vsync callbacks.
682 expectVSyncSetEnabledCallReceived(true);
683
684 // Use the received callback to signal a first vsync event.
685 // The interceptor should receive the event, but not the connection.
686 mCallback->onVSyncEvent(123, 456, 789);
687 expectInterceptCallReceived(123);
688 expectThrottleVsyncReceived(456, mThrottledConnectionUid);
689 mThrottledConnectionEventCallRecorder.waitForUnexpectedCall();
690
691 // Use the received callback to signal a second vsync event.
692 // The interceptor should receive the event, but the connection should
693 // not as it was only interested in the first.
694 mCallback->onVSyncEvent(456, 123, 0);
695 expectInterceptCallReceived(456);
696 expectThrottleVsyncReceived(123, mThrottledConnectionUid);
697 EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value());
698
699 // EventThread should not change the vsync state as it didn't send the event
700 // yet
701 EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value());
702}
703
Lloyd Pique24b0a482018-03-09 18:52:26 -0800704} // namespace
705} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100706
707// TODO(b/129481165): remove the #pragma below and fix conversion issues
708#pragma clang diagnostic pop // ignored "-Wextra"