mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[NFC][lit] Extract 'test time' reading/writing into standalone functions
Simply refactor code into reusable functions, to allow read_test_times() to be reused later.
This commit is contained in:
parent
f090e49be4
commit
c607b2fbf8
@ -3,6 +3,7 @@ import os
|
||||
from json import JSONEncoder
|
||||
|
||||
from lit.BooleanExpression import BooleanExpression
|
||||
from lit.TestTimes import read_test_times
|
||||
|
||||
# Test result codes.
|
||||
|
||||
@ -207,15 +208,7 @@ class TestSuite:
|
||||
# The test suite configuration.
|
||||
self.config = config
|
||||
|
||||
self.test_times = {}
|
||||
test_times_file = os.path.join(exec_root, '.lit_test_times.txt')
|
||||
if not os.path.exists(test_times_file):
|
||||
test_times_file = os.path.join(source_root, '.lit_test_times.txt')
|
||||
if os.path.exists(test_times_file):
|
||||
with open(test_times_file, 'r') as time_file:
|
||||
for line in time_file:
|
||||
time, path = line.split(maxsplit=1)
|
||||
self.test_times[path.strip('\n')] = float(time)
|
||||
self.test_times = read_test_times(self)
|
||||
|
||||
def getSourcePath(self, components):
|
||||
return os.path.join(self.source_root, *components)
|
||||
|
41
utils/lit/lit/TestTimes.py
Normal file
41
utils/lit/lit/TestTimes.py
Normal file
@ -0,0 +1,41 @@
|
||||
import os
|
||||
|
||||
|
||||
def read_test_times(suite):
|
||||
test_times = {}
|
||||
test_times_file = os.path.join(suite.exec_root, '.lit_test_times.txt')
|
||||
if not os.path.exists(test_times_file):
|
||||
test_times_file = os.path.join(
|
||||
suite.source_root, '.lit_test_times.txt')
|
||||
if os.path.exists(test_times_file):
|
||||
with open(test_times_file, 'r') as time_file:
|
||||
for line in time_file:
|
||||
time, path = line.split(maxsplit=1)
|
||||
test_times[path.strip('\n')] = float(time)
|
||||
return test_times
|
||||
|
||||
|
||||
def record_test_times(tests, lit_config):
|
||||
times_by_suite = {}
|
||||
for t in tests:
|
||||
if not t.result.elapsed:
|
||||
continue
|
||||
if not t.suite.exec_root in times_by_suite:
|
||||
times_by_suite[t.suite.exec_root] = []
|
||||
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))
|
||||
|
||||
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:
|
||||
time_file.write(("%e" % time) + ' ' + name + '\n')
|
||||
except:
|
||||
lit_config.warning('Could not save test time: ' + path)
|
||||
continue
|
@ -18,6 +18,7 @@ import lit.reports
|
||||
import lit.run
|
||||
import lit.Test
|
||||
import lit.util
|
||||
from lit.TestTimes import record_test_times
|
||||
|
||||
|
||||
def main(builtin_params={}):
|
||||
@ -256,32 +257,6 @@ def execute_in_tmp_dir(run, lit_config):
|
||||
lit_config.warning("Failed to delete temp directory '%s', try upgrading your version of Python to fix this" % tmp_dir)
|
||||
|
||||
|
||||
def record_test_times(tests, lit_config):
|
||||
times_by_suite = {}
|
||||
for t in tests:
|
||||
if not t.result.elapsed:
|
||||
continue
|
||||
if not t.suite.exec_root in times_by_suite:
|
||||
times_by_suite[t.suite.exec_root] = []
|
||||
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))
|
||||
|
||||
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:
|
||||
time_file.write(("%e" % time) + ' ' + name + '\n')
|
||||
except:
|
||||
lit_config.warning('Could not save test time: ' + path)
|
||||
continue
|
||||
|
||||
|
||||
def print_histogram(tests):
|
||||
test_times = [(t.getFullName(), t.result.elapsed)
|
||||
for t in tests if t.result.elapsed]
|
||||
|
Loading…
Reference in New Issue
Block a user