diff --git a/llvm/docs/CommandGuide/lit.rst b/llvm/docs/CommandGuide/lit.rst --- a/llvm/docs/CommandGuide/lit.rst +++ b/llvm/docs/CommandGuide/lit.rst @@ -404,6 +404,9 @@ given a head start before other tests run. For example, the top five or so slowest tests. See also: `--time-tests` + **late_tests** A regular expression that matches tests that should be run after + the other tests. For example, tests that are fast and low reward. + **pipefail** Normally a test using a shell pipe fails if any of the commands on the pipe fail. If this is not desired, setting this variable to false makes the test fail only if the last command in the pipe fails. diff --git a/llvm/utils/lit/lit/TestingConfig.py b/llvm/utils/lit/lit/TestingConfig.py --- a/llvm/utils/lit/lit/TestingConfig.py +++ b/llvm/utils/lit/lit/TestingConfig.py @@ -129,6 +129,8 @@ self.is_early = bool(is_early) # List of tests to run early. self.early_tests = {} + # Regular expression for tests to run late. + self.late_tests = "^$" self.parallelism_group = parallelism_group self._recursiveExpansionLimit = None diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -153,11 +153,27 @@ for t in tests: print(' %s' % t.getFullName()) +def compile_regular_expression_for_ordering(arg): + import re + try: + return re.compile(arg, re.IGNORECASE) + except re.error as reason: + raise _error("invalid regular expression: '{}', {}", arg, reason) + +def get_order_key(t): + run_late = compile_regular_expression_for_ordering(t.suite.config.late_tests) + name = t.getFullName() + if run_late.search(name): + return (2, name) + if t.isEarlyTest(): + return (0, name) + return (1, name) def determine_order(tests, order): + from lit.cl_arguments import TestOrder if order == TestOrder.EARLY_TESTS_THEN_BY_NAME: - tests.sort(key=lambda t: (not t.isEarlyTest(), t.getFullName())) + tests.sort(key=get_order_key) elif order == TestOrder.FAILING_FIRST: def by_mtime(test): return os.path.getmtime(test.getFilePath()) diff --git a/llvm/utils/lit/tests/Inputs/late-tests/aaa.txt b/llvm/utils/lit/tests/Inputs/late-tests/aaa.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/late-tests/aaa.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/late-tests/bbb.txt b/llvm/utils/lit/tests/Inputs/late-tests/bbb.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/late-tests/bbb.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/late-tests/ccc.txt b/llvm/utils/lit/tests/Inputs/late-tests/ccc.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/late-tests/ccc.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/Inputs/late-tests/lit.cfg b/llvm/utils/lit/tests/Inputs/late-tests/lit.cfg new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/late-tests/lit.cfg @@ -0,0 +1,7 @@ +import lit.formats +config.name = 'late-tests' +config.suffixes = ['.txt'] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None +config.late_tests = "a[a][A]" diff --git a/llvm/utils/lit/tests/late-tests.py b/llvm/utils/lit/tests/late-tests.py new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/late-tests.py @@ -0,0 +1,9 @@ +## Check that we can run tests early. + +# RUN: %{lit} -j1 %{inputs}/late-tests | FileCheck %s + +# CHECK: -- Testing: 3 tests, 1 workers -- +# CHECK-NEXT: PASS: late-tests :: bbb.txt +# CHECK-NEXT: PASS: late-tests :: ccc.txt +# CHECK-NEXT: PASS: late-tests :: aaa.txt +# CHECK: Passed: 3