Skip to content

Instantly share code, notes, and snippets.

@kvakil
Last active July 25, 2022 06:53
Show Gist options
  • Save kvakil/8ed172559f5bc3c8391ec34065682599 to your computer and use it in GitHub Desktop.
Save kvakil/8ed172559f5bc3c8391ec34065682599 to your computer and use it in GitHub Desktop.
import json
import platform
import signal
import sys
import xml.etree.ElementTree as xml
# From utils.IsWindows()
system = platform.system()
is_windows = system == 'Microsoft' or system == 'Windows'
# From HasCrashed()
def is_exit_code_crashing(exit_code):
if is_windows:
return 0x80000000 & exit_code and not (0x3FFFFF00 & exit_code)
return exit_code > 128 and exit_code != 128 + signal.SIGABRT
# From JUnitTestOutput
class JUnitTestOutput:
def __init__(self, test_suite_name):
self.root = xml.Element("testsuite")
self.root.attrib["name"] = test_suite_name
def HasRunTest(self, test_name, test_cmd, test_duration, test_failure):
testCaseElement = xml.Element("testcase")
testCaseElement.attrib["name"] = test_name
testCaseElement.attrib["cmd"] = test_cmd
testCaseElement.attrib["time"] = str(round(test_duration, 3))
if test_failure is not None:
failureElement = xml.Element("failure")
failureElement.text = test_failure
testCaseElement.append(failureElement)
self.root.append(testCaseElement)
def FinishAndWrite(self, f):
xml.ElementTree(self.root).write(f, "UTF-8")
test_results = json.load(sys.stdin)
# V8's JSON test runner only logs failing tests under "results". Use a large
# number for --slow-tests-cutoff, to ensure that all tests appear under
# "slowest_tests".
failing_tests = {result["name"]: result for result in test_results["results"]}
all_tests = {result["name"]: result for result in test_results["slowest_tests"]}
passing_tests = {name: result for name, result in all_tests.items() if name not in failing_tests}
assert len(failing_tests) + len(passing_tests) == len(all_tests)
output = JUnitTestOutput("v8tests")
for name, failing_test in failing_tests.items():
failing_output = []
stdout = failing_test["stdout"].strip()
if len(stdout):
failing_output.extend(["stdout:", stdout])
stderr = failing_test["stderr"].strip()
if len(stderr):
failing_output.extend(["stderr:", stderr])
failing_output.append("Command: " + failing_test["command"])
exit_code = failing_test["exit_code"]
if failing_test["result"] == "TIMEOUT":
failing_output.append("--- TIMEOUT ---")
elif is_exit_code_crashing(exit_code):
failing_output.append("exit code: " + str(exit_code))
failing_output.append("--- CRASHED ---")
output.HasRunTest(
test_name=name,
test_cmd=failing_test["command"],
test_duration=failing_test["duration"],
test_failure="\n".join(failing_output),
)
for name, passing_test in passing_tests.items():
output.HasRunTest(
test_name=name,
test_cmd=passing_test["command"],
test_duration=passing_test["duration"],
test_failure=None,
)
output.FinishAndWrite(sys.stdout.buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment