Skip to content

Commit dc3489c

Browse files
authored
Merge branch 'main' into deferparse
2 parents d84ba0c + 0e92beb commit dc3489c

File tree

14,617 files changed

+858231
-628827
lines changed

Some content is hidden

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

14,617 files changed

+858231
-628827
lines changed

.ci/all_requirements.txt

Lines changed: 192 additions & 2 deletions
Large diffs are not rendered by default.

.ci/generate_test_report_github.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
"""Script to generate a build report for Github."""
55

66
import argparse
7-
import platform
87

98
import generate_test_report_lib
109

11-
def compute_platform_title() -> str:
12-
logo = ":window:" if platform.system() == "Windows" else ":penguin:"
13-
# On Linux the machine value is x86_64 on Windows it is AMD64.
14-
if platform.machine() == "x86_64" or platform.machine() == "AMD64":
15-
arch = "x64"
16-
else:
17-
arch = platform.machine()
18-
return f"{logo} {platform.system()} {arch} Test Results"
19-
2010

2111
if __name__ == "__main__":
2212
parser = argparse.ArgumentParser()
@@ -27,7 +17,9 @@ def compute_platform_title() -> str:
2717
args = parser.parse_args()
2818

2919
report = generate_test_report_lib.generate_report_from_files(
30-
compute_platform_title(), args.return_code, args.build_test_logs
20+
generate_test_report_lib.compute_platform_title(),
21+
args.return_code,
22+
args.build_test_logs,
3123
)
3224

3325
print(report)

.ci/generate_test_report_lib.py

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
"""Library to parse JUnit XML files and return a markdown report."""
55

6+
from typing import TypedDict, Optional
7+
import platform
8+
69
from junitparser import JUnitXml, Failure
710

