Tags

, ,

Recent enhancements to mach test commands make it easier than ever to run tests of all sorts – mochitests, reftests, robocop, etc – against Firefox for Android.

One of the barriers to running tests on an Android device is the device itself. You can run tests on an Android phone or tablet as long as it meets certain requirements:

  • Firefox is supported on your Android version
  • the device is connected via usb
  • the device is visible to “adb devices”
  • the adb shell has sufficient privileges for the test being run: some test types require root permissions to copy files to certain locations or for other privileged operations
  • for some test types (like mochitests), the device must be able to connect back to a web server running on your computer, so your phone typically needs a wifi connection and must be on the same network as your computer.

In my experience, most Android devices work just fine: Connect a phone or tablet by usb, check that adb can see it, check that the phone is connected to wifi, and all is well. But there are several places where things can go wrong. And of course, not everyone has an Android phone available for testing. Running tests in an Android emulator resolves several of these concerns.

Now when you run a mach test command from a Firefox for Android build environment and there is no adb-visible device connected, mach will offer to start an emulator for you:

gbrown@mozpad:~/src$ ./mach robocop testLoad
No Android devices connected. Start an emulator? (Y/n) y
Fetching AVD. This may take a while...
Starting emulator running Android 4.3...

mach will search for the emulator first in the build config location, then in the Android SDK (as found by the ANDROID_SDK_ROOT environment variable), and finally in the “mach bootstrap” cache (under .mozbuild).

Once the emulator is found, mach will then download an Android image (an “AVD”, an Android Virtual Device, including kernel and system images) from Mozilla tooltool servers. The image is selected from those we use for tests on treeherder:

  • mach downloads the Android 4.2 x86 image if your build configuration is for x86 (based on TARGET_CPU); otherwise, it selects one of the arm images:
    • mach downloads the Android 2.3 arm image if your configuration supports Android SDK 9 (MOZ_ANDROID_MIN_SDK_VERSION);
    • mach downloads the Android 4.3 arm image for all other cases.

The AVD download can take a few minutes — those are big files. Don’t worry, they are cached (in your .mozbuild directory) so that subsequent runs are much faster. Once the AVD is downloaded, the emulator is launched and as soon as Android has booted, mach will start the requested tests.

You can also start the emulator directly with “mach android-emulator” and even select an image version; for example:

mach android-emulator --version 2.3

See “mach help android-emulator” for more details.

Once an emulator is started, all mach test commands will recognize that device and use it automatically.

Happy testing!

Advertisements