You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
koreader/spec/unit/wakeupmgr_spec.lua

56 lines
2.3 KiB
Lua

describe("WakeupMgr", function()
local RTC
local WakeupMgr
local epoch1, epoch2, epoch3
setup(function()
require("commonrequire")
package.unloadAll()
RTC = require("ffi/rtc")
WakeupMgr = require("device/wakeupmgr")
-- We could theoretically test this by running the tests as root locally.
stub(WakeupMgr, "setWakeupAlarm")
WakeupMgr.validateWakeupAlarmByProximity = spy.new(function() return true end)
epoch1 = RTC:secondsFromNowToEpoch(1234)
epoch2 = RTC:secondsFromNowToEpoch(123)
epoch3 = RTC:secondsFromNowToEpoch(9999)
end)
it("should add a task", function()
WakeupMgr:addTask(1234, function() end)
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
assert.stub(WakeupMgr.setWakeupAlarm).was.called(1)
end)
it("should add a task in order", function()
WakeupMgr:addTask(9999, function() end)
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
assert.stub(WakeupMgr.setWakeupAlarm).was.called(1)
WakeupMgr:addTask(123, function() end)
assert.is_equal(epoch2, WakeupMgr._task_queue[1].epoch)
assert.stub(WakeupMgr.setWakeupAlarm).was.called(2)
end)
it("should execute top task", function()
assert.is_true(WakeupMgr:wakeupAction())
end)
it("should have removed executed task from stack", function()
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
assert.is_equal(epoch3, WakeupMgr._task_queue[2].epoch)
end)
it("should have scheduled next task after execution", function()
A host of low power states related tweaks (#9036) * Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things). * Kobo: Use our WakeupMgr instance, not the class. * WakupMgr: split `removeTask` in two: * `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`). * `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches. * Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;). * `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window. * `wakeupAction` now re-schedules the next task (if any) on exit. * Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`. * The various network activity timeouts are now halved when autostandby is enabled. * Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009. * UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop. * ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby. * Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state). * Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes. * Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices). * AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038). * PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon). * Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full. * Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
assert.stub(WakeupMgr.setWakeupAlarm).was.called(3) -- 2 from addTask (the second addTask doesn't replace the upcoming task), 1 from wakeupAction (via removeTask).
end)
it("should remove arbitrary task from stack", function()
WakeupMgr:removeTask(2)
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
assert.is_equal(nil, WakeupMgr._task_queue[2])
end)
it("should execute last task", function()
assert.is_true(WakeupMgr:wakeupAction())
end)
it("should not have scheduled a wakeup without a task", function()
A host of low power states related tweaks (#9036) * Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things). * Kobo: Use our WakeupMgr instance, not the class. * WakupMgr: split `removeTask` in two: * `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`). * `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches. * Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;). * `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window. * `wakeupAction` now re-schedules the next task (if any) on exit. * Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`. * The various network activity timeouts are now halved when autostandby is enabled. * Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009. * UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop. * ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby. * Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state). * Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes. * Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices). * AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038). * PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon). * Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full. * Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
assert.stub(WakeupMgr.setWakeupAlarm).was.called(3) -- 2 from addTask, 1 from wakeupAction, 0 from removeTask (because it wasn't the upcoming task that was removed)
end)
end)