Commit 3c223441 authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

cros_healthd: Add DnsResolution routine

Add the DnsResolution routine to the ServiceConnection.

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

Change-Id: If10388526b50c05aab047ba30d00642d28c9e079
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2345005
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@{#819654}
parent 607d9cd7
...@@ -510,6 +510,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback, ...@@ -510,6 +510,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback,
std::move(failed_callback))); std::move(failed_callback)));
break; break;
} }
case chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDnsResolution: {
chromeos::cros_healthd::ServiceConnection::GetInstance()
->RunDnsResolutionRoutine(base::BindOnce(
&DeviceCommandRunRoutineJob::OnCrosHealthdResponseReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(succeeded_callback),
std::move(failed_callback)));
break;
}
} }
} }
......
...@@ -1260,4 +1260,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsLatencyRoutineSuccess) { ...@@ -1260,4 +1260,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsLatencyRoutineSuccess) {
}))); })));
} }
// Note that the DNS resolution routine has no parameters, so we only need
// to test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolutionRoutineSuccess) {
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::kDnsResolution,
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
...@@ -233,6 +233,11 @@ void FakeCrosHealthdService::RunDnsLatencyRoutine( ...@@ -233,6 +233,11 @@ void FakeCrosHealthdService::RunDnsLatencyRoutine(
std::move(callback).Run(run_routine_response_.Clone()); std::move(callback).Run(run_routine_response_.Clone());
} }
void FakeCrosHealthdService::RunDnsResolutionRoutine(
RunDnsResolutionRoutineCallback 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());
......
...@@ -105,6 +105,8 @@ class FakeCrosHealthdService final ...@@ -105,6 +105,8 @@ class FakeCrosHealthdService final
void RunDnsResolverPresentRoutine( void RunDnsResolverPresentRoutine(
RunDnsResolverPresentRoutineCallback callback) override; RunDnsResolverPresentRoutineCallback callback) override;
void RunDnsLatencyRoutine(RunDnsLatencyRoutineCallback callback) override; void RunDnsLatencyRoutine(RunDnsLatencyRoutineCallback callback) override;
void RunDnsResolutionRoutine(
RunDnsResolutionRoutineCallback callback) override;
// CrosHealthdEventService overrides: // CrosHealthdEventService overrides:
void AddBluetoothObserver( void AddBluetoothObserver(
......
...@@ -118,6 +118,9 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -118,6 +118,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunDnsLatencyRoutine( void RunDnsLatencyRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback
callback) override; callback) override;
void RunDnsResolutionRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback
callback) override;
void AddBluetoothObserver( void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override; override;
...@@ -416,6 +419,15 @@ void ServiceConnectionImpl::RunDnsLatencyRoutine( ...@@ -416,6 +419,15 @@ void ServiceConnectionImpl::RunDnsLatencyRoutine(
cros_healthd_diagnostics_service_->RunDnsLatencyRoutine(std::move(callback)); cros_healthd_diagnostics_service_->RunDnsLatencyRoutine(std::move(callback));
} }
void ServiceConnectionImpl::RunDnsResolutionRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunDnsResolutionRoutine(
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_);
......
...@@ -217,6 +217,13 @@ class ServiceConnection { ...@@ -217,6 +217,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsLatencyRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the DNS resolution routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunDnsResolutionRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback
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.
......
...@@ -599,6 +599,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsLatencyRoutine) { ...@@ -599,6 +599,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsLatencyRoutine) {
run_loop.Run(); run_loop.Run();
} }
// Test that we can run the DNS resolution routine.
TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolutionRoutine) {
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunDnsResolutionRoutine(
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;
......
...@@ -359,6 +359,16 @@ interface CrosHealthdDiagnosticsService { ...@@ -359,6 +359,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.
RunDnsLatencyRoutine() => (RunRoutineResponse response); RunDnsLatencyRoutine() => (RunRoutineResponse response);
// Requests that the DnsResolution routine is created and started on the
// platform. This routine checks whether a DNS resolution can be completed
// successfully. This routine is only available if GetAvailableRoutines
// returned kDnsResolution.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunDnsResolutionRoutine() => (RunRoutineResponse response);
}; };
// Event interface exposed by the cros_healthd daemon. // Event interface exposed by the cros_healthd daemon.
......
...@@ -37,6 +37,7 @@ enum DiagnosticRoutineEnum { ...@@ -37,6 +37,7 @@ enum DiagnosticRoutineEnum {
kHasSecureWiFiConnection = 18, kHasSecureWiFiConnection = 18,
kDnsResolverPresent = 19, kDnsResolverPresent = 19,
kDnsLatency = 20, kDnsLatency = 20,
kDnsResolution = 21,
}; };
// 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