Commit 97f15459 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Add backlight info

Add backlight info to the probe service.

Bug: b:158658869
Change-Id: I9c9e19bbc3ee8f46517f9b06faf314280d40e823
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274877
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#786261}
parent e13e665e
......@@ -27,6 +27,7 @@
// - CpuInfo
// - TimezoneInfo
// - MemoryInfo
// - BacklightInfo
// 3) NonRemovableBlockDeviceInfo: use uint32 to store manufacturer_id instead
// of uint8 in case we want to extend manufacturer range.
// 4) LogicalCpuInfo:
......@@ -64,6 +65,7 @@ enum ProbeCategoryEnum {
kCpu,
kTimezone,
kMemory,
kBacklight,
};
// An enumeration of the different categories of errors that can occur when
......@@ -315,6 +317,26 @@ union MemoryResult {
ProbeError error;
};
// Backlight information.
struct BacklightInfo {
// Path to this backlight on the system. Useful if the caller needs to
// correlate with other information.
string? path;
// Maximum brightness for the backlight.
UInt32Value? max_brightness;
// Current brightness of the backlight, between 0 and max_brightness.
UInt32Value? brightness;
};
// Backlight probe result. Can either be populated with the BacklightInfo or an
// error retrieving the information.
union BacklightResult {
// Valid BacklightInfo.
array<BacklightInfo> backlight_info;
// The error that occurred attempting to retrieve the BacklightInfo.
ProbeError error;
};
// 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
// the response for a particular ProbeTelemetryInfo request will only contain
......@@ -342,4 +364,7 @@ struct TelemetryInfo {
// Information about the system's memory. Only present when kMemory was
// included in the categories input to ProbeTelemetryInfo.
MemoryResult? memory_result;
// Information about all of the device's backlights. Only present when
// kBacklight was included in the categories input to ProbeTelemetryInfo.
BacklightResult? backlight_result;
};
......@@ -30,6 +30,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert(
return cros_healthd::mojom::ProbeCategoryEnum::kTimezone;
case health::mojom::ProbeCategoryEnum::kMemory:
return cros_healthd::mojom::ProbeCategoryEnum::kMemory;
case health::mojom::ProbeCategoryEnum::kBacklight:
return cros_healthd::mojom::ProbeCategoryEnum::kBacklight;
}
NOTREACHED();
}
......@@ -189,8 +191,7 @@ health::mojom::TimezoneResultPtr UncheckedConvertPtr(
health::mojom::MemoryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::MemoryInfoPtr input) {
return health::mojom::MemoryInfo::New(
Convert(input->total_memory_kib),
Convert(input->free_memory_kib),
Convert(input->total_memory_kib), Convert(input->free_memory_kib),
Convert(input->available_memory_kib),
Convert(static_cast<uint64_t>(input->page_faults_since_last_boot)));
}
......@@ -208,6 +209,27 @@ health::mojom::MemoryResultPtr UncheckedConvertPtr(
NOTREACHED();
}
health::mojom::BacklightInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::BacklightInfoPtr input) {
return health::mojom::BacklightInfo::New(std::move(input->path),
Convert(input->max_brightness),
Convert(input->brightness));
}
health::mojom::BacklightResultPtr UncheckedConvertPtr(
cros_healthd::mojom::BacklightResultPtr input) {
switch (input->which()) {
case cros_healthd::mojom::BacklightResult::Tag::BACKLIGHT_INFO:
return health::mojom::BacklightResult::NewBacklightInfo(
ConvertPtrVector<health::mojom::BacklightInfoPtr>(
std::move(input->get_backlight_info())));
case cros_healthd::mojom::BacklightResult::Tag::ERROR:
return health::mojom::BacklightResult::NewError(
ConvertPtr(std::move(input->get_error())));
}
NOTREACHED();
}
health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input) {
return health::mojom::TelemetryInfo::New(
......@@ -216,7 +238,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
ConvertPtr(std::move(input->vpd_result)),
ConvertPtr(std::move(input->cpu_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)));
}
} // namespace unchecked
......
......@@ -79,6 +79,12 @@ health::mojom::MemoryInfoPtr UncheckedConvertPtr(
health::mojom::MemoryResultPtr UncheckedConvertPtr(
cros_healthd::mojom::MemoryResultPtr input);
health::mojom::BacklightInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::BacklightInfoPtr input);
health::mojom::BacklightResultPtr UncheckedConvertPtr(
cros_healthd::mojom::BacklightResultPtr input);
health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input);
......
......@@ -24,7 +24,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
health::mojom::ProbeCategoryEnum::kCachedVpdData,
health::mojom::ProbeCategoryEnum::kCpu,
health::mojom::ProbeCategoryEnum::kTimezone,
health::mojom::ProbeCategoryEnum::kMemory};
health::mojom::ProbeCategoryEnum::kMemory,
health::mojom::ProbeCategoryEnum::kBacklight};
EXPECT_THAT(
ConvertCategoryVector(kInput),
ElementsAre(
......@@ -33,7 +34,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
cros_healthd::mojom::ProbeCategoryEnum::kCachedVpdData,
cros_healthd::mojom::ProbeCategoryEnum::kCpu,
cros_healthd::mojom::ProbeCategoryEnum::kTimezone,
cros_healthd::mojom::ProbeCategoryEnum::kMemory));
cros_healthd::mojom::ProbeCategoryEnum::kMemory,
cros_healthd::mojom::ProbeCategoryEnum::kBacklight));
}
// Tests that |ConvertPtr| function returns nullptr if input is nullptr.
......@@ -443,6 +445,56 @@ TEST(ProbeServiceConvertors, MemoryResultPtrError) {
EXPECT_TRUE(output->is_error());
}
TEST(ProbeServiceConvertors, BacklightInfoPtr) {
constexpr char kPath[] = "/sys/backlight";
constexpr uint32_t kMaxBrightness = 100000;
constexpr uint32_t kBrightness = 90000;
auto input = cros_healthd::mojom::BacklightInfo::New();
input->path = kPath;
input->max_brightness = kMaxBrightness;
input->brightness = kBrightness;
const auto output = ConvertPtr(input.Clone());
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));
}
TEST(ProbeServiceConvertors, BacklightResultPtrInfo) {
constexpr char kPath[] = "/sys/backlight";
cros_healthd::mojom::BacklightResultPtr input;
{
auto backlight_info = cros_healthd::mojom::BacklightInfo::New();
backlight_info->path = kPath;
std::vector<cros_healthd::mojom::BacklightInfoPtr> backlight_infos;
backlight_infos.push_back(std::move(backlight_info));
input = cros_healthd::mojom::BacklightResult::NewBacklightInfo(
std::move(backlight_infos));
}
const auto output = ConvertPtr(input.Clone());
ASSERT_TRUE(output);
ASSERT_TRUE(output->is_backlight_info());
const auto& backlight_info_output = output->get_backlight_info();
ASSERT_EQ(backlight_info_output.size(), 1ULL);
ASSERT_TRUE(backlight_info_output[0]);
EXPECT_EQ(backlight_info_output[0]->path, kPath);
}
TEST(ProbeServiceConvertors, BacklightResultPtrError) {
const health::mojom::BacklightResultPtr output =
ConvertPtr(cros_healthd::mojom::BacklightResult::NewError(nullptr));
ASSERT_TRUE(output);
EXPECT_TRUE(output->is_error());
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) {
constexpr int64_t kCycleCount = 1;
......@@ -590,6 +642,34 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasMemoryResult) {
health::mojom::UInt32Value::New(kTotalMemoryKib));
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBacklightResult) {
constexpr uint32_t kMaxBrightness = 10000;
auto input = cros_healthd::mojom::TelemetryInfo::New();
{
auto backlight_info = cros_healthd::mojom::BacklightInfo::New();
backlight_info->max_brightness = kMaxBrightness;
std::vector<cros_healthd::mojom::BacklightInfoPtr> backlight_infos;
backlight_infos.push_back(std::move(backlight_info));
input->backlight_result =
cros_healthd::mojom::BacklightResult::NewBacklightInfo(
std::move(backlight_infos));
}
const health::mojom::TelemetryInfoPtr output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_TRUE(output->backlight_result);
ASSERT_TRUE(output->backlight_result->is_backlight_info());
const auto& backlight_info_output =
output->backlight_result->get_backlight_info();
ASSERT_EQ(backlight_info_output.size(), 1ULL);
EXPECT_EQ(backlight_info_output[0]->max_brightness,
health::mojom::UInt32Value::New(kMaxBrightness));
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
const health::mojom::TelemetryInfoPtr telemetry_info_output =
ConvertPtr(cros_healthd::mojom::TelemetryInfo::New());
......@@ -600,6 +680,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
EXPECT_FALSE(telemetry_info_output->cpu_result);
EXPECT_FALSE(telemetry_info_output->timezone_result);
EXPECT_FALSE(telemetry_info_output->memory_result);
EXPECT_FALSE(telemetry_info_output->backlight_result);
}
} // namespace probe_service_converters
......
......@@ -61,6 +61,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => {
const response = await requestTelemetryInfo();
assertDeepEquals(response, {
'telemetryInfo': {
'backlightResult': null,
'batteryResult': null,
'blockDeviceResult': null,
'cpuResult': 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