androidtest

package
v1.17.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package androidtest is the harness of the device tests (SPEC §24.13): it creates the virtual devices of the emulator in .android-test/ at the module root, starts one headless in a process group of its own under `timeout -k`, with its own adb server and its own HOME so that nothing of the user's ~/.android is read or written, waits for it to boot, and stops it (and the adb server) afterwards. It also installs and starts apps and reads their results.

glutter-android shot uses it too, to start an emulator when no device is given.

Flutter: no counterpart (flutter drive)

Index

Constants

View Source
const (
	// TagAndroidTestImageMissing is the tag of the error for a system image that is not
	// installed; the metadata "install" has the sdkmanager command.
	TagAndroidTestImageMissing = "AndroidTestImageMissing"
	// TagAndroidTestAVDFailed is the tag of the error for a virtual device that cannot be written.
	TagAndroidTestAVDFailed = "AndroidTestAVDFailed"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const (
	// TagAndroidTestEmulatorMissing is the tag of the error for an SDK without the emulator;
	// the metadata "install" has the sdkmanager command.
	TagAndroidTestEmulatorMissing = "AndroidTestEmulatorMissing"
	// TagAndroidTestBootFailed is the tag of the error for an emulator that did not start or
	// did not boot; the metadata "log" has the end of its output.
	TagAndroidTestBootFailed = "AndroidTestBootFailed"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const ScreenshotFile = "files/glutter-screenshot.png"

ScreenshotFile is where the self-capture of an app writes, below the app's directory.

View Source
const TagAndroidTestTimeout = "AndroidTestTimeout"

TagAndroidTestTimeout is the tag of the error for something a device test waited for that did not happen in time.

View Source
const TagAndroidTestValidationLayerMissing = "AndroidTestValidationLayerMissing"

TagAndroidTestValidationLayerMissing is the tag of the error for a device test of Vulkan that needs the validation layer for Android and does not find it; the metadata "install" says how to get it.

Variables

View Source
var AVDs = map[string]AVD{
	"glutter-37":     {Name: "glutter-37", Package: "system-images;android-37.2;google_apis_ps16k;x86_64", API: "37"},
	"glutter-37-16k": {Name: "glutter-37-16k", Package: "system-images;android-37.2;google_apis_ps16k;x86_64", API: "37"},
	"glutter-26":     {Name: "glutter-26", Package: "system-images;android-26;google_apis;x86_64", API: "26"},

	"glutter-37-audio": {Name: "glutter-37-audio", Package: "system-images;android-37.2;google_apis_ps16k;x86_64", API: "37", Audio: true},
}

AVDs are the devices the device tests use (SPEC §24.13), by name.

Deviation: SPEC §24.13 names `system-images;android-37.0;google_apis;x86_64` for glutter-37, but on the emulator 37.2.12 that image does not boot: the system server crashes in a loop with "Invalid feature flag: android.security.aapm_feature_disable_insecure_wifi_autojoin" in AdvancedProtectionService (checked on 2026-10-24). Both API 37 devices use the 16 KB image.

Flutter: no counterpart

Functions

func Describe

func Describe(err error) string

Describe is the text of an error for a failed test: its tag, route and metadata (the command and its output), which err.Error() leaves out.

func Leftovers

func Leftovers(root string) []string

Leftovers lists the processes (as "pid command") that were started with the environment of the harness for root: the emulator, qemu, the adb server and what they started. A device test checks that there are none after it stopped its emulator. Linux reads /proc.

Flutter: no counterpart

func ModuleRoot

func ModuleRoot() (string, error)

ModuleRoot is the directory of go.mod above the current directory.

func ReleaseShared

func ReleaseShared(avd string)

ReleaseShared stops the emulator of the AVD that Shared started, when its tests are done, so that fewer emulators (about 5 GB of memory each) run at once; a later Shared starts it again.

Flutter: no counterpart

func Run

func Run(m *testing.M) int

Run is for the TestMain of a package of device tests: it runs the tests, stops the emulators they started, and returns the exit code.

func TestMain(m *testing.M) { os.Exit(androidtest.Run(m)) }

Flutter: no counterpart

func StopShared

func StopShared()

StopShared stops the emulators that Shared started.

Flutter: no counterpart

func ValidationLayerDir

func ValidationLayerDir() (string, error)

ValidationLayerDir is the directory with the Khronos validation layer of Android, where the device tests of Vulkan expect it: <module root>/.android-test/vvl, with x86_64/libVkLayer_khronos_validation.so in it (the android-binaries zip of a Vulkan-ValidationLayers release, unzipped there; SPEC §24.13). It fails with AndroidTestValidationLayerMissing, with that instruction, when the library is not there.

Flutter: no counterpart

Types

type AVD

type AVD struct {
	// Name is the name of the device, such as "glutter-37".
	Name string
	// Package is the sdkmanager package of its system image, such as
	// "system-images;android-37.2;google_apis_ps16k;x86_64".
	Package string
	// API is the Android API level of the image, such as "37".
	API string
	// Audio gives the device an audio output and input. The emulator runs with -no-audio, so the sound goes nowhere (the guest has the
	// hardware and the host side is a null device); the other devices have no audio hardware, which keeps their boot as it was.
	Audio bool
}

AVD describes a virtual device the harness makes.

Flutter: no counterpart

type Emulator

type Emulator struct {
	// Serial is the emulator's adb serial, "emulator-5584".
	Serial string
	// AVD is the virtual device it runs.
	AVD AVD
	// Root is the directory of the harness's files.
	Root string
	// ADB runs adb for this emulator, on its private server.
	ADB androidtool.ADB
	// SDK is the SDK the emulator came from.
	SDK *androidtool.SDK
	// contains filtered or unexported fields
}

Emulator is a running emulator with its own adb server.

Flutter: no counterpart

func Shared

func Shared(t testing.TB, avd string) *Emulator

Shared returns the emulator of a virtual device for a device test, starting it the first time a test of the package asks: booting takes tens of seconds, so the tests of a package share one, and Run stops it when they are done. A missing emulator or image fails the test: a device test that silently skipped would prove nothing.

Flutter: no counterpart

func Start

func Start(ctx context.Context, o Options) (*Emulator, error)

Start makes the virtual device if it is not there, starts the emulator headless in a process group of its own under `timeout -k`, waits for it to boot, and returns it. The caller stops it with Stop. It fails with AndroidTestImageMissing (the system image is not installed), AndroidTestEmulatorMissing and AndroidTestBootFailed.

Flutter: no counterpart

func (*Emulator) BuildAPK

func (e *Emulator) BuildAPK(ctx context.Context, pkg, dir string, opts androidtool.BuildOptions) (apk, appID string, err error)

BuildAPK builds a package of the module for x86_64 (the emulator's ABI) into dir and returns the APK and its application ID. The debug key is the harness's own, in root/user, so that the tests never touch the developer's config directory. It is a debug build (-tags debug_mode), as the tests drive the apps through the hooks that only debug builds read (GLUTTER_DEV_*). Extra options (a permission, an app ID) go in opts.

Flutter: no counterpart

func (*Emulator) FullLog

func (e *Emulator) FullLog(ctx context.Context) (string, error)

FullLog is the whole log since Launch, every tag: crashes of the runtime and the system's lines about the app included.

func (*Emulator) HasActivity

func (e *Emulator) HasActivity(ctx context.Context, appID string) (bool, error)

HasActivity says whether the system still has an activity of the app (`dumpsys activity activities`).

func (*Emulator) Install

func (e *Emulator) Install(ctx context.Context, apk string) error

Install installs the APK over any earlier version.

func (*Emulator) Launch

func (e *Emulator) Launch(ctx context.Context, appID string, extras map[string]string) error

Launch clears the log, stops the app if it runs and starts it with the given extras (the GLUTTER_ environment of the program).

Right after the boot of an old image (API 26) the log cannot be cleared for a while, so clearing it is tried again for up to two minutes.

func (*Emulator) Log

func (e *Emulator) Log(ctx context.Context, appID string) (string, error)

Log is what the program of the app printed since Launch: the lines logcat has under the app's tag (the application ID, SPEC §24.9).

func (*Emulator) PullAppDir

func (e *Emulator) PullAppDir(ctx context.Context, appID, dir string) (map[string][]byte, error)

PullAppDir reads every file of a directory of the app's private directory (`run-as ls`, then `run-as cat` of each), keyed by name. The directory has no subdirectories.

func (*Emulator) RunAs

func (e *Emulator) RunAs(ctx context.Context, appID string, command ...string) (string, error)

RunAs runs a command as the app (`run-as`, which a debuggable app allows) and returns its output: the way to read the files an app wrote.

func (*Emulator) Screenshot

func (e *Emulator) Screenshot(ctx context.Context, appID string, extras map[string]string, timeout time.Duration) ([]byte, error)

Screenshot starts the app with GLUTTER_SCREENSHOT=1 (and the given extras), waits for it to save the frame of its first idle moment and end, and returns the PNG (proof method E, SPEC §24.13). A test that gets no file reads the app's log with Log.

func (*Emulator) Stop

func (e *Emulator) Stop()

Stop stops the emulator and the adb server: the emulator is asked to quit (`adb emu kill`), and its process group is killed if it is still there after 20 seconds. Nothing of the harness runs afterwards; Leftovers says so.

func (*Emulator) WaitExit

func (e *Emulator) WaitExit(ctx context.Context, appID string, timeout time.Duration) error

WaitExit waits until the app has no process, for at most timeout. It fails with AndroidTestTimeout when the app still runs.

func (*Emulator) WaitLog

func (e *Emulator) WaitLog(ctx context.Context, appID, want string, timeout time.Duration) (string, error)

WaitLog waits until the app's log has a line that contains want, for at most timeout, and returns the log.

func (*Emulator) WaitPid

func (e *Emulator) WaitPid(ctx context.Context, appID string, timeout time.Duration) (int, error)

WaitPid waits until the app has a process and returns its ID.

type Options

type Options struct {
	// AVD is the name of the virtual device, a key of AVDs; "glutter-37" when empty.
	AVD string
	// Root is the directory of the harness's files (virtual devices, HOME of the emulator, its
	// log); <module root>/.android-test when empty.
	Root string
	// GPU is the emulator's -gpu mode; $GLUTTER_ANDROID_GPU, else "swangle_indirect" (ANGLE over SwiftShader: no host GPU and no display needed; swiftshader_indirect crashes the emulator).
	GPU string
	// Lifetime is how long `timeout -k` lets the emulator live at most; 30 minutes by default.
	Lifetime time.Duration
	// BootTimeout is how long to wait for sys.boot_completed; 5 minutes by default.
	BootTimeout time.Duration
	// Args are more arguments for the emulator, such as "-feature", "-Vulkan".
	Args []string
}

Options say how an emulator is started.

Flutter: no counterpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL