Reboot test: Initialize fake clock
[ Merge of http://go/wvgerrit/143630 ] When we run a test with the fake clock, the clock had been initialized to the current time, or to 0. This causes a problem for reboot tests because the clock might go backwards over the reboot. With this change, we monitor the clock at the end of one reboot pass and initialize the clock for the next pass based on the previous value. Bug: 26163469 Test: GtsMediaTestCases on sunfish Change-Id: Ibd0024f963634382af70553fced38da6e1d857d2
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "log.h"
|
||||
#include "test_sleep.h"
|
||||
|
||||
using wvutil::a2b_hex;
|
||||
using wvutil::FileSystem;
|
||||
@@ -227,6 +228,23 @@ void RebootTest::TearDown() {
|
||||
WvCdmTestBase::TearDown();
|
||||
}
|
||||
|
||||
int64_t RebootTest::LoadTime(const std::string& key) {
|
||||
int64_t value = 0;
|
||||
std::istringstream input(persistent_data_[key]);
|
||||
input >> value;
|
||||
if (input.fail()) {
|
||||
LOGE("Could not parse time '%s'", persistent_data_[key].c_str());
|
||||
}
|
||||
if (!input.eof()) {
|
||||
LOGE("Extra text at end of time '%s'", persistent_data_[key].c_str());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void RebootTest::SaveTime(const std::string& key, int64_t time) {
|
||||
persistent_data_[key] = std::to_string(time);
|
||||
}
|
||||
|
||||
/** Test the dump and restore functions above. This does not test CDM
|
||||
functionality. */
|
||||
TEST_F(RebootTest, TestDumpUtil) {
|
||||
@@ -277,4 +295,20 @@ TEST_F(RebootTest, FilesArePersistent) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify that the clock moves forward over a reboot. */
|
||||
TEST_F(RebootTest, TimeMovesForward) {
|
||||
wvutil::TestSleep::Sleep(2);
|
||||
const int64_t start = wvutil::Clock().GetCurrentTime();
|
||||
wvutil::TestSleep::Sleep(2);
|
||||
const int64_t end = wvutil::Clock().GetCurrentTime();
|
||||
EXPECT_NEAR(end - start, 2.0, 1.0);
|
||||
const std::string key = "end_time";
|
||||
if (test_pass() == 0) {
|
||||
// Save off the end of pass 1.
|
||||
SaveTime(key, end);
|
||||
} else {
|
||||
int64_t previous_end = LoadTime(key);
|
||||
EXPECT_LT(previous_end, start);
|
||||
}
|
||||
}
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user