Commit 4f0d9e30 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[blink] Add --enable-tracing flag to layout test runner.

Add a flag to enable capturing a trace file for layout tests, similar
to how browser tests do this:

run_web_tests.py --enable-tracing=CATEGORIES

The implementation passed the following flags to the driver:
--trace-startup
--trace-startup-duration=0
--trace-startup-file

R=robertma@chromium.org

Change-Id: I2f145936f567986219928108eba89c8c60f734a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202807
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769473}
parent 08c5402d
......@@ -349,10 +349,16 @@ class Worker(object):
if self._driver:
# When tracing we need to go through the standard shutdown path to
# ensure that the trace is recorded properly.
if any(i in ['--trace-startup', '--trace-shutdown']
for i in self._options.additional_driver_flag):
tracing_enabled = self._port.get_option(
'enable_tracing') is not None or any(
flag.startswith(tracing_command) for tracing_command in
['--trace-startup', '--trace-shutdown']
for flag in self._options.additional_driver_flag)
if tracing_enabled:
_log.debug('%s waiting %d seconds for %s driver to shutdown',
self._name, self._port.driver_stop_timeout(), label)
self._name, self._port.driver_stop_timeout(),
self._name)
self._driver.stop(
timeout_secs=self._port.driver_stop_timeout())
return
......
......@@ -31,6 +31,7 @@ The Port classes encapsulate Port-specific (platform-specific) behavior
in the web test infrastructure.
"""
import time
import collections
import itertools
import json
......@@ -1195,7 +1196,20 @@ class Port(object):
@memoized
def args_for_test(self, test_name):
return self._lookup_virtual_test_args(test_name)
args = self._lookup_virtual_test_args(test_name)
tracing_categories = self.get_option('enable_tracing')
if tracing_categories:
args.append('--trace-startup=' + tracing_categories)
# Do not finish the trace until the test is finished.
args.append('--trace-startup-duration=0')
# Append the current time to the output file name to ensure that
# the subsequent repetitions of the test do not overwrite older
# trace files.
current_time = time.strftime("%Y-%m-%d-%H-%M-%S")
file_name = 'trace_layout_test_' + test_name.replace(
'/', '_').replace('.', '_') + '_' + current_time + '.json'
args.append('--trace-startup-file=' + file_name)
return args
@memoized
def name_for_test(self, test_name):
......
......@@ -29,6 +29,7 @@
import json
import optparse
import unittest
import mock
from blinkpy.common.path_finder import RELATIVE_WEB_TESTS
from blinkpy.common.system.executive_mock import MockExecutive
......@@ -1664,6 +1665,18 @@ class PortTest(LoggingTestCase):
port.additional_driver_flags())
def test_enable_tracing(self):
options, _ = optparse.OptionParser().parse_args([])
options.enable_tracing = '*,-blink'
port = self.make_port(with_tests=True, options=options)
with mock.patch('time.strftime', return_value='TIME'):
self.assertEqual([
'--trace-startup=*,-blink',
'--trace-startup-duration=0',
'--trace-startup-file=trace_layout_test_non_virtual_TIME.json',
], port.args_for_test('non/virtual'))
class NaturalCompareTest(unittest.TestCase):
def setUp(self):
self._port = TestPort(MockSystemHost())
......
......@@ -295,11 +295,10 @@ def parse_args(args):
dest='build',
action='store_false',
help="Don't check to see if the build is up to date."),
optparse.make_option(
'--child-processes',
'--jobs',
'-j',
help='Number of drivers to run in parallel.'),
optparse.make_option('--child-processes',
'--jobs',
'-j',
help='Number of drivers to run in parallel.'),
optparse.make_option(
'--disable-breakpad',
action='store_true',
......@@ -316,6 +315,12 @@ def parse_args(args):
'--enable-sanitizer',
action='store_true',
help='Only alert on sanitizer-related errors and crashes'),
optparse.make_option(
'--enable-tracing',
type='string',
help='Capture and write a trace file with the specied '
'categories for each test. Passes appropriate --trace-startup '
'flags to the driver.'),
optparse.make_option(
'--exit-after-n-crashes-or-timeouts',
type='int',
......@@ -386,10 +391,9 @@ def parse_args(args):
"'random' == pseudo-random order (default). Seed can be specified "
'via --seed, otherwise it will default to the current unix timestamp. '
"'natural' == use the natural order")),
optparse.make_option(
'--profile',
action='store_true',
help='Output per-test profile information.'),
optparse.make_option('--profile',
action='store_true',
help='Output per-test profile information.'),
optparse.make_option(
'--profiler',
action='store',
......@@ -515,8 +519,8 @@ def parse_args(args):
help='A colon-separated list of tests to run. Wildcards are '
'NOT supported. It is the same as listing the tests as '
'positional arguments.'),
optparse.make_option(
'--time-out-ms', help='Set the timeout for each test'),
optparse.make_option('--time-out-ms',
help='Set the timeout for each test'),
optparse.make_option(
'--wrapper',
help=
......@@ -524,11 +528,10 @@ def parse_args(args):
'is split on whitespace before running. (Example: --wrapper="valgrind '
'--smc-check=all")')),
# FIXME: Display the default number of child processes that will run.
optparse.make_option(
'-f',
'--fully-parallel',
action='store_true',
help='run all tests in parallel'),
optparse.make_option('-f',
'--fully-parallel',
action='store_true',
help='run all tests in parallel'),
optparse.make_option(
'--virtual-parallel',
action='store_true',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment