Auto merge of #11604 - talklittle:mach_test_wpt_paths_10883, r=jdm

Mach re-dispatch test-wpt and test-css based on path

<!-- Please describe your changes on the following line: -->
Print a warning and dispatch to the correct test suite, when non-WPT test paths are given to `mach test-wpt` or non-CSS paths to `mach test-css`

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #10883 (github issue number if applicable).

<!-- Either: -->
- [X] These changes do not require tests because improving mach test script itself

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11604)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-14 07:42:08 -07:00 committed by GitHub
commit 84fbd8946f

View file

@ -14,6 +14,7 @@ import re
import sys import sys
import os import os
import os.path as path import os.path as path
import copy
from collections import OrderedDict from collections import OrderedDict
from time import time from time import time
@ -35,6 +36,26 @@ PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests") WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests")
SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests")
TEST_SUITES = OrderedDict([
("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False},
"include_arg": "include"}),
("wpt", {"kwargs": {"release": False},
"paths": [path.abspath(WEB_PLATFORM_TESTS_PATH),
path.abspath(SERVO_TESTS_PATH)],
"include_arg": "include"}),
("css", {"kwargs": {"release": False},
"paths": [path.abspath(path.join("tests", "wpt", "css-tests"))],
"include_arg": "include"}),
("unit", {"kwargs": {},
"paths": [path.abspath(path.join("tests", "unit"))],
"include_arg": "test_name"}),
("compiletest", {"kwargs": {"release": False},
"paths": [path.abspath(path.join("tests", "compiletest"))],
"include_arg": "test_name"})
])
TEST_SUITES_BY_PREFIX = {path: k for k, v in TEST_SUITES.iteritems() if "paths" in v for path in v["paths"]}
def create_parser_wpt(): def create_parser_wpt():
parser = wptcommandline.create_parser() parser = wptcommandline.create_parser()
@ -79,25 +100,12 @@ class MachCommands(CommandBase):
help="Run all test suites") help="Run all test suites")
def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, tidy_all=False, def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, tidy_all=False,
no_progress=False, self_test=False, all_suites=False): no_progress=False, self_test=False, all_suites=False):
suites = OrderedDict([ suites = copy.deepcopy(TEST_SUITES)
("tidy", {"kwargs": {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test}, suites["tidy"]["kwargs"] = {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test}
"include_arg": "include"}), suites["wpt"]["kwargs"] = {"release": release}
("wpt", {"kwargs": {"release": release}, suites["css"]["kwargs"] = {"release": release}
"paths": [path.abspath(path.join("tests", "wpt", "web-platform-tests")), suites["unit"]["kwargs"] = {}
path.abspath(path.join("tests", "wpt", "mozilla"))], suites["compiletest"]["kwargs"] = {"release": release}
"include_arg": "include"}),
("css", {"kwargs": {"release": release},
"paths": [path.abspath(path.join("tests", "wpt", "css-tests"))],
"include_arg": "include"}),
("unit", {"kwargs": {},
"paths": [path.abspath(path.join("tests", "unit"))],
"include_arg": "test_name"}),
("compiletest", {"kwargs": {"release": release},
"paths": [path.abspath(path.join("tests", "compiletest"))],
"include_arg": "test_name"})
])
suites_by_prefix = {path: k for k, v in suites.iteritems() if "paths" in v for path in v["paths"]}
selected_suites = OrderedDict() selected_suites = OrderedDict()
@ -115,16 +123,14 @@ class MachCommands(CommandBase):
if arg in suites and arg not in selected_suites: if arg in suites and arg not in selected_suites:
selected_suites[arg] = [] selected_suites[arg] = []
found = True found = True
else:
elif os.path.exists(path.abspath(arg)): suite = self.suite_for_path(arg)
abs_path = path.abspath(arg) if suite is not None:
for prefix, suite in suites_by_prefix.iteritems(): if suite not in selected_suites:
if abs_path.startswith(prefix): selected_suites[suite] = []
if suite not in selected_suites: selected_suites[suite].append(arg)
selected_suites[suite] = [] found = True
selected_suites[suite].append(arg) break
found = True
break
if not found: if not found:
print("%s is not a valid test path or suite name" % arg) print("%s is not a valid test path or suite name" % arg)
@ -143,6 +149,15 @@ class MachCommands(CommandBase):
print("Tests completed in %0.2fs" % elapsed) print("Tests completed in %0.2fs" % elapsed)
# Helper to determine which test suite owns the path
def suite_for_path(self, path_arg):
if os.path.exists(path.abspath(path_arg)):
abs_path = path.abspath(path_arg)
for prefix, suite in TEST_SUITES_BY_PREFIX.iteritems():
if abs_path.startswith(prefix):
return suite
return None
@Command('test-unit', @Command('test-unit',
description='Run unit tests', description='Run unit tests',
category='testing') category='testing')
@ -322,11 +337,32 @@ class MachCommands(CommandBase):
parser=create_parser_wpt) parser=create_parser_wpt)
def test_wpt(self, **kwargs): def test_wpt(self, **kwargs):
self.ensure_bootstrapped() self.ensure_bootstrapped()
return self.run_test_list_or_dispatch(kwargs["test_list"], "wpt", self._test_wpt, **kwargs)
def _test_wpt(self, **kwargs):
hosts_file_path = path.join(self.context.topdir, 'tests', 'wpt', 'hosts') hosts_file_path = path.join(self.context.topdir, 'tests', 'wpt', 'hosts')
os.environ["hosts_file_path"] = hosts_file_path os.environ["hosts_file_path"] = hosts_file_path
run_file = path.abspath(path.join(self.context.topdir, "tests", "wpt", "run_wpt.py")) run_file = path.abspath(path.join(self.context.topdir, "tests", "wpt", "run_wpt.py"))
return self.wptrunner(run_file, **kwargs) return self.wptrunner(run_file, **kwargs)
# Helper to ensure all specified paths are handled, otherwise dispatch to appropriate test suite.
def run_test_list_or_dispatch(self, requested_paths, correct_suite, correct_function, **kwargs):
if not requested_paths:
return correct_function(**kwargs)
else:
# Paths specified on command line. Ensure they can be handled, re-dispatch otherwise.
all_handled = True
for test_path in requested_paths:
suite = self.suite_for_path(test_path)
if correct_suite != suite:
all_handled = False
print("Warning: %s is not a %s test. Delegating to test-%s." % (test_path, correct_suite, suite))
if all_handled:
return correct_function(**kwargs)
else:
# Dispatch each test to the correct suite via test()
Registrar.dispatch("test", context=self.context, params=requested_paths)
# Helper for test_css and test_wpt: # Helper for test_css and test_wpt:
def wptrunner(self, run_file, **kwargs): def wptrunner(self, run_file, **kwargs):
os.environ["RUST_BACKTRACE"] = "1" os.environ["RUST_BACKTRACE"] = "1"
@ -413,6 +449,9 @@ class MachCommands(CommandBase):
parser=create_parser_wpt) parser=create_parser_wpt)
def test_css(self, **kwargs): def test_css(self, **kwargs):
self.ensure_bootstrapped() self.ensure_bootstrapped()
return self.run_test_list_or_dispatch(kwargs["test_list"], "css", self._test_css, **kwargs)
def _test_css(self, **kwargs):
run_file = path.abspath(path.join("tests", "wpt", "run_css.py")) run_file = path.abspath(path.join("tests", "wpt", "run_css.py"))
return self.wptrunner(run_file, **kwargs) return self.wptrunner(run_file, **kwargs)