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