Skip to content

Commit 3e84df1

Browse files
authored
Merge branch 'llvm:main' into coro_await_suspend_destroy
2 parents 9fe0b17 + fc44a4f commit 3e84df1

File tree

1,148 files changed

+20745
-15054
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,148 files changed

+20745
-15054
lines changed

.ci/generate_test_report_github.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
if __name__ == "__main__":
1717
parser = argparse.ArgumentParser()
1818
parser.add_argument("return_code", help="The build's return code.", type=int)
19-
parser.add_argument("junit_files", help="Paths to JUnit report files.", nargs="*")
19+
parser.add_argument(
20+
"build_test_logs", help="Paths to JUnit report files and ninja logs.", nargs="*"
21+
)
2022
args = parser.parse_args()
2123

2224
report = generate_test_report_lib.generate_report_from_files(
23-
PLATFORM_TITLES[platform.system()], args.return_code, args.junit_files
25+
PLATFORM_TITLES[platform.system()], args.return_code, args.build_test_logs
2426
)
2527

2628
print(report)

.ci/generate_test_report_lib.py

Lines changed: 143 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,84 @@
1212
"https://github.com/llvm/llvm-project/issues and add the "
1313
"`infrastructure` label."
1414
)
15+
# The maximum number of lines to pull from a ninja failure.
16+
NINJA_LOG_SIZE_THRESHOLD = 500
17+
18+
19+
def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
20+
"""Parses an individual ninja log."""
21+
failures = []
22+
index = 0
23+
while index < len(ninja_log):
24+
while index < len(ninja_log) and not ninja_log[index].startswith("FAILED:"):
25+
index += 1
26+
if index == len(ninja_log):
27+
# We hit the end of the log without finding a build failure, go to
28+
# the next log.
29+
return failures
30+
# We are trying to parse cases like the following:
31+
#
32+
# [4/5] test/4.stamp
33+
# FAILED: touch test/4.stamp
34+
# touch test/4.stamp
35+
#
36+
# index will point to the line that starts with Failed:. The progress
37+
# indicator is the line before this ([4/5] test/4.stamp) and contains a pretty
38+
# printed version of the target being built (test/4.stamp). We use this line
39+
# and remove the progress information to get a succinct name for the target.
40+
failing_action = ninja_log[index - 1].split("] ")[1]
41+
failure_log = []
42+
while (
43+
index < len(ninja_log)
44+
and not ninja_log[index].startswith("[")
45+
and not ninja_log[index].startswith("ninja: build stopped:")
46+
and len(failure_log) < NINJA_LOG_SIZE_THRESHOLD
47+
):
48+
failure_log.append(ninja_log[index])
49+
index += 1
50+
failures.append((failing_action, "\n".join(failure_log)))
51+
return failures
52+
53+
54+
def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, str]]:
55+
"""Extracts failure messages from ninja output.
56+
57+
This function takes stdout/stderr from ninja in the form of a list of files
58+
represented as a list of lines. This function then returns tuples containing
59+
the name of the target and the error message.
60+
61+
Args:
62+
ninja_logs: A list of files in the form of a list of lines representing the log
63+
files captured from ninja.
64+
65+
Returns:
66+
A list of tuples. The first string is the name of the target that failed. The
67+
second string is the error message.
68+
"""
69+
failures = []
70+
for ninja_log in ninja_logs:
71+
log_failures = _parse_ninja_log(ninja_log)
72+
failures.extend(log_failures)
73+
return failures
74+
75+
76+
def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
77+
"""Formats ninja failures into summary views for the report."""
78+
output = []
79+
for build_failure in ninja_failures:
80+
failed_action, failure_message = build_failure
81+
output.extend(
82+
[
83+
"<details>",
84+
f"<summary>{failed_action}</summary>",
85+
"",
86+
"```",
87+
failure_message,
88+
"```",
89+
"</details>",
90+
]
91+
)
92+
return output
1593

1694

1795
# Set size_limit to limit the byte size of the report. The default is 1MB as this
@@ -24,6 +102,7 @@ def generate_report(
24102
title,
25103
return_code,
26104
junit_objects,
105+
ninja_logs: list[list[str]],
27106
size_limit=1024 * 1024,
28107
list_failures=True,
29108
):
@@ -61,15 +140,34 @@ def generate_report(
61140
]
62141
)
63142
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-
)
143+
ninja_failures = find_failure_in_ninja_logs(ninja_logs)
144+
if not ninja_failures:
145+
report.extend(
146+
[
147+
"The build failed before running any tests. Detailed "
148+
"information about the build failure could not be "
149+
"automatically obtained.",
150+
"",
151+
SEE_BUILD_FILE_STR,
152+
"",
153+
UNRELATED_FAILURES_STR,
154+
]
155+
)
156+
else:
157+
report.extend(
158+
[
159+
"The build failed before running any tests. Click on a "
160+
"failure below to see the details.",
161+
"",
162+
]
163+
)
164+
report.extend(_format_ninja_failures(ninja_failures))
165+
report.extend(
166+
[
167+
"",
168+
UNRELATED_FAILURES_STR,
169+
]
170+
)
73171
return "\n".join(report)
74172

75173
tests_passed = tests_run - tests_skipped - tests_failed
@@ -114,14 +212,28 @@ def plural(num_tests):
114212
elif return_code != 0:
115213
# No tests failed but the build was in a failed state. Bring this to the user's
116214
# attention.
117-
report.extend(
118-
[
119-
"",
120-
"All tests passed but another part of the build **failed**.",
121-
"",
122-
SEE_BUILD_FILE_STR,
123-
]
124-
)
215+
ninja_failures = find_failure_in_ninja_logs(ninja_logs)
216+
if not ninja_failures:
217+
report.extend(
218+
[
219+
"",
220+
"All tests passed but another part of the build **failed**. "
221+
"Information about the build failure could not be automatically "
222+
"obtained.",
223+
"",
224+
SEE_BUILD_FILE_STR,
225+
]
226+
)
227+
else:
228+
report.extend(
229+
[
230+
"",
231+
"All tests passed but another part of the build **failed**. Click on "
232+
"a failure below to see the details.",
233+
"",
234+
]
235+
)
236+
report.extend(_format_ninja_failures(ninja_failures))
125237

126238
if failures or return_code != 0:
127239
report.extend(["", UNRELATED_FAILURES_STR])
@@ -139,9 +251,19 @@ def plural(num_tests):
139251
return report
140252

141253

142-
def generate_report_from_files(title, return_code, junit_files):
254+
def generate_report_from_files(title, return_code, build_log_files):
255+
junit_files = [
256+
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
257+
]
258+
ninja_log_files = [
259+
ninja_log for ninja_log in build_log_files if ninja_log.endswith(".log")
260+
]
261+
ninja_logs = []
262+
for ninja_log_file in ninja_log_files:
263+
with open(ninja_log_file, "r") as ninja_log_file_handle:
264+
ninja_logs.append(
265+
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
266+
)
143267
return generate_report(
144-
title,
145-
return_code,
146-
[JUnitXml.fromfile(p) for p in junit_files],
268+
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
147269
)

0 commit comments

Comments
 (0)