Elffuss BraidHub

kikocis/kleidiai public

main · 2.2 KiBRawPermalink
1#!/usr/bin/env python3
2#
3# SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
4#
5# SPDX-License-Identifier: Apache-2.0
6"""Print a compact summary from GTest JUnit XML files."""
7from __future__ import annotations
8
9import argparse
10import sys
11import xml.etree.ElementTree as ET
12from pathlib import Path
13
14
15def _message(element: ET.Element) -> str:
16 message = element.attrib.get("message", "")
17 text = element.text or ""
18 return " ".join((message or text).split())
19
20
21def summarize(path: Path, max_failures: int) -> int:
22 if not path.exists():
23 print(f"{path}: report not found")
24 return 1
25
26 try:
27 root = ET.parse(path).getroot()
28 except ET.ParseError as exc:
29 print(f"{path}: failed to parse JUnit XML: {exc}")
30 return 1
31
32 failures: list[str] = []
33 for testcase in root.iter("testcase"):
34 test_name = f"{testcase.attrib.get('classname', '')}.{testcase.attrib.get('name', '')}".strip(
35 "."
36 )
37 location = ""
38 if "file" in testcase.attrib:
39 location = testcase.attrib["file"]
40 if "line" in testcase.attrib:
41 location += f":{testcase.attrib['line']}"
42
43 for tag in ("failure", "error"):
44 for element in testcase.findall(tag):
45 detail = _message(element)
46 suffix = f" ({location})" if location else ""
47 failures.append(f"{test_name}{suffix}: {detail}")
48
49 print(f"JUnit summary for {path}:")
50 if failures:
51 print(f" failed/error tests: {len(failures)}")
52 for failure in failures[:max_failures]:
53 print(f" - {failure}")
54 if len(failures) > max_failures:
55 print(f" ... {len(failures) - max_failures} more failures omitted")
56 else:
57 print(" failed/error tests: 0")
58
59 return 0
60
61
62def main() -> int:
63 parser = argparse.ArgumentParser(description=__doc__)
64 parser.add_argument("reports", nargs="+", type=Path)
65 parser.add_argument("--max-failures", type=int, default=50)
66 args = parser.parse_args()
67
68 status = 0
69 for report in args.reports:
70 status |= summarize(report, args.max_failures)
71 return status
72
73
74if __name__ == "__main__":
75 sys.exit(main())