1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Some utility methods for getting paths used by run_webkit_tests.py.
"""
import errno
import os
import platform_utils
import subprocess
import sys
import google.path_utils
class PathNotFound(Exception): pass
# Save some paths here so we don't keep re-evaling.
_webkit_root = None
_layout_data_dir = None
_expected_results_dir = None
_platform_results_dirs = {}
# TODO this should probably be moved into path_utils as ToUnixPath().
def WinPathToUnix(path):
"""Convert a windows path to use unix-style path separators (a/b/c)."""
return path.replace('\\', '/')
def WebKitRoot():
"""Returns the full path to the directory containing webkit.sln. Raises
PathNotFound if we're unable to find webkit.sln."""
global _webkit_root
if _webkit_root:
return _webkit_root
webkit_sln_path = google.path_utils.FindUpward(google.path_utils.ScriptDir(),
'webkit.sln')
_webkit_root = os.path.dirname(webkit_sln_path)
return _webkit_root
def LayoutDataDir():
"""Gets the full path to the tests directory. Raises PathNotFound if
we're unable to find it."""
global _layout_data_dir
if _layout_data_dir:
return _layout_data_dir
_layout_data_dir = google.path_utils.FindUpward(WebKitRoot(), 'webkit',
'data', 'layout_tests')
return _layout_data_dir
def ExpectedResultsDir():
"""Gets the full path to the custom_results directory. Raises
PathNotFound if we're unable to find it."""
global _expected_results_dir
if _expected_results_dir:
return _expected_results_dir
_expected_results_dir = google.path_utils.FindUpward(WebKitRoot(), 'webkit',
'data',
'layout_test_results')
return _expected_results_dir
def CustomExpectedResultsDir(custom_id):
"""Gets the full path to the directory in which custom expected results for
this app and build type are located.
Args:
custom_id: a string specifying the particular set of results to use (e.g.,
'v8' or 'kjs')
"""
return os.path.join(ExpectedResultsDir(), custom_id)
def PlatformResultsDir(name):
"""Gets the full path to a platform-specific results directory. Raises
PathNotFound if we're unable to find it."""
global _platform_results_dirs
if _platform_results_dirs.get(name):
return _platform_results_dirs[name]
_platform_results_dirs[name] = google.path_utils.FindUpward(WebKitRoot(),
'webkit', 'data', 'layout_tests', 'LayoutTests', 'platform', name)
return _platform_results_dirs[name]
def ExpectedFilename(filename, suffix, custom_result_id):
"""Given a test name, returns an absolute filename to the most specific
applicable file of expected results.
Args:
filename: absolute filename to test file
suffix: file suffix of the expected results, including dot; e.g. '.txt'
or '.png'. This should not be None, but may be an empty string.
custom_result_id: Tells us where to look for custom results. Currently
this is either kjs or v8.
Return:
If a file named <testname>-expected<suffix> exists in the subdirectory
of the ExpectedResultsDir() specified by this platform's identifier,
return its absolute path. Otherwise, return a path to a
<testname>-expected<suffix> file under the MacExpectedResultsDir() or
<testname>-expected<suffix> file under the MacLeopardExpectedResultsDir()
or (if not found there) in the same directory as the test file (even if
that default file does not exist).
"""
testname = os.path.splitext(RelativeTestFilename(filename))[0]
results_filename = testname + '-expected' + suffix
results_dirs = [
CustomExpectedResultsDir(custom_result_id),
CustomExpectedResultsDir('common'),
LayoutDataDir()
]
for results_dir in results_dirs:
platform_file = os.path.join(results_dir, results_filename)
if os.path.exists(platform_file):
return platform_file
# for 'base' tests, we need to look for mac-specific results
if testname.startswith('LayoutTests'):
layout_test_results_dirs = [
PlatformResultsDir('mac'),
PlatformResultsDir('mac-leopard'),
PlatformResultsDir('mac-tiger')
]
rel_testname = testname[len('LayoutTests') + 1:]
rel_filename = rel_testname + '-expected' + suffix
for results_dir in layout_test_results_dirs:
platform_file = os.path.join(results_dir, rel_filename)
if os.path.exists(platform_file):
return platform_file
# Failed to find the results anywhere, return default path anyway
return os.path.join(results_dirs[0], results_filename)
def TestShellBinaryPath(target):
"""Gets the full path to the test_shell binary for the target build
configuration. Raises PathNotFound if the file doesn't exist"""
platform_util = platform_utils.PlatformUtility('')
full_path = os.path.join(WebKitRoot(), target,
platform_util.TestShellBinary())
if not os.path.exists(full_path):
# try output directory from either Xcode or chrome.sln
full_path = platform_util.TestShellBinaryPath(target)
if not os.path.exists(full_path):
raise PathNotFound('unable to find test_shell at %s' % full_path)
return full_path
def RelativeTestFilename(filename):
"""Provide the filename of the test relative to the layout data
directory as a unix style path (a/b/c)."""
return WinPathToUnix(filename[len(LayoutDataDir()) + 1:])
# Map platform specific path utility functions. We do this as a convenience
# so importing path_utils will get all path related functions even if they are
# platform specific.
def GetAbsolutePath(path):
# Avoid circular import by delaying it.
import layout_package.platform_utils
platform_util = layout_package.platform_utils.PlatformUtility(WebKitRoot())
return platform_util.GetAbsolutePath(path)
def FilenameToUri(path):
# Avoid circular import by delaying it.
import layout_package.platform_utils
platform_util = layout_package.platform_utils.PlatformUtility(WebKitRoot())
return platform_util.FilenameToUri(path)
|