Tools/ChangeLog

 12011-11-04 Ryosuke Niwa <rniwa@webkit.org>
 2
 3 Parse reftest.list and extract types of ref tests
 4 https://bugs.webkit.org/show_bug.cgi?id=66837
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Added a facility to parse reftest.list and pass it to TestInput objects to Manager.
 9
 10 Modified test_files to consider reftest.list as a test file so that port.tests can find
 11 reftest.list files in test directories. These reftest.list entries are removed by
 12 Manager._parse_all_reftest_lists, called by Manager.collect_tests, as it collects test
 13 and reference file mapping.
 14
 15 * Scripts/webkitpy/layout_tests/controllers/manager.py:
 16 * Scripts/webkitpy/layout_tests/controllers/manager_unittest.py: Added a test.
 17 * Scripts/webkitpy/layout_tests/models/test_input.py:
 18 * Scripts/webkitpy/layout_tests/port/test.py:
 19 * Scripts/webkitpy/layout_tests/port/test_files.py:
 20 * Scripts/webkitpy/layout_tests/port/test_files_unittest.py: Added test cases.
 21
1222011-11-04 Eric Seidel <eric@webkit.org>
223
324 Upgrade to the latest Mechanize
99343

Tools/Scripts/webkitpy/layout_tests/controllers/manager.py

@@class Manager(object):
326326 paths = self._strip_test_dir_prefixes(args)
327327 if self._options.test_list:
328328 paths += self._strip_test_dir_prefixes(read_test_files(self._fs, self._options.test_list, self._port.TEST_PATH_SEPARATOR))
 329
329330 self._test_files = self._port.tests(paths)
 331 self._parse_all_reftest_lists()
 332
 333 def _parse_all_reftest_lists(self):
 334 """Parse all reftests.list in tests' directories and populate self._reftests
 335
 336 Args:
 337 tests: list of tests for which references may be parsed
 338 """
 339
 340 self._reftests = {}
 341 test_dirs = set()
 342 reftest_lists = []
 343 for path in self._test_files:
 344 if 'reftest.list' == self._fs.basename(path):
 345 reftest_lists.append(path)
 346 reftest_list_abs_path = self._fs.join(self._port.layout_tests_dir(), path)
 347 self._parse_reftest_list(self._fs.read_text_file(reftest_list_abs_path), self._fs.dirname(path))
 348
 349 for reftest_list in reftest_lists:
 350 self._test_files.remove(reftest_list)
 351
 352 # Don't treat reference files as test files
 353 for expectation_type, ref_file_path in self._reftests.values():
 354 if ref_file_path in self._test_files:
 355 self._test_files.remove(ref_file_path)
 356
 357 def _parse_reftest_list(self, reftest_list, test_dir):
 358 for line in reftest_list.split('\n'):
 359 split_line = line.split()
 360 if len(split_line) < 3:
 361 continue
 362 expectation_type, test_file, ref_file = split_line
 363 ref_file_path = self._fs.join(test_dir, ref_file)
 364 self._reftests[self._fs.join(test_dir, test_file)] = (expectation_type, ref_file_path)
330365
331366 def _strip_test_dir_prefixes(self, paths):
332367 return [self._strip_test_dir_prefix(path) for path in paths if path]

@@class Manager(object):
544579 """Returns the appropriate TestInput object for the file. Mostly this
545580 is used for looking up the timeout value (in ms) to use for the given
546581 test."""
 582 if test_file in self._reftests:
 583 is_mismatch = self._reftests[test_file][0] == '!='
 584 ref_file = self._reftests[test_file][1]
 585 else:
 586 is_mismatch = False
 587 ref_file = None
547588 if self._test_is_slow(test_file):
548  return TestInput(test_file, self._options.slow_time_out_ms)
549  return TestInput(test_file, self._options.time_out_ms)
 589 return TestInput(test_file, self._options.slow_time_out_ms, ref_file, is_mismatch)
 590 return TestInput(test_file, self._options.time_out_ms, ref_file, is_mismatch)
