1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/tools/reftest/b2g_desktop.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,175 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 +from __future__ import print_function, unicode_literals 1.8 + 1.9 +import json 1.10 +import os 1.11 +import signal 1.12 +import sys 1.13 +import threading 1.14 + 1.15 +here = os.path.abspath(os.path.dirname(__file__)) 1.16 + 1.17 +from runreftest import RefTest, ReftestOptions 1.18 + 1.19 +from marionette import Marionette 1.20 +from mozprocess import ProcessHandler 1.21 +from mozrunner import FirefoxRunner 1.22 +import mozinfo 1.23 +import mozlog 1.24 + 1.25 +log = mozlog.getLogger('REFTEST') 1.26 + 1.27 +class B2GDesktopReftest(RefTest): 1.28 + def __init__(self, marionette): 1.29 + RefTest.__init__(self) 1.30 + self.last_test = os.path.basename(__file__) 1.31 + self.marionette = marionette 1.32 + self.profile = None 1.33 + self.runner = None 1.34 + self.test_script = os.path.join(here, 'b2g_start_script.js') 1.35 + self.timeout = None 1.36 + 1.37 + def run_marionette_script(self): 1.38 + assert(self.marionette.wait_for_port()) 1.39 + self.marionette.start_session() 1.40 + self.marionette.set_context(self.marionette.CONTEXT_CHROME) 1.41 + 1.42 + if os.path.isfile(self.test_script): 1.43 + f = open(self.test_script, 'r') 1.44 + self.test_script = f.read() 1.45 + f.close() 1.46 + self.marionette.execute_script(self.test_script) 1.47 + 1.48 + def run_tests(self, test_path, options): 1.49 + reftestlist = self.getManifestPath(test_path) 1.50 + if not reftestlist.startswith('file://'): 1.51 + reftestlist = 'file://%s' % reftestlist 1.52 + 1.53 + self.profile = self.create_profile(options, reftestlist, 1.54 + profile_to_clone=options.profile) 1.55 + env = self.buildBrowserEnv(options, self.profile.profile) 1.56 + kp_kwargs = { 'processOutputLine': [self._on_output], 1.57 + 'onTimeout': [self._on_timeout], 1.58 + 'kill_on_timeout': False } 1.59 + 1.60 + if not options.debugger: 1.61 + if not options.timeout: 1.62 + if mozinfo.info['debug']: 1.63 + options.timeout = 420 1.64 + else: 1.65 + options.timeout = 300 1.66 + self.timeout = options.timeout + 30.0 1.67 + 1.68 + log.info("%s | Running tests: start.", os.path.basename(__file__)) 1.69 + cmd, args = self.build_command_line(options.app, 1.70 + ignore_window_size=options.ignoreWindowSize, 1.71 + browser_arg=options.browser_arg) 1.72 + self.runner = FirefoxRunner(profile=self.profile, 1.73 + binary=cmd, 1.74 + cmdargs=args, 1.75 + env=env, 1.76 + process_class=ProcessHandler, 1.77 + symbols_path=options.symbolsPath, 1.78 + kp_kwargs=kp_kwargs) 1.79 + 1.80 + status = 0 1.81 + try: 1.82 + self.runner.start(outputTimeout=self.timeout) 1.83 + log.info("%s | Application pid: %d", 1.84 + os.path.basename(__file__), 1.85 + self.runner.process_handler.pid) 1.86 + 1.87 + # kick starts the reftest harness 1.88 + self.run_marionette_script() 1.89 + status = self.runner.wait() 1.90 + finally: 1.91 + self.runner.check_for_crashes(test_name=self.last_test) 1.92 + self.runner.cleanup() 1.93 + 1.94 + if status > 0: 1.95 + log.testFail("%s | application terminated with exit code %s", 1.96 + self.last_test, status) 1.97 + elif status < 0: 1.98 + log.info("%s | application killed with signal %s", 1.99 + self.last_test, -status) 1.100 + 1.101 + log.info("%s | Running tests: end.", os.path.basename(__file__)) 1.102 + return status 1.103 + 1.104 + def create_profile(self, options, reftestlist, profile_to_clone=None): 1.105 + profile = RefTest.createReftestProfile(self, options, reftestlist, 1.106 + profile_to_clone=profile_to_clone) 1.107 + 1.108 + prefs = {} 1.109 + # Turn off the locale picker screen 1.110 + prefs["browser.firstrun.show.localepicker"] = False 1.111 + prefs["browser.homescreenURL"] = "app://test-container.gaiamobile.org/index.html" 1.112 + prefs["browser.manifestURL"] = "app://test-container.gaiamobile.org/manifest.webapp" 1.113 + prefs["browser.tabs.remote"] = False 1.114 + prefs["dom.ipc.tabs.disabled"] = False 1.115 + prefs["dom.mozBrowserFramesEnabled"] = True 1.116 + prefs["font.size.inflation.emPerLine"] = 0 1.117 + prefs["font.size.inflation.minTwips"] = 0 1.118 + prefs["network.dns.localDomains"] = "app://test-container.gaiamobile.org" 1.119 + prefs["reftest.browser.iframe.enabled"] = False 1.120 + prefs["reftest.remote"] = False 1.121 + prefs["reftest.uri"] = "%s" % reftestlist 1.122 + # Set a future policy version to avoid the telemetry prompt. 1.123 + prefs["toolkit.telemetry.prompted"] = 999 1.124 + prefs["toolkit.telemetry.notifiedOptOut"] = 999 1.125 + 1.126 + # Set the extra prefs. 1.127 + profile.set_preferences(prefs) 1.128 + return profile 1.129 + 1.130 + def build_command_line(self, app, ignore_window_size=False, 1.131 + browser_arg=None): 1.132 + cmd = os.path.abspath(app) 1.133 + args = ['-marionette'] 1.134 + 1.135 + if browser_arg: 1.136 + args += [browser_arg] 1.137 + 1.138 + if not ignore_window_size: 1.139 + args.extend(['--screen', '800x1000']) 1.140 + return cmd, args 1.141 + 1.142 + def _on_output(self, line): 1.143 + print(line) 1.144 + # TODO use structured logging 1.145 + if "TEST-START" in line and "|" in line: 1.146 + self.last_test = line.split("|")[1].strip() 1.147 + 1.148 + def _on_timeout(self): 1.149 + msg = "%s | application timed out after %s seconds with no output" 1.150 + log.testFail(msg % (self.last_test, self.timeout)) 1.151 + 1.152 + # kill process to get a stack 1.153 + self.runner.stop(sig=signal.SIGABRT) 1.154 + 1.155 + 1.156 +def run_desktop_reftests(parser, options, args): 1.157 + kwargs = {} 1.158 + if options.marionette: 1.159 + host, port = options.marionette.split(':') 1.160 + kwargs['host'] = host 1.161 + kwargs['port'] = int(port) 1.162 + marionette = Marionette.getMarionetteOrExit(**kwargs) 1.163 + 1.164 + reftest = B2GDesktopReftest(marionette) 1.165 + 1.166 + options = ReftestOptions.verifyCommonOptions(parser, options, reftest) 1.167 + if options == None: 1.168 + sys.exit(1) 1.169 + 1.170 + # add a -bin suffix if b2g-bin exists, but just b2g was specified 1.171 + if options.app[-4:] != '-bin': 1.172 + if os.path.isfile("%s-bin" % options.app): 1.173 + options.app = "%s-bin" % options.app 1.174 + 1.175 + if options.desktop and not options.profile: 1.176 + raise Exception("must specify --profile when specifying --desktop") 1.177 + 1.178 + sys.exit(reftest.run_tests(args[0], options))