Commit 31c2595e authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

cros_healthd: Add DnsLatency routine

Add the DnsLatency routine to the ServiceConnection.

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

Change-Id: I2e00fae7f641344a20372923c4d6be8e51cc5a2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2345004
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Reviewed-by: default avatarPaul 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@{#819632}
parent 2ff1a3de
...@@ -502,6 +502,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback, ...@@ -502,6 +502,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback,
std::move(failed_callback))); std::move(failed_callback)));
break; break;
} }
case chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDnsLatency: {
chromeos::cros_healthd::ServiceConnection::GetInstance()
->RunDnsLatencyRoutine(base::BindOnce(
&DeviceCommandRunRoutineJob::OnCrosHealthdResponseReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(succeeded_callback),
std::move(failed_callback)));
break;
}
} }
} }
......
...@@ -1241,4 +1241,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolverPresentRoutineSuccess) { ...@@ -1241,4 +1241,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolverPresentRoutineSuccess) {
}))); })));
} }
// Note that the DNS latency routine has no parameters, so we only need
// to test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunDnsLatencyRoutineSuccess) {
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::kDnsLatency,
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
...@@ -228,6 +228,11 @@ void FakeCrosHealthdService::RunDnsResolverPresentRoutine( ...@@ -228,6 +228,11 @@ void FakeCrosHealthdService::RunDnsResolverPresentRoutine(
std::move(callback).Run(run_routine_response_.Clone()); std::move(callback).Run(run_routine_response_.Clone());
} }
void FakeCrosHealthdService::RunDnsLatencyRoutine(
RunDnsLatencyRoutineCallback 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());
......
...@@ -104,6 +104,7 @@ class FakeCrosHealthdService final ...@@ -104,6 +104,7 @@ class FakeCrosHealthdService final
RunHasSecureWiFiConnectionRoutineCallback callback) override; RunHasSecureWiFiConnectionRoutineCallback callback) override;
void RunDnsResolverPresentRoutine( void RunDnsResolverPresentRoutine(
RunDnsResolverPresentRoutineCallback callback) override; RunDnsResolverPresentRoutineCallback callback) override;
void RunDnsLatencyRoutine(RunDnsLatencyRoutineCallback callback) override;
// CrosHealthdEventService overrides: // CrosHealthdEventService overrides:
void AddBluetoothObserver( void AddBluetoothObserver(
......
...@@ -115,6 +115,9 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -115,6 +115,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunDnsResolverPresentRoutine( void RunDnsResolverPresentRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback
callback) override; callback) override;
void RunDnsLatencyRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback
callback) override;
void AddBluetoothObserver( void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override; override;
...@@ -405,6 +408,14 @@ void ServiceConnectionImpl::RunDnsResolverPresentRoutine( ...@@ -405,6 +408,14 @@ void ServiceConnectionImpl::RunDnsResolverPresentRoutine(
std::move(callback)); std::move(callback));
} }
void ServiceConnectionImpl::RunDnsLatencyRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunDnsLatencyRoutine(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_);
......
...@@ -210,6 +210,13 @@ class ServiceConnection { ...@@ -210,6 +210,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the DNS latency routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunDnsLatencyRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback
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.
......
...@@ -586,6 +586,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolverPresentRoutine) { ...@@ -586,6 +586,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolverPresentRoutine) {
run_loop.Run(); run_loop.Run();
} }
// Test that we can run the DNS latency routine.
TEST_F(CrosHealthdServiceConnectionTest, RunDnsLatencyRoutine) {
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunDnsLatencyRoutine(
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;
......
...@@ -349,6 +349,16 @@ interface CrosHealthdDiagnosticsService { ...@@ -349,6 +349,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.
RunDnsResolverPresentRoutine() => (RunRoutineResponse response); RunDnsResolverPresentRoutine() => (RunRoutineResponse response);
// Requests that the DnsLatency routine is created and started on the
// platform. This routine checks whether the DNS latency is below an
// acceptable threshold. This routine is only available if
// GetAvailableRoutines returned kDnsLatency.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunDnsLatencyRoutine() => (RunRoutineResponse response);
}; };
// Event interface exposed by the cros_healthd daemon. // Event interface exposed by the cros_healthd daemon.
......
...@@ -36,6 +36,7 @@ enum DiagnosticRoutineEnum { ...@@ -36,6 +36,7 @@ enum DiagnosticRoutineEnum {
kGatewayCanBePinged = 17, kGatewayCanBePinged = 17,
kHasSecureWiFiConnection = 18, kHasSecureWiFiConnection = 18,
kDnsResolverPresent = 19, kDnsResolverPresent = 19,
kDnsLatency = 20,
}; };
// 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