550591
551592 def _test_requires_lock(self, test_file):
552593 """Return True if the test needs to be locked when
99285

Tools/Scripts/webkitpy/layout_tests/controllers/manager_unittest.py

@@class ManagerTest(unittest.TestCase):
263263 manager = get_manager_with_tests(['http\\tests\\mime'])
264264 self.assertTrue(manager.needs_servers())
265265
 266 def test_parse_reftest_list(self):
 267 manager = Manager(port=MockHost().port_factory.get('test-win-xp', None), options=MockOptions(), printer=Mock())
 268 manager._reftests = {}
 269 manager._parse_reftest_list("""== test.html test-ref.html
 270
 271!= test.html test-noref.html""", 'foo/')
 272 self.assertEquals(manager._reftests, {'foo/test.html': ('==', 'foo/test-ref.html'), 'foo/test.html': ('!=', 'foo/test-noref.html')})
 273
 274 def test_collect_tests_with_single_reftest(self):
 275 options, args = run_webkit_tests.parse_args(['--platform=test', '--print=nothing', 'reftests/foo/test.html'])
 276 manager = Manager(port=MockHost().port_factory.get('test'), options=options, printer=Mock())
 277 manager.collect_tests(args)
 278 self.assertTrue('reftests/foo/reftest.list' not in manager._test_files)
 279 self.assertTrue('reftests/foo/test.html' in manager._test_files)
 280 self.assertEqual(manager._reftests['reftests/foo/test.html'], ('==', 'reftests/foo/test-ref.html'))
 281
 282 def test_collect_tests_with_reftests(self):
 283 options, args = run_webkit_tests.parse_args(['--platform=test', '--print=nothing', 'reftests/foo'])
 284 manager = Manager(port=MockHost().port_factory.get('test'), options=options, printer=Mock())
 285 manager.collect_tests(args)
 286 self.assertTrue('reftests/foo/reftest.list' not in manager._test_files)
 287 self.assertTrue('reftests/foo/test.html' in manager._test_files)
 288 self.assertTrue('reftests/foo/test-ref.html' not in manager._test_files)
 289 self.assertTrue('reftests/foo/test.html' in manager._reftests)
 290 self.assertTrue('reftests/foo/test-ref.html' not in manager._reftests)
 291 self.assertEqual(manager._reftests['reftests/foo/test.html'], ('==', 'reftests/foo/test-ref.html'))
 292
 293 def test_collect_tests_with_reftests_at_parentdir(self):
 294 options, args = run_webkit_tests.parse_args(['--platform=test', '--print=nothing', 'reftests'])
 295 manager = Manager(port=MockHost().port_factory.get('test'), options=options, printer=Mock())
 296 manager.collect_tests(args)
 297 self.assertTrue('reftests/foo/reftest.list' not in manager._test_files)
 298 self.assertTrue('reftests/foo/test.html' in manager._test_files)
 299 self.assertTrue('reftests/foo/test-ref.html' not in manager._test_files)
 300 self.assertTrue('reftests/foo/test.html' in manager._reftests)
 301 self.assertTrue('reftests/foo/test-ref.html' not in manager._reftests)
 302 self.assertEqual(manager._reftests['reftests/foo/test.html'], ('==', 'reftests/foo/test-ref.html'))
266303
267304class NaturalCompareTest(unittest.TestCase):
268305 def assert_cmp(self, x, y, result):
99285

Tools/Scripts/webkitpy/layout_tests/models/test_input.py

3232class TestInput:
3333 """Groups information about a test for easy passing of data."""
3434
35  def __init__(self, test_name, timeout):
 35 def __init__(self, test_name, timeout, ref_file=None, is_mismatch=False):
3636 """Holds the input parameters for a test.
3737 Args:
3838 test: name of test (not an absolute path!)

@@class TestInput:
4040 """
4141 self.test_name = test_name
4242 self.timeout = timeout
 43 self.ref_file = ref_file
 44 self.is_mismatch = is_mismatch
4345
4446 def __repr__(self):
4547 return "TestInput('%s', %d)" % (self.test_name, self.timeout)
99285

Tools/Scripts/webkitpy/layout_tests/port/test.py

@@layer at (0,0) size 800x34
185185 tests.add_reftest('failures/unexpected/reftest.html', 'failures/unexpected/reftest-expected.html', same_image=False)
186186 tests.add_reftest('failures/unexpected/mismatch.html', 'failures/unexpected/mismatch-expected-mismatch.html', same_image=True)
187187 # FIXME: Add a reftest which crashes.
 188 tests.add('reftests/foo/test.html')
 189 tests.add('reftests/foo/test-ref.html')
188190
189191 tests.add('websocket/tests/passes/text.html')
190192

@@def unit_test_filesystem(files=None):
211213 test_list = unit_test_list()
212214 files = files or {}
213215
214  def add_file(files, test, suffix, contents):
 216 def add_test_file(files, test, suffix, contents):
215217 dirname = test.name[0:test.name.rfind('/')]
216218 base = test.base
217  path = LAYOUT_TEST_DIR + '/' + dirname + '/' + base + suffix
218  files[path] = contents
 219 add_file(files, dirname + '/' + base + suffix, contents)
 220
 221 def add_file(files, file_name, contents):
 222 files[LAYOUT_TEST_DIR + '/' + file_name] = contents
219223
220224 # Add each test and the expected output, if any.
221225 for test in test_list.tests.values():
222  add_file(files, test, '.html', '')
 226 add_test_file(files, test, '.html', '')
223227 if test.is_reftest:
224228 continue
225229 if test.actual_audio:
226  add_file(files, test, '-expected.wav', test.expected_audio)
 230 add_test_file(files, test, '-expected.wav', test.expected_audio)
227231 continue
228232
229  add_file(files, test, '-expected.txt', test.expected_text)
230  add_file(files, test, '-expected.png', test.expected_image)
 233 add_test_file(files, test, '-expected.txt', test.expected_text)
 234 add_test_file(files, test, '-expected.png', test.expected_image)
231235
232236
233237 # Add the test_expectations file.

@@WONTFIX SKIP : failures/expected/keyboar
253257WONTFIX SKIP : failures/expected/exception.html = CRASH
254258"""
255259
 260 add_file(files, 'reftests/foo/reftest.list', """
 261== test.html test-ref.html
 262""")
 263
