Modified: trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py (137942 => 137943)
--- trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py 2012-12-17 21:50:27 UTC (rev 137942)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py 2012-12-17 21:55:27 UTC (rev 137943)
@@ -37,7 +37,6 @@
from webkitpy.common.host import Host
from webkitpy.layout_tests.controllers.manager import Manager
-from webkitpy.layout_tests.models import test_expectations
from webkitpy.layout_tests.port import configuration_options, platform_options
from webkitpy.layout_tests.views import buildbot_results
from webkitpy.layout_tests.views import printing
@@ -54,79 +53,46 @@
EXCEPTIONAL_EXIT_STATUS = 254
-def run(port, options, args, logging_stream):
- try:
- printer = printing.Printer(port, options, logging_stream, logger=logging.getLogger())
+def main(argv, stdout, stderr):
+ options, args = parse_args(argv)
- _set_up_derived_options(port, options)
- manager = Manager(port, options, printer)
- printer.print_config(port.results_directory())
+ if options.platform and 'test' in options.platform:
+ # It's a bit lame to import mocks into real code, but this allows the user
+ # to run tests against the test platform interactively, which is useful for
+ # debugging test failures.
+ from webkitpy.common.host_mock import MockHost
+ host = MockHost()
+ else:
+ host = Host()
- run_details = manager.run(args)
- _log.debug("Testing completed, Exit status: %d" % run_details.exit_code)
- return run_details
- finally:
- printer.cleanup()
+ if options.lint_test_files:
+ from webkitpy.layout_tests.lint_test_expectations import lint
+ return lint(host, options, stderr)
+ try:
+ port = host.port_factory.get(options.platform, options)
+ except NotImplementedError, e:
+ # FIXME: is this the best way to handle unsupported port names?
+ print >> stderr, str(e)
+ return EXCEPTIONAL_EXIT_STATUS
-def _set_up_derived_options(port, options):
- """Sets the options values that depend on other options values."""
- if not options.child_processes:
- options.child_processes = os.environ.get("WEBKIT_TEST_CHILD_PROCESSES",
- str(port.default_child_processes()))
- if not options.max_locked_shards:
- options.max_locked_shards = int(os.environ.get("WEBKIT_TEST_MAX_LOCKED_SHARDS",
- str(port.default_max_locked_shards())))
+ try:
+ run_details = run(port, options, args, stderr)
+ if run_details.exit_code != -1:
+ bot_printer = buildbot_results.BuildBotPrinter(stdout, options.debug_rwt_logging)
+ bot_printer.print_results(run_details)
- if not options.configuration:
- options.configuration = port.default_configuration()
+ return run_details.exit_code
+ except KeyboardInterrupt:
+ return INTERRUPTED_EXIT_STATUS
+ except BaseException as e:
+ if isinstance(e, Exception):
+ print >> stderr, '\n%s raised: %s' % (e.__class__.__name__, str(e))
+ traceback.print_exc(file=stderr)
+ return EXCEPTIONAL_EXIT_STATUS
- if options.pixel_tests is None:
- options.pixel_tests = port.default_pixel_tests()
- if not options.time_out_ms:
- options.time_out_ms = str(port.default_timeout_ms())
-
- options.slow_time_out_ms = str(5 * int(options.time_out_ms))
-
- if options.additional_platform_directory:
- additional_platform_directories = []
- for path in options.additional_platform_directory:
- additional_platform_directories.append(port.host.filesystem.abspath(path))
- options.additional_platform_directory = additional_platform_directories
-
- if not options.http and options.skipped in ('ignore', 'only'):
- _log.warning("--force/--skipped=%s overrides --no-http." % (options.skipped))
- options.http = True
-
- if options.ignore_metrics and (options.new_baseline or options.reset_results):
- _log.warning("--ignore-metrics has no effect with --new-baselines or with --reset-results")
-
- if options.new_baseline:
- options.reset_results = True
- options.add_platform_exceptions = True
-
- if options.pixel_test_directories:
- options.pixel_tests = True
- varified_dirs = set()
- pixel_test_directories = options.pixel_test_directories
- for directory in pixel_test_directories:
- # FIXME: we should support specifying the directories all the ways we support it for additional
- # arguments specifying which tests and directories to run. We should also move the logic for that
- # to Port.
- filesystem = port.host.filesystem
- if not filesystem.isdir(filesystem.join(port.layout_tests_dir(), directory)):
- _log.warning("'%s' was passed to --pixel-test-directories, which doesn't seem to be a directory" % str(directory))
- else:
- varified_dirs.add(directory)
-
- options.pixel_test_directories = list(varified_dirs)
-
- if options.run_singly:
- options.verbose = True
-
-
-def parse_args(args=None):
+def parse_args(args):
option_group_definitions = []
option_group_definitions.append(("Platform options", platform_options()))
@@ -340,48 +306,79 @@
return option_parser.parse_args(args)
-def main(argv=None, stdout=sys.stdout, stderr=sys.stderr):
- options, args = parse_args(argv)
- if options.platform and 'test' in options.platform:
- # It's a bit lame to import mocks into real code, but this allows the user
- # to run tests against the test platform interactively, which is useful for
- # debugging test failures.
- from webkitpy.common.host_mock import MockHost
- host = MockHost()
- else:
- host = Host()
+def _set_up_derived_options(port, options):
+ """Sets the options values that depend on other options values."""
+ if not options.child_processes:
+ options.child_processes = os.environ.get("WEBKIT_TEST_CHILD_PROCESSES",
+ str(port.default_child_processes()))
+ if not options.max_locked_shards:
+ options.max_locked_shards = int(os.environ.get("WEBKIT_TEST_MAX_LOCKED_SHARDS",
+ str(port.default_max_locked_shards())))
- try:
- port = host.port_factory.get(options.platform, options)
- except NotImplementedError, e:
- # FIXME: is this the best way to handle unsupported port names?
- print >> stderr, str(e)
- return EXCEPTIONAL_EXIT_STATUS
+ if not options.configuration:
+ options.configuration = port.default_configuration()
- logging.getLogger().setLevel(logging.DEBUG if options.debug_rwt_logging else logging.INFO)
+ if options.pixel_tests is None:
+ options.pixel_tests = port.default_pixel_tests()
- if options.lint_test_files:
- from webkitpy.layout_tests.lint_test_expectations import lint
- return lint(host, options, stderr)
+ if not options.time_out_ms:
+ options.time_out_ms = str(port.default_timeout_ms())
- try:
- run_details = run(port, options, args, stderr)
- if run_details.exit_code != -1:
- bot_printer = buildbot_results.BuildBotPrinter(stdout, options.debug_rwt_logging)
- bot_printer.print_results(run_details)
+ options.slow_time_out_ms = str(5 * int(options.time_out_ms))
- return run_details.exit_code
- except Exception, e:
- print >> stderr, '\n%s raised: %s' % (e.__class__.__name__, str(e))
- traceback.print_exc(file=stderr)
- raise
+ if options.additional_platform_directory:
+ additional_platform_directories = []
+ for path in options.additional_platform_directory:
+ additional_platform_directories.append(port.host.filesystem.abspath(path))
+ options.additional_platform_directory = additional_platform_directories
+ if not options.http and options.skipped in ('ignore', 'only'):
+ _log.warning("--force/--skipped=%s overrides --no-http." % (options.skipped))
+ options.http = True
-if '__main__' == __name__:
+ if options.ignore_metrics and (options.new_baseline or options.reset_results):
+ _log.warning("--ignore-metrics has no effect with --new-baselines or with --reset-results")
+
+ if options.new_baseline:
+ options.reset_results = True
+ options.add_platform_exceptions = True
+
+ if options.pixel_test_directories:
+ options.pixel_tests = True
+ varified_dirs = set()
+ pixel_test_directories = options.pixel_test_directories
+ for directory in pixel_test_directories:
+ # FIXME: we should support specifying the directories all the ways we support it for additional
+ # arguments specifying which tests and directories to run. We should also move the logic for that
+ # to Port.
+ filesystem = port.host.filesystem
+ if not filesystem.isdir(filesystem.join(port.layout_tests_dir(), directory)):
+ _log.warning("'%s' was passed to --pixel-test-directories, which doesn't seem to be a directory" % str(directory))
+ else:
+ varified_dirs.add(directory)
+
+ options.pixel_test_directories = list(varified_dirs)
+
+ if options.run_singly:
+ options.verbose = True
+
+
+def run(port, options, args, logging_stream):
+ logger = logging.getLogger()
+ logger.setLevel(logging.DEBUG if options.debug_rwt_logging else logging.INFO)
+
try:
- exit_status = main()
- except KeyboardInterrupt:
- exit_status = INTERRUPTED_EXIT_STATUS
- except BaseException, e:
- exit_status = EXCEPTIONAL_EXIT_STATUS
- sys.exit(exit_status)
+ printer = printing.Printer(port, options, logging_stream, logger=logger)
+
+ _set_up_derived_options(port, options)
+ manager = Manager(port, options, printer)
+ printer.print_config(port.results_directory())
+
+ run_details = manager.run(args)
+ _log.debug("Testing completed, Exit status: %d" % run_details.exit_code)
+ return run_details
+ finally:
+ printer.cleanup()
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py (137942 => 137943)
--- trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py 2012-12-17 21:50:27 UTC (rev 137942)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py 2012-12-17 21:55:27 UTC (rev 137943)
@@ -169,7 +169,7 @@
self.assertTrue(stream.getvalue())
-class MainTest(unittest.TestCase, StreamTestingMixin):
+class RunTest(unittest.TestCase, StreamTestingMixin):
def setUp(self):
# A real PlatformInfo object is used here instead of a
# MockPlatformInfo because we need to actually check for
@@ -748,16 +748,16 @@
def test_no_http_tests(self):
batch_tests_dryrun = get_tests_run(['LayoutTests/http', 'websocket/'])
- self.assertTrue(MainTest.has_test_of_type(batch_tests_dryrun, 'http'))
- self.assertTrue(MainTest.has_test_of_type(batch_tests_dryrun, 'websocket'))
+ self.assertTrue(RunTest.has_test_of_type(batch_tests_dryrun, 'http'))
+ self.assertTrue(RunTest.has_test_of_type(batch_tests_dryrun, 'websocket'))
batch_tests_run_no_http = get_tests_run(['--no-http', 'LayoutTests/http', 'websocket/'])
- self.assertFalse(MainTest.has_test_of_type(batch_tests_run_no_http, 'http'))
- self.assertFalse(MainTest.has_test_of_type(batch_tests_run_no_http, 'websocket'))
+ self.assertFalse(RunTest.has_test_of_type(batch_tests_run_no_http, 'http'))
+ self.assertFalse(RunTest.has_test_of_type(batch_tests_run_no_http, 'websocket'))
batch_tests_run_http = get_tests_run(['--http', 'LayoutTests/http', 'websocket/'])
- self.assertTrue(MainTest.has_test_of_type(batch_tests_run_http, 'http'))
- self.assertTrue(MainTest.has_test_of_type(batch_tests_run_http, 'websocket'))
+ self.assertTrue(RunTest.has_test_of_type(batch_tests_run_http, 'http'))
+ self.assertTrue(RunTest.has_test_of_type(batch_tests_run_http, 'websocket'))
def test_platform_tests_are_found(self):
tests_run = get_tests_run(['--platform', 'test-mac-leopard', 'http'])
@@ -921,3 +921,39 @@
def disabled_test_mac_lion(self):
self.assert_mock_port_works('mac-lion')
+
+
+class MainTest(unittest.TestCase):
+ def test_exception_handling(self):
+ orig_run_fn = run_webkit_tests.run
+
+ # unused args pylint: disable=W0613
+ def interrupting_run(port, options, args, stderr):
+ raise KeyboardInterrupt
+
+ def successful_run(port, options, args, stderr):
+
+ class FakeRunDetails(object):
+ exit_code = -1
+
+ return FakeRunDetails()
+
+ def exception_raising_run(port, options, args, stderr):
+ assert False
+
+ stdout = StringIO.StringIO()
+ stderr = StringIO.StringIO()
+ try:
+ run_webkit_tests.run = interrupting_run
+ res = run_webkit_tests.main([], stdout, stderr)
+ self.assertEqual(res, run_webkit_tests.INTERRUPTED_EXIT_STATUS)
+
+ run_webkit_tests.run = successful_run
+ res = run_webkit_tests.main(['--platform', 'test'], stdout, stderr)
+ self.assertEqual(res, -1)
+
+ run_webkit_tests.run = exception_raising_run
+ res = run_webkit_tests.main([], stdout, stderr)
+ self.assertEqual(res, run_webkit_tests.EXCEPTIONAL_EXIT_STATUS)
+ finally:
+ run_webkit_tests.run = orig_run_fn