Update system time for OPK reboot tests

[ Merge of http://go/wvgerrit/154593 ]

This CL updates the initial time used for reboot tests to be
within the valid range used by OPK. Also, the fake clock is
now synced with every use of the TestHost's clock function.

Also, the OPK's system clock is no longer initialized to 0
because this caused some tests to set initial playback time
to 0. That broke code that assumed a time of 0 mean "never".

I also removed some log spam in the WTPI code.

Bug: 222353528
Bug: 236317198
Change-Id: Ibdbdb2440454b9cf561cd9ec65ca3e40cf5a8d93
This commit is contained in:
Alex Dale
2022-07-20 13:35:13 -07:00
parent b08a8feeb3
commit a20ee5bc54
2 changed files with 10 additions and 1 deletions

View File

@@ -223,9 +223,11 @@ void RebootTest::SetUp() {
EXPECT_EQ(read, file_size) << "Error reading persistent data file.";
EXPECT_TRUE(ParseDump(dump, &persistent_data_));
}
TestSleep::SyncFakeClock();
}
void RebootTest::TearDown() {
TestSleep::SyncFakeClock();
auto file = file_system_->Open(persistent_data_filename_,
FileSystem::kCreate | FileSystem::kTruncate);
ASSERT_TRUE(file) << "Failed to open file: " << persistent_data_filename_;
@@ -405,6 +407,7 @@ class OfflineLicense {
// Fetch and load the license. The session is left open.
void LoadLicense() {
license_holder_.OpenSession();
TestSleep::SyncFakeClock();
start_of_rental_clock_ = wvutil::Clock().GetCurrentTime();
license_holder_.FetchLicense();
license_holder_.LoadLicense();
@@ -434,6 +437,7 @@ class OfflineLicense {
// Verify that the license may be used to decrypt content.
void Decrypt() {
TestSleep::SyncFakeClock();
if (start_of_playback_ == 0) {
start_of_playback_ = wvutil::Clock().GetCurrentTime();
}
@@ -451,6 +455,7 @@ class OfflineLicense {
// Verify that the license has expired, and may not be used to decrypt
// content.
void FailDecrypt() {
TestSleep::SyncFakeClock();
const KeyId key_id = "0000000000000000";
EXPECT_EQ(NEED_KEY, license_holder_.Decrypt(key_id))
<< "Decrypt should have failed for " << content_id_
@@ -629,6 +634,7 @@ class OfflineLicenseTest : public RebootTest {
int decrypt_count = 0;
int fail_count = 0;
for (auto time : interesting_times_) {
TestSleep::SyncFakeClock();
int64_t now = wvutil::Clock().GetCurrentTime();
int64_t delta = (time - now);
// It is not necessarily an error for the delta to be negative. But it is
@@ -673,6 +679,7 @@ class OfflineLicenseTest : public RebootTest {
for (size_t i = first_valid_[n] + 1; i < test_case_[n].size(); i++) {
OfflineLicense* license = test_case_[n][i].get();
ASSERT_NO_FATAL_FAILURE(license->ReloadLicense());
TestSleep::SyncFakeClock();
int64_t now = wvutil::Clock().GetCurrentTime();
if (now <= license->cutoff() - kFudge) {
license->Decrypt();