Commit 9080ba54 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Add cached VPD info

Add cached VPD info to the probe service.

Bug: b:158658869
Change-Id: I41854f62e19139e6fab9d15bda67460f2f55d2a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270144
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#785819}
parent e82f5356
...@@ -49,6 +49,7 @@ interface ProbeService { ...@@ -49,6 +49,7 @@ interface ProbeService {
enum ProbeCategoryEnum { enum ProbeCategoryEnum {
kBattery, kBattery,
kNonRemovableBlockDevices, kNonRemovableBlockDevices,
kCachedVpdData,
}; };
// An enumeration of the different categories of errors that can occur when // An enumeration of the different categories of errors that can occur when
...@@ -187,6 +188,21 @@ union NonRemovableBlockDeviceResult { ...@@ -187,6 +188,21 @@ union NonRemovableBlockDeviceResult {
ProbeError error; ProbeError error;
}; };
// Cached VPD read from sysfs.
struct CachedVpdInfo {
// Contents of /sys/firmware/vpd/ro/sku_number, if the device supports it.
string? sku_number;
};
// Cached VPD probe result. Can either be populated with the CachedVpdInfo or an
// error retrieving the information.
union CachedVpdResult {
// Valid CachedVpdInfo.
CachedVpdInfo vpd_info;
// The error that occurred attempting to retrieve the CachedVpdInfo.
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
...@@ -202,4 +218,7 @@ struct TelemetryInfo { ...@@ -202,4 +218,7 @@ struct TelemetryInfo {
// present when kNonRemovableBlockDevices was included in the categories input // present when kNonRemovableBlockDevices was included in the categories input
// to ProbeTelemetryInfo. // to ProbeTelemetryInfo.
NonRemovableBlockDeviceResult? block_device_result; NonRemovableBlockDeviceResult? block_device_result;
// Only present when kCachedVpdData was included in the categories input to
// ProbeTelemetryInfo.
CachedVpdResult? vpd_result;
}; };
...@@ -20,6 +20,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert( ...@@ -20,6 +20,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert(
return cros_healthd::mojom::ProbeCategoryEnum::kBattery; return cros_healthd::mojom::ProbeCategoryEnum::kBattery;
case health::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices: case health::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices:
return cros_healthd::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices; return cros_healthd::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices;
case health::mojom::ProbeCategoryEnum::kCachedVpdData:
return cros_healthd::mojom::ProbeCategoryEnum::kCachedVpdData;
} }
NOTREACHED(); NOTREACHED();
} }
...@@ -182,6 +184,36 @@ health::mojom::NonRemovableBlockDeviceResultPtr Convert( ...@@ -182,6 +184,36 @@ health::mojom::NonRemovableBlockDeviceResultPtr Convert(
return output; return output;
} }
health::mojom::CachedVpdInfoPtr Convert(
cros_healthd::mojom::CachedVpdInfoPtr input) {
if (!input) {
return nullptr;
}
auto output = health::mojom::CachedVpdInfo::New();
output->sku_number = std::move(input->sku_number);
return output;
}
health::mojom::CachedVpdResultPtr Convert(
cros_healthd::mojom::CachedVpdResultPtr input) {
if (!input) {
return nullptr;
}
auto output = health::mojom::CachedVpdResult::New();
if (input->is_error()) {
output->set_error(Convert(std::move(input->get_error())));
} else if (input->is_vpd_info()) {
output->set_vpd_info(Convert(std::move(input->get_vpd_info())));
}
return output;
}
health::mojom::TelemetryInfoPtr Convert( health::mojom::TelemetryInfoPtr Convert(
cros_healthd::mojom::TelemetryInfoPtr input) { cros_healthd::mojom::TelemetryInfoPtr input) {
if (!input) { if (!input) {
...@@ -190,7 +222,8 @@ health::mojom::TelemetryInfoPtr Convert( ...@@ -190,7 +222,8 @@ health::mojom::TelemetryInfoPtr Convert(
return health::mojom::TelemetryInfo::New( return health::mojom::TelemetryInfo::New(
Convert(std::move(input->battery_result)), Convert(std::move(input->battery_result)),
Convert(std::move(input->block_device_result))); Convert(std::move(input->block_device_result)),
Convert(std::move(input->vpd_result)));
} }
} // namespace probe_service_converters } // namespace probe_service_converters
......
...@@ -56,6 +56,12 @@ std::vector<health::mojom::NonRemovableBlockDeviceInfoPtr> Convert( ...@@ -56,6 +56,12 @@ std::vector<health::mojom::NonRemovableBlockDeviceInfoPtr> Convert(
health::mojom::NonRemovableBlockDeviceResultPtr Convert( health::mojom::NonRemovableBlockDeviceResultPtr Convert(
cros_healthd::mojom::NonRemovableBlockDeviceResultPtr input); cros_healthd::mojom::NonRemovableBlockDeviceResultPtr input);
health::mojom::CachedVpdInfoPtr Convert(
cros_healthd::mojom::CachedVpdInfoPtr input);
health::mojom::CachedVpdResultPtr Convert(
cros_healthd::mojom::CachedVpdResultPtr input);
health::mojom::TelemetryInfoPtr Convert( health::mojom::TelemetryInfoPtr Convert(
cros_healthd::mojom::TelemetryInfoPtr input); cros_healthd::mojom::TelemetryInfoPtr input);
......
...@@ -23,6 +23,8 @@ TEST(ProbeServiceConvertors, ProbeCategoryEnum) { ...@@ -23,6 +23,8 @@ TEST(ProbeServiceConvertors, ProbeCategoryEnum) {
EXPECT_EQ( EXPECT_EQ(
Convert(health::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices), Convert(health::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices),
cros_healthd::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices); cros_healthd::mojom::ProbeCategoryEnum::kNonRemovableBlockDevices);
EXPECT_EQ(Convert(health::mojom::ProbeCategoryEnum::kCachedVpdData),
cros_healthd::mojom::ProbeCategoryEnum::kCachedVpdData);
} }
TEST(ProbeServiceConvertors, ProbeCategoryEnumVector) { TEST(ProbeServiceConvertors, ProbeCategoryEnumVector) {
...@@ -119,7 +121,7 @@ TEST(ProbeServiceConvertors, BatteryInfoPtr) { ...@@ -119,7 +121,7 @@ TEST(ProbeServiceConvertors, BatteryInfoPtr) {
battery_info->temperature = battery_info->temperature =
cros_healthd::mojom::UInt64Value::New(kTemperature); cros_healthd::mojom::UInt64Value::New(kTemperature);
// Here we intentionaly use health::mojom::BatteryInfo::New to don't // Here we intentionaly use health::mojom::BatteryInfo::New not to
// forget to test new fields. // forget to test new fields.
EXPECT_EQ( EXPECT_EQ(
Convert(battery_info.Clone()), Convert(battery_info.Clone()),
...@@ -166,8 +168,8 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceInfoPtr) { ...@@ -166,8 +168,8 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceInfoPtr) {
constexpr uint64_t kIoTimeSecondsSinceLastBoot = 100000; constexpr uint64_t kIoTimeSecondsSinceLastBoot = 100000;
constexpr uint64_t kDiscardTimeSecondsSinceLastBoot = 1000000; constexpr uint64_t kDiscardTimeSecondsSinceLastBoot = 1000000;
// Here we don't use cros_healthd::mojom::NonRemovableBlockDeviceInfoPtr::New // Here we don't use cros_healthd::mojom::NonRemovableBlockDeviceInfo::New
// because NonRemovableBlockDeviceInfoPtr may contain some fields that we // because NonRemovableBlockDeviceInfo may contain some fields that we
// don't use yet. // don't use yet.
auto info = cros_healthd::mojom::NonRemovableBlockDeviceInfo::New(); auto info = cros_healthd::mojom::NonRemovableBlockDeviceInfo::New();
...@@ -185,8 +187,8 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceInfoPtr) { ...@@ -185,8 +187,8 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceInfoPtr) {
info->discard_time_seconds_since_last_boot = info->discard_time_seconds_since_last_boot =
cros_healthd::mojom::UInt64Value::New(kDiscardTimeSecondsSinceLastBoot); cros_healthd::mojom::UInt64Value::New(kDiscardTimeSecondsSinceLastBoot);
// Here we intentionaly use health::mojom::NonRemovableBlockDeviceInfoPtr::New // Here we intentionaly use health::mojom::NonRemovableBlockDeviceInfo::New
// to don't forget to test new fields. // not to forget to test new fields.
EXPECT_EQ( EXPECT_EQ(
Convert(info.Clone()), Convert(info.Clone()),
health::mojom::NonRemovableBlockDeviceInfo::New( health::mojom::NonRemovableBlockDeviceInfo::New(
...@@ -237,6 +239,44 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceResultPtrError) { ...@@ -237,6 +239,44 @@ TEST(ProbeServiceConvertors, NonRemovableBlockDeviceResultPtrError) {
EXPECT_TRUE(ptr->is_error()); EXPECT_TRUE(ptr->is_error());
} }
TEST(ProbeServiceConvertors, CachedVpdInfoPtrNull) {
EXPECT_TRUE(Convert(cros_healthd::mojom::CachedVpdInfoPtr()).is_null());
}
TEST(ProbeServiceConvertors, CachedVpdInfoPtr) {
constexpr char kSkuNumber[] = "sku-1";
// Here we don't use cros_healthd::mojom::CachedVpdInfo::New
// because CachedVpdInfo may contain some fields that we
// don't use yet.
auto info = cros_healthd::mojom::CachedVpdInfo::New();
info->sku_number = kSkuNumber;
// Here we intentionaly use health::mojom::CachedVpdInfo::New
// not to forget to test new fields.
EXPECT_EQ(Convert(info.Clone()),
health::mojom::CachedVpdInfo::New(kSkuNumber));
}
TEST(ProbeServiceConvertors, CachedVpdResultPtrNull) {
EXPECT_TRUE(Convert(cros_healthd::mojom::CachedVpdResultPtr()).is_null());
}
TEST(ProbeServiceConvertors, CachedVpdResultPtrInfo) {
const health::mojom::CachedVpdResultPtr ptr =
Convert(cros_healthd::mojom::CachedVpdResult::NewVpdInfo(nullptr));
ASSERT_TRUE(ptr);
EXPECT_TRUE(ptr->is_vpd_info());
}
TEST(ProbeServiceConvertors, CachedVpdResultPtrError) {
const health::mojom::CachedVpdResultPtr ptr =
Convert(cros_healthd::mojom::CachedVpdResult::NewError(nullptr));
ASSERT_TRUE(ptr);
EXPECT_TRUE(ptr->is_error());
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) { TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) {
constexpr int64_t kCycleCount = 1; constexpr int64_t kCycleCount = 1;
...@@ -289,12 +329,38 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBlockDeviceResult) { ...@@ -289,12 +329,38 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBlockDeviceResult) {
EXPECT_EQ(device_info_output[0]->size->value, kSize); EXPECT_EQ(device_info_output[0]->size->value, kSize);
} }
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasCachedVpdResult) {
constexpr char kSkuNumber[] = "sku-2";
auto vpd_info_input = cros_healthd::mojom::CachedVpdInfo::New();
vpd_info_input->sku_number = kSkuNumber;
auto telemetry_info_input = cros_healthd::mojom::TelemetryInfo::New();
telemetry_info_input->vpd_result =
cros_healthd::mojom::CachedVpdResult::NewVpdInfo(
std::move(vpd_info_input));
const health::mojom::TelemetryInfoPtr telemetry_info_output =
Convert(std::move(telemetry_info_input));
ASSERT_TRUE(telemetry_info_output);
ASSERT_TRUE(telemetry_info_output->vpd_result);
ASSERT_TRUE(telemetry_info_output->vpd_result->is_vpd_info());
const auto& vpd_info_output =
telemetry_info_output->vpd_result->get_vpd_info();
ASSERT_TRUE(vpd_info_output);
ASSERT_TRUE(vpd_info_output->sku_number.has_value());
EXPECT_EQ(vpd_info_output->sku_number.value(), kSkuNumber);
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) { TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
const health::mojom::TelemetryInfoPtr telemetry_info_output = const health::mojom::TelemetryInfoPtr telemetry_info_output =
Convert(cros_healthd::mojom::TelemetryInfo::New()); Convert(cros_healthd::mojom::TelemetryInfo::New());
ASSERT_TRUE(telemetry_info_output); ASSERT_TRUE(telemetry_info_output);
EXPECT_FALSE(telemetry_info_output->battery_result); EXPECT_FALSE(telemetry_info_output->battery_result);
EXPECT_FALSE(telemetry_info_output->block_device_result); EXPECT_FALSE(telemetry_info_output->block_device_result);
EXPECT_FALSE(telemetry_info_output->vpd_result);
} }
TEST(ProbeServiceConvertors, TelemetryInfoPtrNull) { TEST(ProbeServiceConvertors, TelemetryInfoPtrNull) {
......
...@@ -59,7 +59,8 @@ UNTRUSTED_TEST('UntrustedCanSpawnWorkers', async () => { ...@@ -59,7 +59,8 @@ UNTRUSTED_TEST('UntrustedCanSpawnWorkers', async () => {
UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => { UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => {
/** @type {!ProbeTelemetryInfoResponse} */ /** @type {!ProbeTelemetryInfoResponse} */
const response = await requestTelemetryInfo(); const response = await requestTelemetryInfo();
assertDeepEquals( assertDeepEquals(response, {
response, 'telemetryInfo':
{'telemetryInfo': {'batteryResult': null, 'blockDeviceResult': null}}); {'batteryResult': null, 'blockDeviceResult': 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