11+
12+
# This data structure should match the definition in llvm-zorg in
13+
# premerge/advisor/advisor_lib.py
14+
# TODO(boomanaiden154): Drop the Optional here and switch to str | None when
15+
# we require Python 3.10.
16+
class FailureExplanation(TypedDict):
17+
name: str
18+
explained: bool
19+
reason: Optional[str]
20+
21+
822
SEE_BUILD_FILE_STR = "Download the build's log file to see the details."
923
UNRELATED_FAILURES_STR = (
1024
"If these failures are unrelated to your changes (for example "
@@ -41,11 +55,25 @@ def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
4155
# touch test/4.stamp
4256
#
4357
# index will point to the line that starts with Failed:. The progress
44-
# indicator is the line before this ([4/5] test/4.stamp) and contains a pretty
45-
# printed version of the target being built (test/4.stamp). We use this line
46-
# and remove the progress information to get a succinct name for the target.
47-
failing_action = ninja_log[index - 1].split("] ")[1]
58+
# indicator is sometimes the line before this ([4/5] test/4.stamp) and
59+
# will contain a pretty printed version of the target being built
60+
# (test/4.stamp) when accurate. We instead parse the failed line rather
61+
# than the progress indicator as the progress indicator may not be
62+
# aligned with the failure.
63+
failing_action = ninja_log[index].split("FAILED: ")[1]
4864
failure_log = []
65+
66+
# Parse the lines above the FAILED: string if the line does not come
67+
# immediately after a progress indicator to ensure that we capture the
68+
# entire failure message.
69+
if not ninja_log[index - 1].startswith("["):
70+
before_index = index - 1
71+
while before_index > 0 and not ninja_log[before_index].startswith("["):
72+
failure_log.append(ninja_log[before_index])
73+
before_index = before_index - 1
74+
failure_log.reverse()
75+
76+
# Parse the failure information, which comes after the FAILED: tag.
4977
while (
5078
index < len(ninja_log)
5179
and not ninja_log[index].startswith("[")
@@ -80,16 +108,29 @@ def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, s
80108
return failures
81109

82110

83-
def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
84-
"""Formats ninja failures into summary views for the report."""
111+
def _format_failures(
112+
failures: list[tuple[str, str]], failure_explanations: dict[str, FailureExplanation]
113+
) -> list[str]:
114+
"""Formats failures into summary views for the report."""
85115
output = []
86-
for build_failure in ninja_failures:
116+
for build_failure in failures:
87117
failed_action, failure_message = build_failure
118+
failure_explanation = None
119+
if failed_action in failure_explanations:
120+
failure_explanation = failure_explanations[failed_action]
121+
output.append("<details>")
122+
if failure_explanation:
123+
output.extend(
124+
[
125+
f"<summary>{failed_action} (Likely Already Failing)</summary>" "",
126+
failure_explanation["reason"],
127+
"",
128+
]
129+
)
130+
else:
131+
output.extend([f"<summary>{failed_action}</summary>", ""])
88132
output.extend(
89133
[
90-
"<details>",
91-
f"<summary>{failed_action}</summary>",
92-
"",
93134
"```",
94135
failure_message,
95136
"```",
@@ -98,6 +139,7 @@ def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
98139
)
99140
return output
100141

142+
101143
def get_failures(junit_objects) -> dict[str, list[tuple[str, str]]]:
102144
failures = {}
103145
for results in junit_objects:
@@ -129,12 +171,19 @@ def generate_report(
129171
ninja_logs: list[list[str]],
130172
size_limit=1024 * 1024,
131173
list_failures=True,
174+
failure_explanations_list: list[FailureExplanation] = [],
132175
):
133176
failures = get_failures(junit_objects)
134177
tests_run = 0
135178
tests_skipped = 0
136179
tests_failed = 0
137180

181+
failure_explanations: dict[str, FailureExplanation] = {}
182+
for failure_explanation in failure_explanations_list:
183+
if not failure_explanation["explained"]:
184+
continue
185+
failure_explanations[failure_explanation["name"]] = failure_explanation
186+
138187
for results in junit_objects:
139188
for testsuite in results:
140189
tests_run += testsuite.tests
@@ -147,8 +196,8 @@ def generate_report(
147196
if return_code == 0:
148197
report.extend(
149198
[
150-
"The build succeeded and no tests ran. This is expected in some "
151-
"build configurations."
199+
":white_check_mark: The build succeeded and no tests ran. "
200+
"This is expected in some build configurations."
152201
]
153202
)
154203
else:
@@ -173,7 +222,7 @@ def generate_report(
173222
"",
174223
]
175224
)
176-
report.extend(_format_ninja_failures(ninja_failures))
225+
report.extend(_format_failures(ninja_failures, failure_explanations))
177226
report.extend(
178227
[
179228
"",
@@ -209,18 +258,7 @@ def plural(num_tests):
209258

210259
for testsuite_name, failures in failures.items():
211260
report.extend(["", f"### {testsuite_name}"])
212-
for name, output in failures:
213-
report.extend(
214-
[
215-
"<details>",
216-
f"<summary>{name}</summary>",
217-
"",
218-
"```",
219-
output,
220-
"```",
221-
"</details>",
222-
]
223-
)
261+
report.extend(_format_failures(failures, failure_explanations))
224262
elif return_code != 0:
225263
# No tests failed but the build was in a failed state. Bring this to the user's
226264
# attention.
@@ -245,7 +283,11 @@ def plural(num_tests):
245283
"",
246284
]
247285
)
248-
report.extend(_format_ninja_failures(ninja_failures))
286+
report.extend(_format_failures(ninja_failures, failure_explanations))
287+
else:
288+
report.extend(
289+
["", ":white_check_mark: The build succeeded and all tests passed."]
290+
)
249291

250292
if failures or return_code != 0:
251293
report.extend(["", UNRELATED_FAILURES_STR])
@@ -282,3 +324,13 @@ def load_info_from_files(build_log_files):
282324
def generate_report_from_files(title, return_code, build_log_files):
283325
junit_objects, ninja_logs = load_info_from_files(build_log_files)
284326
return generate_report(title, return_code, junit_objects, ninja_logs)
327+
328+
329+
def compute_platform_title() -> str:
330+
logo = ":window:" if platform.system() == "Windows" else ":penguin:"
331+
# On Linux the machine value is x86_64 on Windows it is AMD64.
332+
if platform.machine() == "x86_64" or platform.machine() == "AMD64":
333+
arch = "x64"
334+
else:
335+
arch = platform.machine()
336+
return f"{logo} {platform.system()} {arch} Test Results"

0 commit comments

Comments
 (0)