blob: 82daffd28d84af412d8a5a70bd50f82774442cd4 [file] [log] [blame]
Kevin DuBois305bef12019-10-09 13:23:27 -07001/*
2 * Copyright 2019 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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010020#pragma clang diagnostic ignored "-Wextra"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080021
Kevin DuBois305bef12019-10-09 13:23:27 -070022#undef LOG_TAG
23#define LOG_TAG "LibSurfaceFlingerUnittests"
24#define LOG_NDEBUG 0
25
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -080026#include <thread>
Kevin DuBois305bef12019-10-09 13:23:27 -070027
28#include <gmock/gmock.h>
29#include <gtest/gtest.h>
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -080030
31#include <scheduler/TimeKeeper.h>
32
33#include "Scheduler/VSyncDispatchTimerQueue.h"
34#include "Scheduler/VSyncTracker.h"
Kevin DuBois305bef12019-10-09 13:23:27 -070035
36using namespace testing;
37using namespace std::literals;
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -080038
Kevin DuBois305bef12019-10-09 13:23:27 -070039namespace android::scheduler {
40
41class MockVSyncTracker : public VSyncTracker {
42public:
43 MockVSyncTracker(nsecs_t period) : mPeriod{period} {
44 ON_CALL(*this, nextAnticipatedVSyncTimeFrom(_))
45 .WillByDefault(Invoke(this, &MockVSyncTracker::nextVSyncTime));
Kevin DuBois02d5ed92020-01-27 11:05:46 -080046 ON_CALL(*this, addVsyncTimestamp(_)).WillByDefault(Return(true));
Ady Abraham3fcfd8b2022-07-12 12:31:00 -070047 ON_CALL(*this, currentPeriod())
48 .WillByDefault(Invoke(this, &MockVSyncTracker::getCurrentPeriod));
Kevin DuBois305bef12019-10-09 13:23:27 -070049 }
50
Kevin DuBois02d5ed92020-01-27 11:05:46 -080051 MOCK_METHOD1(addVsyncTimestamp, bool(nsecs_t));
Kevin DuBois305bef12019-10-09 13:23:27 -070052 MOCK_CONST_METHOD1(nextAnticipatedVSyncTimeFrom, nsecs_t(nsecs_t));
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080053 MOCK_CONST_METHOD0(currentPeriod, nsecs_t());
Kevin DuBoisee2ad9f2019-11-21 11:10:57 -080054 MOCK_METHOD1(setPeriod, void(nsecs_t));
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -080055 MOCK_METHOD0(resetModel, void());
Kevin DuBoisb818bfa2020-07-10 14:29:36 -070056 MOCK_CONST_METHOD0(needsMoreSamples, bool());
Ady Abraham5cc2e262021-03-25 13:09:17 -070057 MOCK_CONST_METHOD2(isVSyncInPhase, bool(nsecs_t, Fps));
Ady Abrahamace3d052022-11-17 16:25:05 -080058 MOCK_METHOD(void, setDivisor, (unsigned), (override));
Ady Abraham5e7371c2020-03-24 14:47:24 -070059 MOCK_CONST_METHOD1(dump, void(std::string&));
Kevin DuBois305bef12019-10-09 13:23:27 -070060
61 nsecs_t nextVSyncTime(nsecs_t timePoint) const {
62 if (timePoint % mPeriod == 0) {
63 return timePoint;
64 }
65 return (timePoint - (timePoint % mPeriod) + mPeriod);
66 }
67
Ady Abraham3fcfd8b2022-07-12 12:31:00 -070068 nsecs_t getCurrentPeriod() const { return mPeriod; }
69
Kevin DuBois305bef12019-10-09 13:23:27 -070070protected:
71 nsecs_t const mPeriod;
72};
73
74class ControllableClock : public TimeKeeper {
75public:
76 ControllableClock() {
Ady Abrahamb491c902020-08-15 15:47:56 -070077 ON_CALL(*this, alarmAt(_, _))
78 .WillByDefault(Invoke(this, &ControllableClock::alarmAtDefaultBehavior));
Kevin DuBois305bef12019-10-09 13:23:27 -070079 ON_CALL(*this, now()).WillByDefault(Invoke(this, &ControllableClock::fakeTime));
80 }
81
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -080082 MOCK_METHOD(nsecs_t, now, (), (const));
83 MOCK_METHOD(void, alarmAt, (std::function<void()>, nsecs_t), (override));
84 MOCK_METHOD(void, alarmCancel, (), (override));
85 MOCK_METHOD(void, dump, (std::string&), (const, override));
Kevin DuBois305bef12019-10-09 13:23:27 -070086
Ady Abrahamb491c902020-08-15 15:47:56 -070087 void alarmAtDefaultBehavior(std::function<void()> const& callback, nsecs_t time) {
Kevin DuBois305bef12019-10-09 13:23:27 -070088 mCallback = callback;
Ady Abrahamb491c902020-08-15 15:47:56 -070089 mNextCallbackTime = time;
Kevin DuBois305bef12019-10-09 13:23:27 -070090 }
91
92 nsecs_t fakeTime() const { return mCurrentTime; }
93
94 void advanceToNextCallback() {
95 mCurrentTime = mNextCallbackTime;
96 if (mCallback) {
97 mCallback();
98 }
99 }
100
101 void advanceBy(nsecs_t advancement) {
102 mCurrentTime += advancement;
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700103 if (mCurrentTime >= (mNextCallbackTime + mLag) && mCallback) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700104 mCallback();
105 }
106 };
107
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700108 void setLag(nsecs_t lag) { mLag = lag; }
109
Kevin DuBois305bef12019-10-09 13:23:27 -0700110private:
111 std::function<void()> mCallback;
112 nsecs_t mNextCallbackTime = 0;
113 nsecs_t mCurrentTime = 0;
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700114 nsecs_t mLag = 0;
Kevin DuBois305bef12019-10-09 13:23:27 -0700115};
116
117class CountingCallback {
118public:
Leon Scroggins III31d41412022-11-18 16:42:53 -0500119 CountingCallback(std::shared_ptr<VSyncDispatch> dispatch)
120 : mDispatch(std::move(dispatch)),
121 mToken(mDispatch->registerCallback(std::bind(&CountingCallback::counter, this,
122 std::placeholders::_1,
123 std::placeholders::_2,
124 std::placeholders::_3),
125 "test")) {}
126 ~CountingCallback() { mDispatch->unregisterCallback(mToken); }
Kevin DuBois305bef12019-10-09 13:23:27 -0700127
128 operator VSyncDispatch::CallbackToken() const { return mToken; }
129
Ady Abraham9c53ee72020-07-22 21:16:18 -0700130 void counter(nsecs_t time, nsecs_t wakeup_time, nsecs_t readyTime) {
Kevin DuBoisf9477832020-07-16 10:21:36 -0700131 mCalls.push_back(time);
132 mWakeupTime.push_back(wakeup_time);
Ady Abraham9c53ee72020-07-22 21:16:18 -0700133 mReadyTime.push_back(readyTime);
Kevin DuBoisf9477832020-07-16 10:21:36 -0700134 }
Kevin DuBois305bef12019-10-09 13:23:27 -0700135
Leon Scroggins III31d41412022-11-18 16:42:53 -0500136 std::shared_ptr<VSyncDispatch> mDispatch;
Kevin DuBois305bef12019-10-09 13:23:27 -0700137 VSyncDispatch::CallbackToken mToken;
138 std::vector<nsecs_t> mCalls;
Kevin DuBoisf9477832020-07-16 10:21:36 -0700139 std::vector<nsecs_t> mWakeupTime;
Ady Abraham9c53ee72020-07-22 21:16:18 -0700140 std::vector<nsecs_t> mReadyTime;
Kevin DuBois305bef12019-10-09 13:23:27 -0700141};
142
143class PausingCallback {
144public:
Leon Scroggins III31d41412022-11-18 16:42:53 -0500145 PausingCallback(std::shared_ptr<VSyncDispatch> dispatch, std::chrono::milliseconds pauseAmount)
146 : mDispatch(std::move(dispatch)),
147 mToken(mDispatch->registerCallback(std::bind(&PausingCallback::pause, this,
148 std::placeholders::_1,
149 std::placeholders::_2),
150 "test")),
Kevin DuBois305bef12019-10-09 13:23:27 -0700151 mRegistered(true),
152 mPauseAmount(pauseAmount) {}
153 ~PausingCallback() { unregister(); }
154
155 operator VSyncDispatch::CallbackToken() const { return mToken; }
156
Kevin DuBois2968afc2020-01-14 09:48:50 -0800157 void pause(nsecs_t, nsecs_t) {
Ady Abraham8cb21882020-08-26 18:22:05 -0700158 std::unique_lock lock(mMutex);
Kevin DuBois305bef12019-10-09 13:23:27 -0700159 mPause = true;
160 mCv.notify_all();
161
Ady Abraham8cb21882020-08-26 18:22:05 -0700162 mCv.wait_for(lock, mPauseAmount, [this] { return !mPause; });
Kevin DuBois305bef12019-10-09 13:23:27 -0700163
164 mResourcePresent = (mResource.lock() != nullptr);
165 }
166
167 bool waitForPause() {
Ady Abraham8cb21882020-08-26 18:22:05 -0700168 std::unique_lock lock(mMutex);
169 auto waiting = mCv.wait_for(lock, 10s, [this] { return mPause; });
Kevin DuBois305bef12019-10-09 13:23:27 -0700170 return waiting;
171 }
172
173 void stashResource(std::weak_ptr<void> const& resource) { mResource = resource; }
174
175 bool resourcePresent() { return mResourcePresent; }
176
177 void unpause() {
Ady Abraham8cb21882020-08-26 18:22:05 -0700178 std::unique_lock lock(mMutex);
Kevin DuBois305bef12019-10-09 13:23:27 -0700179 mPause = false;
180 mCv.notify_all();
181 }
182
183 void unregister() {
184 if (mRegistered) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500185 mDispatch->unregisterCallback(mToken);
Kevin DuBois305bef12019-10-09 13:23:27 -0700186 mRegistered = false;
187 }
188 }
189
Leon Scroggins III31d41412022-11-18 16:42:53 -0500190 std::shared_ptr<VSyncDispatch> mDispatch;
Kevin DuBois305bef12019-10-09 13:23:27 -0700191 VSyncDispatch::CallbackToken mToken;
192 bool mRegistered = true;
193
194 std::mutex mMutex;
195 std::condition_variable mCv;
196 bool mPause = false;
197 std::weak_ptr<void> mResource;
198 bool mResourcePresent = false;
199 std::chrono::milliseconds const mPauseAmount;
200};
201
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800202class VSyncDispatchTimerQueueTest : public testing::Test {
Kevin DuBois305bef12019-10-09 13:23:27 -0700203protected:
204 std::unique_ptr<TimeKeeper> createTimeKeeper() {
205 class TimeKeeperWrapper : public TimeKeeper {
206 public:
207 TimeKeeperWrapper(TimeKeeper& control) : mControllableClock(control) {}
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -0800208
Kevin DuBois305bef12019-10-09 13:23:27 -0700209 nsecs_t now() const final { return mControllableClock.now(); }
Dominik Laskowski4e0d20d2021-12-06 11:31:02 -0800210
211 void alarmAt(std::function<void()> callback, nsecs_t time) final {
212 mControllableClock.alarmAt(std::move(callback), time);
213 }
214
215 void alarmCancel() final { mControllableClock.alarmCancel(); }
Ady Abraham75398722020-04-07 14:08:45 -0700216 void dump(std::string&) const final {}
Kevin DuBois305bef12019-10-09 13:23:27 -0700217
218 private:
219 TimeKeeper& mControllableClock;
220 };
221 return std::make_unique<TimeKeeperWrapper>(mMockClock);
222 }
223
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800224 ~VSyncDispatchTimerQueueTest() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700225 // destructor of dispatch will cancelAlarm(). Ignore final cancel in common test.
226 Mock::VerifyAndClearExpectations(&mMockClock);
227 }
228
229 void advanceToNextCallback() { mMockClock.advanceToNextCallback(); }
230
231 NiceMock<ControllableClock> mMockClock;
232 static nsecs_t constexpr mDispatchGroupThreshold = 5;
233 nsecs_t const mPeriod = 1000;
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800234 nsecs_t const mVsyncMoveThreshold = 300;
Leon Scroggins III31d41412022-11-18 16:42:53 -0500235 std::shared_ptr<NiceMock<MockVSyncTracker>> mStubTracker =
236 std::make_shared<NiceMock<MockVSyncTracker>>(mPeriod);
237 std::shared_ptr<VSyncDispatch> mDispatch =
238 std::make_shared<VSyncDispatchTimerQueue>(createTimeKeeper(), mStubTracker,
239 mDispatchGroupThreshold, mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -0700240};
241
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800242TEST_F(VSyncDispatchTimerQueueTest, unregistersSetAlarmOnDestruction) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700243 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700244 EXPECT_CALL(mMockClock, alarmCancel());
245 {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500246 std::shared_ptr<VSyncDispatch> mDispatch =
247 std::make_shared<VSyncDispatchTimerQueue>(createTimeKeeper(), mStubTracker,
248 mDispatchGroupThreshold,
249 mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -0700250 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500251 const auto result = mDispatch->schedule(cb,
252 {.workDuration = 100,
253 .readyDuration = 0,
254 .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700255 EXPECT_TRUE(result.has_value());
256 EXPECT_EQ(900, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700257 }
258}
259
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800260TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFuture) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700261 auto intended = mPeriod - 230;
Ady Abrahamb491c902020-08-15 15:47:56 -0700262 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700263
264 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500265 const auto result = mDispatch->schedule(cb,
266 {.workDuration = 100,
267 .readyDuration = 0,
268 .earliestVsync = intended});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700269 EXPECT_TRUE(result.has_value());
270 EXPECT_EQ(900, *result);
271
Kevin DuBois305bef12019-10-09 13:23:27 -0700272 advanceToNextCallback();
273
274 ASSERT_THAT(cb.mCalls.size(), Eq(1));
275 EXPECT_THAT(cb.mCalls[0], Eq(mPeriod));
276}
277
Ady Abraham011f8ba2022-11-22 15:09:07 -0800278TEST_F(VSyncDispatchTimerQueueTest, updateAlarmSettingFuture) {
279 auto intended = mPeriod - 230;
280 Sequence seq;
281 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
282 EXPECT_CALL(mMockClock, alarmAt(_, 700)).InSequence(seq);
283
284 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500285 auto result = mDispatch->schedule(cb,
286 {.workDuration = 100,
287 .readyDuration = 0,
288 .earliestVsync = intended});
Ady Abraham011f8ba2022-11-22 15:09:07 -0800289 EXPECT_TRUE(result.has_value());
290 EXPECT_EQ(900, *result);
291
Leon Scroggins III31d41412022-11-18 16:42:53 -0500292 result =
293 mDispatch->update(cb,
Ady Abraham011f8ba2022-11-22 15:09:07 -0800294 {.workDuration = 300, .readyDuration = 0, .earliestVsync = intended});
295 EXPECT_TRUE(result.has_value());
296 EXPECT_EQ(700, *result);
297
298 advanceToNextCallback();
299
300 ASSERT_THAT(cb.mCalls.size(), Eq(1));
301 EXPECT_THAT(cb.mCalls[0], Eq(mPeriod));
302 EXPECT_THAT(cb.mWakeupTime[0], Eq(700));
303}
304
305TEST_F(VSyncDispatchTimerQueueTest, updateDoesntSchedule) {
306 auto intended = mPeriod - 230;
307 EXPECT_CALL(mMockClock, alarmAt(_, _)).Times(0);
308
309 CountingCallback cb(mDispatch);
310 const auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500311 mDispatch->update(cb,
312 {.workDuration = 300, .readyDuration = 0, .earliestVsync = intended});
Ady Abraham011f8ba2022-11-22 15:09:07 -0800313 EXPECT_FALSE(result.has_value());
314}
315
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800316TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFutureWithAdjustmentToTrueVsync) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500317 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000)).WillOnce(Return(1150));
Ady Abrahamb491c902020-08-15 15:47:56 -0700318 EXPECT_CALL(mMockClock, alarmAt(_, 1050));
Kevin DuBois305bef12019-10-09 13:23:27 -0700319
320 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500321 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = mPeriod});
Kevin DuBois305bef12019-10-09 13:23:27 -0700322 advanceToNextCallback();
323
324 ASSERT_THAT(cb.mCalls.size(), Eq(1));
325 EXPECT_THAT(cb.mCalls[0], Eq(1150));
326}
327
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800328TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingAdjustmentPast) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700329 auto const now = 234;
330 mMockClock.advanceBy(234);
331 auto const workDuration = 10 * mPeriod;
Leon Scroggins III31d41412022-11-18 16:42:53 -0500332 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(now + workDuration))
Kevin DuBois305bef12019-10-09 13:23:27 -0700333 .WillOnce(Return(mPeriod * 11));
Ady Abrahamb491c902020-08-15 15:47:56 -0700334 EXPECT_CALL(mMockClock, alarmAt(_, mPeriod));
Kevin DuBois305bef12019-10-09 13:23:27 -0700335
336 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500337 const auto result = mDispatch->schedule(cb,
338 {.workDuration = workDuration,
339 .readyDuration = 0,
340 .earliestVsync = mPeriod});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700341 EXPECT_TRUE(result.has_value());
342 EXPECT_EQ(mPeriod, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700343}
344
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800345TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancel) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700346 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700347 EXPECT_CALL(mMockClock, alarmCancel());
348
349 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500350 const auto result = mDispatch->schedule(cb,
351 {.workDuration = 100,
352 .readyDuration = 0,
353 .earliestVsync = mPeriod});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700354 EXPECT_TRUE(result.has_value());
355 EXPECT_EQ(mPeriod - 100, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500356 EXPECT_EQ(mDispatch->cancel(cb), CancelResult::Cancelled);
Kevin DuBois305bef12019-10-09 13:23:27 -0700357}
358
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800359TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancelTooLate) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700360 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700361 EXPECT_CALL(mMockClock, alarmCancel());
362
363 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500364 const auto result = mDispatch->schedule(cb,
365 {.workDuration = 100,
366 .readyDuration = 0,
367 .earliestVsync = mPeriod});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700368 EXPECT_TRUE(result.has_value());
369 EXPECT_EQ(mPeriod - 100, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700370 mMockClock.advanceBy(950);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500371 EXPECT_EQ(mDispatch->cancel(cb), CancelResult::TooLate);
Kevin DuBois305bef12019-10-09 13:23:27 -0700372}
373
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800374TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancelTooLateWhenRunning) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700375 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700376 EXPECT_CALL(mMockClock, alarmCancel());
377
378 PausingCallback cb(mDispatch, std::chrono::duration_cast<std::chrono::milliseconds>(1s));
Leon Scroggins III31d41412022-11-18 16:42:53 -0500379 const auto result = mDispatch->schedule(cb,
380 {.workDuration = 100,
381 .readyDuration = 0,
382 .earliestVsync = mPeriod});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700383 EXPECT_TRUE(result.has_value());
384 EXPECT_EQ(mPeriod - 100, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700385
386 std::thread pausingThread([&] { mMockClock.advanceToNextCallback(); });
387 EXPECT_TRUE(cb.waitForPause());
Leon Scroggins III31d41412022-11-18 16:42:53 -0500388 EXPECT_EQ(mDispatch->cancel(cb), CancelResult::TooLate);
Kevin DuBois305bef12019-10-09 13:23:27 -0700389 cb.unpause();
390 pausingThread.join();
391}
392
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800393TEST_F(VSyncDispatchTimerQueueTest, unregisterSynchronizes) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700394 EXPECT_CALL(mMockClock, alarmAt(_, 900));
Kevin DuBois305bef12019-10-09 13:23:27 -0700395 EXPECT_CALL(mMockClock, alarmCancel());
396
397 auto resource = std::make_shared<int>(110);
398
399 PausingCallback cb(mDispatch, 50ms);
400 cb.stashResource(resource);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500401 const auto result = mDispatch->schedule(cb,
402 {.workDuration = 100,
403 .readyDuration = 0,
404 .earliestVsync = mPeriod});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700405 EXPECT_TRUE(result.has_value());
406 EXPECT_EQ(mPeriod - 100, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700407
408 std::thread pausingThread([&] { mMockClock.advanceToNextCallback(); });
409 EXPECT_TRUE(cb.waitForPause());
410
411 cb.unregister();
412 resource.reset();
413
414 cb.unpause();
415 pausingThread.join();
416
417 EXPECT_TRUE(cb.resourcePresent());
418}
419
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800420TEST_F(VSyncDispatchTimerQueueTest, basicTwoAlarmSetting) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500421 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000))
Kevin DuBois305bef12019-10-09 13:23:27 -0700422 .Times(4)
423 .WillOnce(Return(1055))
424 .WillOnce(Return(1063))
425 .WillOnce(Return(1063))
426 .WillOnce(Return(1075));
427
428 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700429 EXPECT_CALL(mMockClock, alarmAt(_, 955)).InSequence(seq);
430 EXPECT_CALL(mMockClock, alarmAt(_, 813)).InSequence(seq);
431 EXPECT_CALL(mMockClock, alarmAt(_, 975)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700432
433 CountingCallback cb0(mDispatch);
434 CountingCallback cb1(mDispatch);
435
Leon Scroggins III31d41412022-11-18 16:42:53 -0500436 mDispatch->schedule(cb0, {.workDuration = 100, .readyDuration = 0, .earliestVsync = mPeriod});
437 mDispatch->schedule(cb1, {.workDuration = 250, .readyDuration = 0, .earliestVsync = mPeriod});
Kevin DuBois305bef12019-10-09 13:23:27 -0700438
439 advanceToNextCallback();
440 advanceToNextCallback();
441
442 ASSERT_THAT(cb0.mCalls.size(), Eq(1));
443 EXPECT_THAT(cb0.mCalls[0], Eq(1075));
444 ASSERT_THAT(cb1.mCalls.size(), Eq(1));
445 EXPECT_THAT(cb1.mCalls[0], Eq(1063));
446}
447
Ady Abraham3fcfd8b2022-07-12 12:31:00 -0700448TEST_F(VSyncDispatchTimerQueueTest, noCloseCallbacksAfterPeriodChange) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500449 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(_))
Ady Abraham3fcfd8b2022-07-12 12:31:00 -0700450 .Times(4)
451 .WillOnce(Return(1000))
452 .WillOnce(Return(2000))
453 .WillOnce(Return(2500))
454 .WillOnce(Return(4000));
455
456 Sequence seq;
457 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
458 EXPECT_CALL(mMockClock, alarmAt(_, 1900)).InSequence(seq);
459 EXPECT_CALL(mMockClock, alarmAt(_, 3900)).InSequence(seq);
460
461 CountingCallback cb(mDispatch);
462
Leon Scroggins III31d41412022-11-18 16:42:53 -0500463 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 0});
Ady Abraham3fcfd8b2022-07-12 12:31:00 -0700464
465 advanceToNextCallback();
466
467 ASSERT_THAT(cb.mCalls.size(), Eq(1));
468 EXPECT_THAT(cb.mCalls[0], Eq(1000));
469
Leon Scroggins III31d41412022-11-18 16:42:53 -0500470 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Ady Abraham3fcfd8b2022-07-12 12:31:00 -0700471
472 advanceToNextCallback();
473
474 ASSERT_THAT(cb.mCalls.size(), Eq(2));
475 EXPECT_THAT(cb.mCalls[1], Eq(2000));
476
Leon Scroggins III31d41412022-11-18 16:42:53 -0500477 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2000});
Ady Abraham3fcfd8b2022-07-12 12:31:00 -0700478
479 advanceToNextCallback();
480
481 ASSERT_THAT(cb.mCalls.size(), Eq(3));
482 EXPECT_THAT(cb.mCalls[2], Eq(4000));
483}
484
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800485TEST_F(VSyncDispatchTimerQueueTest, rearmsFaroutTimeoutWhenCancellingCloseOne) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500486 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(_))
Kevin DuBois305bef12019-10-09 13:23:27 -0700487 .Times(4)
488 .WillOnce(Return(10000))
489 .WillOnce(Return(1000))
490 .WillOnce(Return(10000))
491 .WillOnce(Return(10000));
492
493 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700494 EXPECT_CALL(mMockClock, alarmAt(_, 9900)).InSequence(seq);
495 EXPECT_CALL(mMockClock, alarmAt(_, 750)).InSequence(seq);
496 EXPECT_CALL(mMockClock, alarmAt(_, 9900)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700497
498 CountingCallback cb0(mDispatch);
499 CountingCallback cb1(mDispatch);
500
Leon Scroggins III31d41412022-11-18 16:42:53 -0500501 mDispatch->schedule(cb0,
502 {.workDuration = 100, .readyDuration = 0, .earliestVsync = mPeriod * 10});
503 mDispatch->schedule(cb1, {.workDuration = 250, .readyDuration = 0, .earliestVsync = mPeriod});
504 mDispatch->cancel(cb1);
Kevin DuBois305bef12019-10-09 13:23:27 -0700505}
506
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800507TEST_F(VSyncDispatchTimerQueueTest, noUnnecessaryRearmsWhenRescheduling) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700508 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700509 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
510 EXPECT_CALL(mMockClock, alarmAt(_, 700)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700511
512 CountingCallback cb0(mDispatch);
513 CountingCallback cb1(mDispatch);
514
Leon Scroggins III31d41412022-11-18 16:42:53 -0500515 mDispatch->schedule(cb0, {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
516 mDispatch->schedule(cb1, {.workDuration = 200, .readyDuration = 0, .earliestVsync = 1000});
517 mDispatch->schedule(cb1, {.workDuration = 300, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700518 advanceToNextCallback();
519}
520
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800521TEST_F(VSyncDispatchTimerQueueTest, necessaryRearmsWhenModifying) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700522 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700523 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
524 EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq);
525 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700526
527 CountingCallback cb0(mDispatch);
528 CountingCallback cb1(mDispatch);
529
Leon Scroggins III31d41412022-11-18 16:42:53 -0500530 mDispatch->schedule(cb0, {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
531 mDispatch->schedule(cb1, {.workDuration = 200, .readyDuration = 0, .earliestVsync = 1000});
532 mDispatch->schedule(cb1, {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700533 advanceToNextCallback();
534}
535
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800536TEST_F(VSyncDispatchTimerQueueTest, modifyIntoGroup) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700537 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700538 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
539 EXPECT_CALL(mMockClock, alarmAt(_, 1600)).InSequence(seq);
540 EXPECT_CALL(mMockClock, alarmAt(_, 1590)).InSequence(seq);
541 EXPECT_CALL(mMockClock, alarmAt(_, 1600)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700542
543 auto offset = 400;
544 auto closeOffset = offset + mDispatchGroupThreshold - 1;
545 auto notCloseOffset = offset + 2 * mDispatchGroupThreshold;
546
547 CountingCallback cb0(mDispatch);
548 CountingCallback cb1(mDispatch);
549
Leon Scroggins III31d41412022-11-18 16:42:53 -0500550 mDispatch->schedule(cb0, {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
551 mDispatch->schedule(cb1, {.workDuration = 200, .readyDuration = 0, .earliestVsync = 1000});
552 mDispatch->schedule(cb1,
553 {.workDuration = closeOffset, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700554
555 advanceToNextCallback();
556 ASSERT_THAT(cb0.mCalls.size(), Eq(1));
557 EXPECT_THAT(cb0.mCalls[0], Eq(mPeriod));
558 ASSERT_THAT(cb1.mCalls.size(), Eq(1));
559 EXPECT_THAT(cb1.mCalls[0], Eq(mPeriod));
560
Leon Scroggins III31d41412022-11-18 16:42:53 -0500561 mDispatch->schedule(cb0, {.workDuration = 400, .readyDuration = 0, .earliestVsync = 2000});
562 mDispatch->schedule(cb1,
563 {.workDuration = notCloseOffset,
564 .readyDuration = 0,
565 .earliestVsync = 2000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700566 advanceToNextCallback();
567 ASSERT_THAT(cb1.mCalls.size(), Eq(2));
568 EXPECT_THAT(cb1.mCalls[1], Eq(2000));
569
570 advanceToNextCallback();
571 ASSERT_THAT(cb0.mCalls.size(), Eq(2));
572 EXPECT_THAT(cb0.mCalls[1], Eq(2000));
573}
574
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800575TEST_F(VSyncDispatchTimerQueueTest, rearmsWhenEndingAndDoesntCancel) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700576 Sequence seq;
577 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
578 EXPECT_CALL(mMockClock, alarmAt(_, 800)).InSequence(seq);
579 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700580 EXPECT_CALL(mMockClock, alarmCancel());
581
582 CountingCallback cb0(mDispatch);
583 CountingCallback cb1(mDispatch);
584
Leon Scroggins III31d41412022-11-18 16:42:53 -0500585 mDispatch->schedule(cb0, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
586 mDispatch->schedule(cb1, {.workDuration = 200, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700587 advanceToNextCallback();
Leon Scroggins III31d41412022-11-18 16:42:53 -0500588 EXPECT_EQ(mDispatch->cancel(cb0), CancelResult::Cancelled);
Kevin DuBois305bef12019-10-09 13:23:27 -0700589}
590
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800591TEST_F(VSyncDispatchTimerQueueTest, setAlarmCallsAtCorrectTimeWithChangingVsync) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500592 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(_))
Kevin DuBois305bef12019-10-09 13:23:27 -0700593 .Times(3)
594 .WillOnce(Return(950))
595 .WillOnce(Return(1975))
596 .WillOnce(Return(2950));
597
598 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500599 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 920});
Kevin DuBois305bef12019-10-09 13:23:27 -0700600
601 mMockClock.advanceBy(850);
602 EXPECT_THAT(cb.mCalls.size(), Eq(1));
603
Leon Scroggins III31d41412022-11-18 16:42:53 -0500604 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1900});
Kevin DuBois305bef12019-10-09 13:23:27 -0700605 mMockClock.advanceBy(900);
606 EXPECT_THAT(cb.mCalls.size(), Eq(1));
607 mMockClock.advanceBy(125);
608 EXPECT_THAT(cb.mCalls.size(), Eq(2));
609
Leon Scroggins III31d41412022-11-18 16:42:53 -0500610 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2900});
Kevin DuBois305bef12019-10-09 13:23:27 -0700611 mMockClock.advanceBy(975);
612 EXPECT_THAT(cb.mCalls.size(), Eq(3));
613}
614
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800615TEST_F(VSyncDispatchTimerQueueTest, callbackReentrancy) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700616 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700617 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
618 EXPECT_CALL(mMockClock, alarmAt(_, 1900)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700619
620 VSyncDispatch::CallbackToken tmp;
Leon Scroggins III31d41412022-11-18 16:42:53 -0500621 tmp = mDispatch->registerCallback(
Ady Abraham9c53ee72020-07-22 21:16:18 -0700622 [&](auto, auto, auto) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500623 mDispatch->schedule(tmp,
624 {.workDuration = 100,
625 .readyDuration = 0,
626 .earliestVsync = 2000});
Ady Abraham9c53ee72020-07-22 21:16:18 -0700627 },
628 "o.o");
Kevin DuBois305bef12019-10-09 13:23:27 -0700629
Leon Scroggins III31d41412022-11-18 16:42:53 -0500630 mDispatch->schedule(tmp, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700631 advanceToNextCallback();
632}
633
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800634TEST_F(VSyncDispatchTimerQueueTest, callbackReentrantWithPastWakeup) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700635 VSyncDispatch::CallbackToken tmp;
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800636 std::optional<nsecs_t> lastTarget;
Leon Scroggins III31d41412022-11-18 16:42:53 -0500637 tmp = mDispatch->registerCallback(
Ady Abraham9c53ee72020-07-22 21:16:18 -0700638 [&](auto timestamp, auto, auto) {
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700639 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500640 mDispatch->schedule(tmp,
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700641 {.workDuration = 400,
642 .readyDuration = 0,
Leon Scroggins III31d41412022-11-18 16:42:53 -0500643 .earliestVsync = timestamp - mVsyncMoveThreshold});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700644 EXPECT_TRUE(result.has_value());
645 EXPECT_EQ(mPeriod + timestamp - 400, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500646 result = mDispatch->schedule(tmp,
647 {.workDuration = 400,
648 .readyDuration = 0,
649 .earliestVsync = timestamp});
650 EXPECT_TRUE(result.has_value());
651 EXPECT_EQ(mPeriod + timestamp - 400, *result);
652 result = mDispatch->schedule(tmp,
653 {.workDuration = 400,
654 .readyDuration = 0,
655 .earliestVsync = timestamp + mVsyncMoveThreshold});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700656 EXPECT_TRUE(result.has_value());
657 EXPECT_EQ(mPeriod + timestamp - 400, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800658 lastTarget = timestamp;
Kevin DuBois305bef12019-10-09 13:23:27 -0700659 },
660 "oo");
661
Leon Scroggins III31d41412022-11-18 16:42:53 -0500662 mDispatch->schedule(tmp, {.workDuration = 999, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700663 advanceToNextCallback();
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800664 EXPECT_THAT(lastTarget, Eq(1000));
665
666 advanceToNextCallback();
667 EXPECT_THAT(lastTarget, Eq(2000));
Kevin DuBois305bef12019-10-09 13:23:27 -0700668}
669
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800670TEST_F(VSyncDispatchTimerQueueTest, modificationsAroundVsyncTime) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700671 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700672 EXPECT_CALL(mMockClock, alarmAt(_, 1000)).InSequence(seq);
673 EXPECT_CALL(mMockClock, alarmAt(_, 950)).InSequence(seq);
674 EXPECT_CALL(mMockClock, alarmAt(_, 1950)).InSequence(seq);
675 EXPECT_CALL(mMockClock, alarmAt(_, 1900)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700676
677 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500678 mDispatch->schedule(cb, {.workDuration = 0, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700679
680 mMockClock.advanceBy(750);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500681 mDispatch->schedule(cb, {.workDuration = 50, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700682
683 advanceToNextCallback();
Leon Scroggins III31d41412022-11-18 16:42:53 -0500684 mDispatch->schedule(cb, {.workDuration = 50, .readyDuration = 0, .earliestVsync = 2000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700685
686 mMockClock.advanceBy(800);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500687 mDispatch->schedule(cb, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700688}
689
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800690TEST_F(VSyncDispatchTimerQueueTest, lateModifications) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700691 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700692 EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq);
693 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
694 EXPECT_CALL(mMockClock, alarmAt(_, 850)).InSequence(seq);
695 EXPECT_CALL(mMockClock, alarmAt(_, 1800)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700696
697 CountingCallback cb0(mDispatch);
698 CountingCallback cb1(mDispatch);
699
Leon Scroggins III31d41412022-11-18 16:42:53 -0500700 mDispatch->schedule(cb0, {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
701 mDispatch->schedule(cb1, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700702
703 advanceToNextCallback();
Leon Scroggins III31d41412022-11-18 16:42:53 -0500704 mDispatch->schedule(cb0, {.workDuration = 200, .readyDuration = 0, .earliestVsync = 2000});
705 mDispatch->schedule(cb1, {.workDuration = 150, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700706
707 advanceToNextCallback();
708 advanceToNextCallback();
709}
710
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800711TEST_F(VSyncDispatchTimerQueueTest, doesntCancelPriorValidTimerForFutureMod) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700712 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700713 EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700714
715 CountingCallback cb0(mDispatch);
716 CountingCallback cb1(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500717 mDispatch->schedule(cb0, {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
718 mDispatch->schedule(cb1, {.workDuration = 500, .readyDuration = 0, .earliestVsync = 20000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700719}
720
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800721TEST_F(VSyncDispatchTimerQueueTest, setsTimerAfterCancellation) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700722 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700723 EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700724 EXPECT_CALL(mMockClock, alarmCancel()).InSequence(seq);
Ady Abrahamb491c902020-08-15 15:47:56 -0700725 EXPECT_CALL(mMockClock, alarmAt(_, 900)).InSequence(seq);
Kevin DuBois305bef12019-10-09 13:23:27 -0700726
727 CountingCallback cb0(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500728 mDispatch->schedule(cb0, {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
729 mDispatch->cancel(cb0);
730 mDispatch->schedule(cb0, {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700731}
732
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800733TEST_F(VSyncDispatchTimerQueueTest, makingUpIdsError) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700734 VSyncDispatch::CallbackToken token(100);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500735 EXPECT_FALSE(
736 mDispatch
737 ->schedule(token,
738 {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000})
739 .has_value());
740 EXPECT_THAT(mDispatch->cancel(token), Eq(CancelResult::Error));
Kevin DuBois305bef12019-10-09 13:23:27 -0700741}
742
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800743TEST_F(VSyncDispatchTimerQueueTest, canMoveCallbackBackwardsInTime) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700744 CountingCallback cb0(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700745 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500746 mDispatch->schedule(cb0,
747 {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700748 EXPECT_TRUE(result.has_value());
749 EXPECT_EQ(500, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500750 result = mDispatch->schedule(cb0,
751 {.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700752 EXPECT_TRUE(result.has_value());
753 EXPECT_EQ(900, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800754}
755
756// b/1450138150
757TEST_F(VSyncDispatchTimerQueueTest, doesNotMoveCallbackBackwardsAndSkipAScheduledTargetVSync) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700758 EXPECT_CALL(mMockClock, alarmAt(_, 500));
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800759 CountingCallback cb(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700760 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500761 mDispatch->schedule(cb,
762 {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700763 EXPECT_TRUE(result.has_value());
764 EXPECT_EQ(500, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800765 mMockClock.advanceBy(400);
766
Leon Scroggins III31d41412022-11-18 16:42:53 -0500767 result = mDispatch->schedule(cb,
768 {.workDuration = 800, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700769 EXPECT_TRUE(result.has_value());
770 EXPECT_EQ(1200, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800771 advanceToNextCallback();
772 ASSERT_THAT(cb.mCalls.size(), Eq(1));
773}
774
775TEST_F(VSyncDispatchTimerQueueTest, targetOffsetMovingBackALittleCanStillSchedule) {
Leon Scroggins III31d41412022-11-18 16:42:53 -0500776 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000))
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800777 .Times(2)
778 .WillOnce(Return(1000))
779 .WillOnce(Return(1002));
780 CountingCallback cb(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700781 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500782 mDispatch->schedule(cb,
783 {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700784 EXPECT_TRUE(result.has_value());
785 EXPECT_EQ(500, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800786 mMockClock.advanceBy(400);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500787 result = mDispatch->schedule(cb,
788 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700789 EXPECT_TRUE(result.has_value());
790 EXPECT_EQ(602, *result);
Kevin DuBois305bef12019-10-09 13:23:27 -0700791}
792
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800793TEST_F(VSyncDispatchTimerQueueTest, canScheduleNegativeOffsetAgainstDifferentPeriods) {
794 CountingCallback cb0(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700795 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500796 mDispatch->schedule(cb0,
797 {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700798 EXPECT_TRUE(result.has_value());
799 EXPECT_EQ(500, *result);
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800800 advanceToNextCallback();
Leon Scroggins III31d41412022-11-18 16:42:53 -0500801 result = mDispatch->schedule(cb0,
802 {.workDuration = 1100, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700803 EXPECT_TRUE(result.has_value());
804 EXPECT_EQ(900, *result);
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800805}
806
807TEST_F(VSyncDispatchTimerQueueTest, canScheduleLargeNegativeOffset) {
808 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700809 EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq);
810 EXPECT_CALL(mMockClock, alarmAt(_, 1100)).InSequence(seq);
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800811 CountingCallback cb0(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700812 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500813 mDispatch->schedule(cb0,
814 {.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700815 EXPECT_TRUE(result.has_value());
816 EXPECT_EQ(500, *result);
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800817 advanceToNextCallback();
Leon Scroggins III31d41412022-11-18 16:42:53 -0500818 result = mDispatch->schedule(cb0,
819 {.workDuration = 1900, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700820 EXPECT_TRUE(result.has_value());
821 EXPECT_EQ(1100, *result);
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800822}
823
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800824TEST_F(VSyncDispatchTimerQueueTest, scheduleUpdatesDoesNotAffectSchedulingState) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700825 EXPECT_CALL(mMockClock, alarmAt(_, 600));
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800826
827 CountingCallback cb(mDispatch);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700828 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500829 mDispatch->schedule(cb,
830 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700831 EXPECT_TRUE(result.has_value());
832 EXPECT_EQ(600, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800833
Leon Scroggins III31d41412022-11-18 16:42:53 -0500834 result = mDispatch->schedule(cb,
835 {.workDuration = 1400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700836 EXPECT_TRUE(result.has_value());
837 EXPECT_EQ(600, *result);
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800838
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800839 advanceToNextCallback();
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800840}
841
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800842TEST_F(VSyncDispatchTimerQueueTest, helperMove) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700843 EXPECT_CALL(mMockClock, alarmAt(_, 500)).Times(1);
Kevin DuBois305bef12019-10-09 13:23:27 -0700844 EXPECT_CALL(mMockClock, alarmCancel()).Times(1);
845
846 VSyncCallbackRegistration cb(
Ady Abraham9c53ee72020-07-22 21:16:18 -0700847 mDispatch, [](auto, auto, auto) {}, "");
Kevin DuBois305bef12019-10-09 13:23:27 -0700848 VSyncCallbackRegistration cb1(std::move(cb));
Ady Abraham9c53ee72020-07-22 21:16:18 -0700849 cb.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700850 cb.cancel();
851
Ady Abraham9c53ee72020-07-22 21:16:18 -0700852 cb1.schedule({.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700853 cb1.cancel();
854}
855
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800856TEST_F(VSyncDispatchTimerQueueTest, helperMoveAssign) {
Ady Abrahamb491c902020-08-15 15:47:56 -0700857 EXPECT_CALL(mMockClock, alarmAt(_, 500)).Times(1);
Kevin DuBois305bef12019-10-09 13:23:27 -0700858 EXPECT_CALL(mMockClock, alarmCancel()).Times(1);
859
860 VSyncCallbackRegistration cb(
Ady Abraham9c53ee72020-07-22 21:16:18 -0700861 mDispatch, [](auto, auto, auto) {}, "");
Kevin DuBois305bef12019-10-09 13:23:27 -0700862 VSyncCallbackRegistration cb1(
Ady Abraham9c53ee72020-07-22 21:16:18 -0700863 mDispatch, [](auto, auto, auto) {}, "");
Kevin DuBois305bef12019-10-09 13:23:27 -0700864 cb1 = std::move(cb);
Ady Abraham9c53ee72020-07-22 21:16:18 -0700865 cb.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700866 cb.cancel();
867
Ady Abraham9c53ee72020-07-22 21:16:18 -0700868 cb1.schedule({.workDuration = 500, .readyDuration = 0, .earliestVsync = 1000});
Kevin DuBois305bef12019-10-09 13:23:27 -0700869 cb1.cancel();
870}
871
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700872// b/154303580
873TEST_F(VSyncDispatchTimerQueueTest, skipsSchedulingIfTimerReschedulingIsImminent) {
874 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700875 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
876 EXPECT_CALL(mMockClock, alarmAt(_, 1900)).InSequence(seq);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700877 CountingCallback cb1(mDispatch);
878 CountingCallback cb2(mDispatch);
879
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700880 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500881 mDispatch->schedule(cb1,
882 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700883 EXPECT_TRUE(result.has_value());
884 EXPECT_EQ(600, *result);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700885
886 mMockClock.setLag(100);
887 mMockClock.advanceBy(620);
888
Leon Scroggins III31d41412022-11-18 16:42:53 -0500889 result = mDispatch->schedule(cb2,
890 {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700891 EXPECT_TRUE(result.has_value());
892 EXPECT_EQ(1900, *result);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700893 mMockClock.advanceBy(80);
894
895 EXPECT_THAT(cb1.mCalls.size(), Eq(1));
896 EXPECT_THAT(cb2.mCalls.size(), Eq(0));
897}
898
899// b/154303580.
900// If the same callback tries to reschedule itself after it's too late, timer opts to apply the
901// update later, as opposed to blocking the calling thread.
902TEST_F(VSyncDispatchTimerQueueTest, skipsSchedulingIfTimerReschedulingIsImminentSameCallback) {
903 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700904 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
905 EXPECT_CALL(mMockClock, alarmAt(_, 1630)).InSequence(seq);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700906 CountingCallback cb(mDispatch);
907
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700908 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500909 mDispatch->schedule(cb,
910 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700911 EXPECT_TRUE(result.has_value());
912 EXPECT_EQ(600, *result);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700913
914 mMockClock.setLag(100);
915 mMockClock.advanceBy(620);
916
Leon Scroggins III31d41412022-11-18 16:42:53 -0500917 result = mDispatch->schedule(cb,
918 {.workDuration = 370, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700919 EXPECT_TRUE(result.has_value());
920 EXPECT_EQ(1630, *result);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700921 mMockClock.advanceBy(80);
922
923 EXPECT_THAT(cb.mCalls.size(), Eq(1));
924}
925
Kevin DuBoisb340b732020-06-16 09:07:35 -0700926// b/154303580.
927TEST_F(VSyncDispatchTimerQueueTest, skipsRearmingWhenNotNextScheduled) {
928 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700929 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700930 EXPECT_CALL(mMockClock, alarmCancel()).InSequence(seq);
931 CountingCallback cb1(mDispatch);
932 CountingCallback cb2(mDispatch);
933
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700934 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500935 mDispatch->schedule(cb1,
936 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700937 EXPECT_TRUE(result.has_value());
938 EXPECT_EQ(600, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500939 result = mDispatch->schedule(cb2,
940 {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700941 EXPECT_TRUE(result.has_value());
942 EXPECT_EQ(1900, *result);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700943
944 mMockClock.setLag(100);
945 mMockClock.advanceBy(620);
946
Leon Scroggins III31d41412022-11-18 16:42:53 -0500947 EXPECT_EQ(mDispatch->cancel(cb2), CancelResult::Cancelled);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700948
949 mMockClock.advanceBy(80);
950
951 EXPECT_THAT(cb1.mCalls.size(), Eq(1));
952 EXPECT_THAT(cb2.mCalls.size(), Eq(0));
953}
954
955TEST_F(VSyncDispatchTimerQueueTest, rearmsWhenCancelledAndIsNextScheduled) {
956 Sequence seq;
Ady Abrahamb491c902020-08-15 15:47:56 -0700957 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
958 EXPECT_CALL(mMockClock, alarmAt(_, 1900)).InSequence(seq);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700959 EXPECT_CALL(mMockClock, alarmCancel()).InSequence(seq);
960 CountingCallback cb1(mDispatch);
961 CountingCallback cb2(mDispatch);
962
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700963 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -0500964 mDispatch->schedule(cb1,
965 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700966 EXPECT_TRUE(result.has_value());
967 EXPECT_EQ(600, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500968 result = mDispatch->schedule(cb2,
969 {.workDuration = 100, .readyDuration = 0, .earliestVsync = 2000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700970 EXPECT_TRUE(result.has_value());
971 EXPECT_EQ(1900, *result);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700972
973 mMockClock.setLag(100);
974 mMockClock.advanceBy(620);
975
Leon Scroggins III31d41412022-11-18 16:42:53 -0500976 EXPECT_EQ(mDispatch->cancel(cb1), CancelResult::Cancelled);
Kevin DuBoisb340b732020-06-16 09:07:35 -0700977
978 EXPECT_THAT(cb1.mCalls.size(), Eq(0));
979 EXPECT_THAT(cb2.mCalls.size(), Eq(0));
980 mMockClock.advanceToNextCallback();
981
982 EXPECT_THAT(cb1.mCalls.size(), Eq(0));
983 EXPECT_THAT(cb2.mCalls.size(), Eq(1));
984}
985
Kevin DuBoisf9477832020-07-16 10:21:36 -0700986TEST_F(VSyncDispatchTimerQueueTest, laggedTimerGroupsCallbacksWithinLag) {
987 CountingCallback cb1(mDispatch);
988 CountingCallback cb2(mDispatch);
989
990 Sequence seq;
Leon Scroggins III31d41412022-11-18 16:42:53 -0500991 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000))
Kevin DuBoisf9477832020-07-16 10:21:36 -0700992 .InSequence(seq)
993 .WillOnce(Return(1000));
Ady Abrahamb491c902020-08-15 15:47:56 -0700994 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
Leon Scroggins III31d41412022-11-18 16:42:53 -0500995 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000))
Kevin DuBoisf9477832020-07-16 10:21:36 -0700996 .InSequence(seq)
997 .WillOnce(Return(1000));
998
Ady Abrahamb5d3afa2021-05-07 11:22:23 -0700999 auto result =
Leon Scroggins III31d41412022-11-18 16:42:53 -05001000 mDispatch->schedule(cb1,
1001 {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001002 EXPECT_TRUE(result.has_value());
1003 EXPECT_EQ(600, *result);
Leon Scroggins III31d41412022-11-18 16:42:53 -05001004 result = mDispatch->schedule(cb2,
1005 {.workDuration = 390, .readyDuration = 0, .earliestVsync = 1000});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001006 EXPECT_TRUE(result.has_value());
1007 EXPECT_EQ(610, *result);
Kevin DuBoisf9477832020-07-16 10:21:36 -07001008
1009 mMockClock.setLag(100);
1010 mMockClock.advanceBy(700);
1011
1012 ASSERT_THAT(cb1.mWakeupTime.size(), Eq(1));
1013 EXPECT_THAT(cb1.mWakeupTime[0], Eq(600));
Ady Abraham9c53ee72020-07-22 21:16:18 -07001014 ASSERT_THAT(cb1.mReadyTime.size(), Eq(1));
1015 EXPECT_THAT(cb1.mReadyTime[0], Eq(1000));
Kevin DuBoisf9477832020-07-16 10:21:36 -07001016 ASSERT_THAT(cb2.mWakeupTime.size(), Eq(1));
1017 EXPECT_THAT(cb2.mWakeupTime[0], Eq(610));
Ady Abraham9c53ee72020-07-22 21:16:18 -07001018 ASSERT_THAT(cb2.mReadyTime.size(), Eq(1));
1019 EXPECT_THAT(cb2.mReadyTime[0], Eq(1000));
1020}
1021
1022TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFutureWithReadyDuration) {
1023 auto intended = mPeriod - 230;
1024 EXPECT_CALL(mMockClock, alarmAt(_, 900));
1025
1026 CountingCallback cb(mDispatch);
Leon Scroggins III31d41412022-11-18 16:42:53 -05001027 const auto result = mDispatch->schedule(cb,
1028 {.workDuration = 70,
1029 .readyDuration = 30,
1030 .earliestVsync = intended});
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001031 EXPECT_TRUE(result.has_value());
1032 EXPECT_EQ(900, *result);
Ady Abraham9c53ee72020-07-22 21:16:18 -07001033 advanceToNextCallback();
1034
1035 ASSERT_THAT(cb.mCalls.size(), Eq(1));
1036 EXPECT_THAT(cb.mCalls[0], Eq(mPeriod));
1037 ASSERT_THAT(cb.mWakeupTime.size(), Eq(1));
1038 EXPECT_THAT(cb.mWakeupTime[0], 900);
1039 ASSERT_THAT(cb.mReadyTime.size(), Eq(1));
1040 EXPECT_THAT(cb.mReadyTime[0], 970);
Kevin DuBoisf9477832020-07-16 10:21:36 -07001041}
1042
Ady Abraham69b9e622021-07-19 12:24:31 -07001043TEST_F(VSyncDispatchTimerQueueTest, updatesVsyncTimeForCloseWakeupTime) {
1044 Sequence seq;
1045 EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq);
1046
1047 CountingCallback cb(mDispatch);
1048
Leon Scroggins III31d41412022-11-18 16:42:53 -05001049 mDispatch->schedule(cb, {.workDuration = 400, .readyDuration = 0, .earliestVsync = 1000});
1050 mDispatch->schedule(cb, {.workDuration = 1400, .readyDuration = 0, .earliestVsync = 1000});
Ady Abraham69b9e622021-07-19 12:24:31 -07001051
1052 advanceToNextCallback();
1053
1054 advanceToNextCallback();
1055
1056 ASSERT_THAT(cb.mCalls.size(), Eq(1));
1057 EXPECT_THAT(cb.mCalls[0], Eq(2000));
1058 ASSERT_THAT(cb.mWakeupTime.size(), Eq(1));
1059 EXPECT_THAT(cb.mWakeupTime[0], Eq(600));
1060 ASSERT_THAT(cb.mReadyTime.size(), Eq(1));
1061 EXPECT_THAT(cb.mReadyTime[0], Eq(2000));
1062}
1063
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001064class VSyncDispatchTimerQueueEntryTest : public testing::Test {
Kevin DuBois305bef12019-10-09 13:23:27 -07001065protected:
1066 nsecs_t const mPeriod = 1000;
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001067 nsecs_t const mVsyncMoveThreshold = 200;
Leon Scroggins III31d41412022-11-18 16:42:53 -05001068 std::shared_ptr<NiceMock<MockVSyncTracker>> mStubTracker =
1069 std::make_shared<NiceMock<MockVSyncTracker>>(mPeriod);
Kevin DuBois305bef12019-10-09 13:23:27 -07001070};
1071
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001072TEST_F(VSyncDispatchTimerQueueEntryTest, stateAfterInitialization) {
Kevin DuBois305bef12019-10-09 13:23:27 -07001073 std::string name("basicname");
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001074 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001075 name, [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -07001076 EXPECT_THAT(entry.name(), Eq(name));
1077 EXPECT_FALSE(entry.lastExecutedVsyncTarget());
1078 EXPECT_FALSE(entry.wakeupTime());
1079}
1080
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001081TEST_F(VSyncDispatchTimerQueueEntryTest, stateScheduling) {
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001082 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001083 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -07001084
1085 EXPECT_FALSE(entry.wakeupTime());
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001086 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001087 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001088 .has_value());
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001089 auto const wakeup = entry.wakeupTime();
1090 ASSERT_TRUE(wakeup);
1091 EXPECT_THAT(*wakeup, Eq(900));
Kevin DuBois305bef12019-10-09 13:23:27 -07001092
1093 entry.disarm();
1094 EXPECT_FALSE(entry.wakeupTime());
1095}
1096
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001097TEST_F(VSyncDispatchTimerQueueEntryTest, stateSchedulingReallyLongWakeupLatency) {
Kevin DuBois305bef12019-10-09 13:23:27 -07001098 auto const duration = 500;
1099 auto const now = 8750;
1100
Leon Scroggins III31d41412022-11-18 16:42:53 -05001101 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(now + duration))
Kevin DuBois305bef12019-10-09 13:23:27 -07001102 .Times(1)
1103 .WillOnce(Return(10000));
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001104 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001105 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -07001106
1107 EXPECT_FALSE(entry.wakeupTime());
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001108 EXPECT_TRUE(entry.schedule({.workDuration = 500, .readyDuration = 0, .earliestVsync = 994},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001109 *mStubTracker.get(), now)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001110 .has_value());
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001111 auto const wakeup = entry.wakeupTime();
1112 ASSERT_TRUE(wakeup);
1113 EXPECT_THAT(*wakeup, Eq(9500));
Kevin DuBois305bef12019-10-09 13:23:27 -07001114}
1115
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001116TEST_F(VSyncDispatchTimerQueueEntryTest, runCallback) {
Kevin DuBois305bef12019-10-09 13:23:27 -07001117 auto callCount = 0;
Kevin DuBois2968afc2020-01-14 09:48:50 -08001118 auto vsyncCalledTime = 0;
1119 auto wakeupCalledTime = 0;
Ady Abraham9c53ee72020-07-22 21:16:18 -07001120 auto readyCalledTime = 0;
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001121 VSyncDispatchTimerQueueEntry entry(
1122 "test",
Ady Abraham9c53ee72020-07-22 21:16:18 -07001123 [&](auto vsyncTime, auto wakeupTime, auto readyTime) {
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001124 callCount++;
Kevin DuBois2968afc2020-01-14 09:48:50 -08001125 vsyncCalledTime = vsyncTime;
1126 wakeupCalledTime = wakeupTime;
Ady Abraham9c53ee72020-07-22 21:16:18 -07001127 readyCalledTime = readyTime;
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001128 },
1129 mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -07001130
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001131 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001132 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001133 .has_value());
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001134 auto const wakeup = entry.wakeupTime();
1135 ASSERT_TRUE(wakeup);
1136 EXPECT_THAT(*wakeup, Eq(900));
Kevin DuBois305bef12019-10-09 13:23:27 -07001137
Ady Abraham9c53ee72020-07-22 21:16:18 -07001138 auto const ready = entry.readyTime();
1139 ASSERT_TRUE(ready);
1140 EXPECT_THAT(*ready, Eq(1000));
1141
1142 entry.callback(entry.executing(), *wakeup, *ready);
Kevin DuBois305bef12019-10-09 13:23:27 -07001143
1144 EXPECT_THAT(callCount, Eq(1));
Kevin DuBois2968afc2020-01-14 09:48:50 -08001145 EXPECT_THAT(vsyncCalledTime, Eq(mPeriod));
1146 EXPECT_THAT(wakeupCalledTime, Eq(*wakeup));
Kevin DuBois305bef12019-10-09 13:23:27 -07001147 EXPECT_FALSE(entry.wakeupTime());
1148 auto lastCalledTarget = entry.lastExecutedVsyncTarget();
1149 ASSERT_TRUE(lastCalledTarget);
1150 EXPECT_THAT(*lastCalledTarget, Eq(mPeriod));
1151}
1152
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001153TEST_F(VSyncDispatchTimerQueueEntryTest, updateCallback) {
Leon Scroggins III31d41412022-11-18 16:42:53 -05001154 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(_))
Kevin DuBois305bef12019-10-09 13:23:27 -07001155 .Times(2)
1156 .WillOnce(Return(1000))
1157 .WillOnce(Return(1020));
1158
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001159 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001160 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBois305bef12019-10-09 13:23:27 -07001161
1162 EXPECT_FALSE(entry.wakeupTime());
Leon Scroggins III31d41412022-11-18 16:42:53 -05001163 entry.update(*mStubTracker.get(), 0);
Kevin DuBois305bef12019-10-09 13:23:27 -07001164 EXPECT_FALSE(entry.wakeupTime());
1165
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001166 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001167 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001168 .has_value());
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001169 auto wakeup = entry.wakeupTime();
1170 ASSERT_TRUE(wakeup);
Kevin DuBois305bef12019-10-09 13:23:27 -07001171 EXPECT_THAT(wakeup, Eq(900));
1172
Leon Scroggins III31d41412022-11-18 16:42:53 -05001173 entry.update(*mStubTracker.get(), 0);
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001174 wakeup = entry.wakeupTime();
1175 ASSERT_TRUE(wakeup);
1176 EXPECT_THAT(*wakeup, Eq(920));
Kevin DuBois305bef12019-10-09 13:23:27 -07001177}
1178
Kevin DuBoise4f27a82019-11-12 11:41:41 -08001179TEST_F(VSyncDispatchTimerQueueEntryTest, skipsUpdateIfJustScheduled) {
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001180 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001181 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001182 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001183 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001184 .has_value());
Leon Scroggins III31d41412022-11-18 16:42:53 -05001185 entry.update(*mStubTracker.get(), 0);
Kevin DuBois305bef12019-10-09 13:23:27 -07001186
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001187 auto const wakeup = entry.wakeupTime();
1188 ASSERT_TRUE(wakeup);
1189 EXPECT_THAT(*wakeup, Eq(wakeup));
1190}
1191
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001192TEST_F(VSyncDispatchTimerQueueEntryTest, willSnapToNextTargettableVSync) {
1193 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001194 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001195 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001196 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001197 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001198 entry.executing(); // 1000 is executing
1199 // had 1000 not been executing, this could have been scheduled for time 800.
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001200 EXPECT_TRUE(entry.schedule({.workDuration = 200, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001201 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001202 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001203 EXPECT_THAT(*entry.wakeupTime(), Eq(1800));
Ady Abraham9c53ee72020-07-22 21:16:18 -07001204 EXPECT_THAT(*entry.readyTime(), Eq(2000));
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001205
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001206 EXPECT_TRUE(entry.schedule({.workDuration = 50, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001207 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001208 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001209 EXPECT_THAT(*entry.wakeupTime(), Eq(1950));
Ady Abraham9c53ee72020-07-22 21:16:18 -07001210 EXPECT_THAT(*entry.readyTime(), Eq(2000));
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001211
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001212 EXPECT_TRUE(entry.schedule({.workDuration = 200, .readyDuration = 0, .earliestVsync = 1001},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001213 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001214 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001215 EXPECT_THAT(*entry.wakeupTime(), Eq(1800));
Ady Abraham9c53ee72020-07-22 21:16:18 -07001216 EXPECT_THAT(*entry.readyTime(), Eq(2000));
Kevin DuBois2311b1a2019-11-18 16:19:08 -08001217}
1218
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001219TEST_F(VSyncDispatchTimerQueueEntryTest,
1220 willRequestNextEstimateWhenSnappingToNextTargettableVSync) {
1221 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001222 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001223
1224 Sequence seq;
Leon Scroggins III31d41412022-11-18 16:42:53 -05001225 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(500))
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001226 .InSequence(seq)
1227 .WillOnce(Return(1000));
Leon Scroggins III31d41412022-11-18 16:42:53 -05001228 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(500))
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001229 .InSequence(seq)
1230 .WillOnce(Return(1000));
Leon Scroggins III31d41412022-11-18 16:42:53 -05001231 EXPECT_CALL(*mStubTracker.get(), nextAnticipatedVSyncTimeFrom(1000 + mVsyncMoveThreshold))
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001232 .InSequence(seq)
1233 .WillOnce(Return(2000));
1234
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001235 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001236 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001237 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001238
1239 entry.executing(); // 1000 is executing
1240
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001241 EXPECT_TRUE(entry.schedule({.workDuration = 200, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001242 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001243 .has_value());
Kevin DuBoisc94ca832019-11-26 12:56:24 -08001244}
1245
1246TEST_F(VSyncDispatchTimerQueueEntryTest, reportsScheduledIfStillTime) {
1247 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001248 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001249 EXPECT_TRUE(entry.schedule({.workDuration = 100, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001250 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001251 .has_value());
1252 EXPECT_TRUE(entry.schedule({.workDuration = 200, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001253 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001254 .has_value());
1255 EXPECT_TRUE(entry.schedule({.workDuration = 50, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001256 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001257 .has_value());
1258 EXPECT_TRUE(entry.schedule({.workDuration = 1200, .readyDuration = 0, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001259 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001260 .has_value());
Kevin DuBois305bef12019-10-09 13:23:27 -07001261}
1262
Kevin DuBois5c18c1c2020-05-27 15:50:50 -07001263TEST_F(VSyncDispatchTimerQueueEntryTest, storesPendingUpdatesUntilUpdate) {
1264 static constexpr auto effectualOffset = 200;
1265 VSyncDispatchTimerQueueEntry entry(
Ady Abraham9c53ee72020-07-22 21:16:18 -07001266 "test", [](auto, auto, auto) {}, mVsyncMoveThreshold);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -07001267 EXPECT_FALSE(entry.hasPendingWorkloadUpdate());
Ady Abraham9c53ee72020-07-22 21:16:18 -07001268 entry.addPendingWorkloadUpdate({.workDuration = 100, .readyDuration = 0, .earliestVsync = 400});
1269 entry.addPendingWorkloadUpdate(
1270 {.workDuration = effectualOffset, .readyDuration = 0, .earliestVsync = 400});
Kevin DuBois5c18c1c2020-05-27 15:50:50 -07001271 EXPECT_TRUE(entry.hasPendingWorkloadUpdate());
Leon Scroggins III31d41412022-11-18 16:42:53 -05001272 entry.update(*mStubTracker.get(), 0);
Kevin DuBois5c18c1c2020-05-27 15:50:50 -07001273 EXPECT_FALSE(entry.hasPendingWorkloadUpdate());
1274 EXPECT_THAT(*entry.wakeupTime(), Eq(mPeriod - effectualOffset));
1275}
1276
Ady Abraham9c53ee72020-07-22 21:16:18 -07001277TEST_F(VSyncDispatchTimerQueueEntryTest, runCallbackWithReadyDuration) {
1278 auto callCount = 0;
1279 auto vsyncCalledTime = 0;
1280 auto wakeupCalledTime = 0;
1281 auto readyCalledTime = 0;
1282 VSyncDispatchTimerQueueEntry entry(
1283 "test",
1284 [&](auto vsyncTime, auto wakeupTime, auto readyTime) {
1285 callCount++;
1286 vsyncCalledTime = vsyncTime;
1287 wakeupCalledTime = wakeupTime;
1288 readyCalledTime = readyTime;
1289 },
1290 mVsyncMoveThreshold);
1291
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001292 EXPECT_TRUE(entry.schedule({.workDuration = 70, .readyDuration = 30, .earliestVsync = 500},
Leon Scroggins III31d41412022-11-18 16:42:53 -05001293 *mStubTracker.get(), 0)
Ady Abrahamb5d3afa2021-05-07 11:22:23 -07001294 .has_value());
Ady Abraham9c53ee72020-07-22 21:16:18 -07001295 auto const wakeup = entry.wakeupTime();
1296 ASSERT_TRUE(wakeup);
1297 EXPECT_THAT(*wakeup, Eq(900));
1298
1299 auto const ready = entry.readyTime();
1300 ASSERT_TRUE(ready);
1301 EXPECT_THAT(*ready, Eq(970));
1302
1303 entry.callback(entry.executing(), *wakeup, *ready);
1304
1305 EXPECT_THAT(callCount, Eq(1));
1306 EXPECT_THAT(vsyncCalledTime, Eq(mPeriod));
1307 EXPECT_THAT(wakeupCalledTime, Eq(*wakeup));
1308 EXPECT_FALSE(entry.wakeupTime());
1309 auto lastCalledTarget = entry.lastExecutedVsyncTarget();
1310 ASSERT_TRUE(lastCalledTarget);
1311 EXPECT_THAT(*lastCalledTarget, Eq(mPeriod));
1312}
1313
Kevin DuBois305bef12019-10-09 13:23:27 -07001314} // namespace android::scheduler
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001315
1316// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001317#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"