Skip to content

Commit 1b068ad

Browse files
[CI] Generate Test Report With No Test Results
This patch makes it so that generate_test_report_github.py generates a test report even when we don't get any test results. This otherwise created a pretty confusing user experience on the Github side if the build failed before any tests ran or in cases like running check-libc where none of the tests are run through lit. Pull Request: llvm#147871
1 parent 1469c33 commit 1b068ad

File tree

2 files changed

+60
-24
lines changed

2 files changed

+60
-24
lines changed

.ci/generate_test_report_lib.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
from junitparser import JUnitXml, Failure
77

8+
SEE_BUILD_FILE_STR = "Download the build's log file to see the details."
9+
UNRELATED_FAILURES_STR = (
10+
"If these failures are unrelated to your changes (for example "
11+
"tests are broken or flaky at HEAD), please open an issue at "
12+
"https://github.com/llvm/llvm-project/issues and add the "
13+
"`infrastructure` label."
14+
)
15+
816

917
# Set size_limit to limit the byte size of the report. The default is 1MB as this
1018
# is the most that can be put into an annotation. If the generated report exceeds
@@ -19,14 +27,6 @@ def generate_report(
1927
size_limit=1024 * 1024,
2028
list_failures=True,
2129
):
22-
if not junit_objects:
23-
# Note that we do not post an empty report, therefore we can ignore a
24-
# non-zero return code in situations like this.
25-
#
26-
# If we were going to post a report, then yes, it would be misleading
27-
# to say we succeeded when the final return code was non-zero.
28-
return ""
29-
3030
failures = {}
3131
tests_run = 0
3232
tests_skipped = 0
@@ -50,11 +50,23 @@ def generate_report(
5050
(test.classname + "/" + test.name, test.result[0].text)
5151
)
5252

53-
if not tests_run:
54-
return ""
55-
5653
report = [f"# {title}", ""]
5754

55+
if tests_run == 0:
56+
if return_code == 0:
57+
report.extend(["The build succeeded but no tests ran."])
58+
else:
59+
report.extend(
60+
[
61+
"The build failed before running any tests.",
62+
"",
63+
SEE_BUILD_FILE_STR,
64+
"",
65+
UNRELATED_FAILURES_STR,
66+
]
67+
)
68+
return "\n".join(report)
69+
5870
tests_passed = tests_run - tests_skipped - tests_failed
5971

6072
def plural(num_tests):
@@ -72,7 +84,7 @@ def plural(num_tests):
7284
[
7385
"",
7486
"Failed tests and their output was too large to report. "
75-
"Download the build's log file to see the details.",
87+
+ SEE_BUILD_FILE_STR,
7688
]
7789
)
7890
elif failures:
@@ -102,20 +114,12 @@ def plural(num_tests):
102114
"",
103115
"All tests passed but another part of the build **failed**.",
104116
"",
105-
"Download the build's log file to see the details.",
117+
SEE_BUILD_FILE_STR,
106118
]
107119
)
108120

109121
if failures or return_code != 0:
110-
report.extend(
111-
[
112-
"",
113-
"If these failures are unrelated to your changes (for example "
114-
"tests are broken or flaky at HEAD), please open an issue at "
115-
"https://github.com/llvm/llvm-project/issues and add the "
116-
"`infrastructure` label.",
117-
]
118-
)
122+
report.extend(["", UNRELATED_FAILURES_STR])
119123

120124
report = "\n".join(report)
121125
if len(report.encode("utf-8")) > size_limit:

.ci/generate_test_report_lib_test.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,30 @@ def junit_from_xml(xml):
2020

2121
class TestReports(unittest.TestCase):
2222
def test_title_only(self):
23-
self.assertEqual(generate_test_report_lib.generate_report("Foo", 0, []), "")
23+
self.assertEqual(
24+
generate_test_report_lib.generate_report("Foo", 0, []),
25+
dedent(
26+
"""\
27+
# Foo
28+
29+
The build succeeded but no tests ran."""
30+
),
31+
)
32+
33+
def test_title_only_failure(self):
34+
self.assertEqual(
35+
generate_test_report_lib.generate_report("Foo", 1, []),
36+
dedent(
37+
"""\
38+
# Foo
39+
40+
The build failed before running any tests.
41+
42+
Download the build's log file to see the details.
43+
44+
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label."""
45+
),
46+
)
2447

2548
def test_no_tests_in_testsuite(self):
2649
self.assertEqual(
@@ -40,7 +63,16 @@ def test_no_tests_in_testsuite(self):
4063
)
4164
],
4265
),
43-
"",
66+
dedent(
67+
"""\
68+
# Foo
69+
70+
The build failed before running any tests.
71+
72+
Download the build's log file to see the details.
73+
74+
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label."""
75+
),
4476
)
4577

4678
def test_no_failures(self):

0 commit comments

Comments
 (0)