Example #1
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = options.profilePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if hostos in ['mac', 'darwin']:
            localAutomation.IS_MAC = True
        elif hostos in ['linux', 'linux2']:
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif hostos in ['win32', 'win64']:
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [options.xrePath,
                 localAutomation.DIST_BIN,
                 self._automation._product,
                 os.path.join('..', self._automation._product)]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"

        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
            sys.exit(1)
        # httpd-path is specified by standard makefile targets and may be specified
        # on the command line to select a particular version of httpd.js. If not
        # specified, try to select the one from xre.zip, as required in bug 882932.
        if not options.httpdPath:
            options.httpdPath = os.path.join(options.utilityPath, "components")

        options.profilePath = tempfile.mkdtemp()
        self.server = MochitestServer(localAutomation, options)
        self.server.start()

        if (options.pidFile != ""):
            f = open(options.pidFile + ".xpcshell.pid", 'w')
            f.write("%s" % self.server._process.pid)
            f.close()
        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
Example #2
0
 def __init__(self, deviceManager, appName = ''):
     self._devicemanager = deviceManager
     self._appName = appName
     self._remoteProfile = None
     # Default our product to fennec
     self._product = "fennec"
     Automation.__init__(self)
Example #3
0
def main():
  automation = Automation()
  parser = OptionParser()
  reftest = RefTest(automation)

  # we want to pass down everything from automation.__all__
  addCommonOptions(parser, 
                   defaults=dict(zip(automation.__all__, 
                            [getattr(automation, x) for x in automation.__all__])))
  automation.addCommonOptions(parser)
  parser.add_option("--appname",
                    action = "store", type = "string", dest = "app",
                    default = os.path.join(SCRIPT_DIRECTORY, automation.DEFAULT_APP),
                    help = "absolute path to application, overriding default")
  parser.add_option("--extra-profile-file",
                    action = "append", dest = "extraProfileFiles",
                    default = [],
                    help = "copy specified files/dirs to testing profile")
  parser.add_option("--timeout",              
                    action = "store", dest = "timeout", type = "int", 
                    default = 5 * 60, # 5 minutes per bug 479518
                    help = "reftest will timeout in specified number of seconds. [default %default s].")
  parser.add_option("--leak-threshold",
                    action = "store", type = "int", dest = "leakThreshold",
                    default = 0,
                    help = "fail if the number of bytes leaked through "
                           "refcounted objects (or bytes in classes with "
                           "MOZ_COUNT_CTOR and MOZ_COUNT_DTOR) is greater "
                           "than the given number")
  parser.add_option("--utility-path",
                    action = "store", type = "string", dest = "utilityPath",
                    default = automation.DIST_BIN,
                    help = "absolute path to directory containing utility "
                           "programs (xpcshell, ssltunnel, certutil)")

  options, args = parser.parse_args()
  if len(args) != 1:
    print >>sys.stderr, "No reftest.list specified."
    sys.exit(1)

  options.app = reftest.getFullPath(options.app)
  if not os.path.exists(options.app):
    print """Error: Path %(app)s doesn't exist.
Are you executing $objdir/_tests/reftest/runreftest.py?""" \
            % {"app": options.app}
    sys.exit(1)

  if options.xrePath is None:
    options.xrePath = os.path.dirname(options.app)
  else:
    # allow relative paths
    options.xrePath = reftest.getFullPath(options.xrePath)

  if options.symbolsPath:
    options.symbolsPath = reftest.getFullPath(options.symbolsPath)
  options.utilityPath = reftest.getFullPath(options.utilityPath)

  sys.exit(reftest.runTests(args[0], options))
Example #4
0
 def __init__(self, device, appName='', remoteProfile=None, remoteLog=None,
              processArgs=None):
     self.device = device
     self.appName = appName
     self.remoteProfile = remoteProfile
     self.remoteLog = remoteLog
     self.processArgs = processArgs or {}
     self.lastTestSeen = "remoteautomation.py"
     Automation.__init__(self)
Example #5
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = options.profilePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if hostos in ["mac", "darwin"]:
            localAutomation.IS_MAC = True
        elif hostos in ["linux", "linux2"]:
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif hostos in ["win32", "win64"]:
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [
            options.xrePath,
            localAutomation.DIST_BIN,
            self._automation._product,
            os.path.join("..", self._automation._product),
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if os.name == "nt":
            xpcshell += ".exe"

        if options.utilityPath:
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
            sys.exit(1)

        options.profilePath = tempfile.mkdtemp()
        self.server = MochitestServer(localAutomation, options)
        self.server.start()

        if options.pidFile != "":
            f = open(options.pidFile + ".xpcshell.pid", "w")
            f.write("%s" % self.server._process.pid)
            f.close()
        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
    def __init__(self, deviceManager, appName = '', remoteLog = None):
        self._devicemanager = deviceManager
        self._appName = appName
        self._remoteProfile = None
        self._remoteLog = remoteLog

        # Default our product to fennec
        self._product = "fennec"
        self.lastTestSeen = "remoteautomation.py"
        Automation.__init__(self)
Example #7
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if hostos == "mac" or hostos == "darwin":
            localAutomation.IS_MAC = True
        elif hostos == "linux" or hostos == "linux2":
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif hostos == "win32" or hostos == "win64":
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [
            options.xrePath,
            localAutomation.DIST_BIN,
            self.automation._product,
            os.path.join("..", self.automation._product),
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
            return 1
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if os.name == "nt":
            xpcshell += ".exe"

        if options.utilityPath:
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
            return 1

        options.serverProfilePath = tempfile.mkdtemp()
        self.server = ReftestServer(localAutomation, options, self.scriptDir)
        retVal = self.server.start()
        if retVal:
            return retVal
        retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
        if retVal:
            return retVal

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        return 0
    def __init__(self, deviceManager, appName='', remoteLog=None,
                 marionette=None):
        self._devicemanager = deviceManager
        self._appName = appName
        self._remoteProfile = None
        self._remoteLog = remoteLog
        self.marionette = marionette

        # Default our product to b2g
        self._product = "b2g"
        Automation.__init__(self)
    def __init__(self, deviceManager, appName='', remoteLog=None,
                 marionette=None, context_chrome=True):
        self._devicemanager = deviceManager
        self._appName = appName
        self._remoteProfile = None
        self._remoteLog = remoteLog
        self.marionette = marionette
        self.context_chrome = context_chrome
        self._is_emulator = False

        # Default our product to b2g
        self._product = "b2g"
        # Default log finish to mochitest standard
        self.logFinish = 'INFO SimpleTest FINISHED' 
        Automation.__init__(self)
Example #10
0
 def makeLocalAutomation(self):
     localAutomation = Automation()
     localAutomation.IS_WIN32 = False
     localAutomation.IS_LINUX = False
     localAutomation.IS_MAC = False
     localAutomation.UNIXISH = False
     hostos = sys.platform
     if (hostos == 'mac' or hostos == 'darwin'):
         localAutomation.IS_MAC = True
     elif (hostos == 'linux' or hostos == 'linux2'):
         localAutomation.IS_LINUX = True
         localAutomation.UNIXISH = True
     elif (hostos == 'win32' or hostos == 'win64'):
         localAutomation.BIN_SUFFIX = ".exe"
         localAutomation.IS_WIN32 = True
     return localAutomation
    def checkForCrashes(self, directory, symbolsPath):
        self.checkForANRs()

        logcat = self._devicemanager.getLogcat(filterOutRegexps=fennecLogcatFilters)
        javaException = mozcrash.check_for_java_exception(logcat)
        if javaException:
            return True

        # If crash reporting is disabled (MOZ_CRASHREPORTER!=1), we can't say
        # anything.
        if not self.CRASHREPORTER:
            return False

        try:
            dumpDir = tempfile.mkdtemp()
            remoteCrashDir = self._remoteProfile + '/minidumps/'
            if not self._devicemanager.dirExists(remoteCrashDir):
                # If crash reporting is enabled (MOZ_CRASHREPORTER=1), the
                # minidumps directory is automatically created when Fennec
                # (first) starts, so its lack of presence is a hint that
                # something went wrong.
                print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
                # Whilst no crash was found, the run should still display as a failure
                return True
            self._devicemanager.getDirectory(remoteCrashDir, dumpDir)
            crashed = Automation.checkForCrashes(self, dumpDir, symbolsPath)

        finally:
            try:
                shutil.rmtree(dumpDir)
            except:
                print "WARNING: unable to remove directory: %s" % dumpDir
        return crashed
Example #12
0
 def makeLocalAutomation(self):
     localAutomation = Automation()
     localAutomation.IS_WIN32 = False
     localAutomation.IS_LINUX = False
     localAutomation.IS_MAC = False
     localAutomation.UNIXISH = False
     hostos = sys.platform
     if hostos == "mac" or hostos == "darwin":
         localAutomation.IS_MAC = True
     elif hostos == "linux" or hostos == "linux2":
         localAutomation.IS_LINUX = True
         localAutomation.UNIXISH = True
     elif hostos == "win32" or hostos == "win64":
         localAutomation.BIN_SUFFIX = ".exe"
         localAutomation.IS_WIN32 = True
     return localAutomation
Example #13
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = options.profilePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if (hostos == 'mac' or  hostos == 'darwin'):
          localAutomation.IS_MAC = True
        elif (hostos == 'linux' or hostos == 'linux2'):
          localAutomation.IS_LINUX = True
          localAutomation.UNIXISH = True
        elif (hostos == 'win32' or hostos == 'win64'):
          localAutomation.BIN_SUFFIX = ".exe"
          localAutomation.IS_WIN32 = True

        paths = [options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product)]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"
      
        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
            sys.exit(1)

        options.profilePath = tempfile.mkdtemp()
        self.server = MochitestServer(localAutomation, options)
        self.server.start()

        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
        # if remote profile is specified, use that instead
        if (self._remoteProfile):
            profileDir = self._remoteProfile

        cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)

        return app, args
