2012-09-26 16:43:53 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
2012-10-10 18:08:09 +00:00
|
|
|
# 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/.
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2012-10-10 18:08:09 +00:00
|
|
|
# Integrates the xpcshell test runner with mach.
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2015-06-22 00:39:09 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2014-10-22 19:53:42 +00:00
|
|
|
import argparse
|
2012-10-10 18:08:09 +00:00
|
|
|
import os
|
2013-08-21 16:26:46 +00:00
|
|
|
import shutil
|
2012-11-14 18:05:18 +00:00
|
|
|
import sys
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2014-10-22 19:53:42 +00:00
|
|
|
from mozlog import structured
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2012-11-07 00:57:41 +00:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MozbuildObject,
|
2013-12-14 04:20:39 +00:00
|
|
|
MachCommandConditions as conditions,
|
2012-11-07 00:57:41 +00:00
|
|
|
)
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2012-11-07 00:57:41 +00:00
|
|
|
from mach.decorators import (
|
2012-10-10 18:08:09 +00:00
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
from xpcshellcommandline import parser_desktop, parser_remote, parser_b2g
|
2014-10-22 19:53:42 +00:00
|
|
|
|
2014-03-11 14:08:25 +00:00
|
|
|
ADB_NOT_FOUND = '''
|
|
|
|
The %s command requires the adb binary to be on your path.
|
|
|
|
|
|
|
|
If you have a B2G build, this can be found in
|
|
|
|
'%s/out/host/<platform>/bin'.
|
|
|
|
'''.lstrip()
|
|
|
|
|
2014-04-30 16:57:39 +00:00
|
|
|
BUSYBOX_URLS = {
|
|
|
|
'arm': 'http://www.busybox.net/downloads/binaries/latest/busybox-armv7l',
|
|
|
|
'x86': 'http://www.busybox.net/downloads/binaries/latest/busybox-i686'
|
|
|
|
}
|
2014-03-11 14:08:25 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
2012-09-26 16:43:53 +00:00
|
|
|
|
2012-11-14 18:05:18 +00:00
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
unicode_type = unicode
|
|
|
|
else:
|
|
|
|
unicode_type = str
|
|
|
|
|
2012-11-28 20:19:32 +00:00
|
|
|
# This should probably be consolidated with similar classes in other test
|
|
|
|
# runners.
|
|
|
|
class InvalidTestPathError(Exception):
|
|
|
|
"""Exception raised when the test path is not valid."""
|
|
|
|
|
|
|
|
|
2012-09-26 16:43:53 +00:00
|
|
|
class XPCShellRunner(MozbuildObject):
|
|
|
|
"""Run xpcshell tests."""
|
2012-10-31 17:29:26 +00:00
|
|
|
def run_suite(self, **kwargs):
|
2015-08-27 12:05:50 +00:00
|
|
|
return self._run_xpcshell_harness(**kwargs)
|
|
|
|
|
|
|
|
def run_test(self, **kwargs):
|
2012-09-26 16:43:53 +00:00
|
|
|
"""Runs an individual xpcshell test."""
|
2013-10-22 23:54:40 +00:00
|
|
|
|
2012-12-20 08:43:19 +00:00
|
|
|
# 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)
|
2012-10-31 17:29:26 +00:00
|
|
|
|
2015-07-29 15:50:16 +00:00
|
|
|
src_build_path = os.path.join(self.topsrcdir, 'mozilla', 'build')
|
|
|
|
if os.path.isdir(src_build_path):
|
|
|
|
sys.path.append(src_build_path)
|
2015-01-30 15:54:00 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
self.run_suite(**kwargs)
|
2012-09-26 16:43:53 +00:00
|
|
|
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
def _run_xpcshell_harness(self, **kwargs):
|
2012-09-26 16:43:53 +00:00
|
|
|
# Obtain a reference to the xpcshell test runner.
|
|
|
|
import runxpcshelltests
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
log = kwargs.pop("log")
|
|
|
|
|
2014-10-22 19:53:42 +00:00
|
|
|
xpcshell = runxpcshelltests.XPCShellTests(log=log)
|
2012-09-26 16:43:53 +00:00
|
|
|
self.log_manager.enable_unstructured()
|
|
|
|
|
|
|
|
tests_dir = os.path.join(self.topobjdir, '_tests', 'xpcshell')
|
2014-02-06 02:51:00 +00:00
|
|
|
# We want output from the test to be written immediately if we are only
|
|
|
|
# running a single test.
|
2015-09-29 19:59:55 +00:00
|
|
|
single_test = (len(kwargs["testPaths"]) == 1 and
|
|
|
|
os.path.isfile(kwargs["testPaths"][0]) or
|
|
|
|
kwargs["manifest"] and
|
|
|
|
(len(kwargs["manifest"].test_paths()) == 1))
|
|
|
|
|
|
|
|
if single_test:
|
|
|
|
kwargs["verbose"] = True
|
2015-08-27 12:05:50 +00:00
|
|
|
|
|
|
|
if kwargs["xpcshell"] is None:
|
|
|
|
kwargs["xpcshell"] = self.get_binary_path('xpcshell')
|
|
|
|
|
|
|
|
if kwargs["mozInfo"] is None:
|
|
|
|
kwargs["mozInfo"] = os.path.join(self.topobjdir, 'mozinfo.json')
|
|
|
|
|
|
|
|
if kwargs["symbolsPath"] is None:
|
|
|
|
kwargs["symbolsPath"] = os.path.join(self.distdir, 'crashreporter-symbols')
|
|
|
|
|
|
|
|
if kwargs["logfiles"] is None:
|
|
|
|
kwargs["logfiles"] = False
|
|
|
|
|
|
|
|
if kwargs["profileName"] is None:
|
|
|
|
kwargs["profileName"] = "firefox"
|
|
|
|
|
|
|
|
if kwargs["pluginsPath"] is None:
|
|
|
|
kwargs['pluginsPath'] = os.path.join(self.distdir, 'plugins')
|
|
|
|
|
2015-09-18 14:00:40 +00:00
|
|
|
if kwargs["testingModulesDir"] is None:
|
|
|
|
kwargs["testingModulesDir"] = os.path.join(self.topobjdir, '_tests/modules')
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
if kwargs["utility_path"] is None:
|
|
|
|
kwargs['utility_path'] = self.bindir
|
|
|
|
|
|
|
|
if kwargs["manifest"] is None:
|
|
|
|
kwargs["manifest"] = os.path.join(tests_dir, "xpcshell.ini")
|
|
|
|
|
|
|
|
if kwargs["failure_manifest"] is None:
|
|
|
|
kwargs["failure_manifest"] = os.path.join(self.statedir, 'xpcshell.failures.ini')
|
2013-08-21 16:26:46 +00:00
|
|
|
|
2012-11-14 18:05:18 +00:00
|
|
|
# Python through 2.7.2 has issues with unicode in some of the
|
|
|
|
# arguments. Work around that.
|
|
|
|
filtered_args = {}
|
2015-08-27 12:05:50 +00:00
|
|
|
for k, v in kwargs.iteritems():
|
2012-11-14 18:05:18 +00:00
|
|
|
if isinstance(v, unicode_type):
|
|
|
|
v = v.encode('utf-8')
|
|
|
|
|
|
|
|
if isinstance(k, unicode_type):
|
|
|
|
k = k.encode('utf-8')
|
|
|
|
|
|
|
|
filtered_args[k] = v
|
|
|
|
|
2012-12-05 23:42:11 +00:00
|
|
|
result = xpcshell.runTests(**filtered_args)
|
2012-09-26 16:43:53 +00:00
|
|
|
|
|
|
|
self.log_manager.disable_unstructured()
|
2012-10-10 18:08:09 +00:00
|
|
|
|
2013-08-20 23:07:33 +00:00
|
|
|
if not result and not xpcshell.sequential:
|
2013-08-15 22:22:35 +00:00
|
|
|
print("Tests were run in parallel. Try running with --sequential "
|
|
|
|
"to make sure the failures were not caused by this.")
|
2012-12-05 23:42:11 +00:00
|
|
|
return int(not result)
|
|
|
|
|
2013-12-14 04:20:39 +00:00
|
|
|
class AndroidXPCShellRunner(MozbuildObject):
|
|
|
|
"""Get specified DeviceManager"""
|
|
|
|
def get_devicemanager(self, devicemanager, ip, port, remote_test_root):
|
2015-01-12 21:33:43 +00:00
|
|
|
import mozdevice
|
2013-12-14 04:20:39 +00:00
|
|
|
dm = None
|
|
|
|
if devicemanager == "adb":
|
|
|
|
if ip:
|
2015-01-12 21:33:43 +00:00
|
|
|
dm = mozdevice.DroidADB(ip, port, packageName=None, deviceRoot=remote_test_root)
|
2013-12-14 04:20:39 +00:00
|
|
|
else:
|
2015-01-12 21:33:43 +00:00
|
|
|
dm = mozdevice.DroidADB(packageName=None, deviceRoot=remote_test_root)
|
2013-12-14 04:20:39 +00:00
|
|
|
else:
|
|
|
|
if ip:
|
2015-01-12 21:33:43 +00:00
|
|
|
dm = mozdevice.DroidSUT(ip, port, deviceRoot=remote_test_root)
|
2013-12-14 04:20:39 +00:00
|
|
|
else:
|
|
|
|
raise Exception("You must provide a device IP to connect to via the --ip option")
|
|
|
|
return dm
|
|
|
|
|
|
|
|
"""Run Android xpcshell tests."""
|
2015-08-27 12:05:50 +00:00
|
|
|
def run_test(self, **kwargs):
|
2013-12-14 04:20:39 +00:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
import remotexpcshelltests
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
dm = self.get_devicemanager(kwargs["dm_trans"], kwargs["deviceIP"], kwargs["devicePort"],
|
|
|
|
kwargs["remoteTestRoot"])
|
|
|
|
|
|
|
|
log = kwargs.pop("log")
|
|
|
|
self.log_manager.enable_unstructured()
|
|
|
|
|
|
|
|
if kwargs["xpcshell"] is None:
|
|
|
|
kwargs["xpcshell"] = "xpcshell"
|
|
|
|
|
|
|
|
if not kwargs["objdir"]:
|
|
|
|
kwargs["objdir"] = self.topobjdir
|
|
|
|
|
|
|
|
if not kwargs["localLib"]:
|
|
|
|
kwargs["localLib"] = os.path.join(self.topobjdir, 'dist/fennec')
|
|
|
|
|
|
|
|
if not kwargs["localBin"]:
|
|
|
|
kwargs["localBin"] = os.path.join(self.topobjdir, 'dist/bin')
|
|
|
|
|
|
|
|
if not kwargs["testingModulesDir"]:
|
|
|
|
kwargs["testingModulesDir"] = os.path.join(self.topobjdir, '_tests/modules')
|
|
|
|
|
|
|
|
if not kwargs["mozInfo"]:
|
|
|
|
kwargs["mozInfo"] = os.path.join(self.topobjdir, 'mozinfo.json')
|
|
|
|
|
|
|
|
if not kwargs["manifest"]:
|
|
|
|
kwargs["manifest"] = os.path.join(self.topobjdir, '_tests/xpcshell/xpcshell.ini')
|
|
|
|
|
|
|
|
if not kwargs["symbolsPath"]:
|
|
|
|
kwargs["symbolsPath"] = os.path.join(self.distdir, 'crashreporter-symbols')
|
|
|
|
|
|
|
|
if not kwargs["localAPK"]:
|
|
|
|
for file_name in os.listdir(os.path.join(kwargs["objdir"], "dist")):
|
|
|
|
if file_name.endswith(".apk") and file_name.startswith("fennec"):
|
|
|
|
kwargs["localAPK"] = os.path.join(kwargs["objdir"], "dist", file_name)
|
|
|
|
print ("using APK: %s" % kwargs["localAPK"])
|
2013-12-14 04:20:39 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise Exception("You must specify an APK")
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
options = argparse.Namespace(**kwargs)
|
|
|
|
xpcshell = remotexpcshelltests.XPCShellRemote(dm, options, log)
|
2013-12-14 04:20:39 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
result = xpcshell.runTests(testClass=remotexpcshelltests.RemoteXPCShellTestThread,
|
|
|
|
mobileArgs=xpcshell.mobileArgs,
|
|
|
|
**vars(options))
|
2013-12-14 04:20:39 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
self.log_manager.disable_unstructured()
|
2013-12-14 04:20:39 +00:00
|
|
|
|
|
|
|
return int(not result)
|
2012-10-10 18:08:09 +00:00
|
|
|
|
2014-03-11 14:08:25 +00:00
|
|
|
class B2GXPCShellRunner(MozbuildObject):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
MozbuildObject.__init__(self, *args, **kwargs)
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
build_path = os.path.join(self.topsrcdir, 'build')
|
|
|
|
if build_path not in sys.path:
|
|
|
|
sys.path.append(build_path)
|
|
|
|
|
|
|
|
self.tests_dir = os.path.join(self.topobjdir, '_tests')
|
|
|
|
self.xpcshell_dir = os.path.join(self.tests_dir, 'xpcshell')
|
|
|
|
self.bin_dir = os.path.join(self.distdir, 'bin')
|
|
|
|
|
2014-04-30 16:57:39 +00:00
|
|
|
def _download_busybox(self, b2g_home, emulator):
|
2015-06-25 19:12:15 +00:00
|
|
|
import urllib2
|
|
|
|
|
2014-04-30 16:57:39 +00:00
|
|
|
target_device = 'generic'
|
|
|
|
if emulator == 'x86':
|
|
|
|
target_device = 'generic_x86'
|
|
|
|
system_bin = os.path.join(b2g_home, 'out', 'target', 'product', target_device, 'system', 'bin')
|
2014-03-11 14:08:25 +00:00
|
|
|
busybox_path = os.path.join(system_bin, 'busybox')
|
|
|
|
|
|
|
|
if os.path.isfile(busybox_path):
|
|
|
|
return busybox_path
|
|
|
|
|
|
|
|
if not os.path.isdir(system_bin):
|
|
|
|
os.makedirs(system_bin)
|
|
|
|
|
|
|
|
try:
|
2014-04-30 16:57:39 +00:00
|
|
|
data = urllib2.urlopen(BUSYBOX_URLS[emulator])
|
2014-03-11 14:08:25 +00:00
|
|
|
except urllib2.URLError:
|
|
|
|
print('There was a problem downloading busybox. Proceeding without it,' \
|
|
|
|
'initial setup will be slow.')
|
|
|
|
return
|
|
|
|
|
|
|
|
with open(busybox_path, 'wb') as f:
|
|
|
|
f.write(data.read())
|
|
|
|
return busybox_path
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
def run_test(self, **kwargs):
|
2014-03-11 14:08:25 +00:00
|
|
|
try:
|
|
|
|
import which
|
|
|
|
which.which('adb')
|
|
|
|
except which.WhichError:
|
|
|
|
# TODO Find adb automatically if it isn't on the path
|
2015-08-27 12:05:50 +00:00
|
|
|
print(ADB_NOT_FOUND % ('mochitest-remote', kwargs["b2g_home"]))
|
2014-03-11 14:08:25 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
import runtestsb2g
|
|
|
|
|
|
|
|
log = kwargs.pop("log")
|
|
|
|
self.log_manager.enable_unstructured()
|
2014-06-18 18:17:50 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
if kwargs["xpcshell"] is None:
|
|
|
|
kwargs["xpcshell"] = "xpcshell"
|
|
|
|
if kwargs["b2g_path"] is None:
|
|
|
|
kwargs["b2g_path"] = kwargs["b2g_home"]
|
|
|
|
if kwargs["busybox"] is None:
|
|
|
|
kwargs["busybox"] = os.environ.get('BUSYBOX')
|
|
|
|
if kwargs["busybox"] is None:
|
|
|
|
kwargs["busybox"] = self._download_busybox(kwargs["b2g_home"], kwargs["emulator"])
|
|
|
|
|
|
|
|
if kwargs["localLib"] is None:
|
|
|
|
kwargs["localLib"] = self.bin_dir
|
|
|
|
if kwargs["localBin"] is None:
|
|
|
|
kwargs["localBin"] = self.bin_dir
|
|
|
|
if kwargs["logdir"] is None:
|
|
|
|
kwargs["logdir"] = self.xpcshell_dir
|
|
|
|
if kwargs["manifest"] is None:
|
|
|
|
kwargs["manifest"] = os.path.join(self.xpcshell_dir, 'xpcshell.ini')
|
|
|
|
if kwargs["mozInfo"] is None:
|
|
|
|
kwargs["mozInfo"] = os.path.join(self.topobjdir, 'mozinfo.json')
|
|
|
|
if kwargs["objdir"] is None:
|
|
|
|
kwargs["objdir"] = self.topobjdir
|
|
|
|
if kwargs["symbolsPath"] is None:
|
|
|
|
kwargs["symbolsPath"] = os.path.join(self.distdir, 'crashreporter-symbols')
|
|
|
|
if kwargs["testingModulesDir"] is None:
|
|
|
|
kwargs["testingModulesDir"] = os.path.join(self.tests_dir, 'modules')
|
|
|
|
if kwargs["use_device_libs"] is None:
|
|
|
|
kwargs["use_device_libs"] = True
|
|
|
|
|
|
|
|
if kwargs["device_name"].startswith('emulator') and 'x86' in kwargs["device_name"]:
|
|
|
|
kwargs["emulator"] = 'x86'
|
|
|
|
|
|
|
|
parser = parser_b2g()
|
|
|
|
options = argparse.Namespace(**kwargs)
|
|
|
|
rv = runtestsb2g.run_remote_xpcshell(parser, options, log)
|
2014-03-24 23:19:57 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
self.log_manager.disable_unstructured()
|
|
|
|
return rv
|
2014-03-11 14:08:25 +00:00
|
|
|
|
2015-08-27 12:05:50 +00:00
|
|
|
def get_parser():
|
|
|
|
build_obj = MozbuildObject.from_environment(cwd=here)
|
|
|
|
if conditions.is_android(build_obj):
|
|
|
|
return parser_remote()
|
|
|
|
elif conditions.is_b2g(build_obj):
|
|
|
|
return parser_b2g()
|
|
|
|
else:
|
|
|
|
return parser_desktop()
|
2014-03-11 14:08:25 +00:00
|
|
|
|
2012-10-10 18:08:09 +00:00
|
|
|
@CommandProvider
|
2012-11-07 00:57:41 +00:00
|
|
|
class MachCommands(MachCommandBase):
|
2014-03-11 14:08:25 +00:00
|
|
|
def __init__(self, context):
|
|
|
|
MachCommandBase.__init__(self, context)
|
|
|
|
|
|
|
|
for attr in ('b2g_home', 'device_name'):
|
|
|
|
setattr(self, attr, getattr(context, attr, None))
|
|
|
|
|
2013-05-09 00:56:30 +00:00
|
|
|
@Command('xpcshell-test', category='testing',
|
2015-08-27 12:05:50 +00:00
|
|
|
description='Run XPCOM Shell tests (API direct unit testing)',
|
|
|
|
conditions=[lambda *args: True],
|
|
|
|
parser=get_parser)
|
2015-09-29 19:59:55 +00:00
|
|
|
def run_xpcshell_test(self, test_objects=None, **params):
|
2013-10-01 16:36:44 +00:00
|
|
|
from mozbuild.controller.building import BuildDriver
|
|
|
|
|
2015-09-29 19:59:55 +00:00
|
|
|
if test_objects is not None:
|
|
|
|
from manifestparser import TestManifest
|
|
|
|
m = TestManifest()
|
|
|
|
m.tests.extend(test_objects)
|
|
|
|
params['manifest'] = m
|
|
|
|
|
2012-11-02 17:32:40 +00:00
|
|
|
# We should probably have a utility function to ensure the tree is
|
|
|
|
# ready to run tests. Until then, we just create the state dir (in
|
|
|
|
# case the tree wasn't built with mach).
|
|
|
|
self._ensure_state_subdir_exists('.')
|
|
|
|
|
2013-10-01 16:36:44 +00:00
|
|
|
driver = self._spawn(BuildDriver)
|
|
|
|
driver.install_tests(remove=False)
|
|
|
|
|
2014-10-22 19:53:42 +00:00
|
|
|
params['log'] = structured.commandline.setup_logging("XPCShellTests",
|
|
|
|
params,
|
2015-06-05 09:37:15 +00:00
|
|
|
{"mach": sys.stdout},
|
|
|
|
{"verbose": True})
|
2014-10-22 19:53:42 +00:00
|
|
|
|
2013-12-14 04:20:39 +00:00
|
|
|
if conditions.is_android(self):
|
2015-09-01 21:07:53 +00:00
|
|
|
from mozrunner.devices.android_device import verify_android_device
|
|
|
|
verify_android_device(self)
|
2013-12-14 04:20:39 +00:00
|
|
|
xpcshell = self._spawn(AndroidXPCShellRunner)
|
2014-03-11 14:08:25 +00:00
|
|
|
elif conditions.is_b2g(self):
|
|
|
|
xpcshell = self._spawn(B2GXPCShellRunner)
|
|
|
|
params['b2g_home'] = self.b2g_home
|
2014-04-30 16:57:39 +00:00
|
|
|
params['device_name'] = self.device_name
|
2013-12-14 04:20:39 +00:00
|
|
|
else:
|
|
|
|
xpcshell = self._spawn(XPCShellRunner)
|
2013-10-22 23:54:40 +00:00
|
|
|
xpcshell.cwd = self._mach_context.cwd
|
2012-11-28 20:19:32 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
return xpcshell.run_test(**params)
|
|
|
|
except InvalidTestPathError as e:
|
|
|
|
print(e.message)
|
|
|
|
return 1
|