Commit 4dd4d4a2 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Do not compare field by field in tests

Do not compare field by field in tests to not forget testing new field
in the future.

Bug: b:158658869
Change-Id: I46225a1b3601bd0d7f0cf7026e246eeffb745a95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274891
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Cr-Commit-Position: refs/heads/master@{#786478}
parent 85bee24d
......@@ -17,6 +17,12 @@ using testing::ElementsAre;
namespace chromeos {
namespace probe_service_converters {
// Note: in some tests we intentionally use New() with no arguments for
// cros_healthd::mojom types, because there can be some fields that we don't
// test yet.
// Also, we intentionally use New() with arguments for health::mojom types to
// let the compiler detect untested data members.
TEST(ProbeServiceConvertors, ConvertCategoryVector) {
const std::vector<health::mojom::ProbeCategoryEnum> kInput{
health::mojom::ProbeCategoryEnum::kBattery,
......@@ -111,29 +117,26 @@ TEST(ProbeServiceConvertors, BatteryInfoPtr) {
constexpr char kManufactureDate[] = "2018-10-01";
constexpr uint64_t kTemperature = 3097;
// Here we don't use cros_healthd::mojom::BatteryInfo::New because BatteryInfo
// may contain some fields that we don't use yet.
auto battery_info = cros_healthd::mojom::BatteryInfo::New();
battery_info->cycle_count = kCycleCount;
battery_info->voltage_now = kVoltageNow;
battery_info->vendor = kVendor;
battery_info->serial_number = kSerialNumber;
battery_info->charge_full_design = kChargeFullDesign;
battery_info->charge_full = kChargeFull;
battery_info->voltage_min_design = kVoltageMinDesign;
battery_info->model_name = kModelName;
battery_info->charge_now = kChargeNow;
battery_info->current_now = kCurrentNow;
battery_info->technology = kTechnology;
battery_info->status = kStatus;
battery_info->manufacture_date = kManufactureDate;
battery_info->temperature =
cros_healthd::mojom::UInt64Value::New(kTemperature);
// Here we intentionaly use health::mojom::BatteryInfo::New not to
// forget to test new fields.
auto input = cros_healthd::mojom::BatteryInfo::New();
{
input->cycle_count = kCycleCount;
input->voltage_now = kVoltageNow;
input->vendor = kVendor;
input->serial_number = kSerialNumber;
input->charge_full_design = kChargeFullDesign;
input->charge_full = kChargeFull;
input->voltage_min_design = kVoltageMinDesign;
input->model_name = kModelName;
input->charge_now = kChargeNow;
input->current_now = kCurrentNow;
input->technology = kTechnology;
input->status = kStatus;
input->manufacture_date = kManufactureDate;
input->temperature = cros_healthd::mojom::UInt64Value::New(kTemperature);
}
EXPECT_EQ(
ConvertPtr(battery_info.Clone()),
ConvertPtr(std::move(input)),
health::mojom::BatteryInfo::New(
health::mojom::Int64Value::New(kCycleCount),
health::mojom::DoubleValue::New(kVoltageNow), kVendor, kSerialNumber,
......@@ -173,29 +176,25 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceInfoPtr) {
constexpr uint64_t kIoTimeSecondsSinceLastBoot = 100000;
constexpr uint64_t kDiscardTimeSecondsSinceLastBoot = 1000000;
// Here we don't use cros_healthd::mojom::NonRemovableBlockDeviceInfo::New
// because NonRemovableBlockDeviceInfo may contain some fields that we
// don't use yet.
auto info = cros_healthd::mojom::NonRemovableBlockDeviceInfo::New();
info->path = kPath;
info->size = kSize;
info->type = kType;
info->manufacturer_id = kManufacturerId;
info->name = kName;
info->serial = kSerial;
info->bytes_read_since_last_boot = kBytesReadSinceLastBoot;
info->bytes_written_since_last_boot = kBytesWrittenSinceLastBoot;
info->read_time_seconds_since_last_boot = kReadTimeSecondsSinceLastBoot;
info->write_time_seconds_since_last_boot = kWriteTimeSecondsSinceLastBoot;
info->io_time_seconds_since_last_boot = kIoTimeSecondsSinceLastBoot;
info->discard_time_seconds_since_last_boot =
auto input = cros_healthd::mojom::NonRemovableBlockDeviceInfo::New();
{
input->path = kPath;
input->size = kSize;
input->type = kType;
input->manufacturer_id = kManufacturerId;
input->name = kName;
input->serial = kSerial;
input->bytes_read_since_last_boot = kBytesReadSinceLastBoot;
input->bytes_written_since_last_boot = kBytesWrittenSinceLastBoot;
input->read_time_seconds_since_last_boot = kReadTimeSecondsSinceLastBoot;
input->write_time_seconds_since_last_boot = kWriteTimeSecondsSinceLastBoot;
input->io_time_seconds_since_last_boot = kIoTimeSecondsSinceLastBoot;
input->discard_time_seconds_since_last_boot =
cros_healthd::mojom::UInt64Value::New(kDiscardTimeSecondsSinceLastBoot);
}
// Here we intentionaly use health::mojom::NonRemovableBlockDeviceInfo::New
// not to forget to test new fields.
EXPECT_EQ(
ConvertPtr(info.Clone()),
ConvertPtr(std::move(input)),
health::mojom::NonRemovableBlockDeviceInfo::New(
kPath, health::mojom::UInt64Value::New(kSize), kType,
health::mojom::UInt32Value::New(kManufacturerId), kName,
......@@ -275,11 +274,10 @@ TEST(ProbeServiceConvertors, CpuCStateInfoPtr) {
input->time_in_state_since_last_boot_us = kTimeInStateSinceLastBootUs;
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->name, kName);
EXPECT_EQ(output->time_in_state_since_last_boot_us,
health::mojom::UInt64Value::New(kTimeInStateSinceLastBootUs));
EXPECT_EQ(
ConvertPtr(std::move(input)),
health::mojom::CpuCStateInfo::New(
kName, health::mojom::UInt64Value::New(kTimeInStateSinceLastBootUs)));
}
TEST(ProbeServiceConvertors, LogicalCpuInfoPtr) {
......@@ -289,11 +287,13 @@ TEST(ProbeServiceConvertors, LogicalCpuInfoPtr) {
constexpr uint32_t kIdleTimeUserHz = 1000000;
constexpr char kCpuCStateName[] = "C1";
constexpr uint64_t kCpuCStateTime = 9999999999999;
auto input = cros_healthd::mojom::LogicalCpuInfo::New();
{
auto c_state = cros_healthd::mojom::CpuCStateInfo::New();
c_state->name = kCpuCStateName;
c_state->time_in_state_since_last_boot_us = kCpuCStateTime;
input->max_clock_speed_khz = kMaxClockSpeedKhz;
input->scaling_max_frequency_khz = kScalingMaxFrequencyKhz;
......@@ -302,41 +302,50 @@ TEST(ProbeServiceConvertors, LogicalCpuInfoPtr) {
input->c_states.push_back(std::move(c_state));
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->max_clock_speed_khz,
health::mojom::UInt32Value::New(kMaxClockSpeedKhz));
EXPECT_EQ(output->scaling_max_frequency_khz,
health::mojom::UInt32Value::New(kScalingMaxFrequencyKhz));
EXPECT_EQ(output->scaling_current_frequency_khz,
health::mojom::UInt32Value::New(kScalingCurrentFrequencyKhz));
EXPECT_EQ(output->idle_time_user,
health::mojom::UInt64Value::New(kIdleTimeUserHz));
ASSERT_EQ(output->c_states.size(), 1ULL);
ASSERT_TRUE(output->c_states[0]);
EXPECT_EQ(output->c_states[0]->name, kCpuCStateName);
std::vector<health::mojom::CpuCStateInfoPtr> expected_c_states;
expected_c_states.push_back(health::mojom::CpuCStateInfo::New(
kCpuCStateName, health::mojom::UInt64Value::New(kCpuCStateTime)));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::LogicalCpuInfo::New(
health::mojom::UInt32Value::New(kMaxClockSpeedKhz),
health::mojom::UInt32Value::New(kScalingMaxFrequencyKhz),
health::mojom::UInt32Value::New(kScalingCurrentFrequencyKhz),
health::mojom::UInt64Value::New(kIdleTimeUserHz),
std::move(expected_c_states)));
}
TEST(ProbeServiceConvertors, PhysicalCpuInfoPtr) {
constexpr char kModelName[] = "i9";
constexpr uint32_t kMaxClockSpeedKhz = 1000;
constexpr uint32_t kMaxClockSpeedKhz = 9000;
constexpr uint32_t kScalingMaxFrequencyKhz = 90000;
constexpr uint32_t kScalingCurrentFrequencyKhz = 900000;
constexpr uint32_t kIdleTimeUserHz = 9000000;
auto input = cros_healthd::mojom::PhysicalCpuInfo::New();
{
auto logical_info = cros_healthd::mojom::LogicalCpuInfo::New();
logical_info->max_clock_speed_khz = kMaxClockSpeedKhz;
logical_info->scaling_max_frequency_khz = kScalingMaxFrequencyKhz;
logical_info->scaling_current_frequency_khz = kScalingCurrentFrequencyKhz;
logical_info->idle_time_user_hz = kIdleTimeUserHz;
input->model_name = kModelName;
input->logical_cpus.push_back(std::move(logical_info));
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_EQ(output->model_name, kModelName);
ASSERT_EQ(output->logical_cpus.size(), 1ULL);
ASSERT_TRUE(output->logical_cpus[0]);
EXPECT_EQ(output->logical_cpus[0]->max_clock_speed_khz,
health::mojom::UInt32Value::New(kMaxClockSpeedKhz));
std::vector<health::mojom::LogicalCpuInfoPtr> expected_infos;
expected_infos.push_back(health::mojom::LogicalCpuInfo::New(
health::mojom::UInt32Value::New(kMaxClockSpeedKhz),
health::mojom::UInt32Value::New(kScalingMaxFrequencyKhz),
health::mojom::UInt32Value::New(kScalingCurrentFrequencyKhz),
health::mojom::UInt64Value::New(kIdleTimeUserHz),
std::vector<health::mojom::CpuCStateInfoPtr>{}));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::PhysicalCpuInfo::New(kModelName,
std::move(expected_infos)));
}
TEST(ProbeServiceConvertors, CpuArchitectureEnum) {
......@@ -360,16 +369,19 @@ TEST(ProbeServiceConvertors, CpuInfoPtr) {
physical_info->model_name = kModelName;
input->num_total_threads = kNumTotalThreads;
input->architecture = cros_healthd::mojom::CpuArchitectureEnum::kArmv7l;
input->physical_cpus.push_back(std::move(physical_info));
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_EQ(output->num_total_threads,
health::mojom::UInt32Value::New(kNumTotalThreads));
ASSERT_EQ(output->physical_cpus.size(), 1ULL);
ASSERT_TRUE(output->physical_cpus[0]);
EXPECT_EQ(output->physical_cpus[0]->model_name, kModelName);
std::vector<health::mojom::PhysicalCpuInfoPtr> expected_infos;
expected_infos.push_back(health::mojom::PhysicalCpuInfo::New(
kModelName, std::vector<health::mojom::LogicalCpuInfoPtr>{}));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::CpuInfo::New(
health::mojom::UInt32Value::New(kNumTotalThreads),
health::mojom::CpuArchitectureEnum::kArmv7l,
std::move(expected_infos)));
}
TEST(ProbeServiceConvertors, CpuResultPtrInfo) {
......@@ -394,10 +406,8 @@ TEST(ProbeServiceConvertors, TimezoneInfoPtr) {
input->posix = kPosix;
input->region = kRegion;
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->posix, kPosix);
EXPECT_EQ(output->region, kRegion);
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::TimezoneInfo::New(kPosix, kRegion));
}
TEST(ProbeServiceConvertors, TimezoneResultPtrInfo) {
......@@ -426,16 +436,12 @@ TEST(ProbeServiceConvertors, MemoryInfoPtr) {
input->available_memory_kib = kAvailableMemoryKib;
input->page_faults_since_last_boot = kPageFaultsSinceLastBoot;
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->total_memory_kib,
health::mojom::UInt32Value::New(kTotalMemoryKib));
EXPECT_EQ(output->free_memory_kib,
health::mojom::UInt32Value::New(kFreeMemoryKib));
EXPECT_EQ(output->available_memory_kib,
health::mojom::UInt32Value::New(kAvailableMemoryKib));
EXPECT_EQ(output->page_faults_since_last_boot,
health::mojom::UInt64Value::New(kPageFaultsSinceLastBoot));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::MemoryInfo::New(
health::mojom::UInt32Value::New(kTotalMemoryKib),
health::mojom::UInt32Value::New(kFreeMemoryKib),
health::mojom::UInt32Value::New(kAvailableMemoryKib),
health::mojom::UInt64Value::New(kPageFaultsSinceLastBoot)));
}
TEST(ProbeServiceConvertors, MemoryResultPtrInfo) {
......@@ -462,12 +468,10 @@ TEST(ProbeServiceConvertors, BacklightInfoPtr) {
input->max_brightness = kMaxBrightness;
input->brightness = kBrightness;
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->path, kPath);
EXPECT_EQ(output->max_brightness,
health::mojom::UInt32Value::New(kMaxBrightness));
EXPECT_EQ(output->brightness, health::mojom::UInt32Value::New(kBrightness));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::BacklightInfo::New(
kPath, health::mojom::UInt32Value::New(kMaxBrightness),
health::mojom::UInt32Value::New(kBrightness)));
}
TEST(ProbeServiceConvertors, BacklightResultPtrInfo) {
......@@ -527,15 +531,12 @@ TEST(ProbeServiceConvertors, FanResultPtrInfo) {
input = cros_healthd::mojom::FanResult::NewFanInfo(std::move(fan_infos));
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_TRUE(output->is_fan_info());
std::vector<health::mojom::FanInfoPtr> expected_fans;
expected_fans.push_back(
health::mojom::FanInfo::New(health::mojom::UInt32Value::New(kSpeedRpm)));
const auto& fan_info_output = output->get_fan_info();
ASSERT_EQ(fan_info_output.size(), 1ULL);
ASSERT_TRUE(fan_info_output[0]);
EXPECT_EQ(fan_info_output[0]->speed_rpm,
health::mojom::UInt32Value::New(kSpeedRpm));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::FanResult::NewFanInfo(std::move(expected_fans)));
}
TEST(ProbeServiceConvertors, FanResultPtrError) {
......@@ -555,11 +556,10 @@ TEST(ProbeServiceConvertors, StatefulPartitionInfoPtr) {
input->available_space = kAvailableSpace;
input->total_space = kTotalSpace;
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->available_space,
health::mojom::UInt64Value::New(kRoundedAvailableSpace));
EXPECT_EQ(output->total_space, health::mojom::UInt64Value::New(kTotalSpace));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::StatefulPartitionInfo::New(
health::mojom::UInt64Value::New(kRoundedAvailableSpace),
health::mojom::UInt64Value::New(kTotalSpace)));
}
TEST(ProbeServiceConvertors, StatefulPartitionResultPtrInfo) {
......@@ -583,18 +583,17 @@ TEST(ProbeServiceConvertors, BluetoothAdapterInfoPtr) {
constexpr uint32_t kNumConnectedDevices = 3;
auto input = cros_healthd::mojom::BluetoothAdapterInfo::New();
{
input->name = kName;
input->address = kAddress;
input->powered = kPowered;
input->num_connected_devices = kNumConnectedDevices;
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->name, kName);
EXPECT_EQ(output->address, kAddress);
EXPECT_EQ(output->powered, health::mojom::BoolValue::New(kPowered));
EXPECT_EQ(output->num_connected_devices,
health::mojom::UInt32Value::New(kNumConnectedDevices));
EXPECT_EQ(ConvertPtr(std::move(input)),
health::mojom::BluetoothAdapterInfo::New(
kName, kAddress, health::mojom::BoolValue::New(kPowered),
health::mojom::UInt32Value::New(kNumConnectedDevices)));
}
TEST(ProbeServiceConvertors, BluetoothResultPtrInfo) {
......@@ -632,6 +631,7 @@ TEST(ProbeServiceConvertors, BluetoothResultPtrError) {
TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNotNullFields) {
auto input = cros_healthd::mojom::TelemetryInfo::New();
{
input->battery_result = cros_healthd::mojom::BatteryResult::New();
input->block_device_result =
cros_healthd::mojom::NonRemovableBlockDeviceResult::New();
......@@ -644,34 +644,35 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNotNullFields) {
input->stateful_partition_result =
cros_healthd::mojom::StatefulPartitionResult::New();
input->bluetooth_result = cros_healthd::mojom::BluetoothResult::New();
}
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_TRUE(output->battery_result);
EXPECT_TRUE(output->block_device_result);
EXPECT_TRUE(output->vpd_result);
EXPECT_TRUE(output->cpu_result);
EXPECT_TRUE(output->timezone_result);
EXPECT_TRUE(output->memory_result);
EXPECT_TRUE(output->backlight_result);
EXPECT_TRUE(output->fan_result);
EXPECT_TRUE(output->stateful_partition_result);
EXPECT_TRUE(output->bluetooth_result);
EXPECT_EQ(
ConvertPtr(std::move(input)),
health::mojom::TelemetryInfo::New(
health::mojom::BatteryResult::New(),
health::mojom::NonRemovableBlockDeviceResult::New(),
health::mojom::CachedVpdResult::New(),
health::mojom::CpuResult::New(), health::mojom::TimezoneResult::New(),
health::mojom::MemoryResult::New(),
health::mojom::BacklightResult::New(),
health::mojom::FanResult::New(),
health::mojom::StatefulPartitionResult::New(),
health::mojom::BluetoothResult::New()));
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
const auto output = ConvertPtr(cros_healthd::mojom::TelemetryInfo::New());
ASSERT_TRUE(output);
EXPECT_FALSE(output->battery_result);
EXPECT_FALSE(output->block_device_result);
EXPECT_FALSE(output->vpd_result);
EXPECT_FALSE(output->cpu_result);
EXPECT_FALSE(output->timezone_result);
EXPECT_FALSE(output->memory_result);
EXPECT_FALSE(output->backlight_result);
EXPECT_FALSE(output->fan_result);
EXPECT_FALSE(output->stateful_partition_result);
EXPECT_FALSE(output->bluetooth_result);
EXPECT_EQ(ConvertPtr(cros_healthd::mojom::TelemetryInfo::New()),
health::mojom::TelemetryInfo::New(
health::mojom::BatteryResultPtr(nullptr),
health::mojom::NonRemovableBlockDeviceResultPtr(nullptr),
health::mojom::CachedVpdResultPtr(nullptr),
health::mojom::CpuResultPtr(nullptr),
health::mojom::TimezoneResultPtr(nullptr),
health::mojom::MemoryResultPtr(nullptr),
health::mojom::BacklightResultPtr(nullptr),
health::mojom::FanResultPtr(nullptr),
health::mojom::StatefulPartitionResultPtr(nullptr),
health::mojom::BluetoothResultPtr(nullptr)));
}
} // namespace probe_service_converters
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment