2012-05-21 15:12:37 +04:00
|
|
|
# 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/.
|
2010-03-24 20:51:17 +03:00
|
|
|
|
2019-12-27 00:17:55 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2019-09-10 22:15:30 +03:00
|
|
|
|
2010-03-16 01:35:59 +03:00
|
|
|
import os
|
2018-03-24 03:06:27 +03:00
|
|
|
import posixpath
|
2017-08-30 00:44:18 +03:00
|
|
|
import signal
|
2020-03-11 00:42:26 +03:00
|
|
|
import subprocess
|
2018-02-01 22:18:00 +03:00
|
|
|
import sys
|
2018-02-07 03:20:38 +03:00
|
|
|
import tempfile
|
2018-02-01 22:18:00 +03:00
|
|
|
import time
|
2012-11-05 17:03:54 +04:00
|
|
|
import traceback
|
2018-02-01 22:18:00 +03:00
|
|
|
from contextlib import closing
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2020-05-27 16:07:07 +03:00
|
|
|
from six.moves.urllib_request import urlopen
|
|
|
|
|
2020-07-17 23:43:57 +03:00
|
|
|
from mozdevice import ADBDevice, ADBTimeoutError
|
2012-11-13 01:57:13 +04:00
|
|
|
from remoteautomation import RemoteAutomation, fennecLogcatFilters
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2016-02-05 23:44:20 +03:00
|
|
|
from output import OutputHandler
|
2020-03-17 22:06:34 +03:00
|
|
|
from runreftest import RefTest, ReftestResolver, build_obj
|
2015-08-25 16:07:23 +03:00
|
|
|
import reftestcommandline
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2016-02-05 23:44:20 +03:00
|
|
|
# We need to know our current directory so that we can serve our test files from it.
|
|
|
|
SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
|
|
|
|
|
|
|
|
|
2015-08-25 16:07:23 +03:00
|
|
|
class RemoteReftestResolver(ReftestResolver):
|
|
|
|
def absManifestPath(self, path):
|
|
|
|
script_abs_path = os.path.join(SCRIPT_DIRECTORY, path)
|
|
|
|
if os.path.exists(script_abs_path):
|
|
|
|
rv = script_abs_path
|
|
|
|
elif os.path.exists(os.path.abspath(path)):
|
|
|
|
rv = os.path.abspath(path)
|
2010-07-27 05:43:34 +04:00
|
|
|
else:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("Could not find manifest %s" % script_abs_path, file=sys.stderr)
|
2015-08-25 16:07:23 +03:00
|
|
|
sys.exit(1)
|
|
|
|
return os.path.normpath(rv)
|
2011-04-20 02:17:01 +04:00
|
|
|
|
2015-08-25 16:07:23 +03:00
|
|
|
def manifestURL(self, options, path):
|
2020-04-28 20:08:36 +03:00
|
|
|
# Dynamically build the reftest URL if possible, beware that
|
|
|
|
# args[0] should exist 'inside' webroot. It's possible for
|
|
|
|
# this url to have a leading "..", but reftest.js will fix
|
|
|
|
# that. Use the httpdPath to determine if we are running in
|
|
|
|
# production or locally. If we are running the jsreftests
|
|
|
|
# locally, strip text up to jsreftest. We want the docroot of
|
|
|
|
# the server to include a link jsreftest that points to the
|
|
|
|
# test-stage location of the test files. The desktop oriented
|
|
|
|
# setup has already created a link for tests which points
|
|
|
|
# directly into the source tree. For the remote tests we need
|
|
|
|
# a separate symbolic link to point to the staged test files.
|
|
|
|
if 'jsreftest' not in path or os.environ.get('MOZ_AUTOMATION'):
|
|
|
|
relPath = os.path.relpath(path, SCRIPT_DIRECTORY)
|
|
|
|
else:
|
|
|
|
relPath = 'jsreftest/' + path.split('jsreftest/')[-1]
|
2015-08-25 16:07:23 +03:00
|
|
|
return "http://%s:%s/%s" % (options.remoteWebServer, options.httpPort, relPath)
|
2013-06-27 07:42:46 +04:00
|
|
|
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2010-06-24 13:32:01 +04:00
|
|
|
class ReftestServer:
|
|
|
|
""" Web server used to serve Reftests, for closer fidelity to the real web.
|
|
|
|
It is virtually identical to the server used in mochitest and will only
|
|
|
|
be used for running reftests remotely.
|
2010-07-27 05:43:34 +04:00
|
|
|
Bug 581257 has been filed to refactor this wrapper around httpd.js into
|
2010-06-24 13:32:01 +04:00
|
|
|
it's own class and use it in both remote and non-remote testing. """
|
|
|
|
|
2020-03-17 22:06:34 +03:00
|
|
|
def __init__(self, options, scriptDir, log):
|
|
|
|
self.log = log
|
2018-03-24 03:06:27 +03:00
|
|
|
self.utilityPath = options.utilityPath
|
|
|
|
self.xrePath = options.xrePath
|
|
|
|
self.profileDir = options.serverProfilePath
|
2010-06-24 13:32:01 +04:00
|
|
|
self.webServer = options.remoteWebServer
|
|
|
|
self.httpPort = options.httpPort
|
2010-09-18 04:18:06 +04:00
|
|
|
self.scriptDir = scriptDir
|
2018-03-24 03:06:27 +03:00
|
|
|
self.httpdPath = os.path.abspath(options.httpdPath)
|
2017-04-13 23:33:42 +03:00
|
|
|
if options.remoteWebServer == "10.0.2.2":
|
|
|
|
# probably running an Android emulator and 10.0.2.2 will
|
|
|
|
# not be visible from host
|
|
|
|
shutdownServer = "127.0.0.1"
|
|
|
|
else:
|
|
|
|
shutdownServer = self.webServer
|
2017-02-14 22:50:56 +03:00
|
|
|
self.shutdownURL = "http://%(server)s:%(port)s/server/shutdown" % {
|
2017-04-13 23:33:42 +03:00
|
|
|
"server": shutdownServer, "port": self.httpPort}
|
2010-06-24 13:32:01 +04:00
|
|
|
|
|
|
|
def start(self):
|
|
|
|
"Run the Refest server, returning the process ID of the server."
|
2012-08-10 22:25:20 +04:00
|
|
|
|
2020-03-17 22:06:34 +03:00
|
|
|
env = dict(os.environ)
|
2010-06-24 13:32:01 +04:00
|
|
|
env["XPCOM_DEBUG_BREAK"] = "warn"
|
2020-03-17 22:06:34 +03:00
|
|
|
bin_suffix = ""
|
|
|
|
if sys.platform in ('win32', 'msys', 'cygwin'):
|
2018-03-24 03:06:27 +03:00
|
|
|
env["PATH"] = env["PATH"] + ";" + self.xrePath
|
2020-03-17 22:06:34 +03:00
|
|
|
bin_suffix = ".exe"
|
|
|
|
else:
|
|
|
|
if "LD_LIBRARY_PATH" not in env or env["LD_LIBRARY_PATH"] is None:
|
|
|
|
env["LD_LIBRARY_PATH"] = self.xrePath
|
|
|
|
else:
|
|
|
|
env["LD_LIBRARY_PATH"] = ":".join([self.xrePath, env["LD_LIBRARY_PATH"]])
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2018-03-24 03:06:27 +03:00
|
|
|
args = ["-g", self.xrePath,
|
|
|
|
"-f", os.path.join(self.httpdPath, "httpd.js"),
|
2017-02-14 22:50:56 +03:00
|
|
|
"-e", "const _PROFILE_PATH = '%(profile)s';const _SERVER_PORT = "
|
|
|
|
"'%(port)s'; const _SERVER_ADDR ='%(server)s';" % {
|
2018-03-24 03:06:27 +03:00
|
|
|
"profile": self.profileDir.replace('\\', '\\\\'), "port": self.httpPort,
|
2017-02-14 22:50:56 +03:00
|
|
|
"server": self.webServer},
|
2010-09-18 04:18:06 +04:00
|
|
|
"-f", os.path.join(self.scriptDir, "server.js")]
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2020-03-17 22:06:34 +03:00
|
|
|
xpcshell = os.path.join(self.utilityPath, "xpcshell" + bin_suffix)
|
2013-01-04 05:37:26 +04:00
|
|
|
|
|
|
|
if not os.access(xpcshell, os.F_OK):
|
|
|
|
raise Exception('xpcshell not found at %s' % xpcshell)
|
2020-03-11 00:42:26 +03:00
|
|
|
if RemoteAutomation.elf_arm(xpcshell):
|
2013-01-04 05:37:26 +04:00
|
|
|
raise Exception('xpcshell at %s is an ARM binary; please use '
|
|
|
|
'the --utility-path argument to specify the path '
|
|
|
|
'to a desktop version.' % xpcshell)
|
|
|
|
|
2020-03-11 00:42:26 +03:00
|
|
|
self._process = subprocess.Popen([xpcshell] + args, env=env)
|
2010-06-24 13:32:01 +04:00
|
|
|
pid = self._process.pid
|
|
|
|
if pid < 0:
|
2020-03-17 22:06:34 +03:00
|
|
|
self.log.error("TEST-UNEXPECTED-FAIL | remotereftests.py | Error starting server.")
|
2012-06-13 22:20:43 +04:00
|
|
|
return 2
|
2020-03-17 22:06:34 +03:00
|
|
|
self.log.info("INFO | remotereftests.py | Server pid: %d" % pid)
|
2010-06-24 13:32:01 +04:00
|
|
|
|
|
|
|
def ensureReady(self, timeout):
|
|
|
|
assert timeout >= 0
|
|
|
|
|
2018-03-24 03:06:27 +03:00
|
|
|
aliveFile = os.path.join(self.profileDir, "server_alive.txt")
|
2010-06-24 13:32:01 +04:00
|
|
|
i = 0
|
|
|
|
while i < timeout:
|
|
|
|
if os.path.exists(aliveFile):
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
i += 1
|
|
|
|
else:
|
2020-03-17 22:06:34 +03:00
|
|
|
self.log.error("TEST-UNEXPECTED-FAIL | remotereftests.py | "
|
|
|
|
"Timed out while waiting for server startup.")
|
2010-06-24 13:32:01 +04:00
|
|
|
self.stop()
|
2012-06-13 22:20:43 +04:00
|
|
|
return 1
|
2010-06-24 13:32:01 +04:00
|
|
|
|
|
|
|
def stop(self):
|
2012-08-10 22:25:20 +04:00
|
|
|
if hasattr(self, '_process'):
|
|
|
|
try:
|
2020-05-27 16:07:07 +03:00
|
|
|
with closing(urlopen(self.shutdownURL)) as c:
|
2017-04-13 23:33:42 +03:00
|
|
|
c.read()
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2012-08-10 22:25:20 +04:00
|
|
|
rtncode = self._process.poll()
|
2017-02-14 22:50:56 +03:00
|
|
|
if (rtncode is None):
|
2012-08-10 22:25:20 +04:00
|
|
|
self._process.terminate()
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2020-03-17 22:06:34 +03:00
|
|
|
self.log.info("Failed to shutdown server at %s" % self.shutdownURL)
|
2017-04-13 23:33:42 +03:00
|
|
|
traceback.print_exc()
|
2012-08-10 22:25:20 +04:00
|
|
|
self._process.kill()
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2017-02-14 22:50:56 +03:00
|
|
|
|
2010-03-16 01:35:59 +03:00
|
|
|
class RemoteReftest(RefTest):
|
2016-03-09 22:38:13 +03:00
|
|
|
use_marionette = False
|
2015-08-25 16:07:23 +03:00
|
|
|
resolver_cls = RemoteReftestResolver
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2018-03-24 03:06:27 +03:00
|
|
|
def __init__(self, options, scriptDir):
|
2018-02-09 00:16:34 +03:00
|
|
|
RefTest.__init__(self, options.suite)
|
|
|
|
self.run_by_manifest = False
|
2010-03-16 01:35:59 +03:00
|
|
|
self.scriptDir = scriptDir
|
2018-03-24 03:06:27 +03:00
|
|
|
self.localLogName = options.localLogName
|
|
|
|
|
|
|
|
verbose = False
|
2020-07-17 23:43:57 +03:00
|
|
|
if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug':
|
2018-03-24 03:06:27 +03:00
|
|
|
verbose = True
|
2019-09-10 22:15:30 +03:00
|
|
|
print("set verbose!")
|
2020-07-17 23:43:57 +03:00
|
|
|
self.device = ADBDevice(adb=options.adb_path or 'adb',
|
|
|
|
device=options.deviceSerial,
|
|
|
|
test_root=options.remoteTestRoot,
|
|
|
|
verbose=verbose)
|
2018-03-24 03:06:27 +03:00
|
|
|
if options.remoteTestRoot is None:
|
|
|
|
options.remoteTestRoot = posixpath.join(self.device.test_root, "reftest")
|
|
|
|
options.remoteProfile = posixpath.join(options.remoteTestRoot, "profile")
|
|
|
|
options.remoteLogFile = posixpath.join(options.remoteTestRoot, "reftest.log")
|
|
|
|
options.logFile = options.remoteLogFile
|
2010-06-24 13:32:01 +04:00
|
|
|
self.remoteProfile = options.remoteProfile
|
2010-06-24 13:32:01 +04:00
|
|
|
self.remoteTestRoot = options.remoteTestRoot
|
2018-03-24 03:06:27 +03:00
|
|
|
|
|
|
|
if not options.ignoreWindowSize:
|
|
|
|
parts = self.device.get_info(
|
|
|
|
'screen')['screen'][0].split()
|
|
|
|
width = int(parts[0].split(':')[1])
|
|
|
|
height = int(parts[1].split(':')[1])
|
|
|
|
if (width < 1366 or height < 1050):
|
|
|
|
self.error("ERROR: Invalid screen resolution %sx%s, "
|
|
|
|
"please adjust to 1366x1050 or higher" % (
|
|
|
|
width, height))
|
2010-06-24 13:32:01 +04:00
|
|
|
|
2016-02-05 23:44:20 +03:00
|
|
|
self._populate_logger(options)
|
2018-02-01 22:18:00 +03:00
|
|
|
self.outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath)
|
2016-02-05 23:44:20 +03:00
|
|
|
# RemoteAutomation.py's 'messageLogger' is also used by mochitest. Mimic a mochitest
|
|
|
|
# MessageLogger object to re-use this code path.
|
2018-02-01 22:18:00 +03:00
|
|
|
self.outputHandler.write = self.outputHandler.__call__
|
2018-11-27 19:41:12 +03:00
|
|
|
args = {'messageLogger': self.outputHandler}
|
|
|
|
self.automation = RemoteAutomation(self.device,
|
|
|
|
appName=options.app,
|
|
|
|
remoteProfile=self.remoteProfile,
|
|
|
|
remoteLog=options.remoteLogFile,
|
|
|
|
processArgs=args)
|
2016-02-05 23:44:20 +03:00
|
|
|
|
2018-03-24 03:06:27 +03:00
|
|
|
self.environment = self.automation.environment
|
2020-03-17 22:06:34 +03:00
|
|
|
self.SERVER_STARTUP_TIMEOUT = 90
|
2018-03-24 03:06:27 +03:00
|
|
|
|
|
|
|
self.remoteCache = os.path.join(options.remoteTestRoot, "cache/")
|
|
|
|
|
|
|
|
# Check that Firefox is installed
|
|
|
|
expected = options.app.split('/')[-1]
|
|
|
|
if not self.device.is_app_installed(expected):
|
|
|
|
raise Exception("%s is not installed on this device" % expected)
|
2020-07-17 23:43:57 +03:00
|
|
|
|
2018-03-24 03:06:27 +03:00
|
|
|
self.device.clear_logcat()
|
|
|
|
|
2020-07-17 23:43:57 +03:00
|
|
|
self.device.rm(self.remoteCache, force=True, recursive=True, root=True)
|
2018-03-24 03:06:27 +03:00
|
|
|
|
|
|
|
procName = options.app.split('/')[-1]
|
2018-03-26 21:21:46 +03:00
|
|
|
self.device.stop_application(procName)
|
2018-03-24 03:06:27 +03:00
|
|
|
if self.device.process_exist(procName):
|
|
|
|
self.log.error("unable to kill %s before starting tests!" % procName)
|
|
|
|
|
2017-02-14 22:50:56 +03:00
|
|
|
def findPath(self, paths, filename=None):
|
2010-06-24 13:32:01 +04:00
|
|
|
for path in paths:
|
|
|
|
p = path
|
|
|
|
if filename:
|
|
|
|
p = os.path.join(p, filename)
|
|
|
|
if os.path.exists(self.getFullPath(p)):
|
|
|
|
return path
|
|
|
|
return None
|
|
|
|
|
|
|
|
def startWebServer(self, options):
|
|
|
|
""" Create the webserver on the host and start it up """
|
|
|
|
remoteXrePath = options.xrePath
|
|
|
|
remoteUtilityPath = options.utilityPath
|
2020-03-17 22:06:34 +03:00
|
|
|
|
|
|
|
paths = [options.xrePath]
|
|
|
|
if build_obj:
|
|
|
|
paths.append(os.path.join(build_obj.topobjdir, "dist", "bin"))
|
2010-06-24 13:32:01 +04:00
|
|
|
options.xrePath = self.findPath(paths)
|
2017-02-14 22:50:56 +03:00
|
|
|
if options.xrePath is None:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("ERROR: unable to find xulrunner path for %s, "
|
|
|
|
"please specify with --xre-path" % (os.name))
|
2012-06-13 22:20:43 +04:00
|
|
|
return 1
|
2010-06-24 13:32:01 +04:00
|
|
|
paths.append("bin")
|
|
|
|
paths.append(os.path.join("..", "bin"))
|
|
|
|
|
|
|
|
xpcshell = "xpcshell"
|
|
|
|
if (os.name == "nt"):
|
|
|
|
xpcshell += ".exe"
|
2012-08-10 22:25:20 +04:00
|
|
|
|
2010-06-24 13:32:01 +04:00
|
|
|
if (options.utilityPath):
|
|
|
|
paths.insert(0, options.utilityPath)
|
|
|
|
options.utilityPath = self.findPath(paths, xpcshell)
|
2017-02-14 22:50:56 +03:00
|
|
|
if options.utilityPath is None:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("ERROR: unable to find utility path for %s, "
|
|
|
|
"please specify with --utility-path" % (os.name))
|
2012-06-13 22:20:43 +04:00
|
|
|
return 1
|
2010-06-24 13:32:01 +04:00
|
|
|
|
|
|
|
options.serverProfilePath = tempfile.mkdtemp()
|
2020-03-17 22:06:34 +03:00
|
|
|
self.server = ReftestServer(options, self.scriptDir, self.log)
|
2012-06-13 22:20:43 +04:00
|
|
|
retVal = self.server.start()
|
|
|
|
if retVal:
|
|
|
|
return retVal
|
|
|
|
retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT)
|
|
|
|
if retVal:
|
|
|
|
return retVal
|
2010-06-24 13:32:01 +04:00
|
|
|
|
|
|
|
options.xrePath = remoteXrePath
|
|
|
|
options.utilityPath = remoteUtilityPath
|
2012-06-13 22:20:43 +04:00
|
|
|
return 0
|
2012-08-10 22:25:20 +04:00
|
|
|
|
2010-06-24 13:32:01 +04:00
|
|
|
def stopWebServer(self, options):
|
|
|
|
self.server.stop()
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2017-09-29 19:40:24 +03:00
|
|
|
def killNamedProc(self, pname, orphans=True):
|
2017-08-30 00:44:18 +03:00
|
|
|
""" Kill processes matching the given command name """
|
2020-07-06 17:05:50 +03:00
|
|
|
try:
|
|
|
|
import psutil
|
|
|
|
except ImportError as e:
|
|
|
|
self.log.warning("Unable to import psutil: %s" % str(e))
|
|
|
|
self.log.warning("Unable to verify that %s is not already running." % pname)
|
|
|
|
return
|
|
|
|
|
2017-08-30 00:44:18 +03:00
|
|
|
self.log.info("Checking for %s processes..." % pname)
|
|
|
|
|
2017-09-29 19:40:24 +03:00
|
|
|
for proc in psutil.process_iter():
|
|
|
|
try:
|
|
|
|
if proc.name() == pname:
|
|
|
|
procd = proc.as_dict(attrs=['pid', 'ppid', 'name', 'username'])
|
|
|
|
if proc.ppid() == 1 or not orphans:
|
|
|
|
self.log.info("killing %s" % procd)
|
|
|
|
try:
|
|
|
|
os.kill(proc.pid, getattr(signal, "SIGKILL", signal.SIGTERM))
|
|
|
|
except Exception as e:
|
|
|
|
self.log.info("Failed to kill process %d: %s" % (proc.pid, str(e)))
|
|
|
|
else:
|
|
|
|
self.log.info("NOT killing %s (not an orphan?)" % procd)
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2017-09-29 19:40:24 +03:00
|
|
|
# may not be able to access process info for all processes
|
|
|
|
continue
|
2017-08-30 00:44:18 +03:00
|
|
|
|
2018-02-05 22:24:49 +03:00
|
|
|
def createReftestProfile(self, options, **kwargs):
|
2015-08-25 16:07:23 +03:00
|
|
|
profile = RefTest.createReftestProfile(self,
|
|
|
|
options,
|
|
|
|
server=options.remoteWebServer,
|
2018-02-01 22:18:00 +03:00
|
|
|
port=options.httpPort,
|
|
|
|
**kwargs)
|
2013-08-20 01:40:27 +04:00
|
|
|
profileDir = profile.profile
|
|
|
|
prefs = {}
|
2015-02-03 19:18:13 +03:00
|
|
|
prefs["app.update.url.android"] = ""
|
2013-08-20 01:40:27 +04:00
|
|
|
prefs["reftest.remote"] = True
|
|
|
|
prefs["datareporting.policy.dataSubmissionPolicyBypassAcceptance"] = True
|
2017-08-16 15:55:49 +03:00
|
|
|
# move necko cache to a location that can be cleaned up
|
|
|
|
prefs["browser.cache.disk.parent_directory"] = self.remoteCache
|
2013-08-20 01:40:27 +04:00
|
|
|
|
2013-11-17 16:24:09 +04:00
|
|
|
prefs["layout.css.devPixelsPerPx"] = "1.0"
|
2015-08-24 20:45:45 +03:00
|
|
|
# Because Fennec is a little wacky (see bug 1156817) we need to load the
|
|
|
|
# reftest pages at 1.0 zoom, rather than zooming to fit the CSS viewport.
|
|
|
|
prefs["apz.allow_zooming"] = False
|
2013-08-20 01:40:27 +04:00
|
|
|
|
|
|
|
# Set the extra prefs.
|
|
|
|
profile.set_preferences(prefs)
|
2011-10-18 17:16:24 +04:00
|
|
|
|
Bug 795496 - Make mozdevice raise exceptions on error;r=ahal,jmaher
It turns out that relying on the user to check return codes for every
command was non-intuitive and resulted in many hard to trace bugs.
Now most functinos just return "None", and raise a DMError when there's an
exception. The exception to this are functions like dirExists, which now return
booleans, and throw exceptions on error. This is a fairly major refactor,
and also involved the following internal changes:
* Removed FileError and AgentError exceptions, replaced with DMError
(having to manage three different types of exceptions was confusing,
all the more so when we're raising them)
* Docstrings updated to remove references to return values where no
longer relevant
* pushFile no longer will create a directory to accomodate the file
if it doesn't exist (this makes it consistent with devicemanagerADB)
* dmSUT we validate the file, but assume that we get something back
from the agent, instead of falling back to manual validation in the
case that we didn't
* isDir and dirExists had the same intention, but different
implementations for dmSUT. Replaced the dmSUT impl of getDirectory
with that of isDir's (which was much simpler). Removed
isDir from devicemanager.py, since it wasn't used externally
* killProcess modified to check for process existence before running
(since the actual internal kill command will throw an exception
if the process doesn't exist)
In addition to all this, more unit tests have been added to test these
changes for devicemanagerSUT.
2012-10-04 19:28:07 +04:00
|
|
|
try:
|
2018-03-24 03:06:27 +03:00
|
|
|
self.device.push(profileDir, options.remoteProfile)
|
2020-04-28 20:08:36 +03:00
|
|
|
# make sure the parent directories of the profile which
|
|
|
|
# may have been created by the push, also have their
|
|
|
|
# permissions set to allow access.
|
2020-07-17 23:43:57 +03:00
|
|
|
self.device.chmod(options.remoteTestRoot, recursive=True, root=True)
|
2018-03-24 03:06:27 +03:00
|
|
|
except Exception:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("Automation Error: Failed to copy profiledir to device")
|
Bug 795496 - Make mozdevice raise exceptions on error;r=ahal,jmaher
It turns out that relying on the user to check return codes for every
command was non-intuitive and resulted in many hard to trace bugs.
Now most functinos just return "None", and raise a DMError when there's an
exception. The exception to this are functions like dirExists, which now return
booleans, and throw exceptions on error. This is a fairly major refactor,
and also involved the following internal changes:
* Removed FileError and AgentError exceptions, replaced with DMError
(having to manage three different types of exceptions was confusing,
all the more so when we're raising them)
* Docstrings updated to remove references to return values where no
longer relevant
* pushFile no longer will create a directory to accomodate the file
if it doesn't exist (this makes it consistent with devicemanagerADB)
* dmSUT we validate the file, but assume that we get something back
from the agent, instead of falling back to manual validation in the
case that we didn't
* isDir and dirExists had the same intention, but different
implementations for dmSUT. Replaced the dmSUT impl of getDirectory
with that of isDir's (which was much simpler). Removed
isDir from devicemanager.py, since it wasn't used externally
* killProcess modified to check for process existence before running
(since the actual internal kill command will throw an exception
if the process doesn't exist)
In addition to all this, more unit tests have been added to test these
changes for devicemanagerSUT.
2012-10-04 19:28:07 +04:00
|
|
|
raise
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2013-08-20 01:40:27 +04:00
|
|
|
return profile
|
|
|
|
|
2013-06-25 04:15:40 +04:00
|
|
|
def printDeviceInfo(self, printLogcat=False):
|
|
|
|
try:
|
|
|
|
if printLogcat:
|
2018-03-24 03:06:27 +03:00
|
|
|
logcat = self.device.get_logcat(filter_out_regexps=fennecLogcatFilters)
|
2018-04-10 22:26:08 +03:00
|
|
|
for l in logcat:
|
2018-12-10 23:37:22 +03:00
|
|
|
ul = l.decode('utf-8', errors='replace')
|
|
|
|
sl = ul.encode('iso8859-1', errors='replace')
|
2019-09-10 22:15:30 +03:00
|
|
|
print("%s\n" % sl)
|
|
|
|
print("Device info:")
|
2018-03-24 03:06:27 +03:00
|
|
|
devinfo = self.device.get_info()
|
2015-02-27 23:15:00 +03:00
|
|
|
for category in devinfo:
|
|
|
|
if type(devinfo[category]) is list:
|
2019-09-10 22:15:30 +03:00
|
|
|
print(" %s:" % category)
|
2015-02-27 23:15:00 +03:00
|
|
|
for item in devinfo[category]:
|
2019-09-10 22:15:30 +03:00
|
|
|
print(" %s" % item)
|
2015-02-27 23:15:00 +03:00
|
|
|
else:
|
2019-09-10 22:15:30 +03:00
|
|
|
print(" %s: %s" % (category, devinfo[category]))
|
|
|
|
print("Test root: %s" % self.device.test_root)
|
2018-07-27 18:27:16 +03:00
|
|
|
except ADBTimeoutError:
|
|
|
|
raise
|
2018-03-24 03:06:27 +03:00
|
|
|
except Exception as e:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("WARNING: Error getting device information: %s" % str(e))
|
2013-06-25 04:15:40 +04:00
|
|
|
|
2014-07-29 19:47:50 +04:00
|
|
|
def environment(self, **kwargs):
|
2015-02-27 23:15:00 +03:00
|
|
|
return self.automation.environment(**kwargs)
|
2014-07-29 19:47:50 +04:00
|
|
|
|
2015-05-08 03:49:15 +03:00
|
|
|
def buildBrowserEnv(self, options, profileDir):
|
|
|
|
browserEnv = RefTest.buildBrowserEnv(self, options, profileDir)
|
|
|
|
# remove desktop environment not used on device
|
|
|
|
if "XPCOM_MEM_BLOAT_LOG" in browserEnv:
|
|
|
|
del browserEnv["XPCOM_MEM_BLOAT_LOG"]
|
|
|
|
return browserEnv
|
|
|
|
|
2018-02-01 22:18:00 +03:00
|
|
|
def runApp(self, options, cmdargs=None, timeout=None, debuggerInfo=None, symbolsPath=None,
|
|
|
|
valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None, **profileArgs):
|
|
|
|
if cmdargs is None:
|
|
|
|
cmdargs = []
|
|
|
|
|
|
|
|
if self.use_marionette:
|
|
|
|
cmdargs.append('-marionette')
|
|
|
|
|
|
|
|
binary = options.app
|
|
|
|
profile = self.createReftestProfile(options, **profileArgs)
|
|
|
|
|
|
|
|
# browser environment
|
|
|
|
env = self.buildBrowserEnv(options, profile.profile)
|
|
|
|
|
|
|
|
self.log.info("Running with e10s: {}".format(options.e10s))
|
2020-06-08 22:20:45 +03:00
|
|
|
self.log.info("Running with fission: {}".format(options.fission))
|
2018-02-05 22:24:49 +03:00
|
|
|
status, self.lastTestSeen = self.automation.runApp(None, env,
|
|
|
|
binary,
|
|
|
|
profile.profile,
|
|
|
|
cmdargs,
|
|
|
|
utilityPath=options.utilityPath,
|
|
|
|
xrePath=options.xrePath,
|
|
|
|
debuggerInfo=debuggerInfo,
|
|
|
|
symbolsPath=symbolsPath,
|
2018-11-27 19:41:13 +03:00
|
|
|
timeout=timeout,
|
|
|
|
e10s=options.e10s)
|
2018-02-01 22:18:00 +03:00
|
|
|
|
|
|
|
self.cleanup(profile.profile)
|
2018-02-09 00:16:34 +03:00
|
|
|
return status
|
2014-07-29 19:47:50 +04:00
|
|
|
|
2010-03-16 01:35:59 +03:00
|
|
|
def cleanup(self, profileDir):
|
2020-07-17 23:43:57 +03:00
|
|
|
self.device.rm(self.remoteTestRoot, force=True, recursive=True, root=True)
|
|
|
|
self.device.rm(self.remoteProfile, force=True, recursive=True, root=True)
|
|
|
|
self.device.rm(self.remoteCache, force=True, recursive=True, root=True)
|
2010-03-16 01:35:59 +03:00
|
|
|
RefTest.cleanup(self, profileDir)
|
|
|
|
|
2016-09-13 16:26:09 +03:00
|
|
|
|
|
|
|
def run_test_harness(parser, options):
|
2018-03-24 03:06:27 +03:00
|
|
|
reftest = RemoteReftest(options, SCRIPT_DIRECTORY)
|
2020-03-17 22:06:34 +03:00
|
|
|
parser.validate_remote(options)
|
2015-08-25 16:07:23 +03:00
|
|
|
parser.validate(options, reftest)
|
2010-03-16 01:35:59 +03:00
|
|
|
|
2020-04-28 20:08:36 +03:00
|
|
|
# Hack in a symbolic link for jsreftest in the SCRIPT_DIRECTORY
|
|
|
|
# which is the document root for the reftest web server. This
|
|
|
|
# allows a separate redirection for the jsreftests which must
|
|
|
|
# run through the web server using the staged tests files and
|
|
|
|
# the desktop which will use the tests symbolic link to find
|
|
|
|
# the JavaScript tests.
|
|
|
|
jsreftest_target = str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))
|
|
|
|
if os.environ.get('MOZ_AUTOMATION'):
|
|
|
|
os.system("ln -s ../jsreftest " + jsreftest_target)
|
|
|
|
else:
|
|
|
|
jsreftest_source = os.path.join(build_obj.topobjdir, "dist", "test-stage", "jsreftest")
|
|
|
|
if not os.path.islink(jsreftest_target):
|
|
|
|
os.symlink(jsreftest_source, jsreftest_target)
|
2011-10-19 15:23:54 +04:00
|
|
|
|
2017-08-30 00:44:18 +03:00
|
|
|
# Despite our efforts to clean up servers started by this script, in practice
|
|
|
|
# we still see infrequent cases where a process is orphaned and interferes
|
|
|
|
# with future tests, typically because the old server is keeping the port in use.
|
|
|
|
# Try to avoid those failures by checking for and killing servers before
|
|
|
|
# trying to start new ones.
|
|
|
|
reftest.killNamedProc('ssltunnel')
|
|
|
|
reftest.killNamedProc('xpcshell')
|
|
|
|
|
2011-10-19 13:35:05 +04:00
|
|
|
# Start the webserver
|
2012-06-13 22:20:43 +04:00
|
|
|
retVal = reftest.startWebServer(options)
|
|
|
|
if retVal:
|
|
|
|
return retVal
|
2010-11-05 03:01:13 +03:00
|
|
|
|
2018-05-18 01:19:02 +03:00
|
|
|
if options.printDeviceInfo and not options.verify:
|
2015-10-15 00:20:20 +03:00
|
|
|
reftest.printDeviceInfo()
|
2012-07-26 04:45:36 +04:00
|
|
|
|
2012-10-24 21:34:33 +04:00
|
|
|
retVal = 0
|
2011-09-26 15:41:19 +04:00
|
|
|
try:
|
2017-10-17 17:00:52 +03:00
|
|
|
if options.verify:
|
|
|
|
retVal = reftest.verifyTests(options.tests, options)
|
|
|
|
else:
|
|
|
|
retVal = reftest.runTests(options.tests, options)
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2019-09-10 22:15:30 +03:00
|
|
|
print("Automation Error: Exception caught while running tests")
|
2012-11-05 17:03:54 +04:00
|
|
|
traceback.print_exc()
|
2012-10-24 21:34:33 +04:00
|
|
|
retVal = 1
|
2011-09-26 15:41:19 +04:00
|
|
|
|
2010-06-24 13:32:01 +04:00
|
|
|
reftest.stopWebServer(options)
|
2013-06-25 04:15:40 +04:00
|
|
|
|
2018-05-18 01:19:02 +03:00
|
|
|
if options.printDeviceInfo and not options.verify:
|
2019-05-16 01:48:26 +03:00
|
|
|
reftest.printDeviceInfo(printLogcat=(retVal != 0))
|
2015-10-15 00:20:20 +03:00
|
|
|
|
|
|
|
return retVal
|
|
|
|
|
2012-10-24 21:34:33 +04:00
|
|
|
|
2016-09-13 16:26:09 +03:00
|
|
|
if __name__ == "__main__":
|
2015-10-15 00:20:20 +03:00
|
|
|
parser = reftestcommandline.RemoteArgumentsParser()
|
|
|
|
options = parser.parse_args()
|
2016-09-13 16:26:09 +03:00
|
|
|
sys.exit(run_test_harness(parser, options))
|