update_engine: Use clock and fake clock from SystemState
No need to pass clock and fake clock anywhere anymore. This CL makes it
to just use those objects available from SystemState and
FakeSystemState.
BUG=b:171829801
TEST=cros_workon_make --board reef --test update_engine
Change-Id: I9a3cf6dd2057620c11b862d3317b83489c76f3ca
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2546625
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index b348d50..18705bd 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -37,7 +37,6 @@
#include "update_engine/common/constants.h"
#include "update_engine/common/dlcservice_interface.h"
-#include "update_engine/common/fake_clock.h"
#include "update_engine/common/fake_prefs.h"
#include "update_engine/common/mock_action.h"
#include "update_engine/common/mock_action_processor.h"
@@ -1330,14 +1329,12 @@
// Checks that we only report daily metrics at most every 24 hours.
TEST_F(UpdateAttempterTest, ReportDailyMetrics) {
- FakeClock fake_clock;
FakePrefs fake_prefs;
-
- FakeSystemState::Get()->set_clock(&fake_clock);
FakeSystemState::Get()->set_prefs(&fake_prefs);
+ auto* fake_clock = FakeSystemState::Get()->fake_clock();
Time epoch = Time::FromInternalValue(0);
- fake_clock.SetWallclockTime(epoch);
+ fake_clock->SetWallclockTime(epoch);
// If there is no kPrefsDailyMetricsLastReportedAt state variable,
// we should report.
@@ -1346,32 +1343,32 @@
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// We should not report if only 10 hours has passed.
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(10));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(10));
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// We should not report if only 24 hours - 1 sec has passed.
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24) -
- TimeDelta::FromSeconds(1));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(24) -
+ TimeDelta::FromSeconds(1));
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// We should report if 24 hours has passed.
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(24));
EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
// But then we should not report again..
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// .. until another 24 hours has passed
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(47));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(47));
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(48));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(48));
EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// .. and another 24 hours
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(71));
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(72));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(72));
EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
@@ -1379,23 +1376,21 @@
// negative, we report. This is in order to reset the timestamp and
// avoid an edge condition whereby a distant point in the future is
// in the state variable resulting in us never ever reporting again.
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(71));
EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
// In this case we should not update until the clock reads 71 + 24 = 95.
// Check that.
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(94));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(94));
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
- fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(95));
+ fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(95));
EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
}
TEST_F(UpdateAttempterTest, BootTimeInUpdateMarkerFile) {
- FakeClock fake_clock;
- fake_clock.SetBootTime(Time::FromTimeT(42));
- FakeSystemState::Get()->set_clock(&fake_clock);
+ FakeSystemState::Get()->fake_clock()->SetBootTime(Time::FromTimeT(42));
FakePrefs fake_prefs;
FakeSystemState::Get()->set_prefs(&fake_prefs);
attempter_.Init();
@@ -1965,12 +1960,10 @@
fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
update_first_seen_at.ToInternalValue());
- FakeClock fake_clock;
Time update_finished_at =
update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
- fake_clock.SetWallclockTime(update_finished_at);
+ FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
- FakeSystemState::Get()->set_clock(&fake_clock);
FakeSystemState::Get()->set_prefs(&fake_prefs);
EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
@@ -1995,12 +1988,9 @@
fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
update_first_seen_at.ToInternalValue());
- FakeClock fake_clock;
Time update_finished_at =
update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
- fake_clock.SetWallclockTime(update_finished_at);
-
- FakeSystemState::Get()->set_clock(&fake_clock);
+ FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
FakeSystemState::Get()->set_prefs(&fake_prefs);
EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),