From a20ee5bc54c9b8541852f55e24b1b4d737b2c863 Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Wed, 20 Jul 2022 13:35:13 -0700 Subject: [PATCH] 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 --- libwvdrmengine/cdm/core/test/reboot_test.cpp | 7 +++++++ libwvdrmengine/cdm/util/test/test_clock.cpp | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/cdm/core/test/reboot_test.cpp b/libwvdrmengine/cdm/core/test/reboot_test.cpp index 32950f7b..39e208b2 100644 --- a/libwvdrmengine/cdm/core/test/reboot_test.cpp +++ b/libwvdrmengine/cdm/core/test/reboot_test.cpp @@ -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(); diff --git a/libwvdrmengine/cdm/util/test/test_clock.cpp b/libwvdrmengine/cdm/util/test/test_clock.cpp index 18331bb6..33edd9c3 100644 --- a/libwvdrmengine/cdm/util/test/test_clock.cpp +++ b/libwvdrmengine/cdm/util/test/test_clock.cpp @@ -2,7 +2,9 @@ // source code may only be used and distributed under the Widevine License // Agreement. // -// Clock - A fake clock just for running tests. +// Clock - A fake clock just for running tests. This is used when running +// OEMCrypto unit tests. It is not used when tests include the CE CDM source +// code because that uses the clock in cdm/test_host.cpp instead. #include