[llvm] Add print statements to lit for tracing purposes (PR #92694)
Vlad Serebrennikov via llvm-commits
llvm-commits at lists.llvm.org
Sun May 19 10:27:53 PDT 2024
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/92694
>From 2d419dd0910260272fea457beb59414798ee2594 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 15:54:44 +0300
Subject: [PATCH 1/7] Add print statements to lit for tracing purposes
---
llvm/utils/lit/lit/main.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index db9f24f748d9e..288558b90b77a 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -118,34 +118,56 @@ def main(builtin_params={}):
mark_xfail(discovered_tests, opts)
+ print("Endill 10")
+
mark_excluded(discovered_tests, selected_tests)
+ print("Endill 20")
+
start = time.time()
+ print("Endill 30")
run_tests(selected_tests, lit_config, opts, len(discovered_tests))
+ print("Endill 40")
elapsed = time.time() - start
+ print("Endill 50")
+
record_test_times(selected_tests, lit_config)
+ print("Endill 60")
+
selected_tests, discovered_tests = GoogleTest.post_process_shard_results(
selected_tests, discovered_tests
)
+ print("Endill 70")
+
if opts.time_tests:
print_histogram(discovered_tests)
+ print("Endill 80")
+
print_results(discovered_tests, elapsed, opts)
+ print("Endill 90")
+
tests_for_report = selected_tests if opts.shard else discovered_tests
for report in opts.reports:
report.write_results(tests_for_report, elapsed)
+ print("Endill 100")
+
if lit_config.numErrors:
sys.stderr.write("\n%d error(s) in tests\n" % lit_config.numErrors)
sys.exit(2)
+
+ print("Endill 110")
if lit_config.numWarnings:
sys.stderr.write("\n%d warning(s) in tests\n" % lit_config.numWarnings)
+ print("Endill 120")
+
has_failure = any(t.isFailure() for t in discovered_tests)
if has_failure:
if opts.ignoreFail:
>From 7edeaee2dfa50586406f27609bbd55d75e590aef Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 17:12:16 +0300
Subject: [PATCH 2/7] Add more tracing
---
llvm/utils/lit/lit/main.py | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 288558b90b77a..91e9d2310e52f 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -266,19 +266,23 @@ def mark_excluded(discovered_tests, selected_tests):
def run_tests(tests, lit_config, opts, discovered_tests):
+ print("Endill 310")
workers = min(len(tests), opts.workers)
+ print("Endill 320")
display = lit.display.create_display(opts, tests, discovered_tests, workers)
-
+ print("Endill 330")
run = lit.run.Run(
tests, lit_config, workers, display.update, opts.max_failures, opts.timeout
)
-
+ print("Endill 340")
display.print_header()
-
+ print("Endill 350")
interrupted = False
error = None
try:
+ print("Endill 360")
execute_in_tmp_dir(run, lit_config)
+ print("Endill 370")
except KeyboardInterrupt:
interrupted = True
error = " interrupted by user"
@@ -286,10 +290,13 @@ def run_tests(tests, lit_config, opts, discovered_tests):
error = "warning: reached maximum number of test failures"
except lit.run.TimeoutError:
error = "warning: reached timeout"
+ print("Endill 380")
display.clear(interrupted)
+ print("Endill 390")
if error:
sys.stderr.write("%s, skipping remaining tests\n" % error)
+ print("Endill 3100")
def execute_in_tmp_dir(run, lit_config):
>From 13a86f1060c84e82bfbb925e16f5985907b29dd0 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 17:12:45 +0300
Subject: [PATCH 3/7] Fix indentation
---
llvm/utils/lit/lit/main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 91e9d2310e52f..ee991f5360a4d 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -293,7 +293,7 @@ def run_tests(tests, lit_config, opts, discovered_tests):
print("Endill 380")
display.clear(interrupted)
- print("Endill 390")
+ print("Endill 390")
if error:
sys.stderr.write("%s, skipping remaining tests\n" % error)
print("Endill 3100")
>From 34619d6b865645e30af729aed03ff2d35a974062 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 17:16:15 +0300
Subject: [PATCH 4/7] Add even more tracing
---
llvm/utils/lit/lit/main.py | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index ee991f5360a4d..09354b3092d8a 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -300,6 +300,7 @@ def run_tests(tests, lit_config, opts, discovered_tests):
def execute_in_tmp_dir(run, lit_config):
+ print("Endill 3600")
# Create a temp directory inside the normal temp directory so that we can
# try to avoid temporary test file leaks. The user can avoid this behavior
# by setting LIT_PRESERVES_TMP in the environment, so they can easily use
@@ -308,26 +309,36 @@ def execute_in_tmp_dir(run, lit_config):
tmp_dir = None
if "LIT_PRESERVES_TMP" not in os.environ:
import tempfile
-
+ print("Endill 3610")
# z/OS linker does not support '_' in paths, so use '-'.
tmp_dir = tempfile.mkdtemp(prefix="lit-tmp-")
+ print("Endill 3620")
tmp_dir_envs = {k: tmp_dir for k in ["TMP", "TMPDIR", "TEMP", "TEMPDIR"]}
os.environ.update(tmp_dir_envs)
+ print("Endill 3630")
for cfg in {t.config for t in run.tests}:
cfg.environment.update(tmp_dir_envs)
+ print("Endill 3640")
try:
+ print("Endill 3650")
run.execute()
+ print("Endill 3660")
finally:
+ print("Endill 3670")
if tmp_dir:
try:
+ print("Endill 3680")
import shutil
-
+ print("Endill 3690")
shutil.rmtree(tmp_dir)
+ print("Endill 36100")
except Exception as e:
+ print("Endill 36110")
lit_config.warning(
"Failed to delete temp directory '%s', try upgrading your version of Python to fix this"
% tmp_dir
)
+ print("Endill 36120")
def print_histogram(tests):
>From bc6d8fd4a834a2a48fb450e1627680f36a35e066 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 18:17:34 +0300
Subject: [PATCH 5/7] Add even more tracing
---
llvm/utils/lit/lit/formats/googletest.py | 11 ++++++++--
llvm/utils/lit/lit/run.py | 28 ++++++++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/lit/lit/formats/googletest.py b/llvm/utils/lit/lit/formats/googletest.py
index 8037094a91067..25dcc85df81e4 100644
--- a/llvm/utils/lit/lit/formats/googletest.py
+++ b/llvm/utils/lit/lit/formats/googletest.py
@@ -140,18 +140,20 @@ def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):
)
def execute(self, test, litConfig):
+ print("Endill gt-0")
if test.gtest_json_file is None:
return lit.Test.FAIL, ""
testPath = test.getSourcePath()
from lit.cl_arguments import TestOrder
-
+ print("Endill gt-1")
use_shuffle = TestOrder(litConfig.order) == TestOrder.RANDOM
shard_env = {
"GTEST_OUTPUT": "json:" + test.gtest_json_file,
"GTEST_SHUFFLE": "1" if use_shuffle else "0",
}
if litConfig.gtest_sharding:
+ print("Endill gt-2")
testPath, testName = os.path.split(test.getSourcePath())
while not os.path.exists(testPath):
# Handle GTest parameterized and typed tests, whose name includes
@@ -186,13 +188,16 @@ def get_shard_header(shard_env):
shard_header = get_shard_header(shard_env)
try:
+ print("Endill gt-3")
out, _, exitCode = lit.util.executeCommand(
cmd,
env=test.config.environment,
timeout=litConfig.maxIndividualTestTime,
redirect_stderr=True,
)
+ print("Endill gt-4")
except lit.util.ExecuteCommandTimeoutException as e:
+ print("Endill gt-5")
stream_msg = f"\n{e.out}\n--\nexit: {e.exitCode}\n--\n"
return (
lit.Test.TIMEOUT,
@@ -225,7 +230,9 @@ def get_test_stdout(test_name):
found_failed_test = False
with open(test.gtest_json_file, encoding="utf-8") as f:
+ print("Endill gt-6")
jf = json.load(f)
+ print("Endill gt-7")
if use_shuffle:
shard_env["GTEST_RANDOM_SEED"] = str(jf["random_seed"])
@@ -258,7 +265,7 @@ def get_test_stdout(test_name):
# the shard could still fail due to memory issues.
if not found_failed_test:
output += f"\n{out}\n--\nexit: {exitCode}\n--\n"
-
+ print("Endill gt-8")
return lit.Test.FAIL, output
def prepareCmd(self, cmd):
diff --git a/llvm/utils/lit/lit/run.py b/llvm/utils/lit/lit/run.py
index 535c859352cc4..ebbce0e75a9ce 100644
--- a/llvm/utils/lit/lit/run.py
+++ b/llvm/utils/lit/lit/run.py
@@ -30,6 +30,7 @@ def __init__(
assert workers > 0
def execute(self):
+ print("Endill 36500")
"""
Execute the tests in the run using up to the specified number of
parallel tasks, and inform the caller of each individual result. The
@@ -55,25 +56,36 @@ def execute(self):
deadline = time.time() + timeout
try:
+ print("Endill 36510")
self._execute(deadline)
+ print("Endill 36520")
finally:
+ print("Endill 36530")
skipped = lit.Test.Result(lit.Test.SKIPPED)
+ print("Endill 36540")
for test in self.tests:
+ print("Endill 36550")
if test.result is None:
test.setResult(skipped)
+ print("Endill 36560")
+
def _execute(self, deadline):
+ print("Endill 365100")
self._increase_process_limit()
+ print("Endill 365110")
semaphores = {
k: multiprocessing.BoundedSemaphore(v)
for k, v in self.lit_config.parallelism_groups.items()
if v is not None
}
+ print("Endill 365120")
pool = multiprocessing.Pool(
self.workers, lit.worker.initialize, (self.lit_config, semaphores)
)
+ print("Endill 365130")
async_results = [
pool.apply_async(
@@ -81,29 +93,45 @@ def _execute(self, deadline):
)
for test in self.tests
]
+ print("Endill 365140")
pool.close()
+ print("Endill 365150")
try:
+ print("Endill 365160")
self._wait_for(async_results, deadline)
+ print("Endill 365170")
except:
+ print("Endill 365180")
pool.terminate()
+ print("Endill 365190")
raise
finally:
+ print("Endill 3651100")
pool.join()
+ print("Endill 3651110")
def _wait_for(self, async_results, deadline):
+ print("Endill 3651600")
timeout = deadline - time.time()
for idx, ar in enumerate(async_results):
+ print("Endill 3651610")
try:
+ print("Endill 3651620")
test = ar.get(timeout)
+ print("Endill 3651630")
except multiprocessing.TimeoutError:
+ print("Endill 3651640")
raise TimeoutError()
else:
+ print("Endill 3651650")
self._update_test(self.tests[idx], test)
+ print("Endill 3651660")
if test.isFailure():
self.failures += 1
if self.failures == self.max_failures:
raise MaxFailuresError()
+ print("Endill 3651670")
# Update local test object "in place" from remote test object. This
# ensures that the original test object which is used for printing test
>From e6256b3019b721077847c23b648d0b98eb2fe872 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 19:20:13 +0300
Subject: [PATCH 6/7] Print individual test details
---
llvm/utils/lit/lit/formats/googletest.py | 4 ++++
llvm/utils/lit/lit/run.py | 4 +++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/formats/googletest.py b/llvm/utils/lit/lit/formats/googletest.py
index 25dcc85df81e4..a054e044beff9 100644
--- a/llvm/utils/lit/lit/formats/googletest.py
+++ b/llvm/utils/lit/lit/formats/googletest.py
@@ -205,12 +205,15 @@ def get_shard_header(shard_env):
f"timeout of {litConfig.maxIndividualTestTime} seconds",
)
+ print("Endill gt-5-1")
if not os.path.exists(test.gtest_json_file):
+ print("Endill gt-5-2")
errmsg = f"shard JSON output does not exist: %s" % (test.gtest_json_file)
stream_msg = f"\n{out}\n--\nexit: {exitCode}\n--\n"
return lit.Test.FAIL, shard_header + stream_msg + errmsg
if exitCode == 0:
+ print("Endill gt-5-3")
return lit.Test.PASS, ""
def get_test_stdout(test_name):
@@ -229,6 +232,7 @@ def get_test_stdout(test_name):
found_failed_test = False
+ print("Endill gt-5-4")
with open(test.gtest_json_file, encoding="utf-8") as f:
print("Endill gt-6")
jf = json.load(f)
diff --git a/llvm/utils/lit/lit/run.py b/llvm/utils/lit/lit/run.py
index ebbce0e75a9ce..54482071a67b2 100644
--- a/llvm/utils/lit/lit/run.py
+++ b/llvm/utils/lit/lit/run.py
@@ -64,7 +64,6 @@ def execute(self):
skipped = lit.Test.Result(lit.Test.SKIPPED)
print("Endill 36540")
for test in self.tests:
- print("Endill 36550")
if test.result is None:
test.setResult(skipped)
print("Endill 36560")
@@ -120,6 +119,9 @@ def _wait_for(self, async_results, deadline):
print("Endill 3651620")
test = ar.get(timeout)
print("Endill 3651630")
+ print("Endill: test.file_path: {}".format(test.file_path))
+ print("Endill: test.path_in_suite: {}".format(test.path_in_suite))
+ print("Endill 3651635")
except multiprocessing.TimeoutError:
print("Endill 3651640")
raise TimeoutError()
>From 15fc2f17fbb6aa4b1500f713ea00540b2b70df53 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Sun, 19 May 2024 20:27:31 +0300
Subject: [PATCH 7/7] Print names of unit tests in shards
---
llvm/utils/lit/lit/formats/googletest.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/utils/lit/lit/formats/googletest.py b/llvm/utils/lit/lit/formats/googletest.py
index a054e044beff9..e665ac6a98cae 100644
--- a/llvm/utils/lit/lit/formats/googletest.py
+++ b/llvm/utils/lit/lit/formats/googletest.py
@@ -214,6 +214,16 @@ def get_shard_header(shard_env):
if exitCode == 0:
print("Endill gt-5-3")
+ print("Endill: shard header: {}".format(get_shard_header(shard_env)))
+ with open(test.gtest_json_file, encoding="utf-8") as f:
+ print("Endill gt-5-6")
+ jf = json.load(f)
+ print("Endill gt-5-7")
+ for testcase in jf["testsuites"]:
+ for testinfo in testcase["testsuite"]:
+ testname = testcase["name"] + "." + testinfo["name"]
+ print("Endill: testnamae: {}".format(testname))
+
return lit.Test.PASS, ""
def get_test_stdout(test_name):
More information about the llvm-commits
mailing list