Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

XPCShell tests are headless tests of Gecko XPCOM APIs. You can run XPCShell tests on B2G; in this article we will look at how to do so. Currently, these are mainly tested on the emulator, but should in theory run on devices as well.

Note: In this article $B2G_HOME refers to the cloned B2G repository.

The easiest way to run xpcshell tests on B2G is using mach.

Prerequisites

  • You need to build B2G for the target you're testing (see: Building and installing Firefox OS). Currently only emulator builds are supported, though other devices may work.
  • Make sure adb is on your path. If you have a build, this can be found at $B2G_HOME/out/host/<platform>/bin.

Running the tests

To run the full suite of tests, build B2G and then:

cd $B2G_HOME
./mach xpcshell-test

To run a specific test, or a directory containing tests:

./mach xpcshell-test path/to/test/or/directory

If a directory is specified, it will be searched recursively for test files. To see other options:

./mach xpcshell-test --help

 

The Hard Way

If for some reason you can't or don't wish to use the mach command, you can try running the harness directly. This method is not recommended as it can be tricky to get right.

Prerequisites

  • You need to build B2G for the target you're testing (see: Building and installing Firefox OS). Currently only emulator builds are supported, though other devices may work.
  • You need to install some Python packages, either in a virtualenv or otherwise:
    cd $GECKO_DIR/testing/mozbase
    python setup_development.py
    cd $GECKO_DIR/testing/marionette/client
    python setup.py develop
    
  • Either make sure adb is on your path or specify it with --adbpath (on Linux it is found at $B2G_HOME/out/host/linux-x86/bin/adb.)
  • Have a local copy of Busybox (this isn't strictly necessary but greatly reduces the setup time required.)

Running the tests

You can then run xpcshell tests using one of the following sets of terminal commands:

If you are using an emulator:

cd $B2G_HOME/objdir-gecko
make package-tests
cd dist/test-stage/xpcshell
python runtestsb2g.py --b2gpath $B2G_HOME --adbpath $ADB_PATH --emulator arm --use-device-libs --manifest <path_to_xpcshell_manifest> --testing-modules-dir <path_to_testing_modules_dir> --busybox <path_to_busybox_binary>

If you are using a real device:

cd $B2G_HOME/objdir-gecko
make package-tests
cd dist/test-stage/xpcshell
python runtestsb2g.py --b2gpath $B2G_HOME --adbpath $ADB_PATH --use-device-libs --manifest <path_to_xpcshell_manifest> --testing-modules-dir <path_to_testing_modules_dir>

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

python runtestsb2g.py --help

for a full list of supported arguments.

Important: The manifest path you supply must be under the dist/test-stage/xpcshell directory. Don't use a path to the original source location of the manifest in the tree.

After you invoke runtestsb2g.py, the test runner will launch the emulator for you (if you're running the tests on an emulator) or reboot your device (if you're running the tests on a device), and start running the tests. Because the emulator is slow, and it is necessary to push a test profile to the emulator and restart B2G, the tests can take a few minutes to start. Before they start, you will just see a black or white screen. After they start, you should see the test log being dumped to the console.

When the tests are done, the emulator is shut down for you, or if you're using a device, the device is rebooted.

Installing busybox manually

When running xpcshell tests on devices there is no --busybox option, so setting up the test run can take a very long time. Fortunately you can still install it manually prior to running the tests. For an example of how to do this see https://github.com/mozilla/Negatus/blob/master/setup-tools.sh.

Running xpcshell tests 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 use the same instructions as above, replacing the --b2gpath $B2G_HOME argument for runreftestb2g.py with --b2gpath /path/to/unpacked/emulator.

Document Tags and Contributors

 Last updated by: chrisdavidmills,