From d4cbc5aad28f32c90e18d0fdd5ff8d1150fbd663 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Mon, 24 Sep 2018 14:23:05 -0700 Subject: test/watchdog: Test interval update Adds a test to ensure that setting the interval on the watchdog affects subsequent resetTimeRemaining() calls. Tested: Ran through a unit test run Change-Id: Ibff14bbb40d5b93ffd5eaa5149f5cc9822e21d1e Signed-off-by: William A. Kennington III --- test/watchdog_test.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/watchdog_test.cpp b/test/watchdog_test.cpp index 49890da..aa0ae0f 100644 --- a/test/watchdog_test.cpp +++ b/test/watchdog_test.cpp @@ -154,6 +154,33 @@ TEST_F(WdogTest, verifyIntervalUpdateReceived) EXPECT_EQ(expireTimeMs, wdog->interval()); } +/** @brief Make sure the Interval can be updated while the timer is running. + */ +TEST_F(WdogTest, verifyIntervalUpdateRunning) +{ + const auto oldInterval = milliseconds(wdog->interval()); + const auto newInterval = 5s; + + EXPECT_TRUE(wdog->enabled(true)); + auto remaining = milliseconds(wdog->timeRemaining()); + EXPECT_GE(oldInterval, remaining); + EXPECT_LE(oldInterval - defaultDrift, remaining); + EXPECT_EQ(newInterval, + milliseconds(wdog->interval(milliseconds(newInterval).count()))); + + // Expect only the interval to update + remaining = milliseconds(wdog->timeRemaining()); + EXPECT_GE(oldInterval, remaining); + EXPECT_LE(oldInterval - defaultDrift, remaining); + EXPECT_EQ(newInterval, milliseconds(wdog->interval())); + + // Expect reset to use the new interval + wdog->resetTimeRemaining(false); + remaining = milliseconds(wdog->timeRemaining()); + EXPECT_GE(newInterval, remaining); + EXPECT_LE(newInterval - defaultDrift, remaining); +} + /** @brief Make sure that watchdog is started and enabled. * Wait default interval seconds and make sure that wdog has died */ -- cgit v1.2.1