SF: dispatch add testing surface for VSyncDispatch
Adds a stubbable/mockable surface to the VSyncDispatch class so that
an test relying on this object can be built.
Bug: 140303479
Test: libsurfaceflinger_unittest --gtest_filter="VSyncDisp*"
Change-Id: I7e0a6b14e7032c89c32595a624eef4f75e1ea1ad
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index 4226e9a..f529a44 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -165,7 +165,7 @@
"Scheduler/PhaseOffsets.cpp",
"Scheduler/Scheduler.cpp",
"Scheduler/SchedulerUtils.cpp",
- "Scheduler/VSyncDispatch.cpp",
+ "Scheduler/VSyncDispatchTimerQueue.cpp",
"Scheduler/VSyncModulator.cpp",
"StartPropertySetThread.cpp",
"SurfaceFlinger.cpp",
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatch.h b/services/surfaceflinger/Scheduler/VSyncDispatch.h
index 0050495..4a4bef8 100644
--- a/services/surfaceflinger/Scheduler/VSyncDispatch.h
+++ b/services/surfaceflinger/Scheduler/VSyncDispatch.h
@@ -16,14 +16,9 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <utils/Timers.h>
#include <functional>
-#include <memory>
-#include <mutex>
#include <string>
-#include <string_view>
-#include <unordered_map>
#include "StrongTyping.h"
@@ -34,68 +29,6 @@
enum class ScheduleResult { Scheduled, ReScheduled, CannotSchedule, Error };
enum class CancelResult { Cancelled, TooLate, Error };
-namespace impl {
-
-// VSyncDispatchEntry is a helper class representing internal state for each entry in VSyncDispatch
-// hoisted to public for unit testing.
-class VSyncDispatchEntry {
-public:
- // This is the state of the entry. There are 3 states, armed, running, disarmed.
- // Valid transition: disarmed -> armed ( when scheduled )
- // Valid transition: armed -> running -> disarmed ( when timer is called)
- // Valid transition: armed -> disarmed ( when cancelled )
- VSyncDispatchEntry(std::string const& name, std::function<void(nsecs_t)> const& fn);
- std::string_view name() const;
-
- // Start: functions that are not threadsafe.
- // Return the last vsync time this callback was invoked.
- std::optional<nsecs_t> lastExecutedVsyncTarget() const;
-
- // This moves the state from disarmed->armed and will calculate the wakeupTime.
- nsecs_t schedule(nsecs_t workDuration, nsecs_t earliestVsync, VSyncTracker& tracker,
- nsecs_t now);
- // This will update armed entries with the latest vsync information. Entry remains armed.
- void update(VSyncTracker& tracker, nsecs_t now);
-
- // This will return empty if not armed, or the next calculated wakeup time if armed.
- // It will not update the wakeupTime.
- std::optional<nsecs_t> wakeupTime() const;
-
- // This moves state from armed->disarmed.
- void disarm();
-
- // This moves the state from armed->running.
- // Store the timestamp that this was intended for as the last called timestamp.
- nsecs_t executing();
- // End: functions that are not threadsafe.
-
- // Invoke the callback with the timestamp, moving the state from running->disarmed.
- void callback(nsecs_t timestamp);
- // Block calling thread while the callback is executing.
- void ensureNotRunning();
-
-private:
- void arm(VSyncTracker& tracker, nsecs_t now);
- std::string const mName;
- std::function<void(nsecs_t)> const mCallback;
-
- nsecs_t mWorkDuration;
- nsecs_t mEarliestVsync;
-
- struct ArmingInfo {
- nsecs_t mActualWakeupTime;
- nsecs_t mActualVsyncTime;
- };
- std::optional<ArmingInfo> mArmedInfo;
- std::optional<nsecs_t> mLastDispatchTime;
-
- std::mutex mRunningMutex;
- std::condition_variable mCv;
- bool mRunning GUARDED_BY(mRunningMutex) = false;
-};
-
-} // namespace impl
-
/*
* VSyncDispatch is a class that will dispatch callbacks relative to system vsync events.
*/
@@ -103,15 +36,7 @@
public:
using CallbackToken = StrongTyping<size_t, class CallbackTokenTag, Compare>;
- /* creates a VsyncDispatch.
- * \param [in] a timekeeper object for dispatching events.
- * \param [in] a tracker object that is monitoring expected vsync events.
- * \param [in] a tunable in nanoseconds that indicates when events that fall close together
- * should be dispatched in one timer wakeup.
- */
- explicit VSyncDispatch(std::unique_ptr<TimeKeeper> tk, VSyncTracker& tracker,
- nsecs_t timerSlack);
- ~VSyncDispatch();
+ virtual ~VSyncDispatch();
/*
* Registers a callback that will be called at designated points on the vsync timeline.
@@ -126,8 +51,8 @@
* invocation of callbackFn.
*
*/
- CallbackToken registerCallback(std::function<void(nsecs_t)> const& callbackFn,
- std::string callbackName);
+ virtual CallbackToken registerCallback(std::function<void(nsecs_t)> const& callbackFn,
+ std::string callbackName) = 0;
/*
* Unregisters a callback.
@@ -135,7 +60,7 @@
* \param [in] token The callback to unregister.
*
*/
- void unregisterCallback(CallbackToken token);
+ virtual void unregisterCallback(CallbackToken token) = 0;
/*
* Schedules the registered callback to be dispatched.
@@ -164,7 +89,8 @@
* if a callback was dispatched for the predictedVsync already.
* A ScheduleResult::Error if there was another error.
*/
- ScheduleResult schedule(CallbackToken token, nsecs_t workDuration, nsecs_t earliestVsync);
+ virtual ScheduleResult schedule(CallbackToken token, nsecs_t workDuration,
+ nsecs_t earliestVsync) = 0;
/* Cancels a scheduled callback, if possible.
*
@@ -173,31 +99,12 @@
* A CancelResult::Cancelled if the callback was successfully cancelled.
* A CancelResult::Error if there was an pre-condition violation.
*/
- CancelResult cancel(CallbackToken token);
+ virtual CancelResult cancel(CallbackToken token) = 0;
-private:
+protected:
+ VSyncDispatch() = default;
VSyncDispatch(VSyncDispatch const&) = delete;
VSyncDispatch& operator=(VSyncDispatch const&) = delete;
-
- using CallbackMap = std::unordered_map<size_t, std::shared_ptr<impl::VSyncDispatchEntry>>;
-
- void timerCallback();
- void setTimer(nsecs_t, nsecs_t) REQUIRES(mMutex);
- void rearmTimer(nsecs_t now) REQUIRES(mMutex);
- void rearmTimerSkippingUpdateFor(nsecs_t now, CallbackMap::iterator const& skipUpdate)
- REQUIRES(mMutex);
- void cancelTimer() REQUIRES(mMutex);
-
- static constexpr nsecs_t kInvalidTime = std::numeric_limits<int64_t>::max();
- std::unique_ptr<TimeKeeper> const mTimeKeeper;
- VSyncTracker& mTracker;
- nsecs_t const mTimerSlack;
-
- std::mutex mutable mMutex;
- size_t mCallbackToken GUARDED_BY(mMutex) = 0;
-
- CallbackMap mCallbacks GUARDED_BY(mMutex);
- nsecs_t mIntendedWakeupTime GUARDED_BY(mMutex) = kInvalidTime;
};
/*
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatch.cpp b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
similarity index 74%
rename from services/surfaceflinger/Scheduler/VSyncDispatch.cpp
rename to services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
index c9b2e77..7922484 100644
--- a/services/surfaceflinger/Scheduler/VSyncDispatch.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
@@ -19,65 +19,66 @@
#include <vector>
#include "TimeKeeper.h"
-#include "VSyncDispatch.h"
+#include "VSyncDispatchTimerQueue.h"
#include "VSyncTracker.h"
namespace android::scheduler {
+VSyncDispatch::~VSyncDispatch() = default;
VSyncTracker::~VSyncTracker() = default;
TimeKeeper::~TimeKeeper() = default;
-impl::VSyncDispatchEntry::VSyncDispatchEntry(std::string const& name,
- std::function<void(nsecs_t)> const& cb)
+VSyncDispatchTimerQueueEntry::VSyncDispatchTimerQueueEntry(std::string const& name,
+ std::function<void(nsecs_t)> const& cb)
: mName(name), mCallback(cb), mWorkDuration(0), mEarliestVsync(0) {}
-std::optional<nsecs_t> impl::VSyncDispatchEntry::lastExecutedVsyncTarget() const {
+std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::lastExecutedVsyncTarget() const {
return mLastDispatchTime;
}
-std::string_view impl::VSyncDispatchEntry::name() const {
+std::string_view VSyncDispatchTimerQueueEntry::name() const {
return mName;
}
-std::optional<nsecs_t> impl::VSyncDispatchEntry::wakeupTime() const {
+std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::wakeupTime() const {
if (!mArmedInfo) {
return {};
}
return {mArmedInfo->mActualWakeupTime};
}
-nsecs_t impl::VSyncDispatchEntry::schedule(nsecs_t workDuration, nsecs_t earliestVsync,
- VSyncTracker& tracker, nsecs_t now) {
+nsecs_t VSyncDispatchTimerQueueEntry::schedule(nsecs_t workDuration, nsecs_t earliestVsync,
+ VSyncTracker& tracker, nsecs_t now) {
mWorkDuration = workDuration;
mEarliestVsync = earliestVsync;
arm(tracker, now);
return mArmedInfo->mActualWakeupTime;
}
-void impl::VSyncDispatchEntry::update(VSyncTracker& tracker, nsecs_t now) {
+void VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now) {
if (!mArmedInfo) {
return;
}
arm(tracker, now);
}
-void impl::VSyncDispatchEntry::arm(VSyncTracker& tracker, nsecs_t now) {
+void VSyncDispatchTimerQueueEntry::arm(VSyncTracker& tracker, nsecs_t now) {
auto const nextVsyncTime =
tracker.nextAnticipatedVSyncTimeFrom(std::max(mEarliestVsync, now + mWorkDuration));
mArmedInfo = {nextVsyncTime - mWorkDuration, nextVsyncTime};
}
-void impl::VSyncDispatchEntry::disarm() {
+void VSyncDispatchTimerQueueEntry::disarm() {
mArmedInfo.reset();
}
-nsecs_t impl::VSyncDispatchEntry::executing() {
+nsecs_t VSyncDispatchTimerQueueEntry::executing() {
mLastDispatchTime = mArmedInfo->mActualVsyncTime;
disarm();
return *mLastDispatchTime;
}
-void impl::VSyncDispatchEntry::callback(nsecs_t t) {
+void VSyncDispatchTimerQueueEntry::callback(nsecs_t t) {
{
std::lock_guard<std::mutex> lk(mRunningMutex);
mRunning = true;
@@ -90,36 +91,37 @@
mCv.notify_all();
}
-void impl::VSyncDispatchEntry::ensureNotRunning() {
+void VSyncDispatchTimerQueueEntry::ensureNotRunning() {
std::unique_lock<std::mutex> lk(mRunningMutex);
mCv.wait(lk, [this]() REQUIRES(mRunningMutex) { return !mRunning; });
}
-VSyncDispatch::VSyncDispatch(std::unique_ptr<TimeKeeper> tk, VSyncTracker& tracker,
- nsecs_t timerSlack)
+VSyncDispatchTimerQueue::VSyncDispatchTimerQueue(std::unique_ptr<TimeKeeper> tk,
+ VSyncTracker& tracker, nsecs_t timerSlack)
: mTimeKeeper(std::move(tk)), mTracker(tracker), mTimerSlack(timerSlack) {}
-VSyncDispatch::~VSyncDispatch() {
+VSyncDispatchTimerQueue::~VSyncDispatchTimerQueue() {
std::lock_guard<decltype(mMutex)> lk(mMutex);
cancelTimer();
}
-void VSyncDispatch::cancelTimer() {
+void VSyncDispatchTimerQueue::cancelTimer() {
mIntendedWakeupTime = kInvalidTime;
mTimeKeeper->alarmCancel();
}
-void VSyncDispatch::setTimer(nsecs_t targetTime, nsecs_t now) {
+void VSyncDispatchTimerQueue::setTimer(nsecs_t targetTime, nsecs_t now) {
mIntendedWakeupTime = targetTime;
- mTimeKeeper->alarmIn(std::bind(&VSyncDispatch::timerCallback, this), targetTime - now);
+ mTimeKeeper->alarmIn(std::bind(&VSyncDispatchTimerQueue::timerCallback, this),
+ targetTime - now);
}
-void VSyncDispatch::rearmTimer(nsecs_t now) {
+void VSyncDispatchTimerQueue::rearmTimer(nsecs_t now) {
rearmTimerSkippingUpdateFor(now, mCallbacks.end());
}
-void VSyncDispatch::rearmTimerSkippingUpdateFor(nsecs_t now,
- CallbackMap::iterator const& skipUpdateIt) {
+void VSyncDispatchTimerQueue::rearmTimerSkippingUpdateFor(
+ nsecs_t now, CallbackMap::iterator const& skipUpdateIt) {
std::optional<nsecs_t> min;
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
auto& callback = it->second;
@@ -143,9 +145,9 @@
}
}
-void VSyncDispatch::timerCallback() {
+void VSyncDispatchTimerQueue::timerCallback() {
struct Invocation {
- std::shared_ptr<impl::VSyncDispatchEntry> callback;
+ std::shared_ptr<VSyncDispatchTimerQueueEntry> callback;
nsecs_t timestamp;
};
std::vector<Invocation> invocations;
@@ -174,18 +176,19 @@
}
}
-VSyncDispatch::CallbackToken VSyncDispatch::registerCallback(
+VSyncDispatchTimerQueue::CallbackToken VSyncDispatchTimerQueue::registerCallback(
std::function<void(nsecs_t)> const& callbackFn, std::string callbackName) {
std::lock_guard<decltype(mMutex)> lk(mMutex);
return CallbackToken{
mCallbacks
.emplace(++mCallbackToken,
- std::make_shared<impl::VSyncDispatchEntry>(callbackName, callbackFn))
+ std::make_shared<VSyncDispatchTimerQueueEntry>(callbackName,
+ callbackFn))
.first->first};
}
-void VSyncDispatch::unregisterCallback(CallbackToken token) {
- std::shared_ptr<impl::VSyncDispatchEntry> entry = nullptr;
+void VSyncDispatchTimerQueue::unregisterCallback(CallbackToken token) {
+ std::shared_ptr<VSyncDispatchTimerQueueEntry> entry = nullptr;
{
std::lock_guard<decltype(mMutex)> lk(mMutex);
auto it = mCallbacks.find(token);
@@ -200,8 +203,8 @@
}
}
-ScheduleResult VSyncDispatch::schedule(CallbackToken token, nsecs_t workDuration,
- nsecs_t earliestVsync) {
+ScheduleResult VSyncDispatchTimerQueue::schedule(CallbackToken token, nsecs_t workDuration,
+ nsecs_t earliestVsync) {
auto result = ScheduleResult::Error;
{
std::lock_guard<decltype(mMutex)> lk(mMutex);
@@ -228,7 +231,7 @@
return result;
}
-CancelResult VSyncDispatch::cancel(CallbackToken token) {
+CancelResult VSyncDispatchTimerQueue::cancel(CallbackToken token) {
std::lock_guard<decltype(mMutex)> lk(mMutex);
auto it = mCallbacks.find(token);
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h
new file mode 100644
index 0000000..f058099
--- /dev/null
+++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android-base/thread_annotations.h>
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <string_view>
+#include <unordered_map>
+
+#include "VSyncDispatch.h"
+
+namespace android::scheduler {
+
+// VSyncDispatchTimerQueueEntry is a helper class representing internal state for each entry in
+// VSyncDispatchTimerQueue hoisted to public for unit testing.
+class VSyncDispatchTimerQueueEntry {
+public:
+ // This is the state of the entry. There are 3 states, armed, running, disarmed.
+ // Valid transition: disarmed -> armed ( when scheduled )
+ // Valid transition: armed -> running -> disarmed ( when timer is called)
+ // Valid transition: armed -> disarmed ( when cancelled )
+ VSyncDispatchTimerQueueEntry(std::string const& name, std::function<void(nsecs_t)> const& fn);
+ std::string_view name() const;
+
+ // Start: functions that are not threadsafe.
+ // Return the last vsync time this callback was invoked.
+ std::optional<nsecs_t> lastExecutedVsyncTarget() const;
+
+ // This moves the state from disarmed->armed and will calculate the wakeupTime.
+ nsecs_t schedule(nsecs_t workDuration, nsecs_t earliestVsync, VSyncTracker& tracker,
+ nsecs_t now);
+ // This will update armed entries with the latest vsync information. Entry remains armed.
+ void update(VSyncTracker& tracker, nsecs_t now);
+
+ // This will return empty if not armed, or the next calculated wakeup time if armed.
+ // It will not update the wakeupTime.
+ std::optional<nsecs_t> wakeupTime() const;
+
+ // This moves state from armed->disarmed.
+ void disarm();
+
+ // This moves the state from armed->running.
+ // Store the timestamp that this was intended for as the last called timestamp.
+ nsecs_t executing();
+ // End: functions that are not threadsafe.
+
+ // Invoke the callback with the timestamp, moving the state from running->disarmed.
+ void callback(nsecs_t timestamp);
+ // Block calling thread while the callback is executing.
+ void ensureNotRunning();
+
+private:
+ void arm(VSyncTracker& tracker, nsecs_t now);
+ std::string const mName;
+ std::function<void(nsecs_t)> const mCallback;
+
+ nsecs_t mWorkDuration;
+ nsecs_t mEarliestVsync;
+
+ struct ArmingInfo {
+ nsecs_t mActualWakeupTime;
+ nsecs_t mActualVsyncTime;
+ };
+ std::optional<ArmingInfo> mArmedInfo;
+ std::optional<nsecs_t> mLastDispatchTime;
+
+ std::mutex mRunningMutex;
+ std::condition_variable mCv;
+ bool mRunning GUARDED_BY(mRunningMutex) = false;
+};
+
+/*
+ * VSyncDispatchTimerQueue is a class that will dispatch callbacks as per VSyncDispatch interface
+ * using a single timer queue.
+ */
+class VSyncDispatchTimerQueue : public VSyncDispatch {
+public:
+ explicit VSyncDispatchTimerQueue(std::unique_ptr<TimeKeeper> tk, VSyncTracker& tracker,
+ nsecs_t timerSlack);
+ ~VSyncDispatchTimerQueue();
+
+ CallbackToken registerCallback(std::function<void(nsecs_t)> const& callbackFn,
+ std::string callbackName) final;
+ void unregisterCallback(CallbackToken token) final;
+ ScheduleResult schedule(CallbackToken token, nsecs_t workDuration, nsecs_t earliestVsync) final;
+ CancelResult cancel(CallbackToken token) final;
+
+private:
+ VSyncDispatchTimerQueue(VSyncDispatchTimerQueue const&) = delete;
+ VSyncDispatchTimerQueue& operator=(VSyncDispatchTimerQueue const&) = delete;
+
+ using CallbackMap = std::unordered_map<size_t, std::shared_ptr<VSyncDispatchTimerQueueEntry>>;
+
+ void timerCallback();
+ void setTimer(nsecs_t, nsecs_t) REQUIRES(mMutex);
+ void rearmTimer(nsecs_t now) REQUIRES(mMutex);
+ void rearmTimerSkippingUpdateFor(nsecs_t now, CallbackMap::iterator const& skipUpdate)
+ REQUIRES(mMutex);
+ void cancelTimer() REQUIRES(mMutex);
+
+ static constexpr nsecs_t kInvalidTime = std::numeric_limits<int64_t>::max();
+ std::unique_ptr<TimeKeeper> const mTimeKeeper;
+ VSyncTracker& mTracker;
+ nsecs_t const mTimerSlack;
+
+ std::mutex mutable mMutex;
+ size_t mCallbackToken GUARDED_BY(mMutex) = 0;
+
+ CallbackMap mCallbacks GUARDED_BY(mMutex);
+ nsecs_t mIntendedWakeupTime GUARDED_BY(mMutex) = kInvalidTime;
+};
+
+} // namespace android::scheduler
diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp
index 246a62f..78114a1 100644
--- a/services/surfaceflinger/tests/unittests/Android.bp
+++ b/services/surfaceflinger/tests/unittests/Android.bp
@@ -54,7 +54,7 @@
"FrameTracerTest.cpp",
"TransactionApplicationTest.cpp",
"StrongTypingTest.cpp",
- "VSyncDispatchTest.cpp",
+ "VSyncDispatchTimerQueueTest.cpp",
"mock/DisplayHardware/MockComposer.cpp",
"mock/DisplayHardware/MockDisplay.cpp",
"mock/DisplayHardware/MockPowerAdvisor.cpp",
diff --git a/services/surfaceflinger/tests/unittests/VSyncDispatchTest.cpp b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp
similarity index 86%
rename from services/surfaceflinger/tests/unittests/VSyncDispatchTest.cpp
rename to services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp
index d1ed7e3..82950b5 100644
--- a/services/surfaceflinger/tests/unittests/VSyncDispatchTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp
@@ -19,7 +19,7 @@
#define LOG_NDEBUG 0
#include "Scheduler/TimeKeeper.h"
-#include "Scheduler/VSyncDispatch.h"
+#include "Scheduler/VSyncDispatchTimerQueue.h"
#include "Scheduler/VSyncTracker.h"
#include <gmock/gmock.h>
@@ -166,7 +166,7 @@
std::chrono::milliseconds const mPauseAmount;
};
-class VSyncDispatchTest : public testing::Test {
+class VSyncDispatchTimerQueueTest : public testing::Test {
protected:
std::unique_ptr<TimeKeeper> createTimeKeeper() {
class TimeKeeperWrapper : public TimeKeeper {
@@ -184,7 +184,7 @@
return std::make_unique<TimeKeeperWrapper>(mMockClock);
}
- ~VSyncDispatchTest() {
+ ~VSyncDispatchTimerQueueTest() {
// destructor of dispatch will cancelAlarm(). Ignore final cancel in common test.
Mock::VerifyAndClearExpectations(&mMockClock);
}
@@ -195,20 +195,21 @@
static nsecs_t constexpr mDispatchGroupThreshold = 5;
nsecs_t const mPeriod = 1000;
NiceMock<MockVSyncTracker> mStubTracker{mPeriod};
- VSyncDispatch mDispatch{createTimeKeeper(), mStubTracker, mDispatchGroupThreshold};
+ VSyncDispatchTimerQueue mDispatch{createTimeKeeper(), mStubTracker, mDispatchGroupThreshold};
};
-TEST_F(VSyncDispatchTest, unregistersSetAlarmOnDestruction) {
+TEST_F(VSyncDispatchTimerQueueTest, unregistersSetAlarmOnDestruction) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmCancel());
{
- VSyncDispatch mDispatch{createTimeKeeper(), mStubTracker, mDispatchGroupThreshold};
+ VSyncDispatchTimerQueue mDispatch{createTimeKeeper(), mStubTracker,
+ mDispatchGroupThreshold};
CountingCallback cb(mDispatch);
EXPECT_EQ(mDispatch.schedule(cb, 100, 1000), ScheduleResult::Scheduled);
}
}
-TEST_F(VSyncDispatchTest, basicAlarmSettingFuture) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFuture) {
auto intended = mPeriod - 230;
EXPECT_CALL(mMockClock, alarmIn(_, 900));
@@ -220,7 +221,7 @@
EXPECT_THAT(cb.mCalls[0], Eq(mPeriod));
}
-TEST_F(VSyncDispatchTest, basicAlarmSettingFutureWithAdjustmentToTrueVsync) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFutureWithAdjustmentToTrueVsync) {
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(1000)).WillOnce(Return(1150));
EXPECT_CALL(mMockClock, alarmIn(_, 1050));
@@ -232,7 +233,7 @@
EXPECT_THAT(cb.mCalls[0], Eq(1150));
}
-TEST_F(VSyncDispatchTest, basicAlarmSettingAdjustmentPast) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingAdjustmentPast) {
auto const now = 234;
mMockClock.advanceBy(234);
auto const workDuration = 10 * mPeriod;
@@ -244,7 +245,7 @@
EXPECT_EQ(mDispatch.schedule(cb, workDuration, mPeriod), ScheduleResult::Scheduled);
}
-TEST_F(VSyncDispatchTest, basicAlarmCancel) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancel) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmCancel());
@@ -253,7 +254,7 @@
EXPECT_EQ(mDispatch.cancel(cb), CancelResult::Cancelled);
}
-TEST_F(VSyncDispatchTest, basicAlarmCancelTooLate) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancelTooLate) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmCancel());
@@ -263,7 +264,7 @@
EXPECT_EQ(mDispatch.cancel(cb), CancelResult::TooLate);
}
-TEST_F(VSyncDispatchTest, basicAlarmCancelTooLateWhenRunning) {
+TEST_F(VSyncDispatchTimerQueueTest, basicAlarmCancelTooLateWhenRunning) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmCancel());
@@ -277,7 +278,7 @@
pausingThread.join();
}
-TEST_F(VSyncDispatchTest, unregisterSynchronizes) {
+TEST_F(VSyncDispatchTimerQueueTest, unregisterSynchronizes) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmCancel());
@@ -299,7 +300,7 @@
EXPECT_TRUE(cb.resourcePresent());
}
-TEST_F(VSyncDispatchTest, basicTwoAlarmSetting) {
+TEST_F(VSyncDispatchTimerQueueTest, basicTwoAlarmSetting) {
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(1000))
.Times(4)
.WillOnce(Return(1055))
@@ -327,7 +328,7 @@
EXPECT_THAT(cb1.mCalls[0], Eq(1063));
}
-TEST_F(VSyncDispatchTest, rearmsFaroutTimeoutWhenCancellingCloseOne) {
+TEST_F(VSyncDispatchTimerQueueTest, rearmsFaroutTimeoutWhenCancellingCloseOne) {
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(_))
.Times(4)
.WillOnce(Return(10000))
@@ -348,7 +349,7 @@
mDispatch.cancel(cb1);
}
-TEST_F(VSyncDispatchTest, noUnnecessaryRearmsWhenRescheduling) {
+TEST_F(VSyncDispatchTimerQueueTest, noUnnecessaryRearmsWhenRescheduling) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 600)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 100)).InSequence(seq);
@@ -362,7 +363,7 @@
advanceToNextCallback();
}
-TEST_F(VSyncDispatchTest, necessaryRearmsWhenModifying) {
+TEST_F(VSyncDispatchTimerQueueTest, necessaryRearmsWhenModifying) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 600)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 500)).InSequence(seq);
@@ -377,7 +378,7 @@
advanceToNextCallback();
}
-TEST_F(VSyncDispatchTest, modifyIntoGroup) {
+TEST_F(VSyncDispatchTimerQueueTest, modifyIntoGroup) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 600)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 1000)).InSequence(seq);
@@ -412,7 +413,7 @@
EXPECT_THAT(cb0.mCalls[1], Eq(2000));
}
-TEST_F(VSyncDispatchTest, rearmsWhenEndingAndDoesntCancel) {
+TEST_F(VSyncDispatchTimerQueueTest, rearmsWhenEndingAndDoesntCancel) {
EXPECT_CALL(mMockClock, alarmIn(_, 900));
EXPECT_CALL(mMockClock, alarmIn(_, 800));
EXPECT_CALL(mMockClock, alarmIn(_, 100));
@@ -427,7 +428,7 @@
EXPECT_EQ(mDispatch.cancel(cb0), CancelResult::Cancelled);
}
-TEST_F(VSyncDispatchTest, setAlarmCallsAtCorrectTimeWithChangingVsync) {
+TEST_F(VSyncDispatchTimerQueueTest, setAlarmCallsAtCorrectTimeWithChangingVsync) {
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(_))
.Times(3)
.WillOnce(Return(950))
@@ -451,7 +452,7 @@
EXPECT_THAT(cb.mCalls.size(), Eq(3));
}
-TEST_F(VSyncDispatchTest, callbackReentrancy) {
+TEST_F(VSyncDispatchTimerQueueTest, callbackReentrancy) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 900)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 1000)).InSequence(seq);
@@ -463,7 +464,7 @@
advanceToNextCallback();
}
-TEST_F(VSyncDispatchTest, callbackReentrantWithPastWakeup) {
+TEST_F(VSyncDispatchTimerQueueTest, callbackReentrantWithPastWakeup) {
VSyncDispatch::CallbackToken tmp;
tmp = mDispatch.registerCallback(
[&](auto) {
@@ -475,7 +476,7 @@
advanceToNextCallback();
}
-TEST_F(VSyncDispatchTest, modificationsAroundVsyncTime) {
+TEST_F(VSyncDispatchTimerQueueTest, modificationsAroundVsyncTime) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 1000)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 200)).InSequence(seq);
@@ -495,7 +496,7 @@
mDispatch.schedule(cb, 100, 2000);
}
-TEST_F(VSyncDispatchTest, lateModifications) {
+TEST_F(VSyncDispatchTimerQueueTest, lateModifications) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 500)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmIn(_, 400)).InSequence(seq);
@@ -516,7 +517,7 @@
advanceToNextCallback();
}
-TEST_F(VSyncDispatchTest, doesntCancelPriorValidTimerForFutureMod) {
+TEST_F(VSyncDispatchTimerQueueTest, doesntCancelPriorValidTimerForFutureMod) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 500)).InSequence(seq);
@@ -526,7 +527,7 @@
mDispatch.schedule(cb1, 500, 20000);
}
-TEST_F(VSyncDispatchTest, setsTimerAfterCancellation) {
+TEST_F(VSyncDispatchTimerQueueTest, setsTimerAfterCancellation) {
Sequence seq;
EXPECT_CALL(mMockClock, alarmIn(_, 500)).InSequence(seq);
EXPECT_CALL(mMockClock, alarmCancel()).InSequence(seq);
@@ -538,19 +539,19 @@
mDispatch.schedule(cb0, 100, 1000);
}
-TEST_F(VSyncDispatchTest, makingUpIdsError) {
+TEST_F(VSyncDispatchTimerQueueTest, makingUpIdsError) {
VSyncDispatch::CallbackToken token(100);
EXPECT_THAT(mDispatch.schedule(token, 100, 1000), Eq(ScheduleResult::Error));
EXPECT_THAT(mDispatch.cancel(token), Eq(CancelResult::Error));
}
-TEST_F(VSyncDispatchTest, distinguishesScheduleAndReschedule) {
+TEST_F(VSyncDispatchTimerQueueTest, distinguishesScheduleAndReschedule) {
CountingCallback cb0(mDispatch);
EXPECT_EQ(mDispatch.schedule(cb0, 500, 1000), ScheduleResult::Scheduled);
EXPECT_EQ(mDispatch.schedule(cb0, 100, 1000), ScheduleResult::ReScheduled);
}
-TEST_F(VSyncDispatchTest, helperMove) {
+TEST_F(VSyncDispatchTimerQueueTest, helperMove) {
EXPECT_CALL(mMockClock, alarmIn(_, 500)).Times(1);
EXPECT_CALL(mMockClock, alarmCancel()).Times(1);
@@ -564,7 +565,7 @@
cb1.cancel();
}
-TEST_F(VSyncDispatchTest, helperMoveAssign) {
+TEST_F(VSyncDispatchTimerQueueTest, helperMoveAssign) {
EXPECT_CALL(mMockClock, alarmIn(_, 500)).Times(1);
EXPECT_CALL(mMockClock, alarmCancel()).Times(1);
@@ -580,22 +581,22 @@
cb1.cancel();
}
-class VSyncDispatchEntryTest : public testing::Test {
+class VSyncDispatchTimerQueueEntryTest : public testing::Test {
protected:
nsecs_t const mPeriod = 1000;
NiceMock<MockVSyncTracker> mStubTracker{mPeriod};
};
-TEST_F(VSyncDispatchEntryTest, stateAfterInitialization) {
+TEST_F(VSyncDispatchTimerQueueEntryTest, stateAfterInitialization) {
std::string name("basicname");
- impl::VSyncDispatchEntry entry(name, [](auto) {});
+ VSyncDispatchTimerQueueEntry entry(name, [](auto) {});
EXPECT_THAT(entry.name(), Eq(name));
EXPECT_FALSE(entry.lastExecutedVsyncTarget());
EXPECT_FALSE(entry.wakeupTime());
}
-TEST_F(VSyncDispatchEntryTest, stateScheduling) {
- impl::VSyncDispatchEntry entry("test", [](auto) {});
+TEST_F(VSyncDispatchTimerQueueEntryTest, stateScheduling) {
+ VSyncDispatchTimerQueueEntry entry("test", [](auto) {});
EXPECT_FALSE(entry.wakeupTime());
auto const wakeup = entry.schedule(100, 500, mStubTracker, 0);
@@ -608,14 +609,14 @@
EXPECT_FALSE(entry.wakeupTime());
}
-TEST_F(VSyncDispatchEntryTest, stateSchedulingReallyLongWakeupLatency) {
+TEST_F(VSyncDispatchTimerQueueEntryTest, stateSchedulingReallyLongWakeupLatency) {
auto const duration = 500;
auto const now = 8750;
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(now + duration))
.Times(1)
.WillOnce(Return(10000));
- impl::VSyncDispatchEntry entry("test", [](auto) {});
+ VSyncDispatchTimerQueueEntry entry("test", [](auto) {});
EXPECT_FALSE(entry.wakeupTime());
auto const wakeup = entry.schedule(500, 994, mStubTracker, now);
@@ -625,10 +626,10 @@
EXPECT_THAT(*queried, Eq(9500));
}
-TEST_F(VSyncDispatchEntryTest, runCallback) {
+TEST_F(VSyncDispatchTimerQueueEntryTest, runCallback) {
auto callCount = 0;
auto calledTime = 0;
- impl::VSyncDispatchEntry entry("test", [&](auto time) {
+ VSyncDispatchTimerQueueEntry entry("test", [&](auto time) {
callCount++;
calledTime = time;
});
@@ -646,13 +647,13 @@
EXPECT_THAT(*lastCalledTarget, Eq(mPeriod));
}
-TEST_F(VSyncDispatchEntryTest, updateCallback) {
+TEST_F(VSyncDispatchTimerQueueEntryTest, updateCallback) {
EXPECT_CALL(mStubTracker, nextAnticipatedVSyncTimeFrom(_))
.Times(2)
.WillOnce(Return(1000))
.WillOnce(Return(1020));
- impl::VSyncDispatchEntry entry("test", [](auto) {});
+ VSyncDispatchTimerQueueEntry entry("test", [](auto) {});
EXPECT_FALSE(entry.wakeupTime());
entry.update(mStubTracker, 0);
@@ -667,8 +668,8 @@
EXPECT_THAT(*queried, Eq(920));
}
-TEST_F(VSyncDispatchEntryTest, skipsUpdateIfJustScheduled) {
- impl::VSyncDispatchEntry entry("test", [](auto) {});
+TEST_F(VSyncDispatchTimerQueueEntryTest, skipsUpdateIfJustScheduled) {
+ VSyncDispatchTimerQueueEntry entry("test", [](auto) {});
auto const wakeup = entry.schedule(100, 500, mStubTracker, 0);
entry.update(mStubTracker, 0);