Commit a7728e85 authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

cros_healthd: Add LanConnectivity routine

Add the LanConnectivity routine to the ServiceConnection.

BUG=chromium:956783
TEST=1) chromeos_unittests --gtest_filter=CrosHealthdServiceConnectionTest.*
2) Applied LanConnectivity changes and successfully ran the
LanConnectivity routine on a DUT (verified using cros-health-tool diag
--action=run_routine --routine=lan_connectivity).

Change-Id: Ia0c9fd15d07c121d04fa08466694575cc3048d0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321005
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Reviewed-by: default avatarPaul Moy <pmoy@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809437}
parent fb88d32c
...@@ -494,6 +494,15 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback, ...@@ -494,6 +494,15 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback,
std::move(failed_callback))); std::move(failed_callback)));
break; break;
} }
case chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::
kLanConnectivity: {
chromeos::cros_healthd::ServiceConnection::GetInstance()
->RunLanConnectivityRoutine(base::BindOnce(
&DeviceCommandRunRoutineJob::OnCrosHealthdResponseReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(succeeded_callback),
std::move(failed_callback)));
break;
}
} }
} }
......
...@@ -1293,4 +1293,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunMemoryRoutineSuccess) { ...@@ -1293,4 +1293,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunMemoryRoutineSuccess) {
}))); })));
} }
// Note that the LAN connectivity routine has no parameters, so we only need to
// test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunLanConnectivityRoutineSuccess) {
auto run_routine_response =
chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus);
chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY);
EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kLanConnectivity,
std::move(params_dict),
base::BindLambdaForTesting([](RemoteCommandJob* job) {
EXPECT_EQ(job->status(), RemoteCommandJob::SUCCEEDED);
std::unique_ptr<std::string> payload = job->GetResultPayload();
EXPECT_TRUE(payload);
EXPECT_EQ(CreateSuccessPayload(kId, kStatus), *payload);
})));
}
} // namespace policy } // namespace policy
...@@ -207,6 +207,11 @@ void FakeCrosHealthdService::RunMemoryRoutine( ...@@ -207,6 +207,11 @@ void FakeCrosHealthdService::RunMemoryRoutine(
callback_delay_); callback_delay_);
} }
void FakeCrosHealthdService::RunLanConnectivityRoutine(
RunLanConnectivityRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::AddBluetoothObserver( void FakeCrosHealthdService::AddBluetoothObserver(
mojom::CrosHealthdBluetoothObserverPtr observer) { mojom::CrosHealthdBluetoothObserverPtr observer) {
bluetooth_observers_.Add(observer.PassInterface()); bluetooth_observers_.Add(observer.PassInterface());
......
...@@ -98,6 +98,8 @@ class FakeCrosHealthdService final ...@@ -98,6 +98,8 @@ class FakeCrosHealthdService final
uint32_t minimum_charge_percent_required, uint32_t minimum_charge_percent_required,
RunBatteryChargeRoutineCallback callback) override; RunBatteryChargeRoutineCallback callback) override;
void RunMemoryRoutine(RunMemoryRoutineCallback callback) override; void RunMemoryRoutine(RunMemoryRoutineCallback callback) override;
void RunLanConnectivityRoutine(
RunLanConnectivityRoutineCallback callback) override;
// CrosHealthdEventService overrides: // CrosHealthdEventService overrides:
void AddBluetoothObserver( void AddBluetoothObserver(
......
...@@ -104,6 +104,9 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -104,6 +104,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunMemoryRoutine( void RunMemoryRoutine(
mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback callback) mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback callback)
override; override;
void RunLanConnectivityRoutine(
mojom::CrosHealthdDiagnosticsService::RunLanConnectivityRoutineCallback
callback) override;
void AddBluetoothObserver( void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override; override;
...@@ -353,6 +356,15 @@ void ServiceConnectionImpl::RunMemoryRoutine( ...@@ -353,6 +356,15 @@ void ServiceConnectionImpl::RunMemoryRoutine(
cros_healthd_diagnostics_service_->RunMemoryRoutine(std::move(callback)); cros_healthd_diagnostics_service_->RunMemoryRoutine(std::move(callback));
} }
void ServiceConnectionImpl::RunLanConnectivityRoutine(
mojom::CrosHealthdDiagnosticsService::RunLanConnectivityRoutineCallback
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunLanConnectivityRoutine(
std::move(callback));
}
void ServiceConnectionImpl::AddBluetoothObserver( void ServiceConnectionImpl::AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) { mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
...@@ -179,6 +179,13 @@ class ServiceConnection { ...@@ -179,6 +179,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the lan connectivity routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunLanConnectivityRoutine(
mojom::CrosHealthdDiagnosticsService::RunLanConnectivityRoutineCallback
callback) = 0;
// Subscribes to cros_healthd's Bluetooth-related events. See // Subscribes to cros_healthd's Bluetooth-related events. See
// src/chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
......
...@@ -515,6 +515,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunMemoryRoutine) { ...@@ -515,6 +515,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunMemoryRoutine) {
run_loop.Run(); run_loop.Run();
} }
// Test that we can run the LAN connectivity routine.
TEST_F(CrosHealthdServiceConnectionTest, RunLanConnectivityRoutine) {
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunLanConnectivityRoutine(
base::BindLambdaForTesting([&](mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
run_loop.Quit();
}));
run_loop.Run();
}
// Test that we can add a Bluetooth observer. // Test that we can add a Bluetooth observer.
TEST_F(CrosHealthdServiceConnectionTest, AddBluetoothObserver) { TEST_F(CrosHealthdServiceConnectionTest, AddBluetoothObserver) {
MockCrosHealthdBluetoothObserver observer; MockCrosHealthdBluetoothObserver observer;
......
...@@ -306,6 +306,16 @@ interface CrosHealthdDiagnosticsService { ...@@ -306,6 +306,16 @@ interface CrosHealthdDiagnosticsService {
// * |response| - contains a unique identifier and status for the created // * |response| - contains a unique identifier and status for the created
// routine. // routine.
RunMemoryRoutine() => (RunRoutineResponse response); RunMemoryRoutine() => (RunRoutineResponse response);
// Requests that the LanConnectivity routine is created and started on the
// platform. This routine checks whether the device is connected to a LAN.
// This routine is only available if GetAvailableRoutines returned
// kLanConnectivity.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunLanConnectivityRoutine() => (RunRoutineResponse response);
}; };
// Event interface exposed by the cros_healthd daemon. // Event interface exposed by the cros_healthd daemon.
......
...@@ -31,6 +31,7 @@ enum DiagnosticRoutineEnum { ...@@ -31,6 +31,7 @@ enum DiagnosticRoutineEnum {
kBatteryDischarge = 12, kBatteryDischarge = 12,
kBatteryCharge = 13, kBatteryCharge = 13,
kMemory = 14, kMemory = 14,
kLanConnectivity = 15,
}; };
// Enumeration of the possible DiskRead routine's command type // Enumeration of the possible DiskRead routine's command type
......
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