forked from pyuvm/pyuvm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcombine_results.py
More file actions
executable file
·151 lines (133 loc) · 4.35 KB
/
Copy pathcombine_results.py
File metadata and controls
executable file
·151 lines (133 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
"""
This script comes from cocotb/bin. It checks the result of
every test simulation.
"""
import argparse
import os
import sys
from xml.etree import ElementTree as ET
def find_all(name, path):
for root, dirs, files in os.walk(path):
if name in files:
yield os.path.join(root, name)
def get_parser():
"""Return the cmdline parser"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--directory",
dest="directory",
type=str,
required=False,
default=".",
help="Name of base directory to search from",
)
parser.add_argument(
"--output_file",
dest="output_file",
type=str,
required=False,
default="combined_results.xml",
help="Name of output file",
)
parser.add_argument(
"--testsuites_name",
dest="testsuites_name",
type=str,
required=False,
default="results",
help="Name value for testsuites tag",
)
parser.add_argument(
"--verbose",
dest="debug",
action="store_const",
required=False,
const=True,
default=False,
help="Verbose/debug output",
)
parser.add_argument(
"--suppress_rc",
dest="set_rc",
action="store_const",
required=False,
const=False,
default=True,
help="Suppress return code if failures found",
)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
rc = 0
result = ET.Element("testsuites", name=args.testsuites_name)
for fname in find_all("results.xml", args.directory):
if args.debug:
print(f"Reading file {fname}")
tree = ET.parse(fname)
for ts in tree.iter("testsuite"):
if args.debug:
print(
"Ts name : {}, package : {}".format(
ts.get("name"), ts.get("package")
)
)
use_element = None
for existing in result:
if existing.get("name") == ts.get("name") and existing.get(
"package"
) == ts.get("package"):
if args.debug:
print("Already found")
use_element = existing
break
if use_element is None:
result.append(ts)
else:
# for tc in ts.getiterator("testcase"):
use_element.extend(list(ts))
if args.debug:
ET.dump(result)
testsuite_count = 0
testcase_count = 0
for testsuite in result.iter("testsuite"):
testsuite_count += 1
for testcase in testsuite.iter("testcase"):
testcase_count += 1
for failure in testcase.iter("failure"):
if args.set_rc:
rc = 1
print(
"Failure in testsuite: '{}' classname: '{}' testcase: '{}' with parameters '{}'".format(
testsuite.get("name"),
testcase.get("classname"),
testcase.get("name"),
testsuite.get("package"),
)
)
if os.getenv("GITHUB_ACTIONS") is not None:
# Get test file relative to root of repo
repo_root = os.path.commonprefix(
[
os.path.abspath(testcase.get("file")),
os.path.abspath(__file__),
]
)
relative_file = testcase.get("file").replace(repo_root, "")
print(
"::error file={},line={}::Test {}:{} failed".format(
relative_file,
testcase.get("lineno"),
testcase.get("classname"),
testcase.get("name"),
)
)
print(f"Ran a total of {testsuite_count} TestSuites and {testcase_count} TestCases")
ET.ElementTree(result).write(args.output_file, encoding="UTF-8")
return rc
if __name__ == "__main__":
rc = main()
sys.exit(rc)