Commit 97280771 authored by Preethi Mohan's avatar Preethi Mohan Committed by Commit Bot

Restore order of the tests to be run, if order="none"

Restore the order of the tests to be run if order is "none"

Bug: 1071924
Change-Id: I282c71ea745a8fc4afc5b2b442eb286e9e215806
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391311
Commit-Queue: Preethi Mohan <preethim@google.com>
Reviewed-by: default avatarRakib Hasan <rmhasan@google.com>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808235}
parent 2f70126e
...@@ -36,6 +36,7 @@ including crash logs and mismatches with expectations. ...@@ -36,6 +36,7 @@ including crash logs and mismatches with expectations.
The Manager object has a constructor and one main method called run. The Manager object has a constructor and one main method called run.
""" """
import fnmatch
import json import json
import logging import logging
import random import random
...@@ -113,12 +114,17 @@ class Manager(object): ...@@ -113,12 +114,17 @@ class Manager(object):
exit_code=exit_codes.NO_TESTS_EXIT_STATUS) exit_code=exit_codes.NO_TESTS_EXIT_STATUS)
test_names = self._finder.split_into_chunks(all_test_names) test_names = self._finder.split_into_chunks(all_test_names)
if self._options.order == 'natural': if self._options.order == 'natural':
test_names.sort(key=self._port.test_key) test_names.sort(key=self._port.test_key)
elif self._options.order == 'random': elif self._options.order == 'random':
test_names.sort() test_names.sort()
random.Random(self._options.seed).shuffle(test_names) random.Random(self._options.seed).shuffle(test_names)
elif self._options.order == 'none':
# Restore the test order to user specified order.
# base.tests() may change the order as it returns tests in the
# real, external/wpt, virtual order.
if paths:
test_names = self._restore_order(paths, test_names)
if not self._options.no_expectations: if not self._options.no_expectations:
self._printer.write_update('Parsing expectations ...') self._printer.write_update('Parsing expectations ...')
...@@ -286,6 +292,16 @@ class Manager(object): ...@@ -286,6 +292,16 @@ class Manager(object):
tests_to_retry = self._tests_to_retry(retry_results) tests_to_retry = self._tests_to_retry(retry_results)
return (initial_results, all_retry_results) return (initial_results, all_retry_results)
def _restore_order(self, paths, test_names):
original_test_names = list(test_names)
test_names = []
for path in paths:
for test in original_test_names:
if test.startswith(path) or fnmatch.fnmatch(test, path):
test_names.append(test)
test_names += list(set(original_test_names) - set(test_names))
return test_names
def _collect_tests(self, args): def _collect_tests(self, args):
return self._finder.find_tests( return self._finder.find_tests(
args, args,
......
...@@ -218,3 +218,36 @@ class ManagerTest(unittest.TestCase): ...@@ -218,3 +218,36 @@ class ManagerTest(unittest.TestCase):
if not port.host.filesystem.exists(dir_name): if not port.host.filesystem.exists(dir_name):
deleted_dir_count = deleted_dir_count + 1 deleted_dir_count = deleted_dir_count + 1
self.assertEqual(deleted_dir_count, 5) self.assertEqual(deleted_dir_count, 5)
def test_restore_order(self):
host = MockHost()
port = host.port_factory.get('test-mac-mac10.10')
def get_manager():
manager = Manager(port,
options=optparse.Values({'max_locked_shards':
1}),
printer=FakePrinter())
return manager
manager = get_manager()
paths = [
"external/wpt/css/css-backgrounds/animations/background-size-interpolation.html",
"virtual/gpu/fast/canvas/CanvasFillTextWithMinimalSize.html",
"fast/backgrounds/size/backgroundSize-*"
]
# As returned by base.tests()
test_names = [
"virtual/gpu/fast/canvas/CanvasFillTextWithMinimalSize.html",
"fast/backgrounds/size/backgroundSize-in-background-shorthand.html",
"fast/backgrounds/size/backgroundSize-viewportPercentage-width.html",
"external/wpt/css/css-backgrounds/animations/background-size-interpolation.html"
]
expected_order = [
"external/wpt/css/css-backgrounds/animations/background-size-interpolation.html",
"virtual/gpu/fast/canvas/CanvasFillTextWithMinimalSize.html",
"fast/backgrounds/size/backgroundSize-in-background-shorthand.html",
"fast/backgrounds/size/backgroundSize-viewportPercentage-width.html"
]
test_names_restored = manager._restore_order(paths, test_names)
self.assertEqual(expected_order, test_names_restored)
...@@ -91,8 +91,9 @@ class WebTestFinder(object): ...@@ -91,8 +91,9 @@ class WebTestFinder(object):
running_all_tests = True running_all_tests = True
test_files = filter_tests(test_files, [f.split('::') for f in filters]) test_files = filter_tests(test_files, [f.split('::') for f in filters])
# de-dupe the test list here before running them. # de-dupe the test list and paths here before running them.
test_files = list(OrderedDict.fromkeys(test_files)) test_files = list(OrderedDict.fromkeys(test_files))
paths = list(OrderedDict.fromkeys(paths))
return (paths, test_files, running_all_tests) return (paths, test_files, running_all_tests)
def _times_trie(self): def _times_trie(self):
......
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