-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve what goes into JUnit XML for reporting with Jenkins (#26771)
This PR makes some improvements to the way that we collect JUnit XML entries, which are responsible for 1) flagging Jenkins jobs as "unstable" (as opposed to passing) and 2) showing what failed from the web interface. It does so in the following ways: 1. Hardens the log -> XML extractor against unrelated output. E.g., some prediffs or checks used to print `[Skipping ...`, which was picked up as "skipping a test" when parsing the log output. This is not correct, so this PR introduces an allowlist of all possible skip markers. 2. Ensures that `sub_test` crashes are caught. To this end, standardizes output from failing `sub_test` invocations in `start_test`, and starts treating "Failure running sub_test" as a waypoint of starting / ending a test block (along with `Starting sub_test` and `Finished sub_test`, neither of which are necessarily printed if `sub_test` fails). In doing so, begins detecting failed `sub_test` invocations, and includes them in the JUnit XML. 3. Adds a new script to generate JUnit XML from failed system commands. To this end, stores a list of all executed commands, and adjusts the mysystemlog to include blank lines for commands that succeeded. 4. Adds a new script `merge_junit_xmls` that does as its name suggests. Using this script... * ...incorporates JUnit output from the Chapel Language Server tests into the final report. * ...incorporates errors from system commands (see above) in the final report. The net result is that a _lot_ more failures are detected and reported. Given the exact same set of failures: * A failing chplcheck test * A `sub_test` that crashes after 5 tests * One successful and one failing system command in `nightly` * A failing CLS test The previous script generated the following report: <img width="481" alt="Screenshot 2025-02-24 at 3 45 38 PM" src="https://github.com/user-attachments/assets/0449a19c-5e72-4451-982d-866d03180f52" /> The new script generates the following, much more robust, report: <img width="849" alt="Screenshot 2025-02-24 at 3 45 51 PM" src="https://github.com/user-attachments/assets/85afb801-4632-49da-b377-b5d382f3d038" /> Reviewed by @jabraham17 -- thanks! # Testing - manual invocation of `nightly`
- Loading branch information
Showing
12 changed files
with
199 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ PyYAML==6.0.2 | |
filelock==3.16.1 | ||
argcomplete==3.5.1 | ||
setuptools==75.1.0 | ||
junitparser==3.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
util/test/convert_nightly_system_command_log_to_junit_xml.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import argparse | ||
import xml.etree.ElementTree as XML | ||
|
||
parser = argparse.ArgumentParser(description='Convert nightly system command logs to JUnit XML.') | ||
parser.add_argument('cleanlog', type=str, help='Log listing all commands that were executed') | ||
parser.add_argument('errorlog', type=str, help='Log listing errors in commands that were executed') | ||
parser.add_argument('output', type=str, help='Output JUnit XML file') | ||
|
||
args = parser.parse_args() | ||
|
||
with open(args.cleanlog, 'r') as f: | ||
cleanlog = f.readlines() | ||
|
||
with open(args.errorlog, 'r') as f: | ||
errorlog = f.readlines() | ||
|
||
test_suites = XML.Element('testsuites') | ||
test_suite = XML.SubElement(test_suites, 'testsuite') | ||
|
||
# Error lines are empty when no error occurred. | ||
num_errors = 0 | ||
for (cleanline, errline) in zip(cleanlog, errorlog): | ||
cleanline = cleanline.strip() | ||
errline = errline.strip() | ||
|
||
test_case = XML.SubElement(test_suite, 'testcase') | ||
test_case.set('name', cleanline) | ||
test_case.set('classname', 'nightly system command') | ||
test_case.set('time', '0') | ||
|
||
if errline: | ||
failure = XML.SubElement(test_case, 'failure') | ||
failure.set('message', errline) | ||
num_errors += 1 | ||
|
||
test_suite.set('name', 'nightly system commands') | ||
test_suite.set('errors', str(num_errors)) | ||
test_suite.set('failures', str(num_errors)) | ||
test_suite.set('tests', str(len(cleanlog))) | ||
|
||
tree = XML.ElementTree(test_suites) | ||
tree.write(args.output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env sh | ||
|
||
# get the chpl home directory | ||
FIND_CHPL_HOME=$(cd $(dirname $0) ; cd ../..; pwd) | ||
|
||
$FIND_CHPL_HOME/util/test/run-in-test-venv.bash $FIND_CHPL_HOME/util/test/merge_junit_xmls.py "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Combine reports A.xml, B.xml, C.xml into a combined A.xml""" | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
from junitparser import JUnitXml, TestCase, TestSuite | ||
|
||
def merge_junit_xmls(xml_files): | ||
if not xml_files: | ||
return | ||
|
||
merged = sum((JUnitXml.fromfile(xml) for xml in xml_files), JUnitXml()) | ||
merged.write(xml_files[0]) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument('xml_files', nargs='+', help='JUnit XML files to merge') | ||
args = parser.parse_args() | ||
merge_junit_xmls(args.xml_files) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters