[lit] Do not forget test times for tests that weren't executed

Even though we have read the times before,
we intentionally forget about it for performance reasons.
But that means we also forget all the times for the tests
that weren't executed this time. This is mildly inconvenient.

So, when recording the new times, first re-read the old times,
and update times for the tests that were executed,
thus preserving all original times, too.
This commit is contained in:
Roman Lebedev 2021-03-22 15:24:52 +03:00
parent 0088164477
commit 233db43967
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 7 additions and 6 deletions

View File

@ -18,23 +18,23 @@ def read_test_times(suite):
def record_test_times(tests, lit_config):
times_by_suite = {}
for t in tests:
assert t.suite.test_times is None
if not t.result.elapsed:
continue
if not t.suite.exec_root in times_by_suite:
times_by_suite[t.suite.exec_root] = []
times_by_suite[t.suite.exec_root] = read_test_times(t.suite)
time = -t.result.elapsed if t.isFailure() else t.result.elapsed
# The "path" here is only used as a key into a dictionary. It is never
# used as an actual path to a filesystem API, therefore we use '/' as
# the canonical separator so that Unix and Windows machines can share
# timing data.
times_by_suite[t.suite.exec_root].append(('/'.join(t.path_in_suite),
t.result.elapsed))
times_by_suite[t.suite.exec_root]['/'.join(t.path_in_suite)] = t.result.elapsed
for s, value in times_by_suite.items():
try:
path = os.path.join(s, '.lit_test_times.txt')
with open(path, 'w') as time_file:
for name, time in value:
for name, time in value.items():
time_file.write(("%e" % time) + ' ' + name + '\n')
except:
lit_config.warning('Could not save test time: ' + path)

View File

@ -5,11 +5,12 @@
# RUN: cp %{inputs}/reorder/.lit_test_times.txt %{inputs}/reorder/.lit_test_times.txt.new
# RUN: cp %{inputs}/reorder/.lit_test_times.txt.orig %{inputs}/reorder/.lit_test_times.txt
# RUN: not diff %{inputs}/reorder/.lit_test_times.txt.new %{inputs}/reorder/.lit_test_times.txt.orig
# RUN: FileCheck --check-prefix=TIMES --implicit-check-not=not-executed.txt < %{inputs}/reorder/.lit_test_times.txt.new %s
# RUN: FileCheck --check-prefix=TIMES --implicit-check-not= < %{inputs}/reorder/.lit_test_times.txt.new %s
# RUN: FileCheck < %t.out %s
# END.
# TIMES: subdir/ccc.txt
# TIMES: not-executed.txt
# TIMES-NEXT: subdir/ccc.txt
# TIMES-NEXT: bbb.txt
# TIMES-NEXT: aaa.txt
# TIMES-NEXT: new-test.txt