[llvm] 0088164 - [NFC][lit] Extract 'test time' reading/writing into standalone functions
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 22 05:26:25 PDT 2021
Author: Roman Lebedev
Date: 2021-03-22T15:25:32+03:00
New Revision: 00881644774d6a7cd0465c2318a43d6849b931c8
URL: https://github.com/llvm/llvm-project/commit/00881644774d6a7cd0465c2318a43d6849b931c8
DIFF: https://github.com/llvm/llvm-project/commit/00881644774d6a7cd0465c2318a43d6849b931c8.diff
LOG: [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.
Added:
llvm/utils/lit/lit/TestTimes.py
Modified:
llvm/utils/lit/lit/Test.py
llvm/utils/lit/lit/main.py
Removed:
################################################################################
diff --git a/llvm/utils/lit/lit/Test.py b/llvm/utils/lit/lit/Test.py
index ca715734eab4..7cc610bf56bd 100644
--- a/llvm/utils/lit/lit/Test.py
+++ b/llvm/utils/lit/lit/Test.py
@@ -3,6 +3,7 @@
from json import JSONEncoder
from lit.BooleanExpression import BooleanExpression
+from lit.TestTimes import read_test_times
# Test result codes.
@@ -207,15 +208,7 @@ def __init__(self, name, source_root, exec_root, config):
# 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)
diff --git a/llvm/utils/lit/lit/TestTimes.py b/llvm/utils/lit/lit/TestTimes.py
new file mode 100644
index 000000000000..fe01c3f36eb1
--- /dev/null
+++ b/llvm/utils/lit/lit/TestTimes.py
@@ -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
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 70a31110f796..e4c3a34b2d22 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -18,6 +18,7 @@
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]
More information about the llvm-commits
mailing list