Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 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 | |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wextra" |
| 20 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 21 | #undef LOG_TAG |
| 22 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 23 | |
| 24 | #include <gmock/gmock.h> |
| 25 | #include <gtest/gtest.h> |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 26 | #include <log/log.h> |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 27 | #include <utils/Errors.h> |
| 28 | |
| 29 | #include "AsyncCallRecorder.h" |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 30 | #include "DisplayHardware/DisplayMode.h" |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 31 | #include "FrameTimeline.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 32 | #include "Scheduler/EventThread.h" |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 33 | #include "mock/MockVSyncDispatch.h" |
| 34 | #include "mock/MockVSyncTracker.h" |
| 35 | #include "mock/MockVsyncController.h" |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 36 | |
| 37 | using namespace std::chrono_literals; |
| 38 | using namespace std::placeholders; |
| 39 | |
| 40 | using testing::_; |
| 41 | using testing::Invoke; |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 42 | using testing::Return; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 43 | |
| 44 | namespace android { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 45 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 46 | using namespace ftl::flag_operators; |
| 47 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 48 | namespace { |
| 49 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 50 | constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID = PhysicalDisplayId::fromPort(111u); |
| 51 | constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID = PhysicalDisplayId::fromPort(222u); |
| 52 | constexpr PhysicalDisplayId DISPLAY_ID_64BIT = |
| 53 | PhysicalDisplayId::fromEdid(0xffu, 0xffffu, 0xffff'ffffu); |
| 54 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 55 | constexpr std::chrono::duration VSYNC_PERIOD(16ms); |
| 56 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 57 | } // namespace |
| 58 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 59 | class EventThreadTest : public testing::Test { |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 60 | protected: |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 61 | static constexpr std::chrono::nanoseconds kWorkDuration = 0ms; |
| 62 | static constexpr std::chrono::nanoseconds kReadyDuration = 3ms; |
| 63 | |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 64 | class MockEventThreadConnection : public EventThreadConnection { |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 65 | public: |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 66 | MockEventThreadConnection(impl::EventThread* eventThread, uid_t callingUid, |
| 67 | ResyncCallback&& resyncCallback, |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 68 | EventRegistrationFlags eventRegistration) |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 69 | : EventThreadConnection(eventThread, callingUid, std::move(resyncCallback), |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 70 | eventRegistration) {} |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 71 | MOCK_METHOD1(postEvent, status_t(const DisplayEventReceiver::Event& event)); |
| 72 | }; |
| 73 | |
| 74 | using ConnectionEventRecorder = |
| 75 | AsyncCallRecorderWithCannedReturn<status_t (*)(const DisplayEventReceiver::Event&)>; |
| 76 | |
| 77 | EventThreadTest(); |
| 78 | ~EventThreadTest() override; |
| 79 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 80 | void createThread(); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 81 | sp<MockEventThreadConnection> createConnection(ConnectionEventRecorder& recorder, |
| 82 | EventRegistrationFlags eventRegistration = {}, |
| 83 | uid_t ownerUid = mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 84 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 85 | void expectVSyncCallbackScheduleReceived(bool expectState); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 86 | void expectVSyncSetDurationCallReceived(std::chrono::nanoseconds expectedDuration, |
| 87 | std::chrono::nanoseconds expectedReadyDuration); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 88 | void expectVsyncEventReceivedByConnection(const char* name, |
| 89 | ConnectionEventRecorder& connectionEventRecorder, |
| 90 | nsecs_t expectedTimestamp, unsigned expectedCount); |
| 91 | void expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, unsigned expectedCount); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 92 | void expectVsyncEventFrameTimelinesCorrect( |
| 93 | nsecs_t expectedTimestamp, |
| 94 | /*VSyncSource::VSyncData*/ gui::VsyncEventData::FrameTimeline preferredVsyncData); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 95 | void expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 96 | bool expectedConnected); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 97 | void expectConfigChangedEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 98 | int32_t expectedConfigId, |
| 99 | nsecs_t expectedVsyncPeriod); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 100 | void expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t); |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 101 | void expectUidFrameRateMappingEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
| 102 | std::vector<FrameRateOverride>); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 103 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 104 | void onVSyncEvent(nsecs_t timestamp, nsecs_t expectedPresentationTime, |
| 105 | nsecs_t deadlineTimestamp) { |
| 106 | mThread->onVsync(expectedPresentationTime, timestamp, deadlineTimestamp); |
| 107 | } |
| 108 | |
| 109 | AsyncCallRecorderWithCannedReturn< |
| 110 | scheduler::ScheduleResult (*)(scheduler::VSyncDispatch::CallbackToken, |
| 111 | scheduler::VSyncDispatch::ScheduleTiming)> |
| 112 | mVSyncCallbackScheduleRecorder{0}; |
| 113 | AsyncCallRecorderWithCannedReturn< |
| 114 | scheduler::ScheduleResult (*)(scheduler::VSyncDispatch::CallbackToken, |
| 115 | scheduler::VSyncDispatch::ScheduleTiming)> |
| 116 | mVSyncCallbackUpdateRecorder{0}; |
| 117 | AsyncCallRecorderWithCannedReturn< |
| 118 | scheduler::VSyncDispatch::CallbackToken (*)(scheduler::VSyncDispatch::Callback, |
| 119 | std::string)> |
| 120 | mVSyncCallbackRegisterRecorder{scheduler::VSyncDispatch::CallbackToken(0)}; |
| 121 | AsyncCallRecorder<void (*)(scheduler::VSyncDispatch::CallbackToken)> |
| 122 | mVSyncCallbackUnregisterRecorder; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 123 | AsyncCallRecorder<void (*)()> mResyncCallRecorder; |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 124 | AsyncCallRecorder<void (*)(nsecs_t, uid_t)> mThrottleVsyncCallRecorder; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 125 | ConnectionEventRecorder mConnectionEventCallRecorder{0}; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 126 | ConnectionEventRecorder mThrottledConnectionEventCallRecorder{0}; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 127 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 128 | std::optional<scheduler::VsyncSchedule> mVsyncSchedule; |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 129 | std::unique_ptr<impl::EventThread> mThread; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 130 | sp<MockEventThreadConnection> mConnection; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 131 | sp<MockEventThreadConnection> mThrottledConnection; |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 132 | std::unique_ptr<frametimeline::impl::TokenManager> mTokenManager; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 133 | |
| 134 | static constexpr uid_t mConnectionUid = 443; |
| 135 | static constexpr uid_t mThrottledConnectionUid = 177; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | EventThreadTest::EventThreadTest() { |
| 139 | const ::testing::TestInfo* const test_info = |
| 140 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 141 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 142 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 143 | mVsyncSchedule.emplace(scheduler::VsyncSchedule(std::make_unique<mock::VSyncTracker>(), |
| 144 | std::make_unique<mock::VSyncDispatch>(), |
| 145 | nullptr)); |
| 146 | |
| 147 | mock::VSyncDispatch& mockDispatch = |
| 148 | *static_cast<mock::VSyncDispatch*>(&mVsyncSchedule->getDispatch()); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 149 | EXPECT_CALL(mockDispatch, registerCallback(_, _)) |
| 150 | .WillRepeatedly(Invoke(mVSyncCallbackRegisterRecorder.getInvocable())); |
| 151 | EXPECT_CALL(mockDispatch, schedule(_, _)) |
| 152 | .WillRepeatedly(Invoke(mVSyncCallbackScheduleRecorder.getInvocable())); |
| 153 | EXPECT_CALL(mockDispatch, update(_, _)) |
| 154 | .WillRepeatedly(Invoke(mVSyncCallbackUpdateRecorder.getInvocable())); |
| 155 | EXPECT_CALL(mockDispatch, unregisterCallback(_)) |
| 156 | .WillRepeatedly(Invoke(mVSyncCallbackUnregisterRecorder.getInvocable())); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 157 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 158 | createThread(); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 159 | mConnection = |
| 160 | createConnection(mConnectionEventCallRecorder, |
| 161 | gui::ISurfaceComposer::EventRegistration::modeChanged | |
| 162 | gui::ISurfaceComposer::EventRegistration::frameRateOverride); |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 163 | mThrottledConnection = createConnection(mThrottledConnectionEventCallRecorder, |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 164 | gui::ISurfaceComposer::EventRegistration::modeChanged, |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 165 | mThrottledConnectionUid); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 166 | |
| 167 | // A display must be connected for VSYNC events to be delivered. |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 168 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true); |
| 169 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | EventThreadTest::~EventThreadTest() { |
| 173 | const ::testing::TestInfo* const test_info = |
| 174 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 175 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 176 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 177 | mThread.reset(); |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 178 | // EventThread should unregister itself as VSyncSource callback. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 179 | EXPECT_TRUE(mVSyncCallbackUnregisterRecorder.waitForCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 182 | void EventThreadTest::createThread() { |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 183 | const auto throttleVsync = [&](nsecs_t expectedVsyncTimestamp, uid_t uid) { |
| 184 | mThrottleVsyncCallRecorder.getInvocable()(expectedVsyncTimestamp, uid); |
| 185 | return (uid == mThrottledConnectionUid); |
| 186 | }; |
| 187 | const auto getVsyncPeriod = [](uid_t uid) { |
| 188 | return VSYNC_PERIOD.count(); |
| 189 | }; |
| 190 | |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 191 | mTokenManager = std::make_unique<frametimeline::impl::TokenManager>(); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 192 | mThread = |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 193 | std::make_unique<impl::EventThread>(/*std::move(source), */ "EventThreadTest", |
| 194 | *mVsyncSchedule, mTokenManager.get(), throttleVsync, |
| 195 | getVsyncPeriod, kWorkDuration, kReadyDuration); |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 196 | |
| 197 | // EventThread should register itself as VSyncSource callback. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 198 | EXPECT_TRUE(mVSyncCallbackRegisterRecorder.waitForCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | sp<EventThreadTest::MockEventThreadConnection> EventThreadTest::createConnection( |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 202 | ConnectionEventRecorder& recorder, EventRegistrationFlags eventRegistration, |
| 203 | uid_t ownerUid) { |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 204 | sp<MockEventThreadConnection> connection = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 205 | sp<MockEventThreadConnection>::make(mThread.get(), ownerUid, |
| 206 | mResyncCallRecorder.getInvocable(), |
| 207 | eventRegistration); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 208 | EXPECT_CALL(*connection, postEvent(_)).WillRepeatedly(Invoke(recorder.getInvocable())); |
| 209 | return connection; |
| 210 | } |
| 211 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 212 | void EventThreadTest::expectVSyncCallbackScheduleReceived(bool expectState) { |
| 213 | if (expectState) { |
| 214 | ASSERT_TRUE(mVSyncCallbackScheduleRecorder.waitForCall().has_value()); |
| 215 | } else { |
| 216 | ASSERT_FALSE(mVSyncCallbackScheduleRecorder.waitForUnexpectedCall().has_value()); |
| 217 | } |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 220 | void EventThreadTest::expectVSyncSetDurationCallReceived( |
| 221 | std::chrono::nanoseconds expectedDuration, std::chrono::nanoseconds expectedReadyDuration) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 222 | auto args = mVSyncCallbackUpdateRecorder.waitForCall(); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 223 | ASSERT_TRUE(args.has_value()); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 224 | EXPECT_EQ(expectedDuration.count(), std::get<1>(args.value()).workDuration); |
| 225 | EXPECT_EQ(expectedReadyDuration.count(), std::get<1>(args.value()).readyDuration); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 228 | void EventThreadTest::expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t uid) { |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 229 | auto args = mThrottleVsyncCallRecorder.waitForCall(); |
| 230 | ASSERT_TRUE(args.has_value()); |
| 231 | EXPECT_EQ(expectedTimestamp, std::get<0>(args.value())); |
| 232 | EXPECT_EQ(uid, std::get<1>(args.value())); |
| 233 | } |
| 234 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 235 | void EventThreadTest::expectVsyncEventReceivedByConnection( |
| 236 | const char* name, ConnectionEventRecorder& connectionEventRecorder, |
| 237 | nsecs_t expectedTimestamp, unsigned expectedCount) { |
| 238 | auto args = connectionEventRecorder.waitForCall(); |
| 239 | ASSERT_TRUE(args.has_value()) << name << " did not receive an event for timestamp " |
| 240 | << expectedTimestamp; |
| 241 | const auto& event = std::get<0>(args.value()); |
| 242 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_VSYNC, event.header.type) |
| 243 | << name << " did not get the correct event for timestamp " << expectedTimestamp; |
| 244 | EXPECT_EQ(expectedTimestamp, event.header.timestamp) |
| 245 | << name << " did not get the expected timestamp for timestamp " << expectedTimestamp; |
| 246 | EXPECT_EQ(expectedCount, event.vsync.count) |
| 247 | << name << " did not get the expected count for timestamp " << expectedTimestamp; |
| 248 | } |
| 249 | |
| 250 | void EventThreadTest::expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, |
| 251 | unsigned expectedCount) { |
| 252 | expectVsyncEventReceivedByConnection("mConnectionEventCallRecorder", |
| 253 | mConnectionEventCallRecorder, expectedTimestamp, |
| 254 | expectedCount); |
| 255 | } |
| 256 | |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 257 | void EventThreadTest::expectVsyncEventFrameTimelinesCorrect( |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 258 | nsecs_t expectedTimestamp, VsyncEventData::FrameTimeline preferredVsyncData) { |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 259 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 260 | ASSERT_TRUE(args.has_value()) << " did not receive an event for timestamp " |
| 261 | << expectedTimestamp; |
| 262 | const auto& event = std::get<0>(args.value()); |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 263 | for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) { |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 264 | auto prediction = mTokenManager->getPredictionsForToken( |
| 265 | event.vsync.vsyncData.frameTimelines[i].vsyncId); |
Rachel Lee | 8d0c610 | 2021-11-03 22:00:25 +0000 | [diff] [blame] | 266 | EXPECT_TRUE(prediction.has_value()); |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 267 | EXPECT_EQ(prediction.value().endTime, |
| 268 | event.vsync.vsyncData.frameTimelines[i].deadlineTimestamp) |
Rachel Lee | 8d0c610 | 2021-11-03 22:00:25 +0000 | [diff] [blame] | 269 | << "Deadline timestamp does not match cached value"; |
| 270 | EXPECT_EQ(prediction.value().presentTime, |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 271 | event.vsync.vsyncData.frameTimelines[i].expectedPresentationTime) |
| 272 | << "Expected vsync.vsyncData timestamp does not match cached value"; |
Rachel Lee | 8d0c610 | 2021-11-03 22:00:25 +0000 | [diff] [blame] | 273 | |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 274 | if (i > 0) { |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 275 | EXPECT_GT(event.vsync.vsyncData.frameTimelines[i].deadlineTimestamp, |
| 276 | event.vsync.vsyncData.frameTimelines[i - 1].deadlineTimestamp) |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 277 | << "Deadline timestamp out of order for frame timeline " << i; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 278 | EXPECT_GT(event.vsync.vsyncData.frameTimelines[i].expectedPresentationTime, |
| 279 | event.vsync.vsyncData.frameTimelines[i - 1].expectedPresentationTime) |
| 280 | << "Expected vsync.vsyncData timestamp out of order for frame timeline " << i; |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 281 | } |
Rachel Lee | 0d94320 | 2022-02-01 23:29:41 -0800 | [diff] [blame] | 282 | |
| 283 | // Vsync ID order lines up with registration into test token manager. |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 284 | EXPECT_EQ(i, event.vsync.vsyncData.frameTimelines[i].vsyncId) |
Rachel Lee | 0d94320 | 2022-02-01 23:29:41 -0800 | [diff] [blame] | 285 | << "Vsync ID incorrect for frame timeline " << i; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 286 | if (i == event.vsync.vsyncData.preferredFrameTimelineIndex) { |
| 287 | EXPECT_EQ(event.vsync.vsyncData.frameTimelines[i].deadlineTimestamp, |
| 288 | preferredVsyncData.deadlineTimestamp) |
Rachel Lee | 0d94320 | 2022-02-01 23:29:41 -0800 | [diff] [blame] | 289 | << "Preferred deadline timestamp incorrect" << i; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 290 | EXPECT_EQ(event.vsync.vsyncData.frameTimelines[i].expectedPresentationTime, |
| 291 | preferredVsyncData.expectedPresentationTime) |
| 292 | << "Preferred expected vsync.vsyncData timestamp incorrect" << i; |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 297 | void EventThreadTest::expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
| 298 | bool expectedConnected) { |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 299 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 300 | ASSERT_TRUE(args.has_value()); |
| 301 | const auto& event = std::get<0>(args.value()); |
| 302 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, event.header.type); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 303 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 304 | EXPECT_EQ(expectedConnected, event.hotplug.connected); |
| 305 | } |
| 306 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 307 | void EventThreadTest::expectConfigChangedEventReceivedByConnection( |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 308 | PhysicalDisplayId expectedDisplayId, int32_t expectedConfigId, |
| 309 | nsecs_t expectedVsyncPeriod) { |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 310 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 311 | ASSERT_TRUE(args.has_value()); |
| 312 | const auto& event = std::get<0>(args.value()); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 313 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE, event.header.type); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 314 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 315 | EXPECT_EQ(expectedConfigId, event.modeChange.modeId); |
| 316 | EXPECT_EQ(expectedVsyncPeriod, event.modeChange.vsyncPeriod); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 319 | void EventThreadTest::expectUidFrameRateMappingEventReceivedByConnection( |
| 320 | PhysicalDisplayId expectedDisplayId, std::vector<FrameRateOverride> expectedOverrides) { |
| 321 | for (const auto [uid, frameRateHz] : expectedOverrides) { |
| 322 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 323 | ASSERT_TRUE(args.has_value()); |
| 324 | const auto& event = std::get<0>(args.value()); |
| 325 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE, event.header.type); |
| 326 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
| 327 | EXPECT_EQ(uid, event.frameRateOverride.uid); |
| 328 | EXPECT_EQ(frameRateHz, event.frameRateOverride.frameRateHz); |
| 329 | } |
| 330 | |
| 331 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 332 | ASSERT_TRUE(args.has_value()); |
| 333 | const auto& event = std::get<0>(args.value()); |
| 334 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_FRAME_RATE_OVERRIDE_FLUSH, event.header.type); |
| 335 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
| 336 | } |
| 337 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 338 | namespace { |
| 339 | |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 340 | using namespace testing; |
| 341 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 342 | /* ------------------------------------------------------------------------ |
| 343 | * Test cases |
| 344 | */ |
| 345 | |
| 346 | TEST_F(EventThreadTest, canCreateAndDestroyThreadWithNoEventsSent) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 347 | EXPECT_FALSE(mVSyncCallbackRegisterRecorder.waitForCall(0us).has_value()); |
| 348 | EXPECT_FALSE(mVSyncCallbackScheduleRecorder.waitForCall(0us).has_value()); |
| 349 | EXPECT_FALSE(mVSyncCallbackUpdateRecorder.waitForCall(0us).has_value()); |
| 350 | EXPECT_FALSE(mVSyncCallbackUnregisterRecorder.waitForCall(0us).has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 351 | EXPECT_FALSE(mResyncCallRecorder.waitForCall(0us).has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 352 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForCall(0us).has_value()); |
| 353 | } |
| 354 | |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 355 | TEST_F(EventThreadTest, vsyncRequestIsIgnoredIfDisplayIsDisconnected) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 356 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false); |
| 357 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 358 | |
| 359 | // Signal that we want the next vsync event to be posted to the connection. |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 360 | mThread->requestNextVsync(mConnection); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 361 | |
| 362 | // EventThread should not enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 363 | expectVSyncCallbackScheduleReceived(false); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 366 | TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) { |
| 367 | // Signal that we want the next vsync event to be posted to the connection |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 368 | mThread->requestNextVsync(mConnection); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 369 | |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 370 | // EventThread should immediately request a resync. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 371 | EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value()); |
| 372 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 373 | // EventThread should enable schedule a vsync callback |
| 374 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 375 | |
| 376 | // Use the received callback to signal a first vsync event. |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 377 | // The throttler should receive the event, as well as the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 378 | onVSyncEvent(123, 456, 789); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 379 | expectThrottleVsyncReceived(456, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 380 | expectVsyncEventReceivedByConnection(123, 1u); |
| 381 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 382 | // EventThread is requesting one more callback due to VsyncRequest::SingleSuppressCallback |
| 383 | expectVSyncCallbackScheduleReceived(true); |
| 384 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 385 | // Use the received callback to signal a second vsync event. |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 386 | // The throttler should receive the event, but the connection should |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 387 | // not as it was only interested in the first. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 388 | onVSyncEvent(456, 123, 0); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 389 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 390 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
| 391 | |
| 392 | // EventThread should also detect that at this point that it does not need |
| 393 | // any more vsync events, and should disable their generation. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 394 | expectVSyncCallbackScheduleReceived(false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 397 | TEST_F(EventThreadTest, requestNextVsyncEventFrameTimelinesCorrect) { |
| 398 | // Signal that we want the next vsync event to be posted to the connection |
| 399 | mThread->requestNextVsync(mConnection); |
| 400 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 401 | expectVSyncCallbackScheduleReceived(true); |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 402 | |
| 403 | // Use the received callback to signal a vsync event. |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 404 | // The throttler should receive the event, as well as the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 405 | onVSyncEvent(123, 456, 789); |
| 406 | expectVsyncEventFrameTimelinesCorrect(123, {-1, 789, 456}); |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 409 | TEST_F(EventThreadTest, getLatestVsyncEventData) { |
| 410 | const nsecs_t now = systemTime(); |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 411 | const nsecs_t preferredExpectedPresentationTime = now + 20000000; |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 412 | const nsecs_t preferredDeadline = preferredExpectedPresentationTime - kReadyDuration.count(); |
| 413 | |
| 414 | mock::VSyncTracker& mockTracker = |
| 415 | *static_cast<mock::VSyncTracker*>(&mVsyncSchedule->getTracker()); |
| 416 | EXPECT_CALL(mockTracker, nextAnticipatedVSyncTimeFrom(_)) |
| 417 | .WillOnce(Return(preferredExpectedPresentationTime)); |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 418 | |
| 419 | VsyncEventData vsyncEventData = mThread->getLatestVsyncEventData(mConnection); |
Rachel Lee | b5223cf | 2022-03-14 14:39:27 -0700 | [diff] [blame] | 420 | |
| 421 | // Check EventThread immediately requested a resync. |
| 422 | EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value()); |
| 423 | |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 424 | EXPECT_GT(vsyncEventData.frameTimelines[0].deadlineTimestamp, now) |
| 425 | << "Deadline timestamp should be greater than frame time"; |
| 426 | for (size_t i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) { |
| 427 | auto prediction = |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 428 | mTokenManager->getPredictionsForToken(vsyncEventData.frameTimelines[i].vsyncId); |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 429 | EXPECT_TRUE(prediction.has_value()); |
| 430 | EXPECT_EQ(prediction.value().endTime, vsyncEventData.frameTimelines[i].deadlineTimestamp) |
| 431 | << "Deadline timestamp does not match cached value"; |
| 432 | EXPECT_EQ(prediction.value().presentTime, |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 433 | vsyncEventData.frameTimelines[i].expectedPresentationTime) |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 434 | << "Expected vsync timestamp does not match cached value"; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 435 | EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime, |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 436 | vsyncEventData.frameTimelines[i].deadlineTimestamp) |
| 437 | << "Expected vsync timestamp should be greater than deadline"; |
| 438 | |
| 439 | if (i > 0) { |
| 440 | EXPECT_GT(vsyncEventData.frameTimelines[i].deadlineTimestamp, |
| 441 | vsyncEventData.frameTimelines[i - 1].deadlineTimestamp) |
| 442 | << "Deadline timestamp out of order for frame timeline " << i; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 443 | EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime, |
| 444 | vsyncEventData.frameTimelines[i - 1].expectedPresentationTime) |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 445 | << "Expected vsync timestamp out of order for frame timeline " << i; |
| 446 | } |
| 447 | |
| 448 | // Vsync ID order lines up with registration into test token manager. |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 449 | EXPECT_EQ(i, vsyncEventData.frameTimelines[i].vsyncId) |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 450 | << "Vsync ID incorrect for frame timeline " << i; |
| 451 | if (i == vsyncEventData.preferredFrameTimelineIndex) { |
| 452 | EXPECT_EQ(vsyncEventData.frameTimelines[i].deadlineTimestamp, preferredDeadline) |
| 453 | << "Preferred deadline timestamp incorrect" << i; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 454 | EXPECT_EQ(vsyncEventData.frameTimelines[i].expectedPresentationTime, |
| 455 | preferredExpectedPresentationTime) |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 456 | << "Preferred expected vsync timestamp incorrect" << i; |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 461 | TEST_F(EventThreadTest, setVsyncRateZeroPostsNoVSyncEventsToThatConnection) { |
| 462 | // Create a first connection, register it, and request a vsync rate of zero. |
| 463 | ConnectionEventRecorder firstConnectionEventRecorder{0}; |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 464 | sp<MockEventThreadConnection> firstConnection = createConnection(firstConnectionEventRecorder); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 465 | mThread->setVsyncRate(0, firstConnection); |
| 466 | |
| 467 | // By itself, this should not enable vsync events |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 468 | expectVSyncCallbackScheduleReceived(false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 469 | |
| 470 | // However if there is another connection which wants events at a nonzero rate..... |
| 471 | ConnectionEventRecorder secondConnectionEventRecorder{0}; |
| 472 | sp<MockEventThreadConnection> secondConnection = |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 473 | createConnection(secondConnectionEventRecorder); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 474 | mThread->setVsyncRate(1, secondConnection); |
| 475 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 476 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 477 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 478 | |
| 479 | // Send a vsync event. EventThread should then make a call to the |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 480 | // the second connection. The first connection should not |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 481 | // get the event. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 482 | onVSyncEvent(123, 0456, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 483 | EXPECT_FALSE(firstConnectionEventRecorder.waitForUnexpectedCall().has_value()); |
| 484 | expectVsyncEventReceivedByConnection("secondConnection", secondConnectionEventRecorder, 123, |
| 485 | 1u); |
| 486 | } |
| 487 | |
| 488 | TEST_F(EventThreadTest, setVsyncRateOnePostsAllEventsToThatConnection) { |
| 489 | mThread->setVsyncRate(1, mConnection); |
| 490 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 491 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 492 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 493 | |
| 494 | // Send a vsync event. EventThread should then make a call to the |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 495 | // throttler, and the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 496 | onVSyncEvent(123, 456, 789); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 497 | expectThrottleVsyncReceived(456, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 498 | expectVsyncEventReceivedByConnection(123, 1u); |
| 499 | |
| 500 | // A second event should go to the same places. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 501 | onVSyncEvent(456, 123, 0); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 502 | expectThrottleVsyncReceived(123, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 503 | expectVsyncEventReceivedByConnection(456, 2u); |
| 504 | |
| 505 | // A third event should go to the same places. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 506 | onVSyncEvent(789, 777, 111); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 507 | expectThrottleVsyncReceived(777, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 508 | expectVsyncEventReceivedByConnection(789, 3u); |
| 509 | } |
| 510 | |
| 511 | TEST_F(EventThreadTest, setVsyncRateTwoPostsEveryOtherEventToThatConnection) { |
| 512 | mThread->setVsyncRate(2, mConnection); |
| 513 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 514 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 515 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 516 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 517 | // The first event will not be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 518 | onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 519 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 520 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 521 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 522 | // The second event will be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 523 | onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 524 | expectVsyncEventReceivedByConnection(456, 2u); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 525 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 526 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 527 | // The third event will not be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 528 | onVSyncEvent(789, 777, 744); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 529 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 530 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 531 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 532 | // The fourth event will be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 533 | onVSyncEvent(101112, 7847, 86); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 534 | expectVsyncEventReceivedByConnection(101112, 4u); |
| 535 | } |
| 536 | |
| 537 | TEST_F(EventThreadTest, connectionsRemovedIfInstanceDestroyed) { |
| 538 | mThread->setVsyncRate(1, mConnection); |
| 539 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 540 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 541 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 542 | |
| 543 | // Destroy the only (strong) reference to the connection. |
| 544 | mConnection = nullptr; |
| 545 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 546 | // The first event will not be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 547 | onVSyncEvent(123, 56, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 548 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
| 549 | |
| 550 | // EventThread should disable vsync callbacks |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 551 | expectVSyncCallbackScheduleReceived(false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | TEST_F(EventThreadTest, connectionsRemovedIfEventDeliveryError) { |
| 555 | ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY}; |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 556 | sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 557 | mThread->setVsyncRate(1, errorConnection); |
| 558 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 559 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 560 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 561 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 562 | // The first event will be seen by the connection, which then returns an error. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 563 | onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 564 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
| 565 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 566 | // Another schedule is expected, since the connection is removed only after |
| 567 | // the next vsync is requested. |
| 568 | expectVSyncCallbackScheduleReceived(true); |
| 569 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 570 | // A subsequent event will not be seen by the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 571 | onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 572 | EXPECT_FALSE(errorConnectionEventRecorder.waitForUnexpectedCall().has_value()); |
| 573 | |
| 574 | // EventThread should disable vsync callbacks with the second event |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 575 | expectVSyncCallbackScheduleReceived(false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 578 | TEST_F(EventThreadTest, tracksEventConnections) { |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 579 | EXPECT_EQ(2, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 580 | ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY}; |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 581 | sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 582 | mThread->setVsyncRate(1, errorConnection); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 583 | EXPECT_EQ(3, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 584 | ConnectionEventRecorder secondConnectionEventRecorder{0}; |
| 585 | sp<MockEventThreadConnection> secondConnection = |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 586 | createConnection(secondConnectionEventRecorder); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 587 | mThread->setVsyncRate(1, secondConnection); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 588 | EXPECT_EQ(4, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 589 | |
| 590 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 591 | expectVSyncCallbackScheduleReceived(true); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 592 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 593 | // The first event will be seen by the connection, which then returns an error. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 594 | onVSyncEvent(123, 456, 789); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 595 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
| 596 | expectVsyncEventReceivedByConnection("successConnection", secondConnectionEventRecorder, 123, |
| 597 | 1u); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 598 | EXPECT_EQ(3, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 601 | TEST_F(EventThreadTest, eventsDroppedIfNonfatalEventDeliveryError) { |
| 602 | ConnectionEventRecorder errorConnectionEventRecorder{WOULD_BLOCK}; |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 603 | sp<MockEventThreadConnection> errorConnection = createConnection(errorConnectionEventRecorder); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 604 | mThread->setVsyncRate(1, errorConnection); |
| 605 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 606 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 607 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 608 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 609 | // The first event will be seen by the connection, which then returns a non-fatal error. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 610 | onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 611 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 612 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 613 | |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 614 | // A subsequent event will be seen by the connection, which still then returns a non-fatal |
| 615 | // error. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 616 | onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 617 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 456, 2u); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 618 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 619 | |
| 620 | // EventThread will not disable vsync callbacks as the errors are non-fatal. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 621 | onVSyncEvent(456, 123, 0); |
| 622 | expectVSyncCallbackScheduleReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | TEST_F(EventThreadTest, setPhaseOffsetForwardsToVSyncSource) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 626 | mThread->setDuration(321ns, 456ns); |
| 627 | expectVSyncSetDurationCallReceived(321ns, 456ns); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 630 | TEST_F(EventThreadTest, postHotplugInternalDisconnect) { |
| 631 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false); |
| 632 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 635 | TEST_F(EventThreadTest, postHotplugInternalConnect) { |
| 636 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true); |
| 637 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | TEST_F(EventThreadTest, postHotplugExternalDisconnect) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 641 | mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, false); |
| 642 | expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | TEST_F(EventThreadTest, postHotplugExternalConnect) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 646 | mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, true); |
| 647 | expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 650 | TEST_F(EventThreadTest, postConfigChangedPrimary) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 651 | const auto mode = DisplayMode::Builder(hal::HWConfigId(0)) |
| 652 | .setPhysicalDisplayId(INTERNAL_DISPLAY_ID) |
| 653 | .setId(DisplayModeId(7)) |
| 654 | .setVsyncPeriod(16666666) |
| 655 | .build(); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 656 | const Fps fps = mode->getFps() / 2; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 657 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 658 | mThread->onModeChanged({fps, ftl::as_non_null(mode)}); |
| 659 | expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 7, fps.getPeriodNsecs()); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | TEST_F(EventThreadTest, postConfigChangedExternal) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 663 | const auto mode = DisplayMode::Builder(hal::HWConfigId(0)) |
| 664 | .setPhysicalDisplayId(EXTERNAL_DISPLAY_ID) |
| 665 | .setId(DisplayModeId(5)) |
| 666 | .setVsyncPeriod(16666666) |
| 667 | .build(); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 668 | const Fps fps = mode->getFps() / 2; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 669 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 670 | mThread->onModeChanged({fps, ftl::as_non_null(mode)}); |
| 671 | expectConfigChangedEventReceivedByConnection(EXTERNAL_DISPLAY_ID, 5, fps.getPeriodNsecs()); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Ady Abraham | af0ec27 | 2019-03-28 11:38:31 -0700 | [diff] [blame] | 674 | TEST_F(EventThreadTest, postConfigChangedPrimary64bit) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 675 | const auto mode = DisplayMode::Builder(hal::HWConfigId(0)) |
| 676 | .setPhysicalDisplayId(DISPLAY_ID_64BIT) |
| 677 | .setId(DisplayModeId(7)) |
| 678 | .setVsyncPeriod(16666666) |
| 679 | .build(); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 680 | const Fps fps = mode->getFps() / 2; |
| 681 | mThread->onModeChanged({fps, ftl::as_non_null(mode)}); |
| 682 | expectConfigChangedEventReceivedByConnection(DISPLAY_ID_64BIT, 7, fps.getPeriodNsecs()); |
Ady Abraham | af0ec27 | 2019-03-28 11:38:31 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 685 | TEST_F(EventThreadTest, suppressConfigChanged) { |
| 686 | ConnectionEventRecorder suppressConnectionEventRecorder{0}; |
| 687 | sp<MockEventThreadConnection> suppressConnection = |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 688 | createConnection(suppressConnectionEventRecorder); |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 689 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 690 | const auto mode = DisplayMode::Builder(hal::HWConfigId(0)) |
| 691 | .setPhysicalDisplayId(INTERNAL_DISPLAY_ID) |
| 692 | .setId(DisplayModeId(9)) |
| 693 | .setVsyncPeriod(16666666) |
| 694 | .build(); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 695 | const Fps fps = mode->getFps() / 2; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 696 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 697 | mThread->onModeChanged({fps, ftl::as_non_null(mode)}); |
| 698 | expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 9, fps.getPeriodNsecs()); |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 699 | |
| 700 | auto args = suppressConnectionEventRecorder.waitForCall(); |
| 701 | ASSERT_FALSE(args.has_value()); |
| 702 | } |
| 703 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 704 | TEST_F(EventThreadTest, postUidFrameRateMapping) { |
| 705 | const std::vector<FrameRateOverride> overrides = { |
| 706 | {.uid = 1, .frameRateHz = 20}, |
| 707 | {.uid = 3, .frameRateHz = 40}, |
| 708 | {.uid = 5, .frameRateHz = 60}, |
| 709 | }; |
| 710 | |
| 711 | mThread->onFrameRateOverridesChanged(INTERNAL_DISPLAY_ID, overrides); |
| 712 | expectUidFrameRateMappingEventReceivedByConnection(INTERNAL_DISPLAY_ID, overrides); |
| 713 | } |
| 714 | |
| 715 | TEST_F(EventThreadTest, suppressUidFrameRateMapping) { |
| 716 | const std::vector<FrameRateOverride> overrides = { |
| 717 | {.uid = 1, .frameRateHz = 20}, |
| 718 | {.uid = 3, .frameRateHz = 40}, |
| 719 | {.uid = 5, .frameRateHz = 60}, |
| 720 | }; |
| 721 | |
| 722 | ConnectionEventRecorder suppressConnectionEventRecorder{0}; |
| 723 | sp<MockEventThreadConnection> suppressConnection = |
| 724 | createConnection(suppressConnectionEventRecorder); |
| 725 | |
| 726 | mThread->onFrameRateOverridesChanged(INTERNAL_DISPLAY_ID, overrides); |
| 727 | expectUidFrameRateMappingEventReceivedByConnection(INTERNAL_DISPLAY_ID, overrides); |
| 728 | |
| 729 | auto args = suppressConnectionEventRecorder.waitForCall(); |
| 730 | ASSERT_FALSE(args.has_value()); |
| 731 | } |
| 732 | |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 733 | TEST_F(EventThreadTest, requestNextVsyncWithThrottleVsyncDoesntPostVSync) { |
| 734 | // Signal that we want the next vsync event to be posted to the throttled connection |
| 735 | mThread->requestNextVsync(mThrottledConnection); |
| 736 | |
| 737 | // EventThread should immediately request a resync. |
| 738 | EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value()); |
| 739 | |
| 740 | // EventThread should enable vsync callbacks. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 741 | expectVSyncCallbackScheduleReceived(true); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 742 | |
| 743 | // Use the received callback to signal a first vsync event. |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 744 | // The throttler should receive the event, but not the connection. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 745 | onVSyncEvent(123, 456, 789); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 746 | expectThrottleVsyncReceived(456, mThrottledConnectionUid); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 747 | mThrottledConnectionEventCallRecorder.waitForUnexpectedCall(); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 748 | expectVSyncCallbackScheduleReceived(true); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 749 | |
| 750 | // Use the received callback to signal a second vsync event. |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 751 | // The throttler should receive the event, but the connection should |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 752 | // not as it was only interested in the first. |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 753 | onVSyncEvent(456, 123, 0); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame^] | 754 | expectThrottleVsyncReceived(123, mThrottledConnectionUid); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 755 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 756 | expectVSyncCallbackScheduleReceived(true); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 757 | |
| 758 | // EventThread should not change the vsync state as it didn't send the event |
| 759 | // yet |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 760 | onVSyncEvent(456, 123, 0); |
| 761 | expectVSyncCallbackScheduleReceived(true); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 764 | } // namespace |
| 765 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 766 | |
| 767 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 768 | #pragma clang diagnostic pop // ignored "-Wextra" |