Example #15
0
    def __init__(self, deviceManager, appName='', remoteLog=None,
                 marionette=None):
        self._devicemanager = deviceManager
        self._appName = appName
        self._remoteProfile = None
        self._remoteLog = remoteLog
        self.marionette = marionette
        self._is_emulator = False
        self.test_script = None
        self.test_script_args = None

        # Default our product to b2g
        self._product = "b2g"
        self.lastTestSeen = "b2gautomation.py"
        # Default log finish to mochitest standard
        self.logFinish = 'INFO SimpleTest FINISHED'
        Automation.__init__(self)
Example #16
0
def main():
    automation = Automation()
    mochitest = Mochitest(automation)
    parser = MochitestOptions(automation, mochitest.SCRIPT_DIRECTORY)
    options, args = parser.parse_args()

    options = parser.verifyOptions(options, mochitest)
    if options == None:
        sys.exit(1)

    options.utilityPath = mochitest.getFullPath(options.utilityPath)
    options.certPath = mochitest.getFullPath(options.certPath)
    if options.symbolsPath and not isURL(options.symbolsPath):
        options.symbolsPath = mochitest.getFullPath(options.symbolsPath)

    automation.setServerInfo(options.webServer, options.httpPort, options.sslPort, options.webSocketPort)
    sys.exit(mochitest.runTests(options))
 def initializeProfile(self,  profileDir, extraPrefs=[],
                       useServerLocations=False,
                       initialProfile=None):
     # add b2g specific prefs
     extraPrefs.extend(["browser.manifestURL='dummy (bug 772307)'"])
     return Automation.initializeProfile(self, profileDir,
                                         extraPrefs,
                                         useServerLocations,
                                         initialProfile)
Example #18
0
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL,
                         extraArgs):
        # if remote profile is specified, use that instead
        if (self._remoteProfile):
            profileDir = self._remoteProfile

        cmd, args = Automation.buildCommandLine(self, app, debuggerInfo,
                                                profileDir, testURL, extraArgs)

        return app, args
Example #19
0
    def __init__(self,
                 deviceManager,
                 appName='',
                 remoteLog=None,
                 marionette=None):
        self._devicemanager = deviceManager
        self._appName = appName
        self._remoteProfile = None
        self._remoteLog = remoteLog
        self.marionette = marionette
        self._is_emulator = False
        self.test_script = None
        self.test_script_args = None

        # Default our product to b2g
        self._product = "b2g"
        self.lastTestSeen = "b2gautomation.py"
        # Default log finish to mochitest standard
        self.logFinish = 'INFO SimpleTest FINISHED'
        Automation.__init__(self)
Example #20
0
    def __init__(self, automation=None):
        super(Mochitest, self).__init__()
        self.automation = automation or Automation()

        # Max time in seconds to wait for server startup before tests will fail -- if
        # this seems big, it's mostly for debug machines where cold startup
        # (particularly after a build) takes forever.
        if self.automation.IS_DEBUG_BUILD:
            self.SERVER_STARTUP_TIMEOUT = 180
        else:
            self.SERVER_STARTUP_TIMEOUT = 90
Example #21
0
def main():
  automation = Automation()
  mochitest = Mochitest(automation)
  parser = MochitestOptions(automation, mochitest.SCRIPT_DIRECTORY)
  options, args = parser.parse_args()

  options = parser.verifyOptions(options, mochitest)
  if options == None:
    sys.exit(1)

  options.utilityPath = mochitest.getFullPath(options.utilityPath)
  options.certPath = mochitest.getFullPath(options.certPath)
  if options.symbolsPath and not isURL(options.symbolsPath):
    options.symbolsPath = mochitest.getFullPath(options.symbolsPath)

  automation.setServerInfo(options.webServer, 
                           options.httpPort, 
                           options.sslPort, 
                           options.webSocketPort)
  sys.exit(mochitest.runTests(options))
Example #22
0
    def __init__(self, automation, **kwargs):
        self._automation = automation or Automation()
        MochitestOptions.__init__(self)

        for option in self.remote_options:
            self.add_argument(*option[0], **option[1])

        defaults = {}
        defaults["logFile"] = "mochitest.log"
        defaults["autorun"] = True
        defaults["closeWhenDone"] = True
        defaults["utilityPath"] = None
        self.set_defaults(**defaults)
Example #23
0
    def checkForCrashes(self, directory, symbolsPath):
        self.checkForANRs()
        self.checkForTombstones()

        try:
            logcat = self._devicemanager.getLogcat(
                filterOutRegexps=fennecLogcatFilters)
        except DMError:
            print "getLogcat threw DMError; re-trying just once..."
            time.sleep(1)
            logcat = self._devicemanager.getLogcat(
                filterOutRegexps=fennecLogcatFilters)

        javaException = mozcrash.check_for_java_exception(logcat)
        if javaException:
            return True

        # If crash reporting is disabled (MOZ_CRASHREPORTER!=1), we can't say
        # anything.
        if not self.CRASHREPORTER:
            return False

        try:
            dumpDir = tempfile.mkdtemp()
            remoteCrashDir = self._remoteProfile + '/minidumps/'
            if not self._devicemanager.dirExists(remoteCrashDir):
                # If crash reporting is enabled (MOZ_CRASHREPORTER=1), the
                # minidumps directory is automatically created when Fennec
                # (first) starts, so its lack of presence is a hint that
                # something went wrong.
                print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
                # Whilst no crash was found, the run should still display as a failure
                return True
            self._devicemanager.getDirectory(remoteCrashDir, dumpDir)

            logger = get_default_logger()
            if logger is not None:
                crashed = mozcrash.log_crashes(logger,
                                               dumpDir,
                                               symbolsPath,
                                               test=self.lastTestSeen)
            else:
                crashed = Automation.checkForCrashes(self, dumpDir,
                                                     symbolsPath)

        finally:
            try:
                shutil.rmtree(dumpDir)
            except:
                print "WARNING: unable to remove directory: %s" % dumpDir
        return crashed
Example #24
0
 def __init__(self, parent=None):
     super(MainDialog, self).__init__(parent)
     tabWidget = QtGui.QTabWidget(self)
     system_tab = SysOption()
     self.automation_tab = Automation()
     tabWidget.addTab(self.automation_tab, self.tr("自动化下单"))
     tabWidget.addTab(system_tab, self.tr('系统设置'))
     # 网格布局
     self.mainLayout = QtGui.QGridLayout(self)
     self.mainLayout.addWidget(tabWidget)
     # 设置标题
     self.setWindowTitle(u'吾宁当当自动下单')
     # 设置500左右避免某些低分辨率电脑界面超出屏幕范围
     self.resize(1000, 500)
    def __init__(self, automation=None, **kwargs):
        self._automation = automation or Automation()
        optparse.OptionParser.__init__(self, **kwargs)
        defaults = {}

        # we want to pass down everything from self._automation.__all__
        addCommonOptions(self, defaults=dict(zip(self._automation.__all__,
                 [getattr(self._automation, x) for x in self._automation.__all__])))

        for option in self.mochitest_options:
            self.add_option(*option[0], **option[1])

        self.set_defaults(**defaults)
        self.set_usage(self.__doc__)
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
        # If remote profile is specified, use that instead
        if (self._remoteProfile):
            profileDir = self._remoteProfile

        cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
        # Remove -foreground if it exists, if it doesn't this just returns
        try:
            args.remove('-foreground')
        except:
            pass
