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