Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail early when Android device is not booted #1106

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Microsoft.DotNet.XHarness.Android/AdbRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public int GetDeviceApiVersion()
return apiVersion;
}

public void WaitForDevice()
public bool WaitForDevice()
{
// This command waits for ANY kind of device to be available (emulator or real)
// Needed because emulators start up asynchronously and take a while.
Expand All @@ -215,10 +215,12 @@ public void WaitForDevice()
if (bootCompleted)
{
_log.LogDebug($"Waited {(int)watch.Elapsed.TotalSeconds} seconds for device boot completion");
return true;
}
else
{
_log.LogWarning($"Did not detect boot completion variable on device; device may be in a bad state");
_log.LogError($"Did not detect boot completion variable on device; device may be in a bad state");
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public static ExitCode InvokeHelper(
runner.TimeToWaitForBootCompletion = bootTimeoutSeconds;

// Wait till at least device(s) are ready
runner.WaitForDevice();
if (!runner.WaitForDevice())
{
return ExitCode.DEVICE_NOT_FOUND;
}

logger.LogDebug($"Working with {device.DeviceSerial} (API {device.ApiVersion})");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ protected override ExitCode InvokeCommand(ILogger logger)
runner.TimeToWaitForBootCompletion = Arguments.LaunchTimeout;

// Wait till at least device(s) are ready
runner.WaitForDevice();
if (!runner.WaitForDevice())
{
return ExitCode.DEVICE_NOT_FOUND;
}

logger.LogDebug($"Working with API {runner.GetAdbVersion()}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public static ExitCode InvokeHelper(
runner.TimeToWaitForBootCompletion = bootTimeoutSeconds;

// Wait till at least device(s) are ready
runner.WaitForDevice();
if (!runner.WaitForDevice())
{
return ExitCode.DEVICE_NOT_FOUND;
}

logger.LogDebug($"Working with {device.DeviceSerial} (API {device.ApiVersion})");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ protected override ExitCode InvokeCommand(ILogger logger)
runner.TimeToWaitForBootCompletion = Arguments.LaunchTimeout;

// Wait till at least device(s) are ready
runner.WaitForDevice();
if (!runner.WaitForDevice())
{
return ExitCode.DEVICE_NOT_FOUND;
}

return InvokeHelper(
logger,
Expand Down