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