Reference tests (or reftests) are basically tests that compare two separate renderings of web app UI features (HTML elements, for example) to see if they are the same, or not. This article provides you with all you need to know to run Mozilla's suite of reftests on B2G. To find out more about reftests themselves, read Creating reftest-based unit tests.

Prerequisites for running reftests

You can run reftests on B2G. These are mainly tested on the emulator, but should in theory run on devices as well. In this article $B2G_HOME refers to the cloned B2G repository. Below are the things you need to build or set up before you can try running B2G reftests.

If you get this stacktrace while running reftests:

ImportError: cannot import name expected

File "gecko-dev/objdir-b2g-ics-emulator/_tests/reftest/runreftestb2g.py", line 16, in <module>

from b2g_desktop import run_desktop_reftest

File "Projects/gecko-dev/objdir-b2g-ics-emulator/_tests/reftest/b2g_desktop.py", line 14, in <module>

from marionette import Marionette, expected

This is a known bug from https://bugzilla.mozilla.org/show_bug.cgi?id=1114474#c7

Build B2G for the target you're testing

The B2G config that you will be using (what you pass to ./config.sh) will probably be emulator as that is what reftests are typically run on. Before building B2G for the emulator config, pay special attention to the Emulator build issues section in the Firefox OS build prerequisites page.

As usual, make sure adb is in your path and that it successfully connects to your running emulator or device. Try adb devices to make sure it is working ok.

Running reftests

Having satisfied the above prerequisites, you can then run reftests using one of the following sets of terminal commands.

For the emulator

Use mach:

cd $B2G_HOME
​./mach reftest-remote

This will run all reftests. If you want to run a specific reftest, do the following:

For a real device

Running reftests on a device is not officially supported yet. One problem is that most devices don't support the minimum required resolution (800x1000) for many of the tests. But if you want to try anyway, you should be able to do so using the following steps:

Running jsreftests

JSReftests are not officially supported yet. See bug 972870 for progress updates on adding jsreftests to mach.

Running reftest with non-default options

You can optionally add --total-chunks and --this-chunks arguments as you would with regular desktop reftests. Use:

mach help reftest-remote

for a full list of supported arguments.

Running reftest with a downloaded emulator

If you've built B2G for another config (like otoro) and want to run the tests on an emulator, you can do so without building an emulator yourself. Just download the latest trunk arm emulator and do the following:

I can't build the emulator!

Check that your B2G build/emulator works and that ADB can connect to it

First check that your B2G build runs normally. If this is an emulator build, then ./run-emulator.sh should work: it should start up the emulator and boot B2G inside it. If it doesn't, get the log from adb logcat and ask for help. If ADB fails to connect to the running emulator, make sure that you have no other (Android or B2G) devices connected, and try passing in the -e option to tell adb to focus on the emulator:

adb logcat -e

Once you have verified that your B2G build/emulator works normally and that ADB can connect to it, the next step is to verify that your xpcshell desktop executable runs normally. If you built B2G for a real device and ADB can't connect to it, check out Connecting a Firefox OS device to the desktop.

Note: None of the errors below should occur if you are using mach. If you have problems with mach, please file a bug under Testing/Reftest and CC :ahal

Check that you can run your desktop xpcshell executable

The python runreftestb2g.py command line above will try to run xpcshell on your desktop with the path specified by the --xre-path argument. Check that running xpcshell from the current directory with this relative path actually works.

For example, suppose that your command line contains:

--xre-path /hack/mozilla-central/objdir/dist/bin

Try running this from the same directory as you want to run python runreftestb2g.py from:

$ /hack/mozilla-central/objdir/dist/bin/xpcshell

This should land you in a special-looking shell like this:

js>

If this fails with an error message complaining about being unable to find or load certain shared libraries, like this

then you need to set the right environment variable so that it looks for these libraries in the same directory. On Linux, you would set LD_LIBRARY_PATH to the same directory as you want to pass as --xre-path. For example, this should work:

Check that reftest can find httpd.js

If reftest still fails to run — returning early with an error — the next most likely cause of trouble is it failing to find certain files that it needs to load. The first file that it could fail to find is httpd.js. Typically, the reason why it would not find it is that you accidentally built xpcshell with --disable-tests. So, make sure that the path you pass to --xre-path does contain a httpd.js file under the components subdirectory.

Check that you didn't forget to make package-tests

Forgetting the make package-tests step described above would certainly explain why nothing works.

Check that you passed a correct relative path to the reftest.list

The final argumant in the command line running reftest is the relative/path/from/B2G/objdir-gecko/to/reftest.list. This must be a relative path from the B2G/objdir-gecko directory to a reftest.list file under it. So check that a reftest.list file is actually present there! If it isn't, compare your command line to the sample command line below, and/or check that you didn't forget to make package-tests as explained above.