Commit 0f99699c authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Add fan info

Add fan info to the probe service.

Bug: b:158658869
Change-Id: Icfb3eea6af1999956cc854ef22f4ece6be42cb18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275441
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Cr-Commit-Position: refs/heads/master@{#786263}
parent b22105d6
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
// - TimezoneInfo // - TimezoneInfo
// - MemoryInfo // - MemoryInfo
// - BacklightInfo // - BacklightInfo
// - FanInfo
// 3) NonRemovableBlockDeviceInfo: use uint32 to store manufacturer_id instead // 3) NonRemovableBlockDeviceInfo: use uint32 to store manufacturer_id instead
// of uint8 in case we want to extend manufacturer range. // of uint8 in case we want to extend manufacturer range.
// 4) LogicalCpuInfo: // 4) LogicalCpuInfo:
...@@ -66,6 +67,7 @@ enum ProbeCategoryEnum { ...@@ -66,6 +67,7 @@ enum ProbeCategoryEnum {
kTimezone, kTimezone,
kMemory, kMemory,
kBacklight, kBacklight,
kFan,
}; };
// An enumeration of the different categories of errors that can occur when // An enumeration of the different categories of errors that can occur when
...@@ -337,6 +339,21 @@ union BacklightResult { ...@@ -337,6 +339,21 @@ union BacklightResult {
ProbeError error; ProbeError error;
}; };
// Fan information.
struct FanInfo {
// Fan speed in RPM.
UInt32Value? speed_rpm;
};
// Fan probe result. Can either be populated with the FanInfo or an error
// retrieving the information.
union FanResult {
// A list of valid FanInfo.
array<FanInfo> fan_info;
// The error that occurred attempting to retrieve the FanInfo.
ProbeError error;
};
// A collection of all the device's telemetry information that cros_healthd is // A collection of all the device's telemetry information that cros_healthd is
// capable of reporting. Note that every field in TelemetryInfo is nullable, and // capable of reporting. Note that every field in TelemetryInfo is nullable, and
// the response for a particular ProbeTelemetryInfo request will only contain // the response for a particular ProbeTelemetryInfo request will only contain
...@@ -367,4 +384,7 @@ struct TelemetryInfo { ...@@ -367,4 +384,7 @@ struct TelemetryInfo {
// Information about all of the device's backlights. Only present when // Information about all of the device's backlights. Only present when
// kBacklight was included in the categories input to ProbeTelemetryInfo. // kBacklight was included in the categories input to ProbeTelemetryInfo.
BacklightResult? backlight_result; BacklightResult? backlight_result;
// Information about each of the device's fans. Only present when kFan was
// included in the categories input to ProbeTelemetryInfo.
FanResult? fan_result;
}; };
...@@ -32,6 +32,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert( ...@@ -32,6 +32,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert(
return cros_healthd::mojom::ProbeCategoryEnum::kMemory; return cros_healthd::mojom::ProbeCategoryEnum::kMemory;
case health::mojom::ProbeCategoryEnum::kBacklight: case health::mojom::ProbeCategoryEnum::kBacklight:
return cros_healthd::mojom::ProbeCategoryEnum::kBacklight; return cros_healthd::mojom::ProbeCategoryEnum::kBacklight;
case health::mojom::ProbeCategoryEnum::kFan:
return cros_healthd::mojom::ProbeCategoryEnum::kFan;
} }
NOTREACHED(); NOTREACHED();
} }
...@@ -230,6 +232,25 @@ health::mojom::BacklightResultPtr UncheckedConvertPtr( ...@@ -230,6 +232,25 @@ health::mojom::BacklightResultPtr UncheckedConvertPtr(
NOTREACHED(); NOTREACHED();
} }
health::mojom::FanInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::FanInfoPtr input) {
return health::mojom::FanInfo::New(Convert(input->speed_rpm));
}
health::mojom::FanResultPtr UncheckedConvertPtr(
cros_healthd::mojom::FanResultPtr input) {
switch (input->which()) {
case cros_healthd::mojom::FanResult::Tag::FAN_INFO:
return health::mojom::FanResult::NewFanInfo(
ConvertPtrVector<health::mojom::FanInfoPtr>(
std::move(input->get_fan_info())));
case cros_healthd::mojom::FanResult::Tag::ERROR:
return health::mojom::FanResult::NewError(
ConvertPtr(std::move(input->get_error())));
}
NOTREACHED();
}
health::mojom::TelemetryInfoPtr UncheckedConvertPtr( health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input) { cros_healthd::mojom::TelemetryInfoPtr input) {
return health::mojom::TelemetryInfo::New( return health::mojom::TelemetryInfo::New(
...@@ -239,7 +260,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr( ...@@ -239,7 +260,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
ConvertPtr(std::move(input->cpu_result)), ConvertPtr(std::move(input->cpu_result)),
ConvertPtr(std::move(input->timezone_result)), ConvertPtr(std::move(input->timezone_result)),
ConvertPtr(std::move(input->memory_result)), ConvertPtr(std::move(input->memory_result)),
ConvertPtr(std::move(input->backlight_result))); ConvertPtr(std::move(input->backlight_result)),
ConvertPtr(std::move(input->fan_result)));
} }
} // namespace unchecked } // namespace unchecked
......
...@@ -85,6 +85,12 @@ health::mojom::BacklightInfoPtr UncheckedConvertPtr( ...@@ -85,6 +85,12 @@ health::mojom::BacklightInfoPtr UncheckedConvertPtr(
health::mojom::BacklightResultPtr UncheckedConvertPtr( health::mojom::BacklightResultPtr UncheckedConvertPtr(
cros_healthd::mojom::BacklightResultPtr input); cros_healthd::mojom::BacklightResultPtr input);
health::mojom::FanInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::FanInfoPtr input);
health::mojom::FanResultPtr UncheckedConvertPtr(
cros_healthd::mojom::FanResultPtr input);
health::mojom::TelemetryInfoPtr UncheckedConvertPtr( health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input); cros_healthd::mojom::TelemetryInfoPtr input);
......
...@@ -25,7 +25,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) { ...@@ -25,7 +25,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
health::mojom::ProbeCategoryEnum::kCpu, health::mojom::ProbeCategoryEnum::kCpu,
health::mojom::ProbeCategoryEnum::kTimezone, health::mojom::ProbeCategoryEnum::kTimezone,
health::mojom::ProbeCategoryEnum::kMemory, health::mojom::ProbeCategoryEnum::kMemory,
health::mojom::ProbeCategoryEnum::kBacklight}; health::mojom::ProbeCategoryEnum::kBacklight,
health::mojom::ProbeCategoryEnum::kFan};
EXPECT_THAT( EXPECT_THAT(
ConvertCategoryVector(kInput), ConvertCategoryVector(kInput),
ElementsAre( ElementsAre(
...@@ -35,7 +36,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) { ...@@ -35,7 +36,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
cros_healthd::mojom::ProbeCategoryEnum::kCpu, cros_healthd::mojom::ProbeCategoryEnum::kCpu,
cros_healthd::mojom::ProbeCategoryEnum::kTimezone, cros_healthd::mojom::ProbeCategoryEnum::kTimezone,
cros_healthd::mojom::ProbeCategoryEnum::kMemory, cros_healthd::mojom::ProbeCategoryEnum::kMemory,
cros_healthd::mojom::ProbeCategoryEnum::kBacklight)); cros_healthd::mojom::ProbeCategoryEnum::kBacklight,
cros_healthd::mojom::ProbeCategoryEnum::kFan));
} }
// Tests that |ConvertPtr| function returns nullptr if input is nullptr. // Tests that |ConvertPtr| function returns nullptr if input is nullptr.
...@@ -495,6 +497,49 @@ TEST(ProbeServiceConvertors, BacklightResultPtrError) { ...@@ -495,6 +497,49 @@ TEST(ProbeServiceConvertors, BacklightResultPtrError) {
EXPECT_TRUE(output->is_error()); EXPECT_TRUE(output->is_error());
} }
TEST(ProbeServiceConvertors, FanInfoPtr) {
constexpr uint32_t kSpeedRpm = 1000;
auto input = cros_healthd::mojom::FanInfo::New();
input->speed_rpm = kSpeedRpm;
const auto output = ConvertPtr(input.Clone());
ASSERT_TRUE(output);
EXPECT_EQ(output->speed_rpm, health::mojom::UInt32Value::New(kSpeedRpm));
}
TEST(ProbeServiceConvertors, FanResultPtrInfo) {
constexpr uint32_t kSpeedRpm = 1000;
cros_healthd::mojom::FanResultPtr input;
{
auto fan_info = cros_healthd::mojom::FanInfo::New();
fan_info->speed_rpm = kSpeedRpm;
std::vector<cros_healthd::mojom::FanInfoPtr> fan_infos;
fan_infos.push_back(std::move(fan_info));
input = cros_healthd::mojom::FanResult::NewFanInfo(std::move(fan_infos));
}
const auto output = ConvertPtr(input.Clone());
ASSERT_TRUE(output);
ASSERT_TRUE(output->is_fan_info());
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));
}
TEST(ProbeServiceConvertors, FanResultPtrError) {
const health::mojom::FanResultPtr output =
ConvertPtr(cros_healthd::mojom::FanResult::NewError(nullptr));
ASSERT_TRUE(output);
EXPECT_TRUE(output->is_error());
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) { TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) {
constexpr int64_t kCycleCount = 1; constexpr int64_t kCycleCount = 1;
...@@ -670,6 +715,32 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBacklightResult) { ...@@ -670,6 +715,32 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBacklightResult) {
health::mojom::UInt32Value::New(kMaxBrightness)); health::mojom::UInt32Value::New(kMaxBrightness));
} }
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasFanResult) {
constexpr uint32_t kSpeedRpm = 1400;
auto input = cros_healthd::mojom::TelemetryInfo::New();
{
auto fan_info = cros_healthd::mojom::FanInfo::New();
fan_info->speed_rpm = kSpeedRpm;
std::vector<cros_healthd::mojom::FanInfoPtr> fan_infos;
fan_infos.push_back(std::move(fan_info));
input->fan_result =
cros_healthd::mojom::FanResult::NewFanInfo(std::move(fan_infos));
}
const health::mojom::TelemetryInfoPtr output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_TRUE(output->fan_result);
ASSERT_TRUE(output->fan_result->is_fan_info());
const auto& fan_info_output = output->fan_result->get_fan_info();
ASSERT_EQ(fan_info_output.size(), 1ULL);
EXPECT_EQ(fan_info_output[0]->speed_rpm,
health::mojom::UInt32Value::New(kSpeedRpm));
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) { TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
const health::mojom::TelemetryInfoPtr telemetry_info_output = const health::mojom::TelemetryInfoPtr telemetry_info_output =
ConvertPtr(cros_healthd::mojom::TelemetryInfo::New()); ConvertPtr(cros_healthd::mojom::TelemetryInfo::New());
...@@ -681,6 +752,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) { ...@@ -681,6 +752,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
EXPECT_FALSE(telemetry_info_output->timezone_result); EXPECT_FALSE(telemetry_info_output->timezone_result);
EXPECT_FALSE(telemetry_info_output->memory_result); EXPECT_FALSE(telemetry_info_output->memory_result);
EXPECT_FALSE(telemetry_info_output->backlight_result); EXPECT_FALSE(telemetry_info_output->backlight_result);
EXPECT_FALSE(telemetry_info_output->fan_result);
} }
} // namespace probe_service_converters } // namespace probe_service_converters
......
...@@ -65,6 +65,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => { ...@@ -65,6 +65,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => {
'batteryResult': null, 'batteryResult': null,
'blockDeviceResult': null, 'blockDeviceResult': null,
'cpuResult': null, 'cpuResult': null,
'fanResult': null,
'memoryResult': null, 'memoryResult': null,
'timezoneResult': null, 'timezoneResult': null,
'vpdResult': null, 'vpdResult': null,
......
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