DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (fddffdeab170)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
#!/usr/bin/env python
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import sys
import os
sys.path.insert(0, os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0]))))

import traceback
import remotexpcshelltests
from remotexpcshelltests import RemoteXPCShellTestThread, XPCShellRemote
from mozdevice import devicemanagerADB, DMError
from mozlog import commandline

DEVICE_TEST_ROOT = '/data/local/tests'

from marionette import Marionette
from xpcshellcommandline import parser_b2g

class B2GXPCShellTestThread(RemoteXPCShellTestThread):
    # Overridden
    def launchProcess(self, cmd, stdout, stderr, env, cwd, timeout=None):
        try:
            # This returns 1 even when tests pass - hardcode returncode to 0 (bug 773703)
            outputFile = RemoteXPCShellTestThread.launchProcess(self, cmd, stdout, stderr, env, cwd, timeout=timeout)
            self.shellReturnCode = 0
        except DMError:
            self.shellReturnCode = -1
            outputFile = "xpcshelloutput"
            f = open(outputFile, "a")
            f.write("\n%s" % traceback.format_exc())
            f.close()
        return outputFile

class B2GXPCShellRemote(XPCShellRemote):
    # Overridden
    def setLD_LIBRARY_PATH(self):
        self.env['LD_LIBRARY_PATH'] = '/system/b2g'
        if not self.options.use_device_libs:
            # overwrite /system/b2g if necessary
            XPCShellRemote.setLD_LIBRARY_PATH(self)

    # Overridden
    def setupUtilities(self):
        if self.options.clean:
            # Ensure a fresh directory structure for our tests
            self.clean()
            self.device.mkDir(self.options.remoteTestRoot)

        XPCShellRemote.setupUtilities(self)

    def clean(self):
        print >>sys.stderr, "\nCleaning files from previous run.."
        self.device.removeDir(self.options.remoteTestRoot)

    # Overriden
    def setupTestDir(self):
        if self.device._useZip:
            return XPCShellRemote.setupTestDir(self)

        for root, dirs, files in os.walk(self.xpcDir):
            for filename in files:
                rel_path = os.path.relpath(os.path.join(root, filename), self.xpcDir)
                test_file = os.path.join(self.remoteScriptsDir, rel_path)
                print 'pushing %s' % test_file
                self.device.pushFile(os.path.join(root, filename), test_file, retryLimit=10)

    # Overridden
    def pushLibs(self):
        if not self.options.use_device_libs:
            count = XPCShellRemote.pushLibs(self)
            if not count:
                # couldn't find any libs, fallback to device libs
                self.env['LD_LIBRARY_PATH'] = '/system/b2g'
                self.options.use_device_libs = True

def verifyRemoteOptions(parser, options):
    if options.b2g_path is None:
        parser.error("Need to specify a --b2gpath")

    if options.geckoPath and not options.emulator:
        parser.error("You must specify --emulator if you specify --gecko-path")

    if options.logdir and not options.emulator:
        parser.error("You must specify --emulator if you specify --logdir")
    return remotexpcshelltests.verifyRemoteOptions(parser, options)

def run_remote_xpcshell(parser, options, log):
    options = verifyRemoteOptions(parser, options)

    # Create the Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        if options.no_window:
            kwargs['noWindow'] = True
        if options.geckoPath:
            kwargs['gecko_path'] = options.geckoPath
        if options.logdir:
            kwargs['logdir'] = options.logdir
        if options.busybox:
            kwargs['busybox'] = options.busybox
        if options.symbolsPath:
            kwargs['symbols_path'] = options.symbolsPath
    if options.b2g_path:
        kwargs['homedir'] = options.emu_path or options.b2g_path
    if options.address:
        host, port = options.address.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
        kwargs['baseurl'] = 'http://%s:%d/' % (host, int(port))
        if options.emulator:
            kwargs['connectToRunningEmulator'] = True
    marionette = Marionette(**kwargs)

    if options.emulator:
        dm = marionette.emulator.dm
    else:
        # Create the DeviceManager instance
        kwargs = {'adbPath': options.adb_path}
        if options.deviceIP:
            kwargs['host'] = options.deviceIP
            kwargs['port'] = options.devicePort
        kwargs['deviceRoot'] = options.remoteTestRoot
        dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    if not options.remoteTestRoot:
        options.remoteTestRoot = dm.deviceRoot
    xpcsh = B2GXPCShellRemote(dm, options, log)

    # we don't run concurrent tests on mobile
    options.sequential = True

    if options.xpcshell is None:
        options.xpcshell = "xpcshell"

    try:
        if not xpcsh.runTests(testClass=B2GXPCShellTestThread,
                              mobileArgs=xpcsh.mobileArgs,
                              **vars(options)):
            sys.exit(1)
    except:
        print "Automation Error: Exception caught while running tests"
        traceback.print_exc()
        sys.exit(1)

def main():
    parser = parser_b2g()
    options = parser.parse_args()
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})
    run_remote_xpcshell(parser, options, log)

# You usually run this like :
# python runtestsb2g.py --emulator arm --b2gpath $B2GPATH --manifest $MANIFEST [--xre-path $MOZ_HOST_BIN
#                                                                               --adbpath $ADB_PATH
#                                                                               ...]
if __name__ == '__main__':
    main()