256264 # FIXME: This test was only being ignored because of missing a leading '/'.
257265 # Fixing the typo causes several tests to assert, so disabling the test entirely.
258266 # Add in a file should be ignored by test_files.find().
99285

Tools/Scripts/webkitpy/layout_tests/port/test_files.py

@@def normalized_find(filesystem, paths):
8888 # FIXME: I'm not sure there's much point in this being a set. A list would probably be faster.
8989 test_files = set()
9090 for path in paths_to_walk:
91  files = filesystem.files_under(path, _skipped_directories, _is_test_file)
 91 files = filesystem.files_under(path, _skipped_directories, _is_test_file_or_reftest_list)
9292 test_files.update(set(files))
 93 if filesystem.isfile(path):
 94 test_dir = filesystem.dirname(path)
 95 reftest_list = filesystem.join(test_dir, 'reftest.list')
 96 if reftest_list not in test_files and filesystem.exists(reftest_list):
 97 test_files.add(reftest_list)
9398
9499 gather_time = time.time() - gather_start_time
95100 _log.debug("Test gathering took %f seconds" % gather_time)

@@def is_reference_html_file(filename):
107112 return filename.endswith('-expected.html') or filename.endswith('-expected-mismatch.html')
108113
109114
110 def _is_test_file(filesystem, dirname, filename):
111  return _has_supported_extension(filesystem, filename) and not is_reference_html_file(filename)
 115def _is_test_file_or_reftest_list(filesystem, dirname, filename):
 116 return (_has_supported_extension(filesystem, filename) and not is_reference_html_file(filename)) or filename == 'reftest.list'
99285

Tools/Scripts/webkitpy/layout_tests/port/test_files_unittest.py

@@class TestFilesTest(unittest.TestCase):
5959 tests = test_files.find(port, ['userscripts/resources'])
6060 self.assertEqual(tests, set([]))
6161
62  def test_is_test_file(self):
 62 def test_find_with_reftests(self):
 63 port = test.TestPort()
 64 tests = test_files.find(port, ['reftests/foo/test.html'])
 65 self.assertEqual(tests, set([port.layout_tests_dir() + '/reftests/foo/reftest.list', port.layout_tests_dir() + '/reftests/foo/test.html']))
 66
 67 def test_is_test_file_or_reftest_list(self):
6368 port = test.TestPort()
6469 fs = port._filesystem
65  self.assertTrue(test_files._is_test_file(fs, '', 'foo.html'))
66  self.assertTrue(test_files._is_test_file(fs, '', 'foo.shtml'))
67  self.assertFalse(test_files._is_test_file(fs, '', 'foo.png'))
68  self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected.html'))
69  self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected-mismatch.html'))
 70 self.assertTrue(test_files._is_test_file_or_reftest_list(fs, '', 'foo.html'))
 71 self.assertTrue(test_files._is_test_file_or_reftest_list(fs, '', 'foo.shtml'))
 72 self.assertTrue(test_files._is_test_file_or_reftest_list(fs, '', 'reftest.list'))
 73 self.assertFalse(test_files._is_test_file_or_reftest_list(fs, '', 'foo.png'))
 74 self.assertFalse(test_files._is_test_file_or_reftest_list(fs, '', 'foo-expected.html'))
 75 self.assertFalse(test_files._is_test_file_or_reftest_list(fs, '', 'foo-expected-mismatch.html'))
 76 self.assertFalse(test_files._is_test_file_or_reftest_list(fs, '', 'some.list'))
7077
7178
7279class MockWinFileSystem(object):
99285