#TODO: figure out which platform require NO_EM_RESTART
#        return app, ['--environ:NO_EM_RESTART=1'] + args
        return app, args
Example #27
0
    def runVMCommand(self, command, expectedErrors=[], silent=False):
        """ runs a command in the VM using the vmrun.exe helper """
        commandString = ""
        for part in command:
            commandString += str(part) + " "
        if not silent:
            self.automation.log.info(
                "INFO | runtests.py | Running command: %s" % commandString)

        commonErrors = [
            "Error: Invalid user name or password for the guest OS",
            "Unable to connect to host."
        ]
        expectedErrors.extend(commonErrors)

        # VMware can't run commands until the VM has fully loaded so keep running
        # this command in a loop until it succeeds or we try 100 times.
        errorString = ""
        for i in range(100):
            process = Automation.Process(command, stdout=PIPE)
            result = process.wait()
            if result == 0:
                break

            for line in process.stdout.readlines():
                line = line.strip()
                if not line:
                    continue
                errorString = line
                break

            expected = False
            for error in expectedErrors:
                if errorString.startswith(error):
                    expected = True

            if not expected:
                self.automation.log.warning(
                    "WARNING | runtests.py | Command \"%s\" "
                    "failed with result %d, : %s" %
                    (commandString, result, errorString))
                break

            if not silent:
                self.automation.log.info(
                    "INFO | runtests.py | Running command again.")

        return (result, process.stdout.readlines())
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
        # If remote profile is specified, use that instead
        if self._remoteProfile:
            profileDir = self._remoteProfile

        # Hack for robocop, if app is "am" and extraArgs contains the rest of the stuff, lets
        # assume extraArgs is all we need
        if app == "am" and extraArgs[0] in ('instrument', 'start'):
            return app, extraArgs

        cmd, args = Automation.buildCommandLine(
            self, app, debuggerInfo, profileDir, testURL, extraArgs)
        try:
            args.remove('-foreground')
        except Exception:
            pass
        return app, args
    def test_login(self):

        # test login with improper credentials
        a = Automation(username='', password='')
        res1 = a.handle_login()
        assert not res1
        print(res1)

        # test login with proper credentials
        a = Automation(username='******', password='******')
        res2 = a.handle_login()
        assert res2
        print(res2)
Example #30
0
    def __init__(self, automation, mochitest, **kwargs):
        defaults = {}
        self._automation = automation or Automation()
        MochitestOptions.__init__(self, mochitest.SCRIPT_DIRECTORY)

        def checkPathCallback(option, opt_str, value, parser):
            path = mochitest.getFullPath(value)
            if not os.path.exists(path):
                raise OptionValueError("Path %s does not exist for %s option" %
                                       (path, opt_str))
            setattr(parser.values, option.dest, path)

        self.add_option(
            "--with-vmware-vm",
            action="callback",
            type="string",
            dest="vmx",
            callback=checkPathCallback,
            help="launches the given VM and runs mochitests inside")
        defaults["vmx"] = None

        self.add_option(
            "--with-vmrun-executable",
            action="callback",
            type="string",
            dest="vmrun",
            callback=checkPathCallback,
            help="specifies the vmrun.exe to use for VMware control")
        defaults["vmrun"] = None

        self.add_option("--shutdown-vm-when-done",
                        action="store_true",
                        dest="shutdownVM",
                        help="shuts down the VM when mochitests complete")
        defaults["shutdownVM"] = False

        self.add_option("--repeat-until-failure",
                        action="store_true",
                        dest="repeatUntilFailure",
                        help="Runs tests continuously until failure")
        defaults["repeatUntilFailure"] = False

        self.set_defaults(**defaults)
Example #31
0
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
        # If remote profile is specified, use that instead
        if (self._remoteProfile):
            profileDir = self._remoteProfile

        # Hack for robocop, if app & testURL == None and extraArgs contains the rest of the stuff, lets
        # assume extraArgs is all we need
        if app == "am" and extraArgs[0] in RemoteAutomation._specialAmCommands:
            return app, extraArgs

        cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
        # Remove -foreground if it exists, if it doesn't this just returns
        try:
            args.remove('-foreground')
        except:
            pass
#TODO: figure out which platform require NO_EM_RESTART
#        return app, ['--environ:NO_EM_RESTART=1'] + args
        return app, args
    def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
        # If remote profile is specified, use that instead
        if (self._remoteProfile):
            profileDir = self._remoteProfile

        # Hack for robocop, if app & testURL == None and extraArgs contains the rest of the stuff, lets
        # assume extraArgs is all we need
        if app == "am" and extraArgs[0] == "instrument":
            return app, extraArgs

        cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
        # Remove -foreground if it exists, if it doesn't this just returns
        try:
            args.remove('-foreground')
        except:
            pass
#TODO: figure out which platform require NO_EM_RESTART
#        return app, ['--environ:NO_EM_RESTART=1'] + args
        return app, args
Example #33
0
def main():
    automation = Automation()
    parser = ReftestOptions(automation)
    reftest = RefTest(automation)

    options, args = parser.parse_args()
    if len(args) != 1:
        print >> sys.stderr, "No reftest.list specified."
        sys.exit(1)

    options.app = reftest.getFullPath(options.app)
    if not os.path.exists(options.app):
        print """Error: Path %(app)s doesn't exist.
Are you executing $objdir/_tests/reftest/runreftest.py?""" \
                % {"app": options.app}
        sys.exit(1)

    if options.xrePath is None:
        options.xrePath = os.path.dirname(options.app)
    else:
        # allow relative paths
        options.xrePath = reftest.getFullPath(options.xrePath)

    if options.symbolsPath and not isURL(options.symbolsPath):
        options.symbolsPath = reftest.getFullPath(options.symbolsPath)
    options.utilityPath = reftest.getFullPath(options.utilityPath)

    if options.totalChunks is not None and options.thisChunk is None:
        print "thisChunk must be specified when totalChunks is specified"
        sys.exit(1)

    if options.totalChunks:
        if not 1 <= options.thisChunk <= options.totalChunks:
            print "thisChunk must be between 1 and totalChunks"
            sys.exit(1)

    if options.logFile:
        options.logFile = reftest.getFullPath(options.logFile)

    sys.exit(reftest.runTests(args[0], options))
Example #34
0
    def __init__(self, automation, options):
        if isinstance(options, optparse.Values):
            options = vars(options)
        self._automation = automation or Automation()
        self._closeWhenDone = options['closeWhenDone']
        self._utilityPath = options['utilityPath']
        self._xrePath = options['xrePath']
        self._profileDir = options['profilePath']
        self.webServer = options['webServer']
        self.httpPort = options['httpPort']
        self.shutdownURL = "http://%(server)s:%(port)s/server/shutdown" % {
            "server": self.webServer,
            "port": self.httpPort
        }
        self.testPrefix = "'webapprt_'" if options.get(
            'webapprtContent') else "undefined"

        if options.get('httpdPath'):
            self._httpdPath = options['httpdPath']
        else:
            self._httpdPath = '.'
        self._httpdPath = os.path.abspath(self._httpdPath)
