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 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 19 | |
| 20 | #include <gmock/gmock.h> |
| 21 | #include <gtest/gtest.h> |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 22 | #include <log/log.h> |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 23 | #include <utils/Errors.h> |
| 24 | |
| 25 | #include "AsyncCallRecorder.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 26 | #include "Scheduler/EventThread.h" |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 27 | #include "Scheduler/HwcStrongTypes.h" |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 28 | |
| 29 | using namespace std::chrono_literals; |
| 30 | using namespace std::placeholders; |
| 31 | |
| 32 | using testing::_; |
| 33 | using testing::Invoke; |
| 34 | |
| 35 | namespace android { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 36 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 37 | namespace { |
| 38 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 39 | constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID(111); |
| 40 | constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID(222); |
| 41 | constexpr PhysicalDisplayId DISPLAY_ID_64BIT(0xabcd12349876fedcULL); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 42 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 43 | class MockVSyncSource : public VSyncSource { |
| 44 | public: |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 45 | const char* getName() const override { return "test"; } |
| 46 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 47 | MOCK_METHOD1(setVSyncEnabled, void(bool)); |
| 48 | MOCK_METHOD1(setCallback, void(VSyncSource::Callback*)); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 49 | MOCK_METHOD2(setDuration, |
| 50 | void(std::chrono::nanoseconds workDuration, |
| 51 | std::chrono::nanoseconds readyDuration)); |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 52 | MOCK_METHOD1(pauseVsyncCallback, void(bool)); |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 53 | MOCK_CONST_METHOD1(dump, void(std::string&)); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | class EventThreadTest : public testing::Test { |
| 59 | protected: |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 60 | class MockEventThreadConnection : public EventThreadConnection { |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 61 | public: |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 62 | MockEventThreadConnection(impl::EventThread* eventThread, uid_t callingUid, |
| 63 | ResyncCallback&& resyncCallback, |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 64 | ISurfaceComposer::ConfigChanged configChanged) |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 65 | : EventThreadConnection(eventThread, callingUid, std::move(resyncCallback), |
| 66 | configChanged) {} |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 67 | MOCK_METHOD1(postEvent, status_t(const DisplayEventReceiver::Event& event)); |
| 68 | }; |
| 69 | |
| 70 | using ConnectionEventRecorder = |
| 71 | AsyncCallRecorderWithCannedReturn<status_t (*)(const DisplayEventReceiver::Event&)>; |
| 72 | |
| 73 | EventThreadTest(); |
| 74 | ~EventThreadTest() override; |
| 75 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 76 | void createThread(std::unique_ptr<VSyncSource>); |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 77 | sp<MockEventThreadConnection> createConnection(ConnectionEventRecorder& recorder, |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 78 | ISurfaceComposer::ConfigChanged configChanged, |
| 79 | uid_t ownerUid = mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 80 | |
| 81 | void expectVSyncSetEnabledCallReceived(bool expectedState); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 82 | void expectVSyncSetDurationCallReceived(std::chrono::nanoseconds expectedDuration, |
| 83 | std::chrono::nanoseconds expectedReadyDuration); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 84 | VSyncSource::Callback* expectVSyncSetCallbackCallReceived(); |
| 85 | void expectInterceptCallReceived(nsecs_t expectedTimestamp); |
| 86 | void expectVsyncEventReceivedByConnection(const char* name, |
| 87 | ConnectionEventRecorder& connectionEventRecorder, |
| 88 | nsecs_t expectedTimestamp, unsigned expectedCount); |
| 89 | void expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, unsigned expectedCount); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 90 | void expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 91 | bool expectedConnected); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 92 | void expectConfigChangedEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 93 | int32_t expectedConfigId, |
| 94 | nsecs_t expectedVsyncPeriod); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 95 | void expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 96 | |
| 97 | AsyncCallRecorder<void (*)(bool)> mVSyncSetEnabledCallRecorder; |
| 98 | AsyncCallRecorder<void (*)(VSyncSource::Callback*)> mVSyncSetCallbackCallRecorder; |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 99 | AsyncCallRecorder<void (*)(std::chrono::nanoseconds, std::chrono::nanoseconds)> |
| 100 | mVSyncSetDurationCallRecorder; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 101 | AsyncCallRecorder<void (*)()> mResyncCallRecorder; |
| 102 | AsyncCallRecorder<void (*)(nsecs_t)> mInterceptVSyncCallRecorder; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 103 | AsyncCallRecorder<void (*)(nsecs_t, uid_t)> mThrottleVsyncCallRecorder; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 104 | ConnectionEventRecorder mConnectionEventCallRecorder{0}; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 105 | ConnectionEventRecorder mThrottledConnectionEventCallRecorder{0}; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 106 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 107 | MockVSyncSource* mVSyncSource; |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 108 | VSyncSource::Callback* mCallback = nullptr; |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 109 | std::unique_ptr<impl::EventThread> mThread; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 110 | sp<MockEventThreadConnection> mConnection; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 111 | sp<MockEventThreadConnection> mThrottledConnection; |
| 112 | |
| 113 | static constexpr uid_t mConnectionUid = 443; |
| 114 | static constexpr uid_t mThrottledConnectionUid = 177; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | EventThreadTest::EventThreadTest() { |
| 118 | const ::testing::TestInfo* const test_info = |
| 119 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 120 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 121 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 122 | auto vsyncSource = std::make_unique<MockVSyncSource>(); |
| 123 | mVSyncSource = vsyncSource.get(); |
| 124 | |
| 125 | EXPECT_CALL(*mVSyncSource, setVSyncEnabled(_)) |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 126 | .WillRepeatedly(Invoke(mVSyncSetEnabledCallRecorder.getInvocable())); |
| 127 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 128 | EXPECT_CALL(*mVSyncSource, setCallback(_)) |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 129 | .WillRepeatedly(Invoke(mVSyncSetCallbackCallRecorder.getInvocable())); |
| 130 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 131 | EXPECT_CALL(*mVSyncSource, setDuration(_, _)) |
| 132 | .WillRepeatedly(Invoke(mVSyncSetDurationCallRecorder.getInvocable())); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 133 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 134 | createThread(std::move(vsyncSource)); |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 135 | mConnection = createConnection(mConnectionEventCallRecorder, |
| 136 | ISurfaceComposer::eConfigChangedDispatch); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 137 | mThrottledConnection = |
| 138 | createConnection(mThrottledConnectionEventCallRecorder, |
| 139 | ISurfaceComposer::eConfigChangedDispatch, mThrottledConnectionUid); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 140 | |
| 141 | // A display must be connected for VSYNC events to be delivered. |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 142 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true); |
| 143 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | EventThreadTest::~EventThreadTest() { |
| 147 | const ::testing::TestInfo* const test_info = |
| 148 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 149 | 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] | 150 | |
| 151 | // EventThread should unregister itself as VSyncSource callback. |
Lloyd Pique | 0655b8e | 2019-01-31 18:20:27 -0800 | [diff] [blame] | 152 | EXPECT_TRUE(!mVSyncSetCallbackCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 155 | void EventThreadTest::createThread(std::unique_ptr<VSyncSource> source) { |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 156 | const auto throttleVsync = [&](nsecs_t expectedVsyncTimestamp, uid_t uid) { |
| 157 | mThrottleVsyncCallRecorder.getInvocable()(expectedVsyncTimestamp, uid); |
| 158 | return (uid == mThrottledConnectionUid); |
| 159 | }; |
| 160 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 161 | mThread = std::make_unique<impl::EventThread>(std::move(source), |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 162 | /*tokenManager=*/nullptr, |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 163 | mInterceptVSyncCallRecorder.getInvocable(), |
| 164 | throttleVsync); |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 165 | |
| 166 | // EventThread should register itself as VSyncSource callback. |
| 167 | mCallback = expectVSyncSetCallbackCallReceived(); |
| 168 | ASSERT_TRUE(mCallback); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | sp<EventThreadTest::MockEventThreadConnection> EventThreadTest::createConnection( |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 172 | ConnectionEventRecorder& recorder, ISurfaceComposer::ConfigChanged configChanged, |
| 173 | uid_t ownerUid) { |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 174 | sp<MockEventThreadConnection> connection = |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 175 | new MockEventThreadConnection(mThread.get(), ownerUid, |
| 176 | mResyncCallRecorder.getInvocable(), configChanged); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 177 | EXPECT_CALL(*connection, postEvent(_)).WillRepeatedly(Invoke(recorder.getInvocable())); |
| 178 | return connection; |
| 179 | } |
| 180 | |
| 181 | void EventThreadTest::expectVSyncSetEnabledCallReceived(bool expectedState) { |
| 182 | auto args = mVSyncSetEnabledCallRecorder.waitForCall(); |
| 183 | ASSERT_TRUE(args.has_value()); |
| 184 | EXPECT_EQ(expectedState, std::get<0>(args.value())); |
| 185 | } |
| 186 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 187 | void EventThreadTest::expectVSyncSetDurationCallReceived( |
| 188 | std::chrono::nanoseconds expectedDuration, std::chrono::nanoseconds expectedReadyDuration) { |
| 189 | auto args = mVSyncSetDurationCallRecorder.waitForCall(); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 190 | ASSERT_TRUE(args.has_value()); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 191 | EXPECT_EQ(expectedDuration, std::get<0>(args.value())); |
| 192 | EXPECT_EQ(expectedReadyDuration, std::get<1>(args.value())); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | VSyncSource::Callback* EventThreadTest::expectVSyncSetCallbackCallReceived() { |
| 196 | auto callbackSet = mVSyncSetCallbackCallRecorder.waitForCall(); |
| 197 | return callbackSet.has_value() ? std::get<0>(callbackSet.value()) : nullptr; |
| 198 | } |
| 199 | |
| 200 | void EventThreadTest::expectInterceptCallReceived(nsecs_t expectedTimestamp) { |
| 201 | auto args = mInterceptVSyncCallRecorder.waitForCall(); |
| 202 | ASSERT_TRUE(args.has_value()); |
| 203 | EXPECT_EQ(expectedTimestamp, std::get<0>(args.value())); |
| 204 | } |
| 205 | |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 206 | void EventThreadTest::expectThrottleVsyncReceived(nsecs_t expectedTimestamp, uid_t uid) { |
| 207 | auto args = mThrottleVsyncCallRecorder.waitForCall(); |
| 208 | ASSERT_TRUE(args.has_value()); |
| 209 | EXPECT_EQ(expectedTimestamp, std::get<0>(args.value())); |
| 210 | EXPECT_EQ(uid, std::get<1>(args.value())); |
| 211 | } |
| 212 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 213 | void EventThreadTest::expectVsyncEventReceivedByConnection( |
| 214 | const char* name, ConnectionEventRecorder& connectionEventRecorder, |
| 215 | nsecs_t expectedTimestamp, unsigned expectedCount) { |
| 216 | auto args = connectionEventRecorder.waitForCall(); |
| 217 | ASSERT_TRUE(args.has_value()) << name << " did not receive an event for timestamp " |
| 218 | << expectedTimestamp; |
| 219 | const auto& event = std::get<0>(args.value()); |
| 220 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_VSYNC, event.header.type) |
| 221 | << name << " did not get the correct event for timestamp " << expectedTimestamp; |
| 222 | EXPECT_EQ(expectedTimestamp, event.header.timestamp) |
| 223 | << name << " did not get the expected timestamp for timestamp " << expectedTimestamp; |
| 224 | EXPECT_EQ(expectedCount, event.vsync.count) |
| 225 | << name << " did not get the expected count for timestamp " << expectedTimestamp; |
| 226 | } |
| 227 | |
| 228 | void EventThreadTest::expectVsyncEventReceivedByConnection(nsecs_t expectedTimestamp, |
| 229 | unsigned expectedCount) { |
| 230 | expectVsyncEventReceivedByConnection("mConnectionEventCallRecorder", |
| 231 | mConnectionEventCallRecorder, expectedTimestamp, |
| 232 | expectedCount); |
| 233 | } |
| 234 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 235 | void EventThreadTest::expectHotplugEventReceivedByConnection(PhysicalDisplayId expectedDisplayId, |
| 236 | bool expectedConnected) { |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 237 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 238 | ASSERT_TRUE(args.has_value()); |
| 239 | const auto& event = std::get<0>(args.value()); |
| 240 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, event.header.type); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 241 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 242 | EXPECT_EQ(expectedConnected, event.hotplug.connected); |
| 243 | } |
| 244 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 245 | void EventThreadTest::expectConfigChangedEventReceivedByConnection( |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 246 | PhysicalDisplayId expectedDisplayId, int32_t expectedConfigId, |
| 247 | nsecs_t expectedVsyncPeriod) { |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 248 | auto args = mConnectionEventCallRecorder.waitForCall(); |
| 249 | ASSERT_TRUE(args.has_value()); |
| 250 | const auto& event = std::get<0>(args.value()); |
| 251 | EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, event.header.type); |
| 252 | EXPECT_EQ(expectedDisplayId, event.header.displayId); |
| 253 | EXPECT_EQ(expectedConfigId, event.config.configId); |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 254 | EXPECT_EQ(expectedVsyncPeriod, event.config.vsyncPeriod); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 257 | namespace { |
| 258 | |
| 259 | /* ------------------------------------------------------------------------ |
| 260 | * Test cases |
| 261 | */ |
| 262 | |
| 263 | TEST_F(EventThreadTest, canCreateAndDestroyThreadWithNoEventsSent) { |
| 264 | EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value()); |
| 265 | EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value()); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 266 | EXPECT_FALSE(mVSyncSetDurationCallRecorder.waitForCall(0us).has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 267 | EXPECT_FALSE(mResyncCallRecorder.waitForCall(0us).has_value()); |
| 268 | EXPECT_FALSE(mInterceptVSyncCallRecorder.waitForCall(0us).has_value()); |
| 269 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForCall(0us).has_value()); |
| 270 | } |
| 271 | |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 272 | TEST_F(EventThreadTest, vsyncRequestIsIgnoredIfDisplayIsDisconnected) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 273 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false); |
| 274 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 275 | |
| 276 | // 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] | 277 | mThread->requestNextVsync(mConnection); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 278 | |
| 279 | // EventThread should not enable vsync callbacks. |
| 280 | EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value()); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 283 | TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) { |
| 284 | // 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] | 285 | mThread->requestNextVsync(mConnection); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 286 | |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 287 | // EventThread should immediately request a resync. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 288 | EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value()); |
| 289 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 290 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 291 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 292 | |
| 293 | // Use the received callback to signal a first vsync event. |
| 294 | // The interceptor should receive the event, as well as the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 295 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 296 | expectInterceptCallReceived(123); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 297 | expectThrottleVsyncReceived(456, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 298 | expectVsyncEventReceivedByConnection(123, 1u); |
| 299 | |
| 300 | // Use the received callback to signal a second vsync event. |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 301 | // The interceptor should receive the event, but the connection should |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 302 | // not as it was only interested in the first. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 303 | mCallback->onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 304 | expectInterceptCallReceived(456); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 305 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 306 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
| 307 | |
| 308 | // EventThread should also detect that at this point that it does not need |
| 309 | // any more vsync events, and should disable their generation. |
| 310 | expectVSyncSetEnabledCallReceived(false); |
| 311 | } |
| 312 | |
| 313 | TEST_F(EventThreadTest, setVsyncRateZeroPostsNoVSyncEventsToThatConnection) { |
| 314 | // Create a first connection, register it, and request a vsync rate of zero. |
| 315 | ConnectionEventRecorder firstConnectionEventRecorder{0}; |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 316 | sp<MockEventThreadConnection> firstConnection = |
| 317 | createConnection(firstConnectionEventRecorder, |
| 318 | ISurfaceComposer::eConfigChangedSuppress); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 319 | mThread->setVsyncRate(0, firstConnection); |
| 320 | |
| 321 | // By itself, this should not enable vsync events |
| 322 | EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value()); |
| 323 | EXPECT_FALSE(mVSyncSetCallbackCallRecorder.waitForCall(0us).has_value()); |
| 324 | |
| 325 | // However if there is another connection which wants events at a nonzero rate..... |
| 326 | ConnectionEventRecorder secondConnectionEventRecorder{0}; |
| 327 | sp<MockEventThreadConnection> secondConnection = |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 328 | createConnection(secondConnectionEventRecorder, |
| 329 | ISurfaceComposer::eConfigChangedSuppress); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 330 | mThread->setVsyncRate(1, secondConnection); |
| 331 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 332 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 333 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 334 | |
| 335 | // Send a vsync event. EventThread should then make a call to the |
| 336 | // interceptor, and the second connection. The first connection should not |
| 337 | // get the event. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 338 | mCallback->onVSyncEvent(123, 456, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 339 | expectInterceptCallReceived(123); |
| 340 | EXPECT_FALSE(firstConnectionEventRecorder.waitForUnexpectedCall().has_value()); |
| 341 | expectVsyncEventReceivedByConnection("secondConnection", secondConnectionEventRecorder, 123, |
| 342 | 1u); |
| 343 | } |
| 344 | |
| 345 | TEST_F(EventThreadTest, setVsyncRateOnePostsAllEventsToThatConnection) { |
| 346 | mThread->setVsyncRate(1, mConnection); |
| 347 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 348 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 349 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 350 | |
| 351 | // Send a vsync event. EventThread should then make a call to the |
| 352 | // interceptor, and the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 353 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 354 | expectInterceptCallReceived(123); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 355 | expectThrottleVsyncReceived(456, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 356 | expectVsyncEventReceivedByConnection(123, 1u); |
| 357 | |
| 358 | // A second event should go to the same places. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 359 | mCallback->onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 360 | expectInterceptCallReceived(456); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 361 | expectThrottleVsyncReceived(123, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 362 | expectVsyncEventReceivedByConnection(456, 2u); |
| 363 | |
| 364 | // A third event should go to the same places. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 365 | mCallback->onVSyncEvent(789, 777, 111); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 366 | expectInterceptCallReceived(789); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 367 | expectThrottleVsyncReceived(777, mConnectionUid); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 368 | expectVsyncEventReceivedByConnection(789, 3u); |
| 369 | } |
| 370 | |
| 371 | TEST_F(EventThreadTest, setVsyncRateTwoPostsEveryOtherEventToThatConnection) { |
| 372 | mThread->setVsyncRate(2, mConnection); |
| 373 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 374 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 375 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 376 | |
| 377 | // The first event will be seen by the interceptor, and not the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 378 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 379 | expectInterceptCallReceived(123); |
| 380 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 381 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 382 | |
| 383 | // The second event will be seen by the interceptor and the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 384 | mCallback->onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 385 | expectInterceptCallReceived(456); |
| 386 | expectVsyncEventReceivedByConnection(456, 2u); |
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 | |
| 389 | // The third event will be seen by the interceptor, and not the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 390 | mCallback->onVSyncEvent(789, 777, 744); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 391 | expectInterceptCallReceived(789); |
| 392 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 393 | EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 394 | |
| 395 | // The fourth event will be seen by the interceptor and the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 396 | mCallback->onVSyncEvent(101112, 7847, 86); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 397 | expectInterceptCallReceived(101112); |
| 398 | expectVsyncEventReceivedByConnection(101112, 4u); |
| 399 | } |
| 400 | |
| 401 | TEST_F(EventThreadTest, connectionsRemovedIfInstanceDestroyed) { |
| 402 | mThread->setVsyncRate(1, mConnection); |
| 403 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 404 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 405 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 406 | |
| 407 | // Destroy the only (strong) reference to the connection. |
| 408 | mConnection = nullptr; |
| 409 | |
| 410 | // The first event will be seen by the interceptor, and not the connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 411 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 412 | expectInterceptCallReceived(123); |
| 413 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
| 414 | |
| 415 | // EventThread should disable vsync callbacks |
| 416 | expectVSyncSetEnabledCallReceived(false); |
| 417 | } |
| 418 | |
| 419 | TEST_F(EventThreadTest, connectionsRemovedIfEventDeliveryError) { |
| 420 | ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY}; |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 421 | sp<MockEventThreadConnection> errorConnection = |
| 422 | createConnection(errorConnectionEventRecorder, |
| 423 | ISurfaceComposer::eConfigChangedSuppress); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 424 | mThread->setVsyncRate(1, errorConnection); |
| 425 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 426 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 427 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 428 | |
| 429 | // The first event will be seen by the interceptor, and by the connection, |
| 430 | // which then returns an error. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 431 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 432 | expectInterceptCallReceived(123); |
| 433 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
| 434 | |
| 435 | // A subsequent event will be seen by the interceptor and not by the |
| 436 | // connection. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 437 | mCallback->onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 438 | expectInterceptCallReceived(456); |
| 439 | EXPECT_FALSE(errorConnectionEventRecorder.waitForUnexpectedCall().has_value()); |
| 440 | |
| 441 | // EventThread should disable vsync callbacks with the second event |
| 442 | expectVSyncSetEnabledCallReceived(false); |
| 443 | } |
| 444 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 445 | TEST_F(EventThreadTest, tracksEventConnections) { |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 446 | EXPECT_EQ(2, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 447 | ConnectionEventRecorder errorConnectionEventRecorder{NO_MEMORY}; |
| 448 | sp<MockEventThreadConnection> errorConnection = |
| 449 | createConnection(errorConnectionEventRecorder, |
| 450 | ISurfaceComposer::eConfigChangedSuppress); |
| 451 | mThread->setVsyncRate(1, errorConnection); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 452 | EXPECT_EQ(3, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 453 | ConnectionEventRecorder secondConnectionEventRecorder{0}; |
| 454 | sp<MockEventThreadConnection> secondConnection = |
| 455 | createConnection(secondConnectionEventRecorder, |
| 456 | ISurfaceComposer::eConfigChangedSuppress); |
| 457 | mThread->setVsyncRate(1, secondConnection); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 458 | EXPECT_EQ(4, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 459 | |
| 460 | // EventThread should enable vsync callbacks. |
| 461 | expectVSyncSetEnabledCallReceived(true); |
| 462 | |
| 463 | // The first event will be seen by the interceptor, and by the connection, |
| 464 | // which then returns an error. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 465 | mCallback->onVSyncEvent(123, 456, 789); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 466 | expectInterceptCallReceived(123); |
| 467 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
| 468 | expectVsyncEventReceivedByConnection("successConnection", secondConnectionEventRecorder, 123, |
| 469 | 1u); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 470 | EXPECT_EQ(3, mThread->getEventThreadConnectionCount()); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 473 | TEST_F(EventThreadTest, eventsDroppedIfNonfatalEventDeliveryError) { |
| 474 | ConnectionEventRecorder errorConnectionEventRecorder{WOULD_BLOCK}; |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 475 | sp<MockEventThreadConnection> errorConnection = |
| 476 | createConnection(errorConnectionEventRecorder, |
| 477 | ISurfaceComposer::eConfigChangedSuppress); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 478 | mThread->setVsyncRate(1, errorConnection); |
| 479 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 480 | // EventThread should enable vsync callbacks. |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 481 | expectVSyncSetEnabledCallReceived(true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 482 | |
| 483 | // The first event will be seen by the interceptor, and by the connection, |
| 484 | // which then returns an non-fatal error. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 485 | mCallback->onVSyncEvent(123, 456, 789); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 486 | expectInterceptCallReceived(123); |
| 487 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); |
| 488 | |
| 489 | // A subsequent event will be seen by the interceptor, and by the connection, |
| 490 | // which still then returns an non-fatal error. |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 491 | mCallback->onVSyncEvent(456, 123, 0); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 492 | expectInterceptCallReceived(456); |
| 493 | expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 456, 2u); |
| 494 | |
| 495 | // EventThread will not disable vsync callbacks as the errors are non-fatal. |
| 496 | EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value()); |
| 497 | } |
| 498 | |
| 499 | TEST_F(EventThreadTest, setPhaseOffsetForwardsToVSyncSource) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 500 | mThread->setDuration(321ns, 456ns); |
| 501 | expectVSyncSetDurationCallReceived(321ns, 456ns); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 504 | TEST_F(EventThreadTest, postHotplugInternalDisconnect) { |
| 505 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, false); |
| 506 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 509 | TEST_F(EventThreadTest, postHotplugInternalConnect) { |
| 510 | mThread->onHotplugReceived(INTERNAL_DISPLAY_ID, true); |
| 511 | expectHotplugEventReceivedByConnection(INTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | TEST_F(EventThreadTest, postHotplugExternalDisconnect) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 515 | mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, false); |
| 516 | expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, false); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | TEST_F(EventThreadTest, postHotplugExternalConnect) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 520 | mThread->onHotplugReceived(EXTERNAL_DISPLAY_ID, true); |
| 521 | expectHotplugEventReceivedByConnection(EXTERNAL_DISPLAY_ID, true); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 524 | TEST_F(EventThreadTest, postConfigChangedPrimary) { |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 525 | mThread->onConfigChanged(INTERNAL_DISPLAY_ID, HwcConfigIndexType(7), 16666666); |
| 526 | expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 7, 16666666); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | TEST_F(EventThreadTest, postConfigChangedExternal) { |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 530 | mThread->onConfigChanged(EXTERNAL_DISPLAY_ID, HwcConfigIndexType(5), 16666666); |
| 531 | expectConfigChangedEventReceivedByConnection(EXTERNAL_DISPLAY_ID, 5, 16666666); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Ady Abraham | af0ec27 | 2019-03-28 11:38:31 -0700 | [diff] [blame] | 534 | TEST_F(EventThreadTest, postConfigChangedPrimary64bit) { |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 535 | mThread->onConfigChanged(DISPLAY_ID_64BIT, HwcConfigIndexType(7), 16666666); |
| 536 | expectConfigChangedEventReceivedByConnection(DISPLAY_ID_64BIT, 7, 16666666); |
Ady Abraham | af0ec27 | 2019-03-28 11:38:31 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 539 | TEST_F(EventThreadTest, suppressConfigChanged) { |
| 540 | ConnectionEventRecorder suppressConnectionEventRecorder{0}; |
| 541 | sp<MockEventThreadConnection> suppressConnection = |
| 542 | createConnection(suppressConnectionEventRecorder, |
| 543 | ISurfaceComposer::eConfigChangedSuppress); |
| 544 | |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 545 | mThread->onConfigChanged(INTERNAL_DISPLAY_ID, HwcConfigIndexType(9), 16666666); |
| 546 | expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 9, 16666666); |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 547 | |
| 548 | auto args = suppressConnectionEventRecorder.waitForCall(); |
| 549 | ASSERT_FALSE(args.has_value()); |
| 550 | } |
| 551 | |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame^] | 552 | TEST_F(EventThreadTest, requestNextVsyncWithThrottleVsyncDoesntPostVSync) { |
| 553 | // Signal that we want the next vsync event to be posted to the throttled connection |
| 554 | mThread->requestNextVsync(mThrottledConnection); |
| 555 | |
| 556 | // EventThread should immediately request a resync. |
| 557 | EXPECT_TRUE(mResyncCallRecorder.waitForCall().has_value()); |
| 558 | |
| 559 | // EventThread should enable vsync callbacks. |
| 560 | expectVSyncSetEnabledCallReceived(true); |
| 561 | |
| 562 | // Use the received callback to signal a first vsync event. |
| 563 | // The interceptor should receive the event, but not the connection. |
| 564 | mCallback->onVSyncEvent(123, 456, 789); |
| 565 | expectInterceptCallReceived(123); |
| 566 | expectThrottleVsyncReceived(456, mThrottledConnectionUid); |
| 567 | mThrottledConnectionEventCallRecorder.waitForUnexpectedCall(); |
| 568 | |
| 569 | // Use the received callback to signal a second vsync event. |
| 570 | // The interceptor should receive the event, but the connection should |
| 571 | // not as it was only interested in the first. |
| 572 | mCallback->onVSyncEvent(456, 123, 0); |
| 573 | expectInterceptCallReceived(456); |
| 574 | expectThrottleVsyncReceived(123, mThrottledConnectionUid); |
| 575 | EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |
| 576 | |
| 577 | // EventThread should not change the vsync state as it didn't send the event |
| 578 | // yet |
| 579 | EXPECT_FALSE(mVSyncSetEnabledCallRecorder.waitForUnexpectedCall().has_value()); |
| 580 | } |
| 581 | |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 582 | } // namespace |
| 583 | } // namespace android |