Skip to content

Commit 498aead

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. Reviewers: lnihlen, cmtice Pull Request: #147871
1 parent d14aa0c commit 498aead

File tree

2 files changed

+65
-24
lines changed

2 files changed

+65
-24
lines changed

.ci/generate_test_report_lib.py

Lines changed: 31 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,28 @@ 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(
58+
[
59+
"The build succeeded and no tests ran. This is expected in some "
60+
"build configurations."
61+
]
62+
)
63+
else:
64+
report.extend(
65+
[
66+
"The build failed before running any tests.",
67+
"",
68+
SEE_BUILD_FILE_STR,
69+
"",
70+
UNRELATED_FAILURES_STR,
71+
]
72+
)
73+
return "\n".join(report)
74+
5875
tests_passed = tests_run - tests_skipped - tests_failed
5976

6077
def plural(num_tests):
@@ -72,7 +89,7 @@ def plural(num_tests):
7289
[
7390
"",
7491
"Failed tests and their output was too large to report. "
75-
"Download the build's log file to see the details.",
92+
+ SEE_BUILD_FILE_STR,
7693
]
7794
)
7895
elif failures:
@@ -102,20 +119,12 @@ def plural(num_tests):
102119
"",
103120
"All tests passed but another part of the build **failed**.",
104121
"",
105-
"Download the build's log file to see the details.",
122+
SEE_BUILD_FILE_STR,
106123
]
107124
)
108125

109126
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-
)
127+
report.extend(["", UNRELATED_FAILURES_STR])
119128

120129
report = "\n".join(report)
121130
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 and no tests ran. This is expected in some build configurations."""
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)