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,
std::move(failed_callback)));
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) {
})));
}
// 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
......@@ -207,6 +207,11 @@ void FakeCrosHealthdService::RunMemoryRoutine(
callback_delay_);
}
void FakeCrosHealthdService::RunLanConnectivityRoutine(
RunLanConnectivityRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::AddBluetoothObserver(
mojom::CrosHealthdBluetoothObserverPtr observer) {
bluetooth_observers_.Add(observer.PassInterface());
......
......@@ -98,6 +98,8 @@ class FakeCrosHealthdService final
uint32_t minimum_charge_percent_required,
RunBatteryChargeRoutineCallback callback) override;
void RunMemoryRoutine(RunMemoryRoutineCallback callback) override;
void RunLanConnectivityRoutine(
RunLanConnectivityRoutineCallback callback) override;
// CrosHealthdEventService overrides:
void AddBluetoothObserver(
......
......@@ -104,6 +104,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunMemoryRoutine(
mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback callback)
override;
void RunLanConnectivityRoutine(
mojom::CrosHealthdDiagnosticsService::RunLanConnectivityRoutineCallback
callback) override;
void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override;
......@@ -353,6 +356,15 @@ void ServiceConnectionImpl::RunMemoryRoutine(
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(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -179,6 +179,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunMemoryRoutineCallback
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
// src/chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
......
......@@ -515,6 +515,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunMemoryRoutine) {
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_F(CrosHealthdServiceConnectionTest, AddBluetoothObserver) {
MockCrosHealthdBluetoothObserver observer;
......
......@@ -306,6 +306,16 @@ interface CrosHealthdDiagnosticsService {
// * |response| - contains a unique identifier and status for the created
// routine.
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.
......
......@@ -31,6 +31,7 @@ enum DiagnosticRoutineEnum {
kBatteryDischarge = 12,
kBatteryCharge = 13,
kMemory = 14,
kLanConnectivity = 15,
};
// 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