Example #35
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()

        paths = [
            options.xrePath, localAutomation.DIST_BIN,
            self.automation._product,
            os.path.join('..', self.automation._product)
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (
                os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"

        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (
                os.name)
            sys.exit(1)

        options.serverProfilePath = tempfile.mkdtemp()
        self.server = ReftestServer(localAutomation, options)
        self.server.start()

        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
    def checkForCrashes(self, directory, symbolsPath):
        logcat = self._devicemanager.getLogcat(filterOutRegexps=fennecLogcatFilters)
        javaException = self.checkForJavaException(logcat)
        if javaException:
            return True
        try:
            dumpDir = tempfile.mkdtemp()
            remoteCrashDir = self._remoteProfile + '/minidumps/'
            if not self._devicemanager.dirExists(remoteCrashDir):
                # As of this writing, the minidumps directory is automatically
                # created when fennec (first) starts, so its lack of presence
                # is a hint that something went wrong.
                print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
                # Whilst no crash was found, the run should still display as a failure
                return True
            self._devicemanager.getDirectory(remoteCrashDir, dumpDir)
            crashed = Automation.checkForCrashes(self, dumpDir, symbolsPath)

        finally:
            try:
                shutil.rmtree(dumpDir)
            except:
                print "WARNING: unable to remove directory: %s" % dumpDir
        return crashed
    def run_mochitest_test(self, suite=None, test_file=None, debugger=None,
        shuffle=False, keep_open=False, rerun_failures=False, no_autorun=False,
        repeat=0, slow=False):
        """Runs a mochitest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.

        suite is the type of mochitest to run. It can be one of ('plain',
        'chrome', 'browser', 'metro', 'a11y').

        debugger is a program name or path to a binary (presumably a debugger)
        to run the test in. e.g. 'gdb'

        shuffle is whether test order should be shuffled (defaults to false).

        keep_open denotes whether to keep the browser open after tests
        complete.
        """
        # TODO Bug 794506 remove once mach integrates with virtualenv.
        build_path = os.path.join(self.topobjdir, 'build')
        if build_path not in sys.path:
            sys.path.append(build_path)

        if rerun_failures and test_file:
            print('Cannot specify both --rerun-failures and a test path.')
            return 1

        # Need to call relpath before os.chdir() below.
        test_path = ''
        if test_file:
            test_path = self._wrap_path_argument(test_file).relpath()

        tests_dir = os.path.abspath(os.path.join(self.topobjdir, '_tests'))
        mochitest_dir = os.path.join(tests_dir, 'testing', 'mochitest')

        failure_file_path = os.path.join(self.statedir, 'mochitest_failures.json')

        if rerun_failures and not os.path.exists(failure_file_path):
            print('No failure file present. Did you run mochitests before?')
            return 1

        from automation import Automation

        # runtests.py is ambiguous, so we load the file/module manually.
        if 'mochitest' not in sys.modules:
            import imp
            path = os.path.join(mochitest_dir, 'runtests.py')
            with open(path, 'r') as fh:
                imp.load_module('mochitest', fh, path,
                    ('.py', 'r', imp.PY_SOURCE))

        import mochitest

        # This is required to make other components happy. Sad, isn't it?
        os.chdir(self.topobjdir)

        automation = Automation()
        runner = mochitest.Mochitest(automation)

        opts = mochitest.MochitestOptions(automation, tests_dir)
        options, args = opts.parse_args([])

        # Need to set the suite options before verifyOptions below.
        if suite == 'plain':
            # Don't need additional options for plain.
            pass
        elif suite == 'chrome':
            options.chrome = True
        elif suite == 'browser':
            options.browserChrome = True
        elif suite == 'metro':
            options.immersiveMode = True
            options.browserChrome = True
        elif suite == 'a11y':
            options.a11y = True
        else:
            raise Exception('None or unrecognized mochitest suite type.')

        options = opts.verifyOptions(options, runner)

        if options is None:
            raise Exception('mochitest option validator failed.')

        options.autorun = not no_autorun
        options.closeWhenDone = not keep_open
        options.shuffle = shuffle
        options.consoleLevel = 'INFO'
        options.repeat = repeat
        options.runSlower = slow
        options.testingModulesDir = os.path.join(tests_dir, 'modules')
        options.extraProfileFiles.append(os.path.join(self.distdir, 'plugins'))
        options.symbolsPath = os.path.join(self.distdir, 'crashreporter-symbols')

        options.failureFile = failure_file_path

        automation.setServerInfo(options.webServer, options.httpPort,
            options.sslPort, options.webSocketPort)

        if test_path:
            test_root = runner.getTestRoot(options)
            test_root_file = mozpack.path.join(mochitest_dir, test_root, test_path)
            if not os.path.exists(test_root_file):
                print('Specified test path does not exist: %s' % test_root_file)
                print('You may need to run |mach build| to build the test files.')
                return 1

            options.testPath = test_path
            env = {'TEST_PATH': test_path}

        if rerun_failures:
            options.testManifest = failure_file_path

        if debugger:
            options.debugger = debugger

        return runner.runTests(options)
Example #38
0
#!/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/.

"""
Runs the Bloat test harness
"""

import optparse
import sys
import os
import shutil

from automation import Automation
automation = Automation()

from automationutils import checkForCrashes

class BloatRunTestOptions(optparse.OptionParser):
    """Parses Bloat runtest.py commandline options."""
    def __init__(self, **kwargs):
        optparse.OptionParser.__init__(self, **kwargs)
        defaults = {}

        self.add_option("--distdir",
                        action = "store", type = "string", dest = "distdir",
                        help = "object directory of build to run")
        defaults["distdir"] = "distdir-tb"

        self.add_option("--bin",
Example #39
0
    def __init__(self, automation=None):
        self.automation = automation or Automation()
        OptionParser.__init__(self)
        defaults = {}

        # we want to pass down everything from automation.__all__
        addCommonOptions(self,
                         defaults=dict(
                             zip(self.automation.__all__, [
                                 getattr(self.automation, x)
                                 for x in self.automation.__all__
                             ])))
        self.automation.addCommonOptions(self)
        self.add_option(
            "--appname",
            action="store",
            type="string",
            dest="app",
            default=os.path.join(SCRIPT_DIRECTORY,
                                 self.automation.DEFAULT_APP),
            help="absolute path to application, overriding default")
        self.add_option("--extra-profile-file",
                        action="append",
                        dest="extraProfileFiles",
                        default=[],
                        help="copy specified files/dirs to testing profile")
        self.add_option(
            "--timeout",
            action="store",
            dest="timeout",
            type="int",
            default=5 * 60,  # 5 minutes per bug 479518
            help=
            "reftest will timeout in specified number of seconds. [default %default s]."
        )
        self.add_option("--leak-threshold",
                        action="store",
                        type="int",
                        dest="defaultLeakThreshold",
                        default=0,
                        help="fail if the number of bytes leaked in default "
                        "processes through refcounted objects (or bytes "
                        "in classes with MOZ_COUNT_CTOR and MOZ_COUNT_DTOR) "
                        "is greater than the given number")
        self.add_option("--utility-path",
                        action="store",
                        type="string",
                        dest="utilityPath",
                        default=self.automation.DIST_BIN,
                        help="absolute path to directory containing utility "
                        "programs (xpcshell, ssltunnel, certutil)")
        defaults["utilityPath"] = self.automation.DIST_BIN

        self.add_option("--total-chunks",
                        type="int",
                        dest="totalChunks",
                        help="how many chunks to split the tests up into")
        defaults["totalChunks"] = None

        self.add_option("--this-chunk",
                        type="int",
                        dest="thisChunk",
                        help="which chunk to run between 1 and --total-chunks")
        defaults["thisChunk"] = None

        self.add_option("--log-file",
                        action="store",
                        type="string",
                        dest="logFile",
                        default=None,
                        help="file to log output to in addition to stdout")
        defaults["logFile"] = None

        self.add_option("--skip-slow-tests",
                        dest="skipSlowTests",
                        action="store_true",
                        help="skip tests marked as slow when running")
        defaults["skipSlowTests"] = False

        self.add_option(
            "--ignore-window-size",
            dest="ignoreWindowSize",
            action="store_true",
            help=
            "ignore the window size, which may cause spurious failures and passes"
        )
        defaults["ignoreWindowSize"] = False

        self.add_option(
            "--install-extension",
            action="append",
            dest="extensionsToInstall",
            help="install the specified extension in the testing profile. "
            "The extension file's name should be <id>.xpi where <id> is "
            "the extension's id as indicated in its install.rdf. "
            "An optional path can be specified too.")
        defaults["extensionsToInstall"] = []

        self.add_option("--run-tests-in-parallel",
                        action="store_true",
                        dest="runTestsInParallel",
                        help="run tests in parallel if possible")
        self.add_option("--no-run-tests-in-parallel",
                        action="store_false",
                        dest="runTestsInParallel",
                        help="do not run tests in parallel")
        defaults["runTestsInParallel"] = False

        self.add_option("--setenv",
                        action="append",
                        type="string",
                        dest="environment",
                        metavar="NAME=VALUE",
                        help="sets the given variable in the application's "
                        "environment")
        defaults["environment"] = []

        self.add_option(
            "--filter",
            action="store",
            type="string",
            dest="filter",
            help="specifies a regular expression (as could be passed to the JS "
            "RegExp constructor) to test against URLs in the reftest manifest; "
            "only test items that have a matching test URL will be run.")
        defaults["filter"] = None

        self.add_option("--shuffle",
                        action="store_true",
                        dest="shuffle",
                        help="run reftests in random order")
        defaults["shuffle"] = False

        self.add_option(
            "--focus-filter-mode",
            action="store",
            type="string",
            dest="focusFilterMode",
            help="filters tests to run by whether they require focus. "
            "Valid values are `all', `needs-focus', or `non-needs-focus'. "
            "Defaults to `all'.")
        defaults["focusFilterMode"] = "all"

        self.add_option("--e10s",
                        action="store_true",
                        dest="e10s",
                        help="enables content processes")
        defaults["e10s"] = False

        self.set_defaults(**defaults)
Example #40
0
 def __init__(self, automation=None):
     self.automation = automation or Automation()
Example #41
0
SCRIPT_DIR = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
sys.path.insert(0, SCRIPT_DIR)
from automation import Automation
from automationutils import getDebuggerInfo, addCommonOptions

PORT = 8888
PROFILE_DIRECTORY = os.path.abspath(os.path.join(SCRIPT_DIR, "./pgoprofile"))
MOZ_JAR_LOG_DIR = os.path.abspath(os.path.join(os.path.join(os.getenv("OBJDIR"), "dist"), "jarlog"))
os.chdir(SCRIPT_DIR)

class EasyServer(SocketServer.TCPServer):
  allow_reuse_address = True

if __name__ == '__main__':
  from optparse import OptionParser
  automation = Automation()

  parser = OptionParser()
  addCommonOptions(parser)

  options, args = parser.parse_args()

  debuggerInfo = getDebuggerInfo(".", options.debugger, options.debuggerArgs,
          options.debuggerInteractive)

  httpd = EasyServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
  t = threading.Thread(target=httpd.serve_forever)
  t.setDaemon(True) # don't hang on exit
  t.start()
  
  automation.setServerInfo("localhost", PORT)
Example #42
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = self.remoteProfile
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if hostos in ['mac', 'darwin']:
            localAutomation.IS_MAC = True
        elif hostos in ['linux', 'linux2']:
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif hostos in ['win32', 'win64']:
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [
            options.xrePath, localAutomation.DIST_BIN,
            self.automation._product,
            os.path.join('..', self.automation._product)
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (
                os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"

        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (
                os.name)
            sys.exit(1)

        xpcshell = os.path.join(options.utilityPath, xpcshell)
        if self.automation.elf_arm(xpcshell):
            raise Exception('xpcshell at %s is an ARM binary; please use '
                            'the --utility-path argument to specify the path '
                            'to a desktop version.' % xpcshell)

        options.serverProfilePath = tempfile.mkdtemp()
        self.server = ReftestServer(localAutomation, options, self.scriptDir)
        retVal = self.server.start()
        if retVal:
            return retVal

        if (options.pidFile != ""):
            f = open(options.pidFile + ".xpcshell.pid", 'w')
            f.write("%s" % self.server._process.pid)
            f.close()

        retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
        if retVal:
            return retVal

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
        return 0
Example #43
0
 def makeLocalAutomation(self):
     localAutomation = Automation()
     localAutomation.IS_WIN32 = False
     localAutomation.IS_LINUX = False
     localAutomation.IS_MAC = False
     localAutomation.UNIXISH = False
     hostos = sys.platform
     if (hostos == 'mac' or hostos == 'darwin'):
         localAutomation.IS_MAC = True
     elif (hostos == 'linux' or hostos == 'linux2'):
         localAutomation.IS_LINUX = True
         localAutomation.UNIXISH = True
     elif (hostos == 'win32' or hostos == 'win64'):
         localAutomation.BIN_SUFFIX = ".exe"
         localAutomation.IS_WIN32 = True
     return localAutomation
Example #44
0
 def installExtension(self, extensionSource, profileDir, extensionID=None):
     # Bug 827504 - installing special-powers extension separately causes problems in B2G
     if extensionID != "*****@*****.**":
         Automation.installExtension(self, extensionSource, profileDir, extensionID)
Example #45
0
from github import Github
from automation import Automation

github = Github('rbalves')
projects = github.get_formatted_repositories()

automation = Automation()
automation.add_projects(projects)
Example #46
0
import jsbridge
import mozmill
import socket
import copy

# Python 2.6 has the json module, but Python 2.5 doesn't.
try:
    import json
except ImportError:
    import simplejson as json

SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
sys.path.append(SCRIPT_DIRECTORY)

from automation import Automation
automation = Automation()

# --------------------------------------------------------------
# TODO: this is a hack for mozbase without virtualenv, remove with bug 849900
#
here = os.path.dirname(__file__)
mozbase = os.path.realpath(os.path.join(os.path.dirname(here), 'mozbase'))

try:
    import mozcrash
except:
    deps = ['mozcrash',
            'mozlog']
    for dep in deps:
        module = os.path.join(mozbase, dep)
        if module not in sys.path:
Example #47
0
def runBrowser():
    parser = OptionParser()
    # we want to pass down everything from automation.__all__
    parser.add_option("--valgrind",
                      action="store_true", dest="valgrind",
                      default=False,
                      help="use valgrind with the options given in --vgargs")
    parser.add_option("--vgargs",
                      action="store", dest="vgargs",
                      default=None,
                      help="space-separated arguments to give to valgrind")
    parser.add_option("--symbols-dir",
                      action="store", dest="symbolsDir",
                      default=None)
    parser.add_option("--leak-log-file",
                      action="store", dest="leakLogFile",
                      default=None)
    parser.add_option("--background",
                      action="store_true", dest="background",
                      default=False)
    options, args = parser.parse_args(sys.argv)

    reftestScriptDir = args[1]
    utilityDir = args[2]
    profileDir = args[3]
    url = args[4]

    sys.path.append(reftestScriptDir)
    sys.path.append(os.path.join(reftestScriptDir, "..", "mozbase", "mozinfo"))
    sys.path.append(os.path.join(reftestScriptDir, "..", "mozbase", "mozfile"))
    try:
        from automation import Automation
    except ImportError:
        # The first time running from a local objdir, I get "ImportError: No module named mozcrash".
        # The correct fix is to use virtualenv: https://bugzilla.mozilla.org/show_bug.cgi?id=903616#c12
        # For now, just try again.
        from automation import Automation

    automation = Automation()

    theapp = os.path.join(reftestScriptDir, automation.DEFAULT_APP)
    if not os.path.exists(theapp):
        print "RUNBROWSER ERROR | runbrowser.py | Application %s doesn't exist." % theapp
        sys.exit(1)
    print "theapp: " + theapp

    xrePath = os.path.dirname(theapp)

    if options.valgrind:
        raise Exception("runbrowser isn't working with Valgrind at the moment.")
        #print "About to use valgrind"
        #debuggerInfoVG = automationutils.getDebuggerInfo(oldcwd, "valgrind", "", False)
        #debuggerInfoVG["args"] = options.vgargs.split(" ")
        #if automation.IS_MAC:
        #    debuggerInfoVG["args"].append("--dsymutil=yes")
        #slowness = 3.0
    else:
        debuggerInfoVG = None
        slowness = 1.0

    # browser environment
    browserEnv = automation.environment(xrePath=xrePath)
    gatherAssertionStacks = not automation.IS_WIN32  # bug 573306
    browserEnv["XPCOM_DEBUG_BREAK"] = "stack" if gatherAssertionStacks else "warn"
    browserEnv["MOZ_GDB_SLEEP"] = "2"  # seconds
    if not options.valgrind and "-asan" not in theapp:
        browserEnv["MallocScribble"] = "1"
        browserEnv["MallocPreScribble"] = "1"
    if options.valgrind and automation.IS_LINUX:
        browserEnv["G_SLICE"] = "always-malloc"
    if automation.IS_DEBUG_BUILD and not options.valgrind and options.leakLogFile:
        browserEnv["XPCOM_MEM_LEAK_LOG"] = options.leakLogFile
    browserEnv["MOZ_DISABLE_SAFE_MODE_KEY"] = "1"

    # Defeat Lion's misguided attempt to stop Firefox from crashing repeatedly.
    # (I suspect "restorecount.txt" is the most important file to remove.)
    removeDirIfExists(os.path.expanduser("~/Library/Saved Application State/org.mozilla.nightly.savedState"))
    removeDirIfExists(os.path.expanduser("~/Library/Saved Application State/org.mozilla.nightlydebug.savedState"))

    cmdLineArgs = []
    if "#fuzz=" in url:
        cmdLineArgs.append("-fuzzinject")
    cmdLineArgs.append(url)

    print "RUNBROWSER INFO | runbrowser.py | runApp: start."
    print "RUNBROWSER INFO | runbrowser.py | " + url

    if options.background:
        automation.buildCommandLine = stripForegroundArg(automation.buildCommandLine)

    status = automation.runApp(None, browserEnv, theapp, profileDir, cmdLineArgs,
                               utilityPath=utilityDir,
                               xrePath=xrePath,
                               symbolsPath=options.symbolsDir,
                               debuggerInfo=debuggerInfoVG,
                               maxTime=400.0 * slowness,
                               timeout=200.0 * slowness)
    print "RUNBROWSER INFO | runbrowser.py | runApp: exited with status " + str(status)
Example #48
0
if __name__ == '__main__':
    logger.remove()
    my_format = ("<level>{level: <8}</level> |"
                 "<cyan>{name}</cyan>:<cyan>{function}</cyan>:"
                 "<cyan>{line}</cyan> - <level>{message}</level>")

    logger.add(sys.stdout, colorize=True, format=my_format, level='DEBUG')

    try:
        input_file = open(sys.argv[1], 'r')
    except OSError:
        logger.exception("Can't open input json file")
        sys.exit(1)

    try:
        fa = json.load(input_file, object_hook=lambda d: Automation(**d))
    except json.JSONDecodeError:
        logger.exception("Input json parsing error")
        sys.exit(1)

    try:
        dfa = minimize(determinate(fa))
    except Exception:
        logger.exception("There was an error during automate processing")
        sys.exit(1)

    try:
        output_file = open(sys.argv[2], 'w')
    except OSError:
        logger.exception("Can't open output json file")
        sys.exit(1)
    def run_desktop_test(self, suite=None, test_file=None, debugger=None,
        debugger_args=None, shuffle=False, keep_open=False, rerun_failures=False,
        no_autorun=False, repeat=0, run_until_failure=False, slow=False):
        """Runs a mochitest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.

        suite is the type of mochitest to run. It can be one of ('plain',
        'chrome', 'browser', 'metro', 'a11y').

        debugger is a program name or path to a binary (presumably a debugger)
        to run the test in. e.g. 'gdb'

        debugger_args are the arguments passed to the debugger.

        shuffle is whether test order should be shuffled (defaults to false).

        keep_open denotes whether to keep the browser open after tests
        complete.
        """
        if rerun_failures and test_file:
            print('Cannot specify both --rerun-failures and a test path.')
            return 1

        # Need to call relpath before os.chdir() below.
        test_path = ''
        if test_file:
            test_path = self._wrap_path_argument(test_file).relpath()

        failure_file_path = os.path.join(self.statedir, 'mochitest_failures.json')

        if rerun_failures and not os.path.exists(failure_file_path):
            print('No failure file present. Did you run mochitests before?')
            return 1

        from StringIO import StringIO
        from automation import Automation

        # runtests.py is ambiguous, so we load the file/module manually.
        if 'mochitest' not in sys.modules:
            import imp
            path = os.path.join(self.mochitest_dir, 'runtests.py')
            with open(path, 'r') as fh:
                imp.load_module('mochitest', fh, path,
                    ('.py', 'r', imp.PY_SOURCE))

        import mochitest

        # This is required to make other components happy. Sad, isn't it?
        os.chdir(self.topobjdir)

        automation = Automation()

        # Automation installs its own stream handler to stdout. Since we want
        # all logging to go through us, we just remove their handler.
        remove_handlers = [l for l in logging.getLogger().handlers
            if isinstance(l, logging.StreamHandler)]
        for handler in remove_handlers:
            logging.getLogger().removeHandler(handler)

        runner = mochitest.Mochitest(automation)

        opts = mochitest.MochitestOptions(automation)
        options, args = opts.parse_args([])

        appname = ''
        if sys.platform.startswith('darwin'):
            appname = os.path.join(self.distdir, self.substs['MOZ_MACBUNDLE_NAME'],
            'Contents', 'MacOS', 'webapprt-stub' + automation.BIN_SUFFIX)
        else:
            appname = os.path.join(self.distdir, 'bin', 'webapprt-stub' +
            automation.BIN_SUFFIX)

        # Need to set the suite options before verifyOptions below.
        if suite == 'plain':
            # Don't need additional options for plain.
            pass
        elif suite == 'chrome':
            options.chrome = True
        elif suite == 'browser':
            options.browserChrome = True
        elif suite == 'metro':
            options.immersiveMode = True
            options.browserChrome = True
        elif suite == 'a11y':
            options.a11y = True
        elif suite == 'webapprt-content':
            options.webapprtContent = True
            options.app = appname
        elif suite == 'webapprt-chrome':
            options.webapprtChrome = True
            options.app = appname
            options.browserArgs.append("-test-mode")
        else:
            raise Exception('None or unrecognized mochitest suite type.')

        options.autorun = not no_autorun
        options.closeWhenDone = not keep_open
        options.shuffle = shuffle
        options.consoleLevel = 'INFO'
        options.repeat = repeat
        options.runUntilFailure = run_until_failure
        options.runSlower = slow
        options.testingModulesDir = os.path.join(self.tests_dir, 'modules')
        options.extraProfileFiles.append(os.path.join(self.distdir, 'plugins'))
        options.symbolsPath = os.path.join(self.distdir, 'crashreporter-symbols')

        options.failureFile = failure_file_path

        if test_path:
            test_root = runner.getTestRoot(options)
            test_root_file = mozpack.path.join(self.mochitest_dir, test_root, test_path)
            if not os.path.exists(test_root_file):
                print('Specified test path does not exist: %s' % test_root_file)
                print('You may need to run |mach build| to build the test files.')
                return 1

            options.testPath = test_path

        if rerun_failures:
            options.testManifest = failure_file_path

        if debugger:
            options.debugger = debugger

        if debugger_args:
            if options.debugger == None:
                print("--debugger-args passed, but no debugger specified.")
                return 1
            options.debuggerArgs = debugger_args

        options = opts.verifyOptions(options, runner)

        if options is None:
            raise Exception('mochitest option validator failed.')

        automation.setServerInfo(options.webServer, options.httpPort,
            options.sslPort, options.webSocketPort)


        # We need this to enable colorization of output.
        self.log_manager.enable_unstructured()

        # Output processing is a little funky here. The old make targets
        # grepped the log output from TEST-UNEXPECTED-* and printed these lines
        # after test execution. Ideally the test runner would expose a Python
        # API for obtaining test results and we could just format failures
        # appropriately. Unfortunately, it doesn't yet do that. So, we capture
        # all output to a buffer then "grep" the buffer after test execution.
        # Bug 858197 tracks a Python API that would facilitate this.
        test_output = StringIO()
        handler = logging.StreamHandler(test_output)
        handler.addFilter(UnexpectedFilter())
        handler.setFormatter(StructuredHumanFormatter(0, write_times=False))
        logging.getLogger().addHandler(handler)

        result = runner.runTests(options)

        # Need to remove our buffering handler before we echo failures or else
        # it will catch them again!
        logging.getLogger().removeHandler(handler)
        self.log_manager.disable_unstructured()

        if test_output.getvalue():
            result = 1
            for line in test_output.getvalue().splitlines():
                self.log(logging.INFO, 'unexpected', {'msg': line}, '{msg}')

        return result
Example #50
0
    def run_mochitest_test(self,
                           suite=None,
                           test_file=None,
                           debugger=None,
                           shuffle=False,
                           keep_open=False,
                           rerun_failures=False,
                           no_autorun=False,
                           repeat=0,
                           slow=False):
        """Runs a mochitest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.

        suite is the type of mochitest to run. It can be one of ('plain',
        'chrome', 'browser', 'metro', 'a11y').

        debugger is a program name or path to a binary (presumably a debugger)
        to run the test in. e.g. 'gdb'

        shuffle is whether test order should be shuffled (defaults to false).

        keep_open denotes whether to keep the browser open after tests
        complete.
        """
        # TODO Bug 794506 remove once mach integrates with virtualenv.
        build_path = os.path.join(self.topobjdir, 'build')
        if build_path not in sys.path:
            sys.path.append(build_path)

        if rerun_failures and test_file:
            print('Cannot specify both --rerun-failures and a test path.')
            return 1

        # Need to call relpath before os.chdir() below.
        test_path = ''
        if test_file:
            test_path = self._wrap_path_argument(test_file).relpath()

        tests_dir = os.path.join(self.topobjdir, '_tests')
        mochitest_dir = os.path.join(tests_dir, 'testing', 'mochitest')

        failure_file_path = os.path.join(self.statedir,
                                         'mochitest_failures.json')

        if rerun_failures and not os.path.exists(failure_file_path):
            print('No failure file present. Did you run mochitests before?')
            return 1

        from StringIO import StringIO
        from automation import Automation

        # runtests.py is ambiguous, so we load the file/module manually.
        if 'mochitest' not in sys.modules:
            import imp
            path = os.path.join(mochitest_dir, 'runtests.py')
            with open(path, 'r') as fh:
                imp.load_module('mochitest', fh, path,
                                ('.py', 'r', imp.PY_SOURCE))

        import mochitest

        # This is required to make other components happy. Sad, isn't it?
        os.chdir(self.topobjdir)

        automation = Automation()

        # Automation installs its own stream handler to stdout. Since we want
        # all logging to go through us, we just remove their handler.
        remove_handlers = [
            l for l in logging.getLogger().handlers
            if isinstance(l, logging.StreamHandler)
        ]
        for handler in remove_handlers:
            logging.getLogger().removeHandler(handler)

        runner = mochitest.Mochitest(automation)

        opts = mochitest.MochitestOptions(automation, tests_dir)
        options, args = opts.parse_args([])

        # Need to set the suite options before verifyOptions below.
        if suite == 'plain':
            # Don't need additional options for plain.
            pass
        elif suite == 'chrome':
            options.chrome = True
        elif suite == 'browser':
            options.browserChrome = True
        elif suite == 'metro':
            options.immersiveMode = True
            options.browserChrome = True
        elif suite == 'a11y':
            options.a11y = True
        else:
            raise Exception('None or unrecognized mochitest suite type.')

        options = opts.verifyOptions(options, runner)

        if options is None:
            raise Exception('mochitest option validator failed.')

        options.autorun = not no_autorun
        options.closeWhenDone = not keep_open
        options.shuffle = shuffle
        options.consoleLevel = 'INFO'
        options.repeat = repeat
        options.runSlower = slow
        options.testingModulesDir = os.path.join(tests_dir, 'modules')
        options.extraProfileFiles.append(os.path.join(self.distdir, 'plugins'))
        options.symbolsPath = os.path.join(self.distdir,
                                           'crashreporter-symbols')

        options.failureFile = failure_file_path

        automation.setServerInfo(options.webServer, options.httpPort,
                                 options.sslPort, options.webSocketPort)

        if test_path:
            test_root = runner.getTestRoot(options)
            test_root_file = mozpack.path.join(mochitest_dir, test_root,
                                               test_path)
            if not os.path.exists(test_root_file):
                print('Specified test path does not exist: %s' %
                      test_root_file)
                print(
                    'You may need to run |mach build| to build the test files.'
                )
                return 1

            options.testPath = test_path
            env = {'TEST_PATH': test_path}

        if rerun_failures:
            options.testManifest = failure_file_path

        if debugger:
            options.debugger = debugger

        # We need this to enable colorization of output.
        self.log_manager.enable_unstructured()

        # Output processing is a little funky here. The old make targets
        # grepped the log output from TEST-UNEXPECTED-* and printed these lines
        # after test execution. Ideally the test runner would expose a Python
        # API for obtaining test results and we could just format failures
        # appropriately. Unfortunately, it doesn't yet do that. So, we capture
        # all output to a buffer then "grep" the buffer after test execution.
        # Bug 858197 tracks a Python API that would facilitate this.
        test_output = StringIO()
        handler = logging.StreamHandler(test_output)
        handler.addFilter(UnexpectedFilter())
        handler.setFormatter(StructuredHumanFormatter(0, write_times=False))
        logging.getLogger().addHandler(handler)

        result = runner.runTests(options)

        # Need to remove our buffering handler before we echo failures or else
        # it will catch them again!
        logging.getLogger().removeHandler(handler)
        self.log_manager.disable_unstructured()

        if test_output.getvalue():
            for line in test_output.getvalue().splitlines():
                self.log(logging.INFO, 'unexpected', {'msg': line}, '{msg}')

        return result
Example #51
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = options.profilePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if (hostos == 'mac' or  hostos == 'darwin'):
          localAutomation.IS_MAC = True
        elif (hostos == 'linux' or hostos == 'linux2'):
          localAutomation.IS_LINUX = True
          localAutomation.UNIXISH = True
        elif (hostos == 'win32' or hostos == 'win64'):
          localAutomation.BIN_SUFFIX = ".exe"
          localAutomation.IS_WIN32 = True

        paths = [options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product)]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
            sys.exit(1)
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"
      
        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
            sys.exit(1)

        xpcshell_path = os.path.join(options.utilityPath, xpcshell)
        if localAutomation.elf_arm(xpcshell_path):
            self.error('xpcshell at %s is an ARM binary; please use '
                       'the --utility-path argument to specify the path '
                       'to a desktop version.' % xpcshell)

        options.profilePath = tempfile.mkdtemp()
        self.server = MochitestServer(localAutomation, options)
        self.server.start()

        if (options.pidFile != ""):
            f = open(options.pidFile + ".xpcshell.pid", 'w')
            f.write("%s" % self.server._process.pid)
            f.close()
        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
Example #52
0
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

"""
Runs the Bloat test harness
"""

import optparse
import sys
import os
import shutil

from automation import Automation
automation = Automation()

from automationutils import checkForCrashes

class BloatRunTestOptions(optparse.OptionParser):
    """Parses Bloat runtest.py commandline options."""
    def __init__(self, **kwargs):
        optparse.OptionParser.__init__(self, **kwargs)
        defaults = {}

        self.add_option("--distdir",
                        action = "store", type = "string", dest = "distdir",
                        help = "object directory of build to run")
        defaults["distdir"] = "distdir-tb"

        self.add_option("--bin",
Example #53
0
    def __init__(self, automation, **kwargs):
        defaults = {}
        self._automation = automation or Automation()
        MochitestOptions.__init__(self)

        self.add_option("--remote-app-path", action="store",
                    type = "string", dest = "remoteAppPath",
                    help = "Path to remote executable relative to device root using only forward slashes. Either this or app must be specified but not both")
        defaults["remoteAppPath"] = None

        self.add_option("--deviceIP", action="store",
                    type = "string", dest = "deviceIP",
                    help = "ip address of remote device to test")
        defaults["deviceIP"] = None

        self.add_option("--dm_trans", action="store",
                    type = "string", dest = "dm_trans",
                    help = "the transport to use to communicate with device: [adb|sut]; default=sut")
        defaults["dm_trans"] = "sut"

        self.add_option("--devicePort", action="store",
                    type = "string", dest = "devicePort",
                    help = "port of remote device to test")
        defaults["devicePort"] = 20701

        self.add_option("--remote-product-name", action="store",
                    type = "string", dest = "remoteProductName",
                    help = "The executable's name of remote product to test - either fennec or firefox, defaults to fennec")
        defaults["remoteProductName"] = "fennec"

        self.add_option("--remote-logfile", action="store",
                    type = "string", dest = "remoteLogFile",
                    help = "Name of log file on the device relative to the device root.  PLEASE ONLY USE A FILENAME.")
        defaults["remoteLogFile"] = None

        self.add_option("--remote-webserver", action = "store",
                    type = "string", dest = "remoteWebServer",
                    help = "ip address where the remote web server is hosted at")
        defaults["remoteWebServer"] = None

        self.add_option("--http-port", action = "store",
                    type = "string", dest = "httpPort",
                    help = "http port of the remote web server")
        defaults["httpPort"] = automation.DEFAULT_HTTP_PORT

        self.add_option("--ssl-port", action = "store",
                    type = "string", dest = "sslPort",
                    help = "ssl port of the remote web server")
        defaults["sslPort"] = automation.DEFAULT_SSL_PORT

        self.add_option("--robocop-ini", action = "store",
                    type = "string", dest = "robocopIni",
                    help = "name of the .ini file containing the list of tests to run")
        defaults["robocopIni"] = ""

        self.add_option("--robocop", action = "store",
                    type = "string", dest = "robocop",
                    help = "name of the .ini file containing the list of tests to run. [DEPRECATED- please use --robocop-ini")
        defaults["robocop"] = ""

        self.add_option("--robocop-apk", action = "store",
                    type = "string", dest = "robocopApk",
                    help = "name of the Robocop APK to use for ADB test running")
        defaults["robocopApk"] = ""

        self.add_option("--robocop-path", action = "store",
                    type = "string", dest = "robocopPath",
                    help = "Path to the folder where robocop.apk is located at.  Primarily used for ADB test running. [DEPRECATED- please use --robocop-apk]")
        defaults["robocopPath"] = ""

        self.add_option("--robocop-ids", action = "store",
                    type = "string", dest = "robocopIds",
                    help = "name of the file containing the view ID map (fennec_ids.txt)")
        defaults["robocopIds"] = ""

        self.add_option("--remoteTestRoot", action = "store",
                    type = "string", dest = "remoteTestRoot",
                    help = "remote directory to use as test root (eg. /mnt/sdcard/tests or /data/local/tests)")
        defaults["remoteTestRoot"] = None

        defaults["logFile"] = "mochitest.log"
        defaults["autorun"] = True
        defaults["closeWhenDone"] = True
        defaults["testPath"] = ""
        defaults["app"] = None
        defaults["utilityPath"] = None

        self.set_defaults(**defaults)
def main():
    a = Automation(username='******', password='******')
    a.run_test()
Example #55
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteProfilePath = options.profilePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if hostos == "mac" or hostos == "darwin":
            localAutomation.IS_MAC = True
        elif hostos == "linux" or hostos == "linux2":
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif hostos == "win32" or hostos == "win64":
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [
            options.xrePath,
            localAutomation.DIST_BIN,
            self._automation._product,
            os.path.join("..", self._automation._product),
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            log.error("unable to find xulrunner path for %s, please specify with --xre-path", os.name)
            sys.exit(1)

        xpcshell = "xpcshell"
        if os.name == "nt":
            xpcshell += ".exe"

        if options.utilityPath:
            paths = [options.utilityPath, options.xrePath]
        else:
            paths = [options.xrePath]
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            log.error("unable to find utility path for %s, please specify with --utility-path", os.name)
            sys.exit(1)
        # httpd-path is specified by standard makefile targets and may be specified
        # on the command line to select a particular version of httpd.js. If not
        # specified, try to select the one from hostutils.zip, as required in bug 882932.
        if not options.httpdPath:
            options.httpdPath = os.path.join(options.utilityPath, "components")

        xpcshell_path = os.path.join(options.utilityPath, xpcshell)
        if localAutomation.elf_arm(xpcshell_path):
            log.error(
                "xpcshell at %s is an ARM binary; please use "
                "the --utility-path argument to specify the path "
                "to a desktop version." % xpcshell_path
            )
            sys.exit(1)

        options.profilePath = tempfile.mkdtemp()
        self.server = MochitestServer(options)
        self.server.start()

        if options.pidFile != "":
            f = open(options.pidFile + ".xpcshell.pid", "w")
            f.write("%s" % self.server._process.pid)
            f.close()
        self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        options.profilePath = remoteProfilePath
Example #56
0
    def startWebServer(self, options):
        """ Create the webserver on the host and start it up """
        remoteXrePath = options.xrePath
        remoteUtilityPath = options.utilityPath
        localAutomation = Automation()
        localAutomation.IS_WIN32 = False
        localAutomation.IS_LINUX = False
        localAutomation.IS_MAC = False
        localAutomation.UNIXISH = False
        hostos = sys.platform
        if (hostos == 'mac' or hostos == 'darwin'):
            localAutomation.IS_MAC = True
        elif (hostos == 'linux' or hostos == 'linux2'):
            localAutomation.IS_LINUX = True
            localAutomation.UNIXISH = True
        elif (hostos == 'win32' or hostos == 'win64'):
            localAutomation.BIN_SUFFIX = ".exe"
            localAutomation.IS_WIN32 = True

        paths = [
            options.xrePath, localAutomation.DIST_BIN,
            self.automation._product,
            os.path.join('..', self.automation._product)
        ]
        options.xrePath = self.findPath(paths)
        if options.xrePath == None:
            print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (
                os.name)
            return 1
        paths.append("bin")
        paths.append(os.path.join("..", "bin"))

        xpcshell = "xpcshell"
        if (os.name == "nt"):
            xpcshell += ".exe"

        if (options.utilityPath):
            paths.insert(0, options.utilityPath)
        options.utilityPath = self.findPath(paths, xpcshell)
        if options.utilityPath == None:
            print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (
                os.name)
            return 1

        options.serverProfilePath = tempfile.mkdtemp()
        self.server = ReftestServer(localAutomation, options, self.scriptDir)
        retVal = self.server.start()
        if retVal:
            return retVal
        retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
        if retVal:
            return retVal

        options.xrePath = remoteXrePath
        options.utilityPath = remoteUtilityPath
        return 0
def runBrowser():
    parser = OptionParser()
    # we want to pass down everything from automation.__all__
    parser.add_option("--valgrind",
                      action="store_true",
                      dest="valgrind",
                      default=False,
                      help="use valgrind with the options given in --vgargs")
    parser.add_option("--vgargs",
                      action="store",
                      dest="vgargs",
                      default=None,
                      help="space-separated arguments to give to valgrind")
    parser.add_option("--symbols-dir",
                      action="store",
                      dest="symbolsDir",
                      default=None)
    parser.add_option("--leak-log-file",
                      action="store",
                      dest="leakLogFile",
                      default=None)
    parser.add_option("--background",
                      action="store_true",
                      dest="background",
                      default=False)
    options, args = parser.parse_args(sys.argv)

    reftestScriptDir = args[1]
    utilityDir = args[2]
    profileDir = args[3]
    url = args[4]

    sys.path.append(reftestScriptDir)
    sys.path.append(os.path.join(reftestScriptDir, "..", "mozbase", "mozinfo"))
    sys.path.append(os.path.join(reftestScriptDir, "..", "mozbase", "mozfile"))
    try:
        from automation import Automation
    except ImportError:
        # The first time running from a local objdir, I get "ImportError: No module named mozcrash".
        # The correct fix is to use virtualenv: https://bugzilla.mozilla.org/show_bug.cgi?id=903616#c12
        # For now, just try again.
        from automation import Automation

    automation = Automation()

    theapp = os.path.join(reftestScriptDir, automation.DEFAULT_APP)
    if not os.path.exists(theapp):
        print "RUNBROWSER ERROR | runbrowser.py | Application %s doesn't exist." % theapp
        sys.exit(1)
    print "theapp: " + theapp

    xrePath = os.path.dirname(theapp)

    if options.valgrind:
        raise Exception(
            "runbrowser isn't working with Valgrind at the moment.")
        #print "About to use valgrind"
        #debuggerInfoVG = automationutils.getDebuggerInfo(oldcwd, "valgrind", "", False)
        #debuggerInfoVG["args"] = options.vgargs.split(" ")
        #if automation.IS_MAC:
        #    debuggerInfoVG["args"].append("--dsymutil=yes")
        #slowness = 3.0
    else:
        debuggerInfoVG = None
        slowness = 1.0

    # browser environment
    browserEnv = automation.environment(xrePath=xrePath)
    gatherAssertionStacks = False  # windows output entangling (bug 573306); mac symbolizing slowness and output bloat
    if gatherAssertionStacks:
        browserEnv["XPCOM_DEBUG_BREAK"] = "stack"
    browserEnv["MOZ_GDB_SLEEP"] = "2"  # seconds
    if not options.valgrind and "-asan" not in theapp:
        browserEnv["MallocScribble"] = "1"
        browserEnv["MallocPreScribble"] = "1"
    if options.valgrind and automation.IS_LINUX:
        browserEnv["G_SLICE"] = "always-malloc"
    if automation.IS_DEBUG_BUILD and not options.valgrind and options.leakLogFile:
        browserEnv["XPCOM_MEM_LEAK_LOG"] = options.leakLogFile
    browserEnv["MOZ_DISABLE_SAFE_MODE_KEY"] = "1"

    # Defeat Lion's misguided attempt to stop Firefox from crashing repeatedly.
    # (I suspect "restorecount.txt" is the most important file to remove.)
    removeDirIfExists(
        os.path.expanduser(
            "~/Library/Saved Application State/org.mozilla.nightly.savedState")
    )
    removeDirIfExists(
        os.path.expanduser(
            "~/Library/Saved Application State/org.mozilla.nightlydebug.savedState"
        ))

    cmdLineArgs = []
    if "#fuzz=" in url:
        cmdLineArgs.append("-fuzzinject")
    cmdLineArgs.append(url)

    print "RUNBROWSER INFO | runbrowser.py | runApp: start."
    print "RUNBROWSER INFO | runbrowser.py | " + url

    if options.background:
        automation.buildCommandLine = stripForegroundArg(
            automation.buildCommandLine)

    status = automation.runApp(None,
                               browserEnv,
                               theapp,
                               profileDir,
                               cmdLineArgs,
                               utilityPath=utilityDir,
                               xrePath=xrePath,
                               symbolsPath=options.symbolsDir,
                               debuggerInfo=debuggerInfoVG,
                               maxTime=400.0 * slowness,
                               timeout=200.0 * slowness)
    print "RUNBROWSER INFO | runbrowser.py | runApp: exited with status " + str(
        status)