[tests] Capture device state on device-test failure - #11832
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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.CleanupTestfailure artifact collection to generate and attachdevice-state-failed.log. - Add
CaptureDeviceState()helper that runs a small suite ofadbqueries (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>
jonathanpeppers
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an on-device test fails,
DeviceTest.CleanupTest([TearDown]) already attaches ascreenshot.png,logcat-failed.log, andui.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.logto the on-failure teardown, capturing:adb devices -l,adb get-stategetprop sys.boot_completed,getprop dev.bootcompletedf /data,df /storage/emulated/0,dumpsys diskstatsdumpsys storaged(theStorageStatsManager.isQuotaSupported(...) on a null objectNPE we've seen thrown frominstall-create)pm list packages -3It covers the
InstallAndRunTests/InstallTests/FastDevTestfamilies (e.g.DeployToDevice,IncrementalFastDeployment), which all derive fromDeviceTest. The capture is best-effort (RunAdbCommandalready 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 fromXAGCPU7000.Motivation
Seen on build 1488657 (PR #11825, unrelated change): 14 install/deploy tests failed together with
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.yamlMTP install lane). Both feed the tracking issue #11830.