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