Commit 57170687 authored by tony@chromium.org's avatar tony@chromium.org
Browse files

2010-09-10 Tony Chang <tony@chromium.org>

        Reviewed by Ojan Vafai.

        deduplicate-tests should be runnable from any WebKit directory
        https://bugs.webkit.org/show_bug.cgi?id=44709

        * Scripts/webkitpy/layout_tests/deduplicate_tests.py:
        * Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67216 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7aa9c774
2010-09-10 Tony Chang <tony@chromium.org>
Reviewed by Ojan Vafai.
deduplicate-tests should be runnable from any WebKit directory
https://bugs.webkit.org/show_bug.cgi?id=44709
* Scripts/webkitpy/layout_tests/deduplicate_tests.py:
* Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:
2010-09-09 Hans Wennborg <hans@chromium.org> 2010-09-09 Hans Wennborg <hans@chromium.org>
Reviewed by Jeremy Orlow. Reviewed by Jeremy Orlow.
......
...@@ -36,6 +36,7 @@ import os ...@@ -36,6 +36,7 @@ import os
import subprocess import subprocess
import sys import sys
import re import re
import webkitpy.common.checkout.scm as scm
import webkitpy.common.system.executive as executive import webkitpy.common.system.executive as executive
import webkitpy.common.system.logutils as logutils import webkitpy.common.system.logutils as logutils
import webkitpy.layout_tests.port.factory as port_factory import webkitpy.layout_tests.port.factory as port_factory
...@@ -56,7 +57,8 @@ def port_fallbacks(): ...@@ -56,7 +57,8 @@ def port_fallbacks():
try: try:
platforms = port_factory.get(port_name).baseline_search_path() platforms = port_factory.get(port_name).baseline_search_path()
except NotImplementedError: except NotImplementedError:
_log.error("'%s' lacks baseline_search_path(), please fix." % port_name) _log.error("'%s' lacks baseline_search_path(), please fix."
% port_name)
fallbacks[port_name] = [_BASE_PLATFORM] fallbacks[port_name] = [_BASE_PLATFORM]
continue continue
fallbacks[port_name] = [os.path.basename(p) for p in platforms][1:] fallbacks[port_name] = [os.path.basename(p) for p in platforms][1:]
...@@ -156,11 +158,35 @@ def has_intermediate_results(test, fallbacks, matching_platform, ...@@ -156,11 +158,35 @@ def has_intermediate_results(test, fallbacks, matching_platform,
return False return False
def find_dups(hashes, port_fallbacks): def get_relative_test_path(filename, relative_to):
"""Constructs a relative path to |filename| from |relative_to|. Also, if
|relative_to| is a sub directory of the layout test directory and
|filename| is not in |relative_to|, return None. This lets us filter
the results to only show results that are under where the script was run
from.
Args:
filename: The test file we're trying to get a relative path to.
relative_to: The absolute path we're relative to.
Returns:
A relative path to filename or None.
"""
layout_test_dir = os.path.join(scm.find_checkout_root(), 'LayoutTests')
abs_path = os.path.join(layout_test_dir, filename)
path = os.path.relpath(abs_path, relative_to)
# If we're in the layout test directory, only return results that are below
# where the tool was run from.
if (relative_to.startswith(layout_test_dir) and path.startswith('..')):
return None
return path
def find_dups(hashes, port_fallbacks, relative_to):
"""Yields info about redundant test expectations. """Yields info about redundant test expectations.
Args: Args:
hashes: a list of hashes as returned by cluster_file_hashes. hashes: a list of hashes as returned by cluster_file_hashes.
port_fallbacks: a list of fallback information as returned by get_port_fallbacks. port_fallbacks: a list of fallback information as returned by
get_port_fallbacks.
relative_to: the directory that we want the results relative to
Returns: Returns:
a tuple containing (test, platform, fallback, platforms) a tuple containing (test, platform, fallback, platforms)
""" """
...@@ -176,13 +202,20 @@ def find_dups(hashes, port_fallbacks): ...@@ -176,13 +202,20 @@ def find_dups(hashes, port_fallbacks):
# See if any of the platforms are redundant with each other. # See if any of the platforms are redundant with each other.
for platform in platforms.keys(): for platform in platforms.keys():
for fallback in port_fallbacks[platform]: for fallback in port_fallbacks[platform]:
if fallback in platforms.keys(): if fallback not in platforms.keys():
# We have to verify that there isn't an intermediate result continue
# that causes this duplicate hash to exist. # We have to verify that there isn't an intermediate result
if not has_intermediate_results(test, # that causes this duplicate hash to exist.
port_fallbacks[platform], fallback): if has_intermediate_results(test, port_fallbacks[platform],
path = os.path.join('LayoutTests', platforms[platform]) fallback):
yield test, platform, fallback, path continue
# We print the relative path so it's easy to pipe the results
# to xargs rm.
path = get_relative_test_path(platforms[platform], relative_to)
if not path:
continue
yield {'test': test, 'platform': platform,
'fallback': fallback, 'path': path}
def deduplicate(glob_pattern): def deduplicate(glob_pattern):
...@@ -192,7 +225,11 @@ def deduplicate(glob_pattern): ...@@ -192,7 +225,11 @@ def deduplicate(glob_pattern):
Returns: Returns:
a dictionary containing test, path, platform and fallback. a dictionary containing test, path, platform and fallback.
""" """
fallbacks = port_fallbacks() current_dir = os.getcwd()
hashes = cluster_file_hashes(glob_pattern) try:
return [{'test': test, 'path': path, 'platform': platform, 'fallback': fallback} os.chdir(scm.find_checkout_root())
for test, platform, fallback, path in find_dups(hashes, fallbacks)] fallbacks = port_fallbacks()
hashes = cluster_file_hashes(glob_pattern)
return list(find_dups(hashes, fallbacks, current_dir))
finally:
os.chdir(current_dir)
...@@ -186,3 +186,22 @@ class ListDuplicatesTest(unittest.TestCase): ...@@ -186,3 +186,22 @@ class ListDuplicatesTest(unittest.TestCase):
'fallback': 'chromium-win', 'fallback': 'chromium-win',
'platform': 'chromium-linux'}, 'platform': 'chromium-linux'},
result[0]) result[0])
def test_get_relative_test_path(self):
checkout_root = scm.find_checkout_root()
layout_test_dir = os.path.join(checkout_root, 'LayoutTests')
test_cases = (
('platform/mac/test.html',
('platform/mac/test.html', layout_test_dir)),
('LayoutTests/platform/mac/test.html',
('platform/mac/test.html', checkout_root)),
('../LayoutTests/platform/mac/test.html',
('platform/mac/test.html', os.path.join(checkout_root, 'WebCore'))),
('test.html',
('platform/mac/test.html', os.path.join(layout_test_dir, 'platform/mac'))),
(None,
('platform/mac/test.html', os.path.join(layout_test_dir, 'platform/win'))),
)
for expected, inputs in test_cases:
self.assertEquals(expected,
deduplicate_tests.get_relative_test_path(*inputs))
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