123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #include "update_engine/metrics_utils.h"
- #include <gtest/gtest.h>
- #include "update_engine/common/fake_clock.h"
- #include "update_engine/common/fake_prefs.h"
- #include "update_engine/fake_system_state.h"
- namespace chromeos_update_engine {
- namespace metrics_utils {
- class MetricsUtilsTest : public ::testing::Test {};
- TEST(MetricsUtilsTest, GetConnectionType) {
-
- EXPECT_EQ(metrics::ConnectionType::kUnknown,
- GetConnectionType(ConnectionType::kUnknown,
- ConnectionTethering::kUnknown));
- EXPECT_EQ(metrics::ConnectionType::kDisconnected,
- GetConnectionType(ConnectionType::kDisconnected,
- ConnectionTethering::kUnknown));
- EXPECT_EQ(metrics::ConnectionType::kEthernet,
- GetConnectionType(ConnectionType::kEthernet,
- ConnectionTethering::kUnknown));
- EXPECT_EQ(
- metrics::ConnectionType::kWifi,
- GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown));
- EXPECT_EQ(
- metrics::ConnectionType::kWimax,
- GetConnectionType(ConnectionType::kWimax, ConnectionTethering::kUnknown));
- EXPECT_EQ(metrics::ConnectionType::kBluetooth,
- GetConnectionType(ConnectionType::kBluetooth,
- ConnectionTethering::kUnknown));
- EXPECT_EQ(metrics::ConnectionType::kCellular,
- GetConnectionType(ConnectionType::kCellular,
- ConnectionTethering::kUnknown));
- EXPECT_EQ(metrics::ConnectionType::kTetheredEthernet,
- GetConnectionType(ConnectionType::kEthernet,
- ConnectionTethering::kConfirmed));
- EXPECT_EQ(metrics::ConnectionType::kTetheredWifi,
- GetConnectionType(ConnectionType::kWifi,
- ConnectionTethering::kConfirmed));
-
- EXPECT_EQ(metrics::ConnectionType::kEthernet,
- GetConnectionType(ConnectionType::kEthernet,
- ConnectionTethering::kNotDetected));
- EXPECT_EQ(metrics::ConnectionType::kEthernet,
- GetConnectionType(ConnectionType::kEthernet,
- ConnectionTethering::kSuspected));
- EXPECT_EQ(metrics::ConnectionType::kEthernet,
- GetConnectionType(ConnectionType::kEthernet,
- ConnectionTethering::kUnknown));
-
- EXPECT_EQ(metrics::ConnectionType::kWifi,
- GetConnectionType(ConnectionType::kWifi,
- ConnectionTethering::kNotDetected));
- EXPECT_EQ(metrics::ConnectionType::kWifi,
- GetConnectionType(ConnectionType::kWifi,
- ConnectionTethering::kSuspected));
- EXPECT_EQ(
- metrics::ConnectionType::kWifi,
- GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown));
- }
- TEST(MetricsUtilsTest, WallclockDurationHelper) {
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- base::TimeDelta duration;
- const std::string state_variable_key = "test-prefs";
- FakePrefs fake_prefs;
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
-
- fake_clock.SetWallclockTime(base::Time::FromInternalValue(1000000));
-
- EXPECT_FALSE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
-
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
-
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
-
- fake_clock.SetWallclockTime(base::Time::FromInternalValue(2000000));
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 1);
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
- fake_clock.SetWallclockTime(base::Time::FromInternalValue(4000000));
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 2);
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
-
-
- fake_clock.SetWallclockTime(base::Time::FromInternalValue(3000000));
- EXPECT_FALSE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- fake_clock.SetWallclockTime(base::Time::FromInternalValue(4000000));
- EXPECT_TRUE(metrics_utils::WallclockDurationHelper(
- &fake_system_state, state_variable_key, &duration));
- EXPECT_EQ(duration.InSeconds(), 1);
- }
- TEST(MetricsUtilsTest, MonotonicDurationHelper) {
- int64_t storage = 0;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- base::TimeDelta duration;
- fake_system_state.set_clock(&fake_clock);
-
- fake_clock.SetMonotonicTime(base::Time::FromInternalValue(1000000));
-
- EXPECT_FALSE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
-
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
-
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
-
- fake_clock.SetMonotonicTime(base::Time::FromInternalValue(2000000));
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 1);
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
-
- fake_clock.SetMonotonicTime(base::Time::FromInternalValue(4000000));
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 2);
- EXPECT_TRUE(metrics_utils::MonotonicDurationHelper(
- &fake_system_state, &storage, &duration));
- EXPECT_EQ(duration.InSeconds(), 0);
- }
- }
- }
|