Commit d4d753df authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Add stateful partition info

Add stateful partition info to the probe service.

Bug: b:158658869
Change-Id: Ie90406b06a790424c1f2771d6f718a16914a6591
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275442
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@{#786268}
parent 072896f3
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// - MemoryInfo // - MemoryInfo
// - BacklightInfo // - BacklightInfo
// - FanInfo // - FanInfo
// - StatefulPartitionInfo
// 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:
...@@ -68,6 +69,7 @@ enum ProbeCategoryEnum { ...@@ -68,6 +69,7 @@ enum ProbeCategoryEnum {
kMemory, kMemory,
kBacklight, kBacklight,
kFan, kFan,
kStatefulPartition,
}; };
// An enumeration of the different categories of errors that can occur when // An enumeration of the different categories of errors that can occur when
...@@ -354,6 +356,24 @@ union FanResult { ...@@ -354,6 +356,24 @@ union FanResult {
ProbeError error; ProbeError error;
}; };
// Stateful partition info
struct StatefulPartitionInfo {
// Available space for user data storage in the device in bytes. Rounded down
// to multiples of 100MiB (100 * 1024 * 1024 bytes).
UInt64Value? available_space;
// Total space for user data storage in the device in bytes.
UInt64Value? total_space;
};
// Stateful partition probe result. Can either be populated with a valid
// StatefulPartitionInfo or an error retrieving the information.
union StatefulPartitionResult {
// A valid StatefulPartitionInfo.
StatefulPartitionInfo partition_info;
// The error that occurred attempting to retrieve the StatefulPartitionInfo.
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
...@@ -387,4 +407,8 @@ struct TelemetryInfo { ...@@ -387,4 +407,8 @@ struct TelemetryInfo {
// Information about each of the device's fans. Only present when kFan was // Information about each of the device's fans. Only present when kFan was
// included in the categories input to ProbeTelemetryInfo. // included in the categories input to ProbeTelemetryInfo.
FanResult? fan_result; FanResult? fan_result;
// Information about the stateful partition. Only present when
// kStatefulPartition was included in the categories input to
// ProbeTelemetryInfo.
StatefulPartitionResult? stateful_partition_result;
}; };
...@@ -34,6 +34,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert( ...@@ -34,6 +34,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert(
return cros_healthd::mojom::ProbeCategoryEnum::kBacklight; return cros_healthd::mojom::ProbeCategoryEnum::kBacklight;
case health::mojom::ProbeCategoryEnum::kFan: case health::mojom::ProbeCategoryEnum::kFan:
return cros_healthd::mojom::ProbeCategoryEnum::kFan; return cros_healthd::mojom::ProbeCategoryEnum::kFan;
case health::mojom::ProbeCategoryEnum::kStatefulPartition:
return cros_healthd::mojom::ProbeCategoryEnum::kStatefulPartition;
} }
NOTREACHED(); NOTREACHED();
} }
...@@ -251,6 +253,27 @@ health::mojom::FanResultPtr UncheckedConvertPtr( ...@@ -251,6 +253,27 @@ health::mojom::FanResultPtr UncheckedConvertPtr(
NOTREACHED(); NOTREACHED();
} }
health::mojom::StatefulPartitionInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::StatefulPartitionInfoPtr input) {
constexpr uint64_t k100MiB = 100 * 1024 * 1024;
return health::mojom::StatefulPartitionInfo::New(
Convert(input->available_space / k100MiB * k100MiB),
Convert(input->total_space));
}
health::mojom::StatefulPartitionResultPtr UncheckedConvertPtr(
cros_healthd::mojom::StatefulPartitionResultPtr input) {
switch (input->which()) {
case cros_healthd::mojom::StatefulPartitionResult::Tag::PARTITION_INFO:
return health::mojom::StatefulPartitionResult::NewPartitionInfo(
ConvertPtr(std::move(input->get_partition_info())));
case cros_healthd::mojom::StatefulPartitionResult::Tag::ERROR:
return health::mojom::StatefulPartitionResult::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(
...@@ -261,7 +284,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr( ...@@ -261,7 +284,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
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))); ConvertPtr(std::move(input->fan_result)),
ConvertPtr(std::move(input->stateful_partition_result)));
} }
} // namespace unchecked } // namespace unchecked
......
...@@ -91,6 +91,12 @@ health::mojom::FanInfoPtr UncheckedConvertPtr( ...@@ -91,6 +91,12 @@ health::mojom::FanInfoPtr UncheckedConvertPtr(
health::mojom::FanResultPtr UncheckedConvertPtr( health::mojom::FanResultPtr UncheckedConvertPtr(
cros_healthd::mojom::FanResultPtr input); cros_healthd::mojom::FanResultPtr input);
health::mojom::StatefulPartitionInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::StatefulPartitionInfoPtr input);
health::mojom::StatefulPartitionResultPtr UncheckedConvertPtr(
cros_healthd::mojom::StatefulPartitionResultPtr input);
health::mojom::TelemetryInfoPtr UncheckedConvertPtr( health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input); cros_healthd::mojom::TelemetryInfoPtr input);
......
...@@ -26,7 +26,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) { ...@@ -26,7 +26,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
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}; health::mojom::ProbeCategoryEnum::kFan,
health::mojom::ProbeCategoryEnum::kStatefulPartition};
EXPECT_THAT( EXPECT_THAT(
ConvertCategoryVector(kInput), ConvertCategoryVector(kInput),
ElementsAre( ElementsAre(
...@@ -37,7 +38,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) { ...@@ -37,7 +38,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
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)); cros_healthd::mojom::ProbeCategoryEnum::kFan,
cros_healthd::mojom::ProbeCategoryEnum::kStatefulPartition));
} }
// Tests that |ConvertPtr| function returns nullptr if input is nullptr. // Tests that |ConvertPtr| function returns nullptr if input is nullptr.
...@@ -540,6 +542,37 @@ TEST(ProbeServiceConvertors, FanResultPtrError) { ...@@ -540,6 +542,37 @@ TEST(ProbeServiceConvertors, FanResultPtrError) {
EXPECT_TRUE(output->is_error()); EXPECT_TRUE(output->is_error());
} }
TEST(ProbeServiceConvertors, StatefulPartitionInfoPtr) {
constexpr uint64_t k100MiB = 100 * 1024 * 1024;
constexpr uint64_t kTotalSpace = 9000 * k100MiB + 17;
constexpr uint64_t kRoundedAvailableSpace = 1000 * k100MiB;
constexpr uint64_t kAvailableSpace = kRoundedAvailableSpace + 2000;
auto input = cros_healthd::mojom::StatefulPartitionInfo::New();
input->available_space = kAvailableSpace;
input->total_space = kTotalSpace;
const auto output = ConvertPtr(input.Clone());
ASSERT_TRUE(output);
EXPECT_EQ(output->available_space,
health::mojom::UInt64Value::New(kRoundedAvailableSpace));
EXPECT_EQ(output->total_space, health::mojom::UInt64Value::New(kTotalSpace));
}
TEST(ProbeServiceConvertors, StatefulPartitionResultPtrInfo) {
const health::mojom::StatefulPartitionResultPtr output = ConvertPtr(
cros_healthd::mojom::StatefulPartitionResult::NewPartitionInfo(nullptr));
ASSERT_TRUE(output);
EXPECT_TRUE(output->is_partition_info());
}
TEST(ProbeServiceConvertors, StatefulPartitionResultPtrError) {
const health::mojom::StatefulPartitionResultPtr output = ConvertPtr(
cros_healthd::mojom::StatefulPartitionResult::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;
...@@ -741,6 +774,31 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasFanResult) { ...@@ -741,6 +774,31 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasFanResult) {
health::mojom::UInt32Value::New(kSpeedRpm)); health::mojom::UInt32Value::New(kSpeedRpm));
} }
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasStatefulPartitionResult) {
constexpr uint64_t kTotalSpace = 90000000;
auto input = cros_healthd::mojom::TelemetryInfo::New();
{
auto partition_info = cros_healthd::mojom::StatefulPartitionInfo::New();
partition_info->total_space = kTotalSpace;
input->stateful_partition_result =
cros_healthd::mojom::StatefulPartitionResult::NewPartitionInfo(
std::move(partition_info));
}
const health::mojom::TelemetryInfoPtr output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
ASSERT_TRUE(output->stateful_partition_result);
ASSERT_TRUE(output->stateful_partition_result->is_partition_info());
const auto& partition_info_output =
output->stateful_partition_result->get_partition_info();
ASSERT_TRUE(partition_info_output);
EXPECT_EQ(partition_info_output->total_space,
health::mojom::UInt64Value::New(kTotalSpace));
}
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());
...@@ -753,6 +811,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) { ...@@ -753,6 +811,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
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); EXPECT_FALSE(telemetry_info_output->fan_result);
EXPECT_FALSE(telemetry_info_output->stateful_partition_result);
} }
} // namespace probe_service_converters } // namespace probe_service_converters
......
...@@ -67,6 +67,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => { ...@@ -67,6 +67,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => {
'cpuResult': null, 'cpuResult': null,
'fanResult': null, 'fanResult': null,
'memoryResult': null, 'memoryResult': null,
'statefulPartitionResult': 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