Skip to content

Commit 867ff2d

Browse files
authored
[lit] Add a flag to disable lit time tests (llvm#98270)
LLVM lit assumes control of the test parallelism when running a test suite. This style of testing doesn't play nicely with build systems like Buck or Bazel since it prefers finer grained actions on a per-test level. In order for external build systems to control the test parallelism, add an option to disable `.lit_test_times.txt` under the `--skip-test-time-recording` flag, thus allowing other build systems to determine the parallelism and avoid race conditions when writing to that file. I went for `--skip-test-time-recording` instead of `--time-tests` in order to preserve the original functionality of writing to `.lit_test_times.txt` as the default behavior and only opt-in for those who do _not_ want `.lit_test_times.txt` file.
1 parent c2019a3 commit 867ff2d

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

llvm/docs/CommandGuide/lit.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ EXECUTION OPTIONS
151151
feature that can be used to conditionally disable (or expect failure in)
152152
certain tests.
153153

154+
.. option:: --skip-test-time-recording
155+
156+
Disable tracking the wall time individual tests take to execute.
157+
154158
.. option:: --time-tests
155159

156160
Track the wall time individual tests take to execute and includes the results

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ def parse_args():
154154
action="append",
155155
default=[],
156156
)
157-
execution_group.add_argument(
158-
"--time-tests",
159-
help="Track elapsed wall time for each test",
160-
action="store_true",
161-
)
162157
execution_group.add_argument(
163158
"--no-execute",
164159
dest="noExecute",
@@ -209,6 +204,17 @@ def parse_args():
209204
action="store_true",
210205
help="Exit with status zero even if some tests fail",
211206
)
207+
execution_test_time_group = execution_group.add_mutually_exclusive_group()
208+
execution_test_time_group.add_argument(
209+
"--skip-test-time-recording",
210+
help="Do not track elapsed wall time for each test",
211+
action="store_true",
212+
)
213+
execution_test_time_group.add_argument(
214+
"--time-tests",
215+
help="Track elapsed wall time for each test printed in a histogram",
216+
action="store_true",
217+
)
212218

213219
selection_group = parser.add_argument_group("Test Selection")
214220
selection_group.add_argument(

llvm/utils/lit/lit/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def main(builtin_params={}):
124124
run_tests(selected_tests, lit_config, opts, len(discovered_tests))
125125
elapsed = time.time() - start
126126

127-
record_test_times(selected_tests, lit_config)
127+
if not opts.skip_test_time_recording:
128+
record_test_times(selected_tests, lit_config)
128129

129130
selected_tests, discovered_tests = GoogleTest.post_process_shard_results(
130131
selected_tests, discovered_tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# RUN: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import lit.formats
2+
3+
config.name = "time-tests"
4+
config.suffixes = [".txt"]
5+
config.test_format = lit.formats.ShTest()
6+
config.test_source_root = None
7+
config.test_exec_root = None

llvm/utils/lit/tests/time-tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Check that --skip-test-time-recording skips .lit_test_times.txt recording.
2+
3+
# RUN: %{lit-no-order-opt} --skip-test-time-recording %{inputs}/time-tests
4+
# RUN: not ls %{inputs}/time-tests/.lit_test_times.txt
5+
6+
## Check that --time-tests generates a printed histogram.
7+
8+
# RUN: %{lit-no-order-opt} --time-tests %{inputs}/time-tests > %t.out
9+
# RUN: FileCheck < %t.out %s
10+
# RUN: rm %{inputs}/time-tests/.lit_test_times.txt
11+
12+
# CHECK: Tests Times:
13+
# CHECK-NEXT: --------------------------------------------------------------------------
14+
# CHECK-NEXT: [ Range ] :: [ Percentage ] :: [Count]
15+
# CHECK-NEXT: --------------------------------------------------------------------------

0 commit comments

Comments
 (0)