Commit 8b122c1d authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

cros_healthd: add the AC power routine

Add the first interactive routine, AC power, to cros_healthd.
This routine checks the power supply's status and type against
the routine inputs.

--gtest_filter=CrosHealthdServiceConnectionTest.*

Bug: chromium:1046452
Test: chromeos_unittests
Change-Id: I26a317c681781bed096513502240ba4663253fc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033809
Commit-Queue: Paul Moy <pmoy@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738213}
parent 387f7dbb
...@@ -63,6 +63,13 @@ void FakeCrosHealthdService::RunSmartctlCheckRoutine( ...@@ -63,6 +63,13 @@ void FakeCrosHealthdService::RunSmartctlCheckRoutine(
std::move(callback).Run(run_routine_response_.Clone()); std::move(callback).Run(run_routine_response_.Clone());
} }
void FakeCrosHealthdService::RunAcPowerRoutine(
mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
RunAcPowerRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::ProbeTelemetryInfo( void FakeCrosHealthdService::ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories, const std::vector<mojom::ProbeCategoryEnum>& categories,
ProbeTelemetryInfoCallback callback) { ProbeTelemetryInfoCallback callback) {
......
...@@ -51,6 +51,9 @@ class FakeCrosHealthdService final ...@@ -51,6 +51,9 @@ class FakeCrosHealthdService final
RunBatteryHealthRoutineCallback callback) override; RunBatteryHealthRoutineCallback callback) override;
void RunSmartctlCheckRoutine( void RunSmartctlCheckRoutine(
RunSmartctlCheckRoutineCallback callback) override; RunSmartctlCheckRoutineCallback callback) override;
void RunAcPowerRoutine(mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
RunAcPowerRoutineCallback callback) override;
// CrosHealthdProbeService overrides: // CrosHealthdProbeService overrides:
void ProbeTelemetryInfo( void ProbeTelemetryInfo(
......
...@@ -53,6 +53,11 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -53,6 +53,11 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunSmartctlCheckRoutine( void RunSmartctlCheckRoutine(
mojom::CrosHealthdDiagnosticsService::RunSmartctlCheckRoutineCallback mojom::CrosHealthdDiagnosticsService::RunSmartctlCheckRoutineCallback
callback) override; callback) override;
void RunAcPowerRoutine(
mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
mojom::CrosHealthdDiagnosticsService::RunAcPowerRoutineCallback callback)
override;
void ProbeTelemetryInfo( void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test, const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback) mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback)
...@@ -150,6 +155,16 @@ void ServiceConnectionImpl::RunSmartctlCheckRoutine( ...@@ -150,6 +155,16 @@ void ServiceConnectionImpl::RunSmartctlCheckRoutine(
std::move(callback)); std::move(callback));
} }
void ServiceConnectionImpl::RunAcPowerRoutine(
mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
mojom::CrosHealthdDiagnosticsService::RunAcPowerRoutineCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunAcPowerRoutine(
expected_status, expected_power_type, std::move(callback));
}
void ServiceConnectionImpl::ProbeTelemetryInfo( void ServiceConnectionImpl::ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test, const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback) { mojom::CrosHealthdProbeService::ProbeTelemetryInfoCallback callback) {
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#define CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_ #define CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_
#include <cstdint> #include <cstdint>
#include <string>
#include "base/optional.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
namespace chromeos { namespace chromeos {
...@@ -70,6 +72,15 @@ class ServiceConnection { ...@@ -70,6 +72,15 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunSmartctlCheckRoutineCallback mojom::CrosHealthdDiagnosticsService::RunSmartctlCheckRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the AC power routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunAcPowerRoutine(
mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
mojom::CrosHealthdDiagnosticsService::RunAcPowerRoutineCallback
callback) = 0;
// Gather pieces of information about the platform. See // Gather pieces of information about the platform. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h" #include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h" #include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h"
...@@ -260,6 +261,21 @@ TEST_F(CrosHealthdServiceConnectionTest, RunSmartctlCheckRoutine) { ...@@ -260,6 +261,21 @@ TEST_F(CrosHealthdServiceConnectionTest, RunSmartctlCheckRoutine) {
EXPECT_TRUE(callback_done); EXPECT_TRUE(callback_done);
} }
TEST_F(CrosHealthdServiceConnectionTest, RunAcPowerRoutine) {
// Test that we can run the AC power routine.
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunAcPowerRoutine(
mojom::AcPowerStatusEnum::kConnected,
/*expected_power_type=*/"power_type",
base::BindLambdaForTesting([&](mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
run_loop.Quit();
}));
run_loop.Run();
}
TEST_F(CrosHealthdServiceConnectionTest, ProbeTelemetryInfo) { TEST_F(CrosHealthdServiceConnectionTest, ProbeTelemetryInfo) {
// Test that we can send a request without categories. // Test that we can send a request without categories.
auto empty_info = mojom::TelemetryInfo::New(); auto empty_info = mojom::TelemetryInfo::New();
......
...@@ -106,6 +106,24 @@ interface CrosHealthdDiagnosticsService { ...@@ -106,6 +106,24 @@ interface CrosHealthdDiagnosticsService {
// * |response| - contains a unique identifier and status for the created // * |response| - contains a unique identifier and status for the created
// routine. // routine.
RunSmartctlCheckRoutine() => (RunRoutineResponse response); RunSmartctlCheckRoutine() => (RunRoutineResponse response);
// Requests that the AcPower routine is created and started on the
// platform. This routine checks the status of the power supply, and if
// |expected_power_type| is specified, checks to see that
// |expected_power_type| matches the type reported by the power supply. This
// routine is only available if GetAvailableRoutines returned kAcPower.
//
// The request:
// * |expected_status| - whether or not the adapter is expected to be online.
// * |expected_power_type| - if specified, must match the type of the power
// supply for the routine to succeed.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunAcPowerRoutine(AcPowerStatusEnum expected_status,
string? expected_power_type)
=> (RunRoutineResponse response);
}; };
// Probe interface exposed by the cros_healthd daemon. // Probe interface exposed by the cros_healthd daemon.
......
...@@ -20,6 +20,7 @@ enum DiagnosticRoutineEnum { ...@@ -20,6 +20,7 @@ enum DiagnosticRoutineEnum {
kBatteryHealth = 1, kBatteryHealth = 1,
kUrandom = 2, kUrandom = 2,
kSmartctlCheck = 3, kSmartctlCheck = 3,
kAcPower = 4,
}; };
// Enumeration of each of the possible statuses for a diagnostics routine. // Enumeration of each of the possible statuses for a diagnostics routine.
...@@ -44,6 +45,7 @@ enum DiagnosticRoutineStatusEnum { ...@@ -44,6 +45,7 @@ enum DiagnosticRoutineStatusEnum {
[Extensible] [Extensible]
enum DiagnosticRoutineUserMessageEnum { enum DiagnosticRoutineUserMessageEnum {
kUnplugACPower = 0, // The user needs to unplug the AC power cord. kUnplugACPower = 0, // The user needs to unplug the AC power cord.
kPlugInACPower = 1, // The user needs to plug in the AC power cord.
}; };
// Enumeration of the possible commands to send a diagnostics routine. // Enumeration of the possible commands to send a diagnostics routine.
...@@ -105,3 +107,11 @@ struct RoutineUpdate { ...@@ -105,3 +107,11 @@ struct RoutineUpdate {
// noninteractive. // noninteractive.
RoutineUpdateUnion routine_update_union; RoutineUpdateUnion routine_update_union;
}; };
// Enumeration of the possible statuses for a power supply in the AC power
// routine.
[Extensible]
enum AcPowerStatusEnum {
kConnected = 0, // Power supply is connected.
kDisconnected = 1, // Power supply is disconnected.
};
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