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