[ 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
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
//
|
|
// 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 <chrono>
|
|
|
|
#include "clock.h"
|
|
#include "test_sleep.h"
|
|
|
|
namespace wvutil {
|
|
|
|
namespace {
|
|
// A fake clock that only advances when TestSleep::Sleep is called.
|
|
class FakeClock : public TestSleep::CallBack {
|
|
public:
|
|
FakeClock() {
|
|
auto now = std::chrono::system_clock().now();
|
|
now_ = now.time_since_epoch() / std::chrono::milliseconds(1);
|
|
TestSleep::set_callback(this);
|
|
}
|
|
~FakeClock() { TestSleep::set_callback(nullptr); }
|
|
void ElapseTime(int64_t milliseconds) { now_ += milliseconds; }
|
|
|
|
int64_t now() const { return now_; }
|
|
|
|
private:
|
|
int64_t now_;
|
|
};
|
|
|
|
FakeClock* g_fake_clock = nullptr;
|
|
} // namespace
|
|
|
|
// On devices running a fake OEMCrypto, we can use a fake sleep and fake time.
|
|
int64_t Clock::GetCurrentTime() {
|
|
TestSleep::SyncFakeClock();
|
|
if (g_fake_clock == nullptr) g_fake_clock = new FakeClock();
|
|
return g_fake_clock->now() / 1000;
|
|
}
|
|
|
|
} // namespace wvutil
|