Skip to content

[tests] Capture device state on device-test failure - #11832

Merged
jonathanpeppers merged 4 commits into
mainfrom
dev/simonrozsival/device-state-diagnostics
Jul 1, 2026
Merged

[tests] Capture device state on device-test failure#11832
jonathanpeppers merged 4 commits into
mainfrom
dev/simonrozsival/device-state-diagnostics

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Description

When an on-device test fails, DeviceTest.CleanupTest ([TearDown]) already attaches a screenshot.png, logcat-failed.log, and ui.xml. But we capture no device-state snapshot, so on-device install/deploy failures can't be classified after the fact — we're left guessing between connectivity, disk pressure, and an unready storage service.

This adds a best-effort device-state-failed.log to the on-failure teardown, capturing:

  • Connectivityadb devices -l, adb get-state
  • Boot completiongetprop sys.boot_completed, getprop dev.bootcomplete
  • Disk pressuredf /data, df /storage/emulated/0, dumpsys diskstats
  • Storage-service readinessdumpsys storaged (the StorageStatsManager.isQuotaSupported(...) on a null object NPE we've seen thrown from install-create)
  • Accumulated appspm list packages -3

It covers the InstallAndRunTests / InstallTests / FastDevTest families (e.g. DeployToDevice, IncrementalFastDeployment), which all derive from DeviceTest. The capture is best-effort (RunAdbCommand already ignores errors) and only runs when the test failed and a device is still attached — for a truly offline device there is nothing to query, and that case is already obvious from XAGCPU7000.

Motivation

Seen on build 1488657 (PR #11825, unrelated change): 14 install/deploy tests failed together with

InstallException: 'package install-create ...' returns 'Unknown failure: ...
  NullPointerException: ...StorageStatsManager.isQuotaSupported(String) on a null object reference
    at StorageManagerService.getAllocatableBytes(...)

We could not tell from the artifacts whether this was disk pressure or an unready storage service. This snapshot makes the next occurrence self-diagnosing.

Context

Companion to #11831 (which adds the equivalent snapshot to the apk-instrumentation.yaml MTP install lane). Both feed the tracking issue #11830.

When an on-device test fails, DeviceTest.CleanupTest already attaches a
screenshot, logcat, and UI dump. Add a best-effort device-state snapshot
(device-state-failed.log) so on-device install/deploy failures can be
classified from CI artifacts instead of guessed: connectivity
(adb devices/get-state), disk pressure (df, dumpsys diskstats),
storage-service readiness (dumpsys storaged - the StorageStatsManager
NPE seen during install-create), boot completion, and how many test apps
have accumulated.

This covers the InstallAndRunTests/InstallTests/FastDevTest families
(e.g. DeployToDevice), which all derive from DeviceTest.

Context: #11830

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 1, 2026 08:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a best-effort “device state” snapshot to failing on-device test teardowns so CI artifacts contain enough context to triage install/deploy failures (connectivity/boot/disk/storage service readiness/app accumulation) after the fact.

Changes:

  • Extend DeviceTest.CleanupTest failure artifact collection to generate and attach device-state-failed.log.
  • Add CaptureDeviceState() helper that runs a small suite of adb queries (devices/get-state/getprop/df/dumpsys/pm) and writes the consolidated output to the test output directory.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs On failure, captures and attaches a consolidated ADB/device-state snapshot log alongside existing screenshot/logcat/UI artifacts.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Address review feedback: the cached IsDeviceAttached() value can be
stale if the device disconnected mid-test, in which case each adb
command in CaptureDeviceState would wait the full timeout against an
unresponsive device. Re-check with a fresh probe and, when no device is
attached, log 'No device attached; skipping device-state capture.'
instead of silently doing nothing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pass CultureInfo.InvariantCulture to StringBuilder.AppendLine to satisfy
the CA1305 analyzer for the interpolated section header.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival added the copilot `copilot-cli` or other AIs were used to author this label Jul 1, 2026
@jonathanpeppers
jonathanpeppers merged commit 4d95103 into main Jul 1, 2026
40 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/device-state-diagnostics branch July 1, 2026 18:00
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

copilot `copilot-cli` or other AIs were used to author this flaky-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants