Commit cc342452 authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

cros_healthd: add support for diagnostics

Add diagnostics-related methods to cros_healthd::ServiceConnection.
These methods will allow Chrome to initiate and control diagnostic
routines on the platform. In the future, remote commands will
consume these diagnostics methods.

Bug: b:128683357
Test: chromeos_unittests --gtest_filter=CrosHealthdServiceConnection.*
Change-Id: I1629a5ae97fb731e49b160edb3d8c2d79f2fc863
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1967968Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Paul Moy <pmoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726007}
parent 5b5bc453
...@@ -109,7 +109,7 @@ void CrosHealthdClient::Initialize(dbus::Bus* bus) { ...@@ -109,7 +109,7 @@ void CrosHealthdClient::Initialize(dbus::Bus* bus) {
// static // static
void CrosHealthdClient::InitializeFake() { void CrosHealthdClient::InitializeFake() {
new FakeCrosHealthdClient(); new cros_healthd::FakeCrosHealthdClient();
} }
// static // static
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#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 {
namespace cros_healthd {
namespace { namespace {
...@@ -31,19 +32,35 @@ FakeCrosHealthdClient* FakeCrosHealthdClient::Get() { ...@@ -31,19 +32,35 @@ FakeCrosHealthdClient* FakeCrosHealthdClient::Get() {
return g_instance; return g_instance;
} }
mojo::Remote<cros_healthd::mojom::CrosHealthdService> mojo::Remote<mojom::CrosHealthdService>
FakeCrosHealthdClient::BootstrapMojoConnection( FakeCrosHealthdClient::BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) { base::OnceCallback<void(bool success)> result_callback) {
mojo::Remote<cros_healthd::mojom::CrosHealthdService> remote( mojo::Remote<mojom::CrosHealthdService> remote(
receiver_.BindNewPipeAndPassRemote()); receiver_.BindNewPipeAndPassRemote());
std::move(result_callback).Run(/*success=*/true); std::move(result_callback).Run(/*success=*/true);
return remote; return remote;
} }
void FakeCrosHealthdClient::SetAvailableRoutinesForTesting(
const std::vector<mojom::DiagnosticRoutineEnum>& available_routines) {
fake_service_.SetAvailableRoutinesForTesting(available_routines);
}
void FakeCrosHealthdClient::SetRunRoutineResponseForTesting(
mojom::RunRoutineResponsePtr& response) {
fake_service_.SetRunRoutineResponseForTesting(response);
}
void FakeCrosHealthdClient::SetGetRoutineUpdateResponseForTesting(
mojom::RoutineUpdatePtr& response) {
fake_service_.SetGetRoutineUpdateResponseForTesting(response);
}
void FakeCrosHealthdClient::SetProbeTelemetryInfoResponseForTesting( void FakeCrosHealthdClient::SetProbeTelemetryInfoResponseForTesting(
TelemetryInfoPtr& info) { mojom::TelemetryInfoPtr& info) {
fake_service_.SetProbeTelemetryInfoResponseForTesting(info); fake_service_.SetProbeTelemetryInfoResponseForTesting(info);
} }
} // namespace cros_healthd
} // namespace chromeos } // namespace chromeos
...@@ -11,17 +11,17 @@ ...@@ -11,17 +11,17 @@
#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_service.h" #include "chromeos/dbus/cros_healthd/fake_cros_healthd_service.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos { namespace chromeos {
namespace cros_healthd {
// Fake implementation of CrosHealthdClient. // Fake implementation of CrosHealthdClient.
class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
: public CrosHealthdClient { : public CrosHealthdClient {
public: public:
using TelemetryInfoPtr = cros_healthd::mojom::TelemetryInfoPtr;
// FakeCrosHealthdClient can be embedded in unit tests, but the // FakeCrosHealthdClient can be embedded in unit tests, but the
// InitializeFake/Shutdown pattern should be preferred. Constructing the // InitializeFake/Shutdown pattern should be preferred. Constructing the
// instance will set the global instance for the fake and for the base class, // instance will set the global instance for the fake and for the base class,
...@@ -34,21 +34,34 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient ...@@ -34,21 +34,34 @@ class COMPONENT_EXPORT(CROS_HEALTHD) FakeCrosHealthdClient
static FakeCrosHealthdClient* Get(); static FakeCrosHealthdClient* Get();
// CrosHealthdClient overrides: // CrosHealthdClient overrides:
mojo::Remote<cros_healthd::mojom::CrosHealthdService> BootstrapMojoConnection( mojo::Remote<mojom::CrosHealthdService> BootstrapMojoConnection(
base::OnceCallback<void(bool success)> result_callback) override; base::OnceCallback<void(bool success)> result_callback) override;
// Set the list of routines that will be used in the response to any
// GetAvailableRoutines IPCs received.
void SetAvailableRoutinesForTesting(
const std::vector<mojom::DiagnosticRoutineEnum>& available_routines);
// Set the RunRoutine response that will be used in the response to any
// RunSomeRoutine IPCs received.
void SetRunRoutineResponseForTesting(mojom::RunRoutineResponsePtr& response);
// Set the GetRoutineUpdate response that will be used in the response to any
// GetRoutineUpdate IPCs received.
void SetGetRoutineUpdateResponseForTesting(mojom::RoutineUpdatePtr& response);
// Set the TelemetryInfoPtr that will be used in the response to any // Set the TelemetryInfoPtr that will be used in the response to any
// ProbeTelemetryInfo IPCs received. // ProbeTelemetryInfo IPCs received.
void SetProbeTelemetryInfoResponseForTesting(TelemetryInfoPtr& info); void SetProbeTelemetryInfoResponseForTesting(mojom::TelemetryInfoPtr& info);
private: private:
cros_healthd::FakeCrosHealthdService fake_service_; FakeCrosHealthdService fake_service_;
mojo::Receiver<cros_healthd::mojom::CrosHealthdService> receiver_{ mojo::Receiver<mojom::CrosHealthdService> receiver_{&fake_service_};
&fake_service_};
DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdClient); DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdClient);
}; };
} // namespace cros_healthd
} // namespace chromeos } // namespace chromeos
#endif // CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_CLIENT_H_ #endif // CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_CLIENT_H_
...@@ -12,15 +12,71 @@ namespace cros_healthd { ...@@ -12,15 +12,71 @@ namespace cros_healthd {
FakeCrosHealthdService::FakeCrosHealthdService() = default; FakeCrosHealthdService::FakeCrosHealthdService() = default;
FakeCrosHealthdService::~FakeCrosHealthdService() = default; FakeCrosHealthdService::~FakeCrosHealthdService() = default;
void FakeCrosHealthdService::GetAvailableRoutines(
GetAvailableRoutinesCallback callback) {
std::move(callback).Run(available_routines_);
}
void FakeCrosHealthdService::GetRoutineUpdate(
int32_t id,
mojom::DiagnosticRoutineCommandEnum command,
bool include_output,
GetRoutineUpdateCallback callback) {
std::move(callback).Run(mojom::RoutineUpdate::New(
routine_update_response_->progress_percent,
std::move(routine_update_response_->output),
std::move(routine_update_response_->routine_update_union)));
}
void FakeCrosHealthdService::RunUrandomRoutine(
uint32_t length_seconds,
RunUrandomRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::RunBatteryCapacityRoutine(
uint32_t low_mah,
uint32_t high_mah,
RunBatteryCapacityRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
RunBatteryHealthRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::RunSmartctlCheckRoutine(
RunSmartctlCheckRoutineCallback 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) {
std::move(callback).Run(response_info_.Clone()); std::move(callback).Run(telemetry_response_info_.Clone());
}
void FakeCrosHealthdService::SetAvailableRoutinesForTesting(
const std::vector<mojom::DiagnosticRoutineEnum>& available_routines) {
available_routines_ = available_routines;
}
void FakeCrosHealthdService::SetRunRoutineResponseForTesting(
mojom::RunRoutineResponsePtr& response) {
run_routine_response_.Swap(&response);
}
void FakeCrosHealthdService::SetGetRoutineUpdateResponseForTesting(
mojom::RoutineUpdatePtr& response) {
routine_update_response_.Swap(&response);
} }
void FakeCrosHealthdService::SetProbeTelemetryInfoResponseForTesting( void FakeCrosHealthdService::SetProbeTelemetryInfoResponseForTesting(
mojom::TelemetryInfoPtr& response_info) { mojom::TelemetryInfoPtr& response_info) {
response_info_.Swap(&response_info); telemetry_response_info_.Swap(&response_info);
} }
} // namespace cros_healthd } // namespace cros_healthd
......
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
#ifndef CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_SERVICE_H_ #ifndef CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_SERVICE_H_
#define CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_SERVICE_H_ #define CHROMEOS_DBUS_CROS_HEALTHD_FAKE_CROS_HEALTHD_SERVICE_H_
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
namespace chromeos { namespace chromeos {
...@@ -18,18 +21,55 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService { ...@@ -18,18 +21,55 @@ class FakeCrosHealthdService final : public mojom::CrosHealthdService {
~FakeCrosHealthdService() override; ~FakeCrosHealthdService() override;
// CrosHealthdService overrides: // CrosHealthdService overrides:
void GetAvailableRoutines(GetAvailableRoutinesCallback callback) override;
void GetRoutineUpdate(int32_t id,
mojom::DiagnosticRoutineCommandEnum command,
bool include_output,
GetRoutineUpdateCallback callback) override;
void RunUrandomRoutine(uint32_t length_seconds,
RunUrandomRoutineCallback callback) override;
void RunBatteryCapacityRoutine(
uint32_t low_mah,
uint32_t high_mah,
RunBatteryCapacityRoutineCallback callback) override;
void RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
RunBatteryHealthRoutineCallback callback) override;
void RunSmartctlCheckRoutine(
RunSmartctlCheckRoutineCallback callback) override;
void ProbeTelemetryInfo( void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories, const std::vector<mojom::ProbeCategoryEnum>& categories,
ProbeTelemetryInfoCallback callback) override; ProbeTelemetryInfoCallback callback) override;
// Set the list of routines that will be used in the response to any
// GetAvailableRoutines IPCs received.
void SetAvailableRoutinesForTesting(
const std::vector<mojom::DiagnosticRoutineEnum>& available_routines);
// Set the RunRoutine response that will be used in the response to any
// RunSomeRoutine IPCs received.
void SetRunRoutineResponseForTesting(mojom::RunRoutineResponsePtr& response);
// Set the GetRoutineUpdate response that will be used in the response to any
// GetRoutineUpdate IPCs received.
void SetGetRoutineUpdateResponseForTesting(mojom::RoutineUpdatePtr& response);
// Set the TelemetryInfoPtr that will be used in the response to any // Set the TelemetryInfoPtr that will be used in the response to any
// ProbeTelemetryInfo IPCs received. // ProbeTelemetryInfo IPCs received.
void SetProbeTelemetryInfoResponseForTesting( void SetProbeTelemetryInfoResponseForTesting(
mojom::TelemetryInfoPtr& response_info); mojom::TelemetryInfoPtr& response_info);
private: private:
// Used as the response to any GetAvailableRoutines IPCs received.
std::vector<mojom::DiagnosticRoutineEnum> available_routines_;
// Used as the response to any RunSomeRoutine IPCs received.
mojom::RunRoutineResponsePtr run_routine_response_{
mojom::RunRoutineResponse::New()};
// Used as the response to any GetRoutineUpdate IPCs received.
mojom::RoutineUpdatePtr routine_update_response_{mojom::RoutineUpdate::New()};
// Used as the response to any ProbeTelemetryInfo IPCs received. // Used as the response to any ProbeTelemetryInfo IPCs received.
mojom::TelemetryInfoPtr response_info_{mojom::TelemetryInfo::New()}; mojom::TelemetryInfoPtr telemetry_response_info_{mojom::TelemetryInfo::New()};
DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdService); DISALLOW_COPY_AND_ASSIGN(FakeCrosHealthdService);
}; };
......
...@@ -27,6 +27,30 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -27,6 +27,30 @@ class ServiceConnectionImpl : public ServiceConnection {
private: private:
// ServiceConnection overrides: // ServiceConnection overrides:
void GetAvailableRoutines(
mojom::CrosHealthdService::GetAvailableRoutinesCallback callback)
override;
void GetRoutineUpdate(
int32_t id,
mojom::DiagnosticRoutineCommandEnum command,
bool include_output,
mojom::CrosHealthdService::GetRoutineUpdateCallback callback) override;
void RunUrandomRoutine(
uint32_t length_seconds,
mojom::CrosHealthdService::RunUrandomRoutineCallback callback) override;
void RunBatteryCapacityRoutine(
uint32_t low_mah,
uint32_t high_mah,
mojom::CrosHealthdService::RunBatteryCapacityRoutineCallback callback)
override;
void RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
mojom::CrosHealthdService::RunBatteryHealthRoutineCallback callback)
override;
void RunSmartctlCheckRoutine(
mojom::CrosHealthdService::RunSmartctlCheckRoutineCallback callback)
override;
void ProbeTelemetryInfo( void ProbeTelemetryInfo(
const std::vector<mojom::ProbeCategoryEnum>& categories_to_test, const std::vector<mojom::ProbeCategoryEnum>& categories_to_test,
mojom::CrosHealthdService::ProbeTelemetryInfoCallback callback) override; mojom::CrosHealthdService::ProbeTelemetryInfoCallback callback) override;
...@@ -50,6 +74,59 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -50,6 +74,59 @@ class ServiceConnectionImpl : public ServiceConnection {
DISALLOW_COPY_AND_ASSIGN(ServiceConnectionImpl); DISALLOW_COPY_AND_ASSIGN(ServiceConnectionImpl);
}; };
void ServiceConnectionImpl::GetAvailableRoutines(
mojom::CrosHealthdService::GetAvailableRoutinesCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->GetAvailableRoutines(std::move(callback));
}
void ServiceConnectionImpl::GetRoutineUpdate(
int32_t id,
mojom::DiagnosticRoutineCommandEnum command,
bool include_output,
mojom::CrosHealthdService::GetRoutineUpdateCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->GetRoutineUpdate(id, command, include_output,
std::move(callback));
}
void ServiceConnectionImpl::RunUrandomRoutine(
uint32_t length_seconds,
mojom::CrosHealthdService::RunUrandomRoutineCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->RunUrandomRoutine(length_seconds, std::move(callback));
}
void ServiceConnectionImpl::RunBatteryCapacityRoutine(
uint32_t low_mah,
uint32_t high_mah,
mojom::CrosHealthdService::RunBatteryCapacityRoutineCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->RunBatteryCapacityRoutine(low_mah, high_mah,
std::move(callback));
}
void ServiceConnectionImpl::RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
mojom::CrosHealthdService::RunBatteryHealthRoutineCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->RunBatteryHealthRoutine(
maximum_cycle_count, percent_battery_wear_allowed, std::move(callback));
}
void ServiceConnectionImpl::RunSmartctlCheckRoutine(
mojom::CrosHealthdService::RunSmartctlCheckRoutineCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdServiceIfNeeded();
cros_healthd_service_->RunSmartctlCheckRoutine(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::CrosHealthdService::ProbeTelemetryInfoCallback callback) { mojom::CrosHealthdService::ProbeTelemetryInfoCallback callback) {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_ #ifndef CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_
#define CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_ #define CHROMEOS_SERVICES_CROS_HEALTHD_PUBLIC_CPP_SERVICE_CONNECTION_H_
#include <cstdint>
#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 {
...@@ -17,6 +19,52 @@ class ServiceConnection { ...@@ -17,6 +19,52 @@ class ServiceConnection {
public: public:
static ServiceConnection* GetInstance(); static ServiceConnection* GetInstance();
// Retrieve a list of available diagnostic routines. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void GetAvailableRoutines(
mojom::CrosHealthdService::GetAvailableRoutinesCallback callback) = 0;
// Send a command to an existing routine. Also returns status information
// for the routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void GetRoutineUpdate(
int32_t id,
mojom::DiagnosticRoutineCommandEnum command,
bool include_output,
mojom::CrosHealthdService::GetRoutineUpdateCallback callback) = 0;
// Requests that cros_healthd runs the urandom routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunUrandomRoutine(
uint32_t length_seconds,
mojom::CrosHealthdService::RunUrandomRoutineCallback callback) = 0;
// Requests that cros_healthd runs the battery capacity routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunBatteryCapacityRoutine(
uint32_t low_mah,
uint32_t high_mah,
mojom::CrosHealthdService::RunBatteryCapacityRoutineCallback
callback) = 0;
// Requests that cros_healthd runs the battery health routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
mojom::CrosHealthdService::RunBatteryHealthRoutineCallback callback) = 0;
// Requests that cros_healthd runs the smartcl check routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunSmartctlCheckRoutine(
mojom::CrosHealthdService::RunSmartctlCheckRoutineCallback 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.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#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"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -27,6 +28,45 @@ namespace chromeos { ...@@ -27,6 +28,45 @@ namespace chromeos {
namespace cros_healthd { namespace cros_healthd {
namespace { namespace {
std::vector<mojom::DiagnosticRoutineEnum> MakeAvailableRoutines() {
return std::vector<mojom::DiagnosticRoutineEnum>{
mojom::DiagnosticRoutineEnum::kUrandom,
mojom::DiagnosticRoutineEnum::kBatteryCapacity,
mojom::DiagnosticRoutineEnum::kBatteryHealth,
mojom::DiagnosticRoutineEnum::kSmartctlCheck,
};
}
mojom::RunRoutineResponsePtr MakeRunRoutineResponse() {
return mojom::RunRoutineResponse::New(
/*id=*/13, /*status=*/mojom::DiagnosticRoutineStatusEnum::kReady);
}
mojom::RoutineUpdatePtr MakeInteractiveRoutineUpdate() {
mojom::InteractiveRoutineUpdate interactive_update(
/*user_message=*/mojom::DiagnosticRoutineUserMessageEnum::kUnplugACPower);
mojom::RoutineUpdateUnion update_union;
update_union.set_interactive_update(interactive_update.Clone());
return mojom::RoutineUpdate::New(
/*progress_percent=*/42,
/*output=*/mojo::ScopedHandle(), update_union.Clone());
}
mojom::RoutineUpdatePtr MakeNonInteractiveRoutineUpdate() {
mojom::NonInteractiveRoutineUpdate noninteractive_update(
/*status=*/mojom::DiagnosticRoutineStatusEnum::kRunning,
/*status_message=*/"status_message");
mojom::RoutineUpdateUnion update_union;
update_union.set_noninteractive_update(noninteractive_update.Clone());
return mojom::RoutineUpdate::New(
/*progress_percent=*/43,
/*output=*/mojo::ScopedHandle(), update_union.Clone());
}
base::Optional<std::vector<mojom::NonRemovableBlockDeviceInfoPtr>> base::Optional<std::vector<mojom::NonRemovableBlockDeviceInfoPtr>>
MakeNonRemovableBlockDeviceInfo() { MakeNonRemovableBlockDeviceInfo() {
std::vector<mojom::NonRemovableBlockDeviceInfoPtr> info; std::vector<mojom::NonRemovableBlockDeviceInfoPtr> info;
...@@ -81,7 +121,12 @@ class CrosHealthdServiceConnectionTest : public testing::Test { ...@@ -81,7 +121,12 @@ class CrosHealthdServiceConnectionTest : public testing::Test {
void SetUp() override { CrosHealthdClient::InitializeFake(); } void SetUp() override { CrosHealthdClient::InitializeFake(); }
void TearDown() override { CrosHealthdClient::Shutdown(); } void TearDown() override {
CrosHealthdClient::Shutdown();
// Wait for ServiceConnection to observe the destruction of the client.
base::RunLoop().RunUntilIdle();
}
private: private:
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
...@@ -89,6 +134,124 @@ class CrosHealthdServiceConnectionTest : public testing::Test { ...@@ -89,6 +134,124 @@ class CrosHealthdServiceConnectionTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(CrosHealthdServiceConnectionTest); DISALLOW_COPY_AND_ASSIGN(CrosHealthdServiceConnectionTest);
}; };
TEST_F(CrosHealthdServiceConnectionTest, GetAvailableRoutines) {
// Test that we can retrieve a list of available routines.
auto routines = MakeAvailableRoutines();
FakeCrosHealthdClient::Get()->SetAvailableRoutinesForTesting(routines);
bool callback_done = false;
ServiceConnection::GetInstance()->GetAvailableRoutines(base::BindOnce(
[](bool* callback_done,
const std::vector<mojom::DiagnosticRoutineEnum>& response) {
EXPECT_EQ(response, MakeAvailableRoutines());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
TEST_F(CrosHealthdServiceConnectionTest, GetRoutineUpdate) {
// Test that we can get an interactive routine update.
auto interactive_update = MakeInteractiveRoutineUpdate();
FakeCrosHealthdClient::Get()->SetGetRoutineUpdateResponseForTesting(
interactive_update);
bool callback_done = false;
ServiceConnection::GetInstance()->GetRoutineUpdate(
/*id=*/542, /*command=*/mojom::DiagnosticRoutineCommandEnum::kGetStatus,
/*include_output=*/true,
base::BindOnce(
[](bool* callback_done, mojom::RoutineUpdatePtr response) {
EXPECT_EQ(response, MakeInteractiveRoutineUpdate());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
// Test that we can get a noninteractive routine update.
auto noninteractive_update = MakeNonInteractiveRoutineUpdate();
FakeCrosHealthdClient::Get()->SetGetRoutineUpdateResponseForTesting(
noninteractive_update);
callback_done = false;
ServiceConnection::GetInstance()->GetRoutineUpdate(
/*id=*/543, /*command=*/mojom::DiagnosticRoutineCommandEnum::kCancel,
/*include_output=*/false,
base::BindOnce(
[](bool* callback_done, mojom::RoutineUpdatePtr response) {
EXPECT_EQ(response, MakeNonInteractiveRoutineUpdate());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
TEST_F(CrosHealthdServiceConnectionTest, RunUrandomRoutine) {
// Test that we can run the urandom routine.
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
bool callback_done = false;
ServiceConnection::GetInstance()->RunUrandomRoutine(
/*length_seconds=*/10,
base::BindOnce(
[](bool* callback_done, mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
TEST_F(CrosHealthdServiceConnectionTest, RunBatteryCapacityRoutine) {
// Test that we can run the battery capacity routine.
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
bool callback_done = false;
ServiceConnection::GetInstance()->RunBatteryCapacityRoutine(
/*low_mah=*/1001, /*high_mah=*/120345,
base::BindOnce(
[](bool* callback_done, mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
TEST_F(CrosHealthdServiceConnectionTest, RunBatteryHealthRoutine) {
// Test that we can run the battery health routine.
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
bool callback_done = false;
ServiceConnection::GetInstance()->RunBatteryHealthRoutine(
/*maximum_cycle_count=*/2, /*percent_battery_wear_allowed=*/90,
base::BindOnce(
[](bool* callback_done, mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
TEST_F(CrosHealthdServiceConnectionTest, RunSmartctlCheckRoutine) {
// Test that we can run the smartctl check routine.
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
bool callback_done = false;
ServiceConnection::GetInstance()->RunSmartctlCheckRoutine(base::BindOnce(
[](bool* callback_done, mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
*callback_done = true;
},
&callback_done));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_done);
}
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();
......
...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") { mojom("mojom") {
sources = [ sources = [
"cros_healthd.mojom", "cros_healthd.mojom",
"cros_healthd_diagnostics.mojom",
"cros_healthd_probe.mojom", "cros_healthd_probe.mojom",
] ]
} }
...@@ -10,10 +10,97 @@ ...@@ -10,10 +10,97 @@
module chromeos.cros_healthd.mojom; module chromeos.cros_healthd.mojom;
import "chromeos/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom";
import "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom"; import "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom";
// Interface exposed by the cros_healthd daemon. // Interface exposed by the cros_healthd daemon.
interface CrosHealthdService { interface CrosHealthdService {
// ------------------- Start of diagnostics definitions ---------------------
// Returns an array of all diagnostic routines that the platform supports.
GetAvailableRoutines()
=> (array<DiagnosticRoutineEnum> available_routines);
// Sends commands to an existing routine. Also returns status information for
// the routine.
//
// The request:
// * |id| - specifies which routine the command will be sent to. This must be
// the same id that was returned from the RunSomeRoutine function
// call used to create the routine.
// * |command| - command to send the routine.
// * |include_output| - whether or not the response should include any output
// accumulated from the routine.
//
// The response:
// * |routine_update| - status information for the specified routine. See
// cros_healthd_diagnostics.mojom for the structure.
GetRoutineUpdate(int32 id, DiagnosticRoutineCommandEnum command,
bool include_output)
=> (RoutineUpdate routine_update);
// Requests that the Urandom routine is created and started on the platform.
// This routine attempts to continually read from /dev/urandom to stress the
// cpu. The routine will pass iff all the reads from /dev/urandom succeed.
// This routine is only available if GetAvailableRoutines returned kUrandom.
//
// The request:
// * |length_seconds| - length of time, in seconds, to run the urandom routine
// for. If all reads from /dev/urandom for this length of
// time are successful, then the test will pass. This
// parameter needs to be strictly greater than zero.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunUrandomRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
// Requests that the BatteryCapacity routine is created and started on the
// platform. This routine checks the battery's design capacity against the
// inputs. The routine will pass iff the design capacity of the battery read
// from the platform is inclusively within these bounds. This routine is only
// available if GetAvailableRoutines returned kBatteryCapactity.
//
// The request:
// * |low_mah| - lower bound for the battery's design capacity (mAh).
// * |high_mah| - upper bound for the battery's design capacity (mAh).
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunBatteryCapacityRoutine(uint32 low_mah, uint32 high_mah)
=> (RunRoutineResponse response);
// Requests that the BatteryHealth routine is created and started on the
// platform. This routine checks the cycle count and percent wear of the
// battery. This routine is only available if GetAvailableRoutines returned
// kBatteryHealth.
//
// The request:
// * |maximum_cycle_count| - maximum cycle count allowed for the routine to
// pass.
// * |percent_battery_wear_allowed| - maximum percent battery wear allowed for
// the routine to pass.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunBatteryHealthRoutine(uint32 maximum_cycle_count,
uint32 percent_battery_wear_allowed)
=> (RunRoutineResponse response);
// Requests that the SmartctlCheck routine is created and started on the
// platform. This routine checks available spare NVMe capacity against the
// threshold. This routine is only available if GetAvailableRoutines returned
// kSmartctlCheck.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunSmartctlCheckRoutine() => (RunRoutineResponse response);
// ------------------- End of diagnostics definitions -----------------------
// ------------------- Start of probe definitions --------------------- // ------------------- Start of probe definitions ---------------------
// Returns telemetry information for the desired categories. This IPC is // Returns telemetry information for the desired categories. This IPC is
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Definitions for the diagnostics API exposed by the cros_healthd daemon. This
// API is normally consumed by the browser and the diag command-line tool.
// NOTE: This mojom should be kept in sync with the copy in Chromium's repo in
// src/platform2/diagnostics/mojo/cros_healthd_diagnostics.mojom.
module chromeos.cros_healthd.mojom;
// Special id that will be returned if a routine was unable to be created.
const int32 kFailedToStartId = 0;
// Enumeration of each of the diagnostics routines the platform may support.
[Extensible]
enum DiagnosticRoutineEnum {
kBatteryCapacity = 0,
kBatteryHealth = 1,
kUrandom = 2,
kSmartctlCheck = 3,
};
// Enumeration of each of the possible statuses for a diagnostics routine.
[Extensible]
enum DiagnosticRoutineStatusEnum {
kReady = 0, // Routine is ready to start.
kRunning = 1, // Routine is currently running.
kWaiting = 2, // Routine needs user input to continue.
kPassed = 3, // Routine completed and passed.
kFailed = 4, // Routine completed and failed.
kError = 5, // An error prevented the routine from completing.
kCancelled = 6, // Routine was cancelled before completion. A cancelled
// routine's information can still be accessed with a
// GetRoutineUpdateRequest.
kFailedToStart = 7, // Routine could not be created.
kRemoved = 8, // Routine has been removed and is no longer valid.
kCancelling = 9, // Routine is in the process of being cancelled.
};
// Enumeration of each of the messages a diagnostics routine can pass back.
// These messages prompt interaction from the user of the routine.
[Extensible]
enum DiagnosticRoutineUserMessageEnum {
kUnplugACPower = 0, // The user needs to unplug the AC power cord.
};
// Enumeration of the possible commands to send a diagnostics routine.
[Extensible]
enum DiagnosticRoutineCommandEnum {
kContinue = 0, // Resume a routine that is waiting.
kCancel = 1, // Cancelled routines must still be removed before the routine
// is destroyed.
kGetStatus = 2, // Used to get status but not otherwise control a routine.
kRemove = 3, // All routines which started successfully must be removed,
// otherwise they will persist on the system. This makes sure
// the routine is terminated before removing it.
};
// Generic return value for a RunSomeRoutine call.
struct RunRoutineResponse {
// Unique identifier for the newly-created routine. An id of kFailedToStartId
// means that the routine was unable to be created. Can be used in a
// GetRoutineUpdate call to control or get the status of the created routine.
int32 id;
// Current status of the newly-created routine. A status of kFailedToStart
// means the routine was unable to be created.
DiagnosticRoutineStatusEnum status;
};
// Status fields specific to interactive routines.
struct InteractiveRoutineUpdate {
// Request for user action. This message should be localized and displayed to
// the user.
DiagnosticRoutineUserMessageEnum user_message;
};
// Status fields specific to noninteractive routines.
struct NonInteractiveRoutineUpdate {
// Current status of the routine.
DiagnosticRoutineStatusEnum status;
// More detailed status - for example, if |status| was kError,
// |status_message| would describe the error encountered, like "failed to
// read file."
string status_message;
};
// Responses will be either interactive or noninteractive.
union RoutineUpdateUnion {
InteractiveRoutineUpdate interactive_update;
NonInteractiveRoutineUpdate noninteractive_update;
};
// Response type for GetRoutineUpdate.
struct RoutineUpdate {
// Percent complete, must be between 0 and 100, inclusive.
uint32 progress_percent;
// Any accumulated output, like logs, from the routine. This field is only
// valid when GetRoutineUpdate (see cros_healthd.mojom) is called with
// include_output = true.
handle? output;
// Information specific to the type of response - interactive or
// noninteractive.
RoutineUpdateUnion routine_update_union;
};
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