mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Make the test-wpt mach command support all the command line arguments of wptrunner.
Also remove the shell script and ensure that default options are set in a single location
This commit is contained in:
parent
0a7429f147
commit
2bde318d24
7 changed files with 162 additions and 77 deletions
|
@ -11,8 +11,11 @@ import sys
|
|||
SEARCH_PATHS = [
|
||||
"python/mach",
|
||||
"python/toml",
|
||||
"python/mozlog",
|
||||
"python/mozinfo",
|
||||
"python/mozdebug",
|
||||
"tests/wpt",
|
||||
"tests/wpt/harness",
|
||||
]
|
||||
|
||||
# Individual files providing mach commands.
|
||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
|||
import os
|
||||
import os.path as path
|
||||
import subprocess
|
||||
from distutils.spawn import find_executable
|
||||
from time import time
|
||||
|
||||
from mach.registrar import Registrar
|
||||
|
@ -15,8 +16,9 @@ from mach.decorators import (
|
|||
)
|
||||
|
||||
from servo.command_base import CommandBase
|
||||
from wptrunner import wptcommandline
|
||||
from update import updatecommandline
|
||||
import tidy
|
||||
import multiprocessing
|
||||
|
||||
|
||||
@CommandProvider
|
||||
|
@ -215,32 +217,65 @@ class MachCommands(CommandBase):
|
|||
|
||||
@Command('test-wpt',
|
||||
description='Run the web platform tests',
|
||||
category='testing')
|
||||
@CommandArgument(
|
||||
'--processes', default=None,
|
||||
help="Number of servo processes to spawn")
|
||||
@CommandArgument(
|
||||
"params", default=None, nargs='...',
|
||||
help="command-line arguments to be passed through to wpt/run.sh")
|
||||
def test_wpt(self, processes=None, params=None):
|
||||
category='testing',
|
||||
parser=wptcommandline.create_parser())
|
||||
@CommandArgument('--release', default=False, action="store_true",
|
||||
help="Run with a release build of servo")
|
||||
def test_wpt(self, **kwargs):
|
||||
self.ensure_bootstrapped()
|
||||
|
||||
if params is None:
|
||||
params = []
|
||||
else:
|
||||
# Allow the first argument to be a relative path from Servo's root
|
||||
# directory, converting it to `--include some/wpt/test.html`
|
||||
maybe_path = path.normpath(params[0])
|
||||
wpt_path = path.join('tests', 'wpt', 'web-platform-tests')
|
||||
|
||||
if path.exists(maybe_path) and wpt_path in maybe_path:
|
||||
params = ["--include",
|
||||
path.relpath(maybe_path, wpt_path)]
|
||||
|
||||
processes = str(multiprocessing.cpu_count()) if processes is None else processes
|
||||
params = params + ["--processes", processes]
|
||||
self.ensure_wpt_virtualenv()
|
||||
hosts_file_path = path.join('tests', 'wpt', 'hosts')
|
||||
|
||||
return subprocess.call(
|
||||
["bash", path.join("tests", "wpt", "run.sh")] + params,
|
||||
env=self.build_env(hosts_file_path=hosts_file_path))
|
||||
os.environ["hosts_file_path"] = hosts_file_path
|
||||
|
||||
run_file = path.abspath(path.join("tests", "wpt", "run_wpt.py"))
|
||||
run_globals = {"__file__": run_file}
|
||||
execfile(run_file, run_globals)
|
||||
return run_globals["run_tests"](**kwargs)
|
||||
|
||||
@Command('update-wpt',
|
||||
description='Update the web platform tests',
|
||||
category='testing',
|
||||
parser=updatecommandline.create_parser())
|
||||
def update_wpt(self, **kwargs):
|
||||
self.ensure_bootstrapped()
|
||||
self.ensure_wpt_virtualenv()
|
||||
run_file = path.abspath(path.join("tests", "wpt", "update.py"))
|
||||
run_globals = {"__file__": run_file}
|
||||
execfile(run_file, run_globals)
|
||||
return run_globals["update_tests"](**kwargs)
|
||||
|
||||
|
||||
def ensure_wpt_virtualenv(self):
|
||||
virtualenv_path = path.join("tests", "wpt", "_virtualenv")
|
||||
python = self.get_exec("python2", "python")
|
||||
|
||||
if not os.path.exists(virtualenv_path):
|
||||
virtualenv = self.get_exec("virtualenv2", "virtualenv")
|
||||
subprocess.check_call([virtualenv, "-p", python, virtualenv_path])
|
||||
|
||||
activate_path = path.join(virtualenv_path, "bin", "activate_this.py")
|
||||
|
||||
execfile(activate_path, dict(__file__=activate_path))
|
||||
|
||||
try:
|
||||
import wptrunner
|
||||
except ImportError:
|
||||
subprocess.check_call(["pip", "install", "-r",
|
||||
path.join("tests", "wpt", "harness", "requirements.txt")])
|
||||
subprocess.check_call(["pip", "install", "-r",
|
||||
path.join("tests", "wpt", "harness", "requirements_servo.txt")])
|
||||
|
||||
# This is an unfortunate hack. Because mozlog gets imported by wptcommandline
|
||||
# before the virtualenv is initalised it doesn't see the blessings module so we don't
|
||||
# get coloured output. Setting the blessings global explicitly fixes that.
|
||||
from mozlog.structured.formatters import machformatter
|
||||
import blessings
|
||||
machformatter.blessings = blessings
|
||||
|
||||
def get_exec(self, name, default=None):
|
||||
path = find_executable(name)
|
||||
if not path:
|
||||
return default
|
||||
|
||||
return path
|
||||
|
|
|
@ -4,7 +4,7 @@ servo =
|
|||
[web-platform-tests]
|
||||
remote_url = https://github.com/w3c/web-platform-tests.git
|
||||
branch = master
|
||||
sync_path = web-platform-tests
|
||||
sync_path = sync
|
||||
|
||||
[paths]
|
||||
run-info = .
|
||||
|
|
|
@ -2,34 +2,54 @@
|
|||
# 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/.
|
||||
|
||||
import sys, os, argparse
|
||||
import argparse
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
here = os.path.split(__file__)[0]
|
||||
servo_root = os.path.abspath(os.path.join(here, "..", ".."))
|
||||
|
||||
def wptsubdir(*args):
|
||||
def wpt_path(*args):
|
||||
return os.path.join(here, *args)
|
||||
|
||||
def servo_path(*args):
|
||||
return os.path.join(servo_root, *args)
|
||||
|
||||
# Imports
|
||||
sys.path.append(wptsubdir("web-platform-tests"))
|
||||
sys.path.append(wpt_path("harness"))
|
||||
from wptrunner import wptrunner, wptcommandline
|
||||
|
||||
def run_tests(**kwargs):
|
||||
wptrunner.setup_logging(kwargs, {"raw": sys.stdout})
|
||||
def run_tests(paths=None, **kwargs):
|
||||
if paths is None:
|
||||
paths = {}
|
||||
set_defaults(paths, kwargs)
|
||||
wptrunner.setup_logging(kwargs, {"mach": sys.stdout})
|
||||
return wptrunner.run_tests(**kwargs)
|
||||
|
||||
def set_defaults(args):
|
||||
args.include_manifest = args.include_manifest if args.include_manifest else wptsubdir("include.ini")
|
||||
args.product = "servo"
|
||||
rv = vars(args)
|
||||
wptcommandline.check_args(rv)
|
||||
return rv
|
||||
def set_defaults(paths, kwargs):
|
||||
if kwargs["product"] is None:
|
||||
kwargs["product"] = "servo"
|
||||
|
||||
def main():
|
||||
if kwargs["config"] is None and "config" in paths:
|
||||
kwargs["config"] = paths["config"]
|
||||
|
||||
if kwargs["include_manifest"] is None and "include_manifest" in paths:
|
||||
kwargs["include_manifest"] = paths["include_manifest"]
|
||||
|
||||
if kwargs["binary"] is None:
|
||||
bin_dir = "release" if kwargs["release"] else "debug"
|
||||
bin_path = servo_path("components", "servo", "target", bin_dir, "servo")
|
||||
|
||||
kwargs["binary"] = bin_path
|
||||
|
||||
if kwargs["processes"] is None:
|
||||
kwargs["processes"] = multiprocessing.cpu_count()
|
||||
|
||||
wptcommandline.check_args(kwargs)
|
||||
|
||||
def main(paths=None):
|
||||
parser = wptcommandline.create_parser()
|
||||
args = parser.parse_args()
|
||||
kwargs = set_defaults(args)
|
||||
return run_tests(**kwargs)
|
||||
kwargs = vars(parser.parse_args())
|
||||
return run_tests(paths, **kwargs)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0 if main() else 1)
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
# 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/.
|
||||
|
||||
set -e
|
||||
|
||||
wpt_root=$(dirname $0)
|
||||
binary_dir=$wpt_root/../../components/servo/target
|
||||
if [[ $1 == "--release" ]]; then
|
||||
binary_dir=$binary_dir/release
|
||||
shift
|
||||
else
|
||||
binary_dir=$binary_dir/debug
|
||||
fi
|
||||
|
||||
PYTHON=$(which python2 2> /dev/null || echo python)
|
||||
VIRTUALENV=$(which virtualenv2 2> /dev/null || echo virtualenv)
|
||||
|
||||
test -d $wpt_root/_virtualenv || $VIRTUALENV $wpt_root/_virtualenv -p $PYTHON
|
||||
test -d $wpt_root/metadata || mkdir -p $wpt_root/metadata
|
||||
test -d $wpt_root/prefs || mkdir -p $wpt_root/prefs
|
||||
source $wpt_root/_virtualenv/bin/activate
|
||||
if [[ $* == *--update-manifest* ]]; then
|
||||
(python -c "import html5lib" &>/dev/null) || pip install html5lib
|
||||
fi
|
||||
(python -c "import wptrunner" &>/dev/null) || pip install 'wptrunner==1.14'
|
||||
|
||||
python $wpt_root/run.py \
|
||||
--config $wpt_root/config.ini \
|
||||
--binary $binary_dir/servo \
|
||||
--log-mach - \
|
||||
"$@"
|
19
tests/wpt/run_wpt.py
Normal file
19
tests/wpt/run_wpt.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# 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/.
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
import run
|
||||
|
||||
paths = {"include_manifest": run.wpt_path("include.ini"),
|
||||
"config": run.wpt_path("config.ini")}
|
||||
|
||||
def run_tests(**kwargs):
|
||||
return run.run_tests(paths=paths, **kwargs)
|
||||
|
||||
def main():
|
||||
return run.main(paths)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0 if main() else 1)
|
40
tests/wpt/update.py
Normal file
40
tests/wpt/update.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
# 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/.
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
here = os.path.split(__file__)[0]
|
||||
|
||||
def wpt_path(*args):
|
||||
return os.path.join(here, *args)
|
||||
|
||||
# Imports
|
||||
from update import updatecommandline
|
||||
|
||||
def update_tests(**kwargs):
|
||||
import update
|
||||
|
||||
set_defaults(kwargs)
|
||||
logger = update.setup_logging(kwargs, {"mach": sys.stdout})
|
||||
|
||||
rv = update.run_update(logger, **kwargs)
|
||||
return 0 if rv is update.exit_unclean else 1
|
||||
|
||||
def set_defaults(kwargs):
|
||||
if kwargs["config"] is None:
|
||||
kwargs["config"] = wpt_path('config.ini')
|
||||
updatecommandline.check_args(kwargs)
|
||||
|
||||
def main():
|
||||
parser = wptcommandline.create_parser()
|
||||
kwargs = vars(parser.parse_args())
|
||||
return update_tests(**kwargs)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0 if main() else 1)
|
Loading…
Add table
Add a link
Reference in a new issue