michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import ConfigParser michael@0: import os michael@0: import sys michael@0: import tempfile michael@0: import traceback michael@0: michael@0: # We need to know our current directory so that we can serve our test files from it. michael@0: here = os.path.abspath(os.path.dirname(__file__)) michael@0: michael@0: from automation import Automation michael@0: from b2gautomation import B2GRemoteAutomation michael@0: from b2g_desktop import run_desktop_reftests michael@0: from runreftest import RefTest michael@0: from runreftest import ReftestOptions michael@0: from remotereftest import ReftestServer michael@0: michael@0: from mozdevice import DeviceManagerADB, DMError michael@0: from marionette import Marionette michael@0: import moznetwork michael@0: michael@0: class B2GOptions(ReftestOptions): michael@0: michael@0: def __init__(self, automation=None, **kwargs): michael@0: defaults = {} michael@0: if not automation: michael@0: automation = B2GRemoteAutomation(None, "fennec", context_chrome=True) michael@0: michael@0: ReftestOptions.__init__(self, automation) michael@0: michael@0: self.add_option("--browser-arg", action="store", michael@0: type = "string", dest = "browser_arg", michael@0: help = "Optional command-line arg to pass to the browser") michael@0: defaults["browser_arg"] = None michael@0: michael@0: self.add_option("--b2gpath", action="store", michael@0: type = "string", dest = "b2gPath", michael@0: help = "path to B2G repo or qemu dir") michael@0: defaults["b2gPath"] = None michael@0: michael@0: self.add_option("--marionette", action="store", michael@0: type = "string", dest = "marionette", michael@0: help = "host:port to use when connecting to Marionette") michael@0: defaults["marionette"] = None michael@0: michael@0: self.add_option("--emulator", action="store", michael@0: type="string", dest = "emulator", michael@0: help = "Architecture of emulator to use: x86 or arm") michael@0: defaults["emulator"] = None michael@0: self.add_option("--emulator-res", action="store", michael@0: type="string", dest = "emulator_res", michael@0: help = "Emulator resolution of the format 'x'") michael@0: defaults["emulator_res"] = None michael@0: michael@0: self.add_option("--no-window", action="store_true", michael@0: dest = "noWindow", michael@0: help = "Pass --no-window to the emulator") michael@0: defaults["noWindow"] = False michael@0: michael@0: self.add_option("--adbpath", action="store", michael@0: type = "string", dest = "adbPath", michael@0: help = "path to adb") michael@0: defaults["adbPath"] = "adb" michael@0: michael@0: self.add_option("--deviceIP", action="store", michael@0: type = "string", dest = "deviceIP", michael@0: help = "ip address of remote device to test") michael@0: defaults["deviceIP"] = None michael@0: michael@0: self.add_option("--devicePort", action="store", michael@0: type = "string", dest = "devicePort", michael@0: help = "port of remote device to test") michael@0: defaults["devicePort"] = 20701 michael@0: michael@0: self.add_option("--remote-logfile", action="store", michael@0: type = "string", dest = "remoteLogFile", michael@0: help = "Name of log file on the device relative to the device root. PLEASE ONLY USE A FILENAME.") michael@0: defaults["remoteLogFile"] = None michael@0: michael@0: self.add_option("--remote-webserver", action = "store", michael@0: type = "string", dest = "remoteWebServer", michael@0: help = "ip address where the remote web server is hosted at") michael@0: defaults["remoteWebServer"] = None michael@0: michael@0: self.add_option("--http-port", action = "store", michael@0: type = "string", dest = "httpPort", michael@0: help = "ip address where the remote web server is hosted at") michael@0: defaults["httpPort"] = automation.DEFAULT_HTTP_PORT michael@0: michael@0: self.add_option("--ssl-port", action = "store", michael@0: type = "string", dest = "sslPort", michael@0: help = "ip address where the remote web server is hosted at") michael@0: defaults["sslPort"] = automation.DEFAULT_SSL_PORT michael@0: michael@0: self.add_option("--pidfile", action = "store", michael@0: type = "string", dest = "pidFile", michael@0: help = "name of the pidfile to generate") michael@0: defaults["pidFile"] = "" michael@0: self.add_option("--gecko-path", action="store", michael@0: type="string", dest="geckoPath", michael@0: help="the path to a gecko distribution that should " michael@0: "be installed on the emulator prior to test") michael@0: defaults["geckoPath"] = None michael@0: self.add_option("--logcat-dir", action="store", michael@0: type="string", dest="logcat_dir", michael@0: help="directory to store logcat dump files") michael@0: defaults["logcat_dir"] = None michael@0: self.add_option('--busybox', action='store', michael@0: type='string', dest='busybox', michael@0: help="Path to busybox binary to install on device") michael@0: defaults['busybox'] = None michael@0: self.add_option("--httpd-path", action = "store", michael@0: type = "string", dest = "httpdPath", michael@0: help = "path to the httpd.js file") michael@0: defaults["httpdPath"] = None michael@0: self.add_option("--profile", action="store", michael@0: type="string", dest="profile", michael@0: help="for desktop testing, the path to the " michael@0: "gaia profile to use") michael@0: defaults["profile"] = None michael@0: self.add_option("--desktop", action="store_true", michael@0: dest="desktop", michael@0: help="Run the tests on a B2G desktop build") michael@0: defaults["desktop"] = False michael@0: defaults["remoteTestRoot"] = "/data/local/tests" michael@0: defaults["logFile"] = "reftest.log" michael@0: defaults["autorun"] = True michael@0: defaults["closeWhenDone"] = True michael@0: defaults["testPath"] = "" michael@0: defaults["runTestsInParallel"] = False michael@0: michael@0: self.set_defaults(**defaults) michael@0: michael@0: def verifyRemoteOptions(self, options): michael@0: if options.runTestsInParallel: michael@0: self.error("Cannot run parallel tests here") michael@0: michael@0: if not options.remoteTestRoot: michael@0: options.remoteTestRoot = self.automation._devicemanager.getDeviceRoot() + "/reftest" michael@0: options.remoteProfile = options.remoteTestRoot + "/profile" michael@0: michael@0: productRoot = options.remoteTestRoot + "/" + self.automation._product michael@0: if options.utilityPath == self.automation.DIST_BIN: michael@0: options.utilityPath = productRoot + "/bin" michael@0: michael@0: if options.remoteWebServer == None: michael@0: if os.name != "nt": michael@0: options.remoteWebServer = moznetwork.get_ip() michael@0: else: michael@0: print "ERROR: you must specify a --remote-webserver=\n" michael@0: return None michael@0: michael@0: options.webServer = options.remoteWebServer michael@0: michael@0: if options.geckoPath and not options.emulator: michael@0: self.error("You must specify --emulator if you specify --gecko-path") michael@0: michael@0: if options.logcat_dir and not options.emulator: michael@0: self.error("You must specify --emulator if you specify --logcat-dir") michael@0: michael@0: #if not options.emulator and not options.deviceIP: michael@0: # print "ERROR: you must provide a device IP" michael@0: # return None michael@0: michael@0: if options.remoteLogFile == None: michael@0: options.remoteLogFile = "reftest.log" michael@0: michael@0: options.localLogName = options.remoteLogFile michael@0: options.remoteLogFile = options.remoteTestRoot + '/' + options.remoteLogFile michael@0: michael@0: # Ensure that the options.logfile (which the base class uses) is set to michael@0: # the remote setting when running remote. Also, if the user set the michael@0: # log file name there, use that instead of reusing the remotelogfile as above. michael@0: if (options.logFile): michael@0: # If the user specified a local logfile name use that michael@0: options.localLogName = options.logFile michael@0: options.logFile = options.remoteLogFile michael@0: michael@0: # Only reset the xrePath if it wasn't provided michael@0: if options.xrePath == None: michael@0: options.xrePath = options.utilityPath michael@0: options.xrePath = os.path.abspath(options.xrePath) michael@0: michael@0: if options.pidFile != "": michael@0: f = open(options.pidFile, 'w') michael@0: f.write("%s" % os.getpid()) michael@0: f.close() michael@0: michael@0: # httpd-path is specified by standard makefile targets and may be specified michael@0: # on the command line to select a particular version of httpd.js. If not michael@0: # specified, try to select the one from from the xre bundle, as required in bug 882932. michael@0: if not options.httpdPath: michael@0: options.httpdPath = os.path.join(options.xrePath, "components") michael@0: michael@0: return options michael@0: michael@0: michael@0: class ProfileConfigParser(ConfigParser.RawConfigParser): michael@0: """Subclass of RawConfigParser that outputs .ini files in the exact michael@0: format expected for profiles.ini, which is slightly different michael@0: than the default format. michael@0: """ michael@0: michael@0: def optionxform(self, optionstr): michael@0: return optionstr michael@0: michael@0: def write(self, fp): michael@0: if self._defaults: michael@0: fp.write("[%s]\n" % ConfigParser.DEFAULTSECT) michael@0: for (key, value) in self._defaults.items(): michael@0: fp.write("%s=%s\n" % (key, str(value).replace('\n', '\n\t'))) michael@0: fp.write("\n") michael@0: for section in self._sections: michael@0: fp.write("[%s]\n" % section) michael@0: for (key, value) in self._sections[section].items(): michael@0: if key == "__name__": michael@0: continue michael@0: if (value is not None) or (self._optcre == self.OPTCRE): michael@0: key = "=".join((key, str(value).replace('\n', '\n\t'))) michael@0: fp.write("%s\n" % (key)) michael@0: fp.write("\n") michael@0: michael@0: class B2GRemoteReftest(RefTest): michael@0: michael@0: _devicemanager = None michael@0: localProfile = None michael@0: remoteApp = '' michael@0: profile = None michael@0: michael@0: def __init__(self, automation, devicemanager, options, scriptDir): michael@0: RefTest.__init__(self, automation) michael@0: self._devicemanager = devicemanager michael@0: self.runSSLTunnel = False michael@0: self.remoteTestRoot = options.remoteTestRoot michael@0: self.remoteProfile = options.remoteProfile michael@0: self.automation.setRemoteProfile(self.remoteProfile) michael@0: self.localLogName = options.localLogName michael@0: self.remoteLogFile = options.remoteLogFile michael@0: self.bundlesDir = '/system/b2g/distribution/bundles' michael@0: self.userJS = '/data/local/user.js' michael@0: self.remoteMozillaPath = '/data/b2g/mozilla' michael@0: self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini') michael@0: self.originalProfilesIni = None michael@0: self.scriptDir = scriptDir michael@0: self.SERVER_STARTUP_TIMEOUT = 90 michael@0: if self.automation.IS_DEBUG_BUILD: michael@0: self.SERVER_STARTUP_TIMEOUT = 180 michael@0: michael@0: def cleanup(self, profileDir): michael@0: # Pull results back from device michael@0: if (self.remoteLogFile): michael@0: try: michael@0: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) michael@0: except: michael@0: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile michael@0: sys.exit(5) michael@0: michael@0: # Delete any bundled extensions michael@0: if profileDir: michael@0: extensionDir = os.path.join(profileDir, 'extensions', 'staged') michael@0: for filename in os.listdir(extensionDir): michael@0: try: michael@0: self._devicemanager._checkCmd(['shell', 'rm', '-rf', michael@0: os.path.join(self.bundlesDir, filename)]) michael@0: except DMError: michael@0: pass michael@0: michael@0: # Restore the original profiles.ini. michael@0: if self.originalProfilesIni: michael@0: try: michael@0: if not self.automation._is_emulator: michael@0: self.restoreProfilesIni() michael@0: os.remove(self.originalProfilesIni) michael@0: except: michael@0: pass michael@0: michael@0: if not self.automation._is_emulator: michael@0: self._devicemanager.removeFile(self.remoteLogFile) michael@0: self._devicemanager.removeDir(self.remoteProfile) michael@0: self._devicemanager.removeDir(self.remoteTestRoot) michael@0: michael@0: # Restore the original user.js. michael@0: self._devicemanager._checkCmd(['shell', 'rm', '-f', self.userJS]) michael@0: self._devicemanager._checkCmd(['shell', 'dd', 'if=%s.orig' % self.userJS, 'of=%s' % self.userJS]) michael@0: michael@0: # We've restored the original profile, so reboot the device so that michael@0: # it gets picked up. michael@0: self.automation.rebootDevice() michael@0: michael@0: RefTest.cleanup(self, profileDir) michael@0: if getattr(self, 'pidFile', '') != '': michael@0: try: michael@0: os.remove(self.pidFile) michael@0: os.remove(self.pidFile + ".xpcshell.pid") michael@0: except: michael@0: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile michael@0: michael@0: def findPath(self, paths, filename = None): michael@0: for path in paths: michael@0: p = path michael@0: if filename: michael@0: p = os.path.join(p, filename) michael@0: if os.path.exists(self.getFullPath(p)): michael@0: return path michael@0: return None michael@0: michael@0: def startWebServer(self, options): michael@0: """ Create the webserver on the host and start it up """ michael@0: remoteXrePath = options.xrePath michael@0: remoteProfilePath = self.remoteProfile michael@0: remoteUtilityPath = options.utilityPath michael@0: localAutomation = Automation() michael@0: localAutomation.IS_WIN32 = False michael@0: localAutomation.IS_LINUX = False michael@0: localAutomation.IS_MAC = False michael@0: localAutomation.UNIXISH = False michael@0: hostos = sys.platform michael@0: if hostos in ['mac', 'darwin']: michael@0: localAutomation.IS_MAC = True michael@0: elif hostos in ['linux', 'linux2']: michael@0: localAutomation.IS_LINUX = True michael@0: localAutomation.UNIXISH = True michael@0: elif hostos in ['win32', 'win64']: michael@0: localAutomation.BIN_SUFFIX = ".exe" michael@0: localAutomation.IS_WIN32 = True michael@0: michael@0: paths = [options.xrePath, michael@0: localAutomation.DIST_BIN, michael@0: self.automation._product, michael@0: os.path.join('..', self.automation._product)] michael@0: options.xrePath = self.findPath(paths) michael@0: if options.xrePath == None: michael@0: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) michael@0: sys.exit(1) michael@0: paths.append("bin") michael@0: paths.append(os.path.join("..", "bin")) michael@0: michael@0: xpcshell = "xpcshell" michael@0: if (os.name == "nt"): michael@0: xpcshell += ".exe" michael@0: michael@0: if (options.utilityPath): michael@0: paths.insert(0, options.utilityPath) michael@0: options.utilityPath = self.findPath(paths, xpcshell) michael@0: if options.utilityPath == None: michael@0: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) michael@0: sys.exit(1) michael@0: michael@0: xpcshell = os.path.join(options.utilityPath, xpcshell) michael@0: if self.automation.elf_arm(xpcshell): michael@0: raise Exception('xpcshell at %s is an ARM binary; please use ' michael@0: 'the --utility-path argument to specify the path ' michael@0: 'to a desktop version.' % xpcshell) michael@0: michael@0: options.serverProfilePath = tempfile.mkdtemp() michael@0: self.server = ReftestServer(localAutomation, options, self.scriptDir) michael@0: retVal = self.server.start() michael@0: if retVal: michael@0: return retVal michael@0: michael@0: if (options.pidFile != ""): michael@0: f = open(options.pidFile + ".xpcshell.pid", 'w') michael@0: f.write("%s" % self.server._process.pid) michael@0: f.close() michael@0: michael@0: retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) michael@0: if retVal: michael@0: return retVal michael@0: michael@0: options.xrePath = remoteXrePath michael@0: options.utilityPath = remoteUtilityPath michael@0: options.profilePath = remoteProfilePath michael@0: return 0 michael@0: michael@0: def stopWebServer(self, options): michael@0: if hasattr(self, 'server'): michael@0: self.server.stop() michael@0: michael@0: def restoreProfilesIni(self): michael@0: # restore profiles.ini on the device to its previous state michael@0: if not self.originalProfilesIni or not os.access(self.originalProfilesIni, os.F_OK): michael@0: raise DMError('Unable to install original profiles.ini; file not found: %s', michael@0: self.originalProfilesIni) michael@0: michael@0: self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) michael@0: michael@0: def updateProfilesIni(self, profilePath): michael@0: # update profiles.ini on the device to point to the test profile michael@0: self.originalProfilesIni = tempfile.mktemp() michael@0: self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) michael@0: michael@0: config = ProfileConfigParser() michael@0: config.read(self.originalProfilesIni) michael@0: for section in config.sections(): michael@0: if 'Profile' in section: michael@0: config.set(section, 'IsRelative', 0) michael@0: config.set(section, 'Path', profilePath) michael@0: michael@0: newProfilesIni = tempfile.mktemp() michael@0: with open(newProfilesIni, 'wb') as configfile: michael@0: config.write(configfile) michael@0: michael@0: self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) michael@0: try: michael@0: os.remove(newProfilesIni) michael@0: except: michael@0: pass michael@0: michael@0: michael@0: def createReftestProfile(self, options, reftestlist): michael@0: profile = RefTest.createReftestProfile(self, options, reftestlist, michael@0: server=options.remoteWebServer, michael@0: special_powers=False) michael@0: profileDir = profile.profile michael@0: michael@0: prefs = {} michael@0: # Turn off the locale picker screen michael@0: prefs["browser.firstrun.show.localepicker"] = False michael@0: prefs["browser.homescreenURL"] = "app://test-container.gaiamobile.org/index.html" michael@0: prefs["browser.manifestURL"] = "app://test-container.gaiamobile.org/manifest.webapp" michael@0: prefs["browser.tabs.remote"] = False michael@0: prefs["dom.ipc.tabs.disabled"] = False michael@0: prefs["dom.mozBrowserFramesEnabled"] = True michael@0: prefs["font.size.inflation.emPerLine"] = 0 michael@0: prefs["font.size.inflation.minTwips"] = 0 michael@0: prefs["network.dns.localDomains"] = "app://test-container.gaiamobile.org" michael@0: prefs["reftest.browser.iframe.enabled"] = False michael@0: prefs["reftest.remote"] = True michael@0: prefs["reftest.uri"] = "%s" % reftestlist michael@0: # Set a future policy version to avoid the telemetry prompt. michael@0: prefs["toolkit.telemetry.prompted"] = 999 michael@0: prefs["toolkit.telemetry.notifiedOptOut"] = 999 michael@0: michael@0: # Set the extra prefs. michael@0: profile.set_preferences(prefs) michael@0: michael@0: # Copy the profile to the device. michael@0: self._devicemanager.removeDir(self.remoteProfile) michael@0: try: michael@0: self._devicemanager.pushDir(profileDir, self.remoteProfile) michael@0: except DMError: michael@0: print "Automation Error: Unable to copy profile to device." michael@0: raise michael@0: michael@0: # Copy the extensions to the B2G bundles dir. michael@0: extensionDir = os.path.join(profileDir, 'extensions', 'staged') michael@0: # need to write to read-only dir michael@0: self._devicemanager._checkCmd(['remount']) michael@0: for filename in os.listdir(extensionDir): michael@0: self._devicemanager._checkCmd(['shell', 'rm', '-rf', michael@0: os.path.join(self.bundlesDir, filename)]) michael@0: try: michael@0: self._devicemanager.pushDir(extensionDir, self.bundlesDir) michael@0: except DMError: michael@0: print "Automation Error: Unable to copy extensions to device." michael@0: raise michael@0: michael@0: # In B2G, user.js is always read from /data/local, not the profile michael@0: # directory. Backup the original user.js first so we can restore it. michael@0: self._devicemanager._checkCmd(['shell', 'rm', '-f', '%s.orig' % self.userJS]) michael@0: self._devicemanager._checkCmd(['shell', 'dd', 'if=%s' % self.userJS, 'of=%s.orig' % self.userJS]) michael@0: self._devicemanager.pushFile(os.path.join(profileDir, "user.js"), self.userJS) michael@0: michael@0: self.updateProfilesIni(self.remoteProfile) michael@0: michael@0: options.profilePath = self.remoteProfile michael@0: return profile michael@0: michael@0: def copyExtraFilesToProfile(self, options, profile): michael@0: profileDir = profile.profile michael@0: RefTest.copyExtraFilesToProfile(self, options, profile) michael@0: try: michael@0: self._devicemanager.pushDir(profileDir, options.remoteProfile) michael@0: except DMError: michael@0: print "Automation Error: Failed to copy extra files to device" michael@0: raise michael@0: michael@0: def getManifestPath(self, path): michael@0: return path michael@0: michael@0: michael@0: def run_remote_reftests(parser, options, args): michael@0: auto = B2GRemoteAutomation(None, "fennec", context_chrome=True) michael@0: michael@0: # create our Marionette instance michael@0: kwargs = {} michael@0: if options.emulator: michael@0: kwargs['emulator'] = options.emulator michael@0: auto.setEmulator(True) michael@0: if options.noWindow: michael@0: kwargs['noWindow'] = True michael@0: if options.geckoPath: michael@0: kwargs['gecko_path'] = options.geckoPath michael@0: if options.logcat_dir: michael@0: kwargs['logcat_dir'] = options.logcat_dir michael@0: if options.busybox: michael@0: kwargs['busybox'] = options.busybox michael@0: if options.symbolsPath: michael@0: kwargs['symbols_path'] = options.symbolsPath michael@0: if options.emulator_res: michael@0: kwargs['emulator_res'] = options.emulator_res michael@0: if options.b2gPath: michael@0: kwargs['homedir'] = options.b2gPath michael@0: if options.marionette: michael@0: host,port = options.marionette.split(':') michael@0: kwargs['host'] = host michael@0: kwargs['port'] = int(port) michael@0: marionette = Marionette.getMarionetteOrExit(**kwargs) michael@0: auto.marionette = marionette michael@0: michael@0: if options.emulator: michael@0: dm = marionette.emulator.dm michael@0: else: michael@0: # create the DeviceManager michael@0: kwargs = {'adbPath': options.adbPath, michael@0: 'deviceRoot': options.remoteTestRoot} michael@0: if options.deviceIP: michael@0: kwargs.update({'host': options.deviceIP, michael@0: 'port': options.devicePort}) michael@0: dm = DeviagerADB(**kwargs) michael@0: auto.setDeviceManager(dm) michael@0: michael@0: options = parser.verifyRemoteOptions(options) michael@0: michael@0: if (options == None): michael@0: print "ERROR: Invalid options specified, use --help for a list of valid options" michael@0: sys.exit(1) michael@0: michael@0: # TODO fix exception michael@0: if not options.ignoreWindowSize: michael@0: parts = dm.getInfo('screen')['screen'][0].split() michael@0: width = int(parts[0].split(':')[1]) michael@0: height = int(parts[1].split(':')[1]) michael@0: if (width < 1366 or height < 1050): michael@0: print "ERROR: Invalid screen resolution %sx%s, please adjust to 1366x1050 or higher" % (width, height) michael@0: return 1 michael@0: michael@0: auto.setProduct("b2g") michael@0: auto.test_script = os.path.join(here, 'b2g_start_script.js') michael@0: auto.test_script_args = [options.remoteWebServer, options.httpPort] michael@0: auto.logFinish = "REFTEST TEST-START | Shutdown" michael@0: michael@0: reftest = B2GRemoteReftest(auto, dm, options, here) michael@0: options = parser.verifyCommonOptions(options, reftest) michael@0: michael@0: logParent = os.path.dirname(options.remoteLogFile) michael@0: dm.mkDir(logParent); michael@0: auto.setRemoteLog(options.remoteLogFile) michael@0: auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) michael@0: michael@0: # Hack in a symbolic link for jsreftest michael@0: os.system("ln -s %s %s" % (os.path.join('..', 'jsreftest'), os.path.join(here, 'jsreftest'))) michael@0: michael@0: # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot michael@0: manifest = args[0] michael@0: if os.path.exists(os.path.join(here, args[0])): michael@0: manifest = "http://%s:%s/%s" % (options.remoteWebServer, options.httpPort, args[0]) michael@0: elif os.path.exists(args[0]): michael@0: manifestPath = os.path.abspath(args[0]).split(here)[1].strip('/') michael@0: manifest = "http://%s:%s/%s" % (options.remoteWebServer, options.httpPort, manifestPath) michael@0: else: michael@0: print "ERROR: Could not find test manifest '%s'" % manifest michael@0: return 1 michael@0: michael@0: # Start the webserver michael@0: retVal = 1 michael@0: try: michael@0: retVal = reftest.startWebServer(options) michael@0: if retVal: michael@0: return retVal michael@0: procName = options.app.split('/')[-1] michael@0: if (dm.processExist(procName)): michael@0: dm.killProcess(procName) michael@0: michael@0: cmdlineArgs = ["-reftest", manifest] michael@0: if getattr(options, 'bootstrap', False): michael@0: cmdlineArgs = [] michael@0: michael@0: retVal = reftest.runTests(manifest, options, cmdlineArgs) michael@0: except: michael@0: print "Automation Error: Exception caught while running tests" michael@0: traceback.print_exc() michael@0: reftest.stopWebServer(options) michael@0: try: michael@0: reftest.cleanup(None) michael@0: except: michael@0: pass michael@0: return 1 michael@0: michael@0: reftest.stopWebServer(options) michael@0: return retVal michael@0: michael@0: def main(args=sys.argv[1:]): michael@0: parser = B2GOptions() michael@0: options, args = parser.parse_args(args) michael@0: michael@0: if options.desktop: michael@0: return run_desktop_reftests(parser, options, args) michael@0: return run_remote_reftests(parser, options, args) michael@0: michael@0: michael@0: if __name__ == "__main__": michael@0: sys.exit(main()) michael@0: