Tags

, ,

:kats recently wrote about Valgrinding fennec in the android emulator.

In bug 777440, there is interest in running valgrind in the android emulator from an automated job — perhaps as part of a build script. I have been looking into how that would work and now have a prototype script that can start the emulator, valgrind fennec, retrieve logs, cleanup and stop the emulator.

Some lessons learned:

When running the emulator interactively, one normally configures an AVD and then starts the emulator with that AVD. To run the emulator from a script, it’s more convenient to specify arguments on the emulator command line. For bug 777440, I use a command line like this:

emulator -kernel $ANDROID_IMAGES/kernel-qemu -sysdir $ANDROID_IMAGES -data $ANDROID_IMAGES/userdata.img -sdcard $ANDROID_IMAGES/sdcard.img -memory $EMULATOR_MEMORY -gpu on -no-window -qemu -cpu 'cortex-a8'

More info on command line options at: Android Emulator and Using the Android Emulator.

Fennec needs OpenGL support, so to launch Fennec in the emulator, GPU emulation must be enabled: simply passing the “-gpu on” option does the trick. (I had some problems with this in a VM environment. The emulator GPU emulation seems to forward graphics calls to the host environment, so you also need OpenGL ES support on your host.)

Once the emulator is started, adb can be used to install applications, push files to the emulator environment, etc:

adb -e install $FENNEC_OBJDIR/dist/fennec*.apk
adb -e shell mkdir -p /mnt/sdcard/symbols/data/data/$FENNEC_PACKAGE/cache
adb -e push $FENNEC_OBJDIR/dist/lib/libxul.so /mnt/sdcard/symbols/data/data/$FENNEC_PACKAGE/cache/

The Android screen-lock / key-guard presents another minor challenge. We probably don’t want the key-guard active while testing, as it will affect Fennec’s startup. I chose to use the existing “watcher” application, which is used on the Tegras, to disable the key-guard. Watcher disables the key-guard as soon as it is started, and it is automatically started when the device is booted, so I thought I could simply install Watcher and re-start the emulator to disable the key-guard — but that did not work. It turns out that the Watcher relies on the BOOT_COMPLETED intent, and that intent is not generated in the emulator environment. Fortunately, we can send it ourselves from the host script:

adb -e shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n com.mozilla.watcher/.WatcherReceiver

Now Fennec can be started with something like:

adb -e shell am start -n org.mozilla.fennec/.App

and Fennec can be stopped with:

adb -e shell am force-stop org.mozilla.fennec
adb -e shell am kill org.mozilla.fennec

Of course, logs or other files can be retrieved with adb -e pull.

Finally,the emulator can be stopped by killing it:

kill `ps h -o pid -C emulator-arm`

There is still lots of work to do on bug 777440, but I’m hopeful these techniques give us a simple way to run automated tasks in an Android environment without the need for physical devices.

Advertisements