forked from chipsalliance/sv-tests
-
Notifications
You must be signed in to change notification settings - Fork 2
/
report_analyzer.py
executable file
·201 lines (159 loc) · 5.69 KB
/
report_analyzer.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
import argparse
import csv
import json
import sys
import pytablewriter
relevant_headers = ["Tool", "TestName", "Pass"]
def get_data(csv_path):
with open(csv_path, newline="") as csv_file:
report = list(csv.DictReader(csv_file))
header = report[0].keys()
assert set(relevant_headers).issubset(
header), "Lack of crucial headers in CSV report " + csv_path
tools = set(row["Tool"] for row in report)
sorted_report = {}
for tool in tools:
sorted_report[tool] = {}
for row in report:
sorted_report[row["Tool"]][row["TestName"]] = row["Pass"]
return sorted_report
def check_tool(tool_reportA, tool_reportB, tool_name):
results = {
"new_passes": [],
"new_failures": [],
"added": [],
"removed": [],
"summary": {},
}
testsA = set(tool_reportA.keys())
testsB = set(tool_reportB.keys())
tests_added = testsA.difference(testsB)
tests_removed = testsB.difference(testsA)
tests_comparable = testsA.intersection(testsB)
added_cnt = len(tests_added)
removed_cnt = len(tests_removed)
no_change_cnt = 0
for test in tests_comparable:
res = check_test(tool_reportA[test], tool_reportB[test])
if (res == -1):
results["new_failures"].append(test)
elif (res == 1):
results["new_passes"].append(test)
else:
no_change_cnt += 1
fail_cnt = len(results["new_failures"])
pass_cnt = len(results["new_passes"])
for added_test in tests_added:
results["added"].append(added_test)
for removed_test in tests_removed:
results["removed"].append(removed_test)
results["summary"]["new_failures"] = fail_cnt
results["summary"]["new_passes"] = pass_cnt
results["summary"]["added"] = added_cnt
results["summary"]["removed"] = removed_cnt
results["summary"]["not_affected"] = no_change_cnt
return results
def check_test(test_reportA, test_reportB):
if (test_reportA == test_reportB):
return 0
elif (test_reportA == "True" and test_reportB == "False"):
return 1
elif (test_reportA == "False" and test_reportB == "True"):
return -1
else:
raise ValueError(
"unknown test result occured: A -> " + test_reportA + " B -> " +
test_reportB)
def check_reports(reportA, reportB):
summary = {
"comparable_tools": {},
"added_tools": [],
"removed_tools": [],
}
toolsA = set(reportA.keys())
toolsB = set(reportB.keys())
tools = toolsA.intersection(toolsB)
if (toolsA != toolsB):
tools_added = toolsA.difference(toolsB)
tools_removed = toolsB.difference(toolsA)
summary["added_tools"] = list(tools_added)
summary["removed_tools"] = list(tools_removed)
for tool in tools:
tool_results = check_tool(reportA[tool], reportB[tool], tool)
summary["comparable_tools"][tool] = tool_results
return summary
def prepare_comment(summary, table_path):
tools = list(summary["comparable_tools"].keys())
cols = list(summary["comparable_tools"][tools[0]]["summary"].keys())
cols.insert(0, "tool")
matrix = []
for tool in tools:
vals = list(summary["comparable_tools"][tool]["summary"].values())
vals.insert(0, tool)
matrix.append(vals)
writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "Compared test results"
writer.header_list = cols
writer.value_matrix = matrix
writer.write_table()
with open(table_path, "w") as f:
writer.stream = f
writer.write_table()
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"report_compare",
help="csv report that will be compared with base report")
parser.add_argument(
"report_base", help="csv report that will be a base of comparison")
parser.add_argument(
"-o",
"--output",
dest="output_path",
default="report_summary.json",
help="path to output json file, defaults to \"report_summary.json\"")
parser.add_argument(
"-t",
"--table",
dest="table_path",
default="report_summary.md",
help=
"path to output md file with summary, defaults to \"report_summary.md\""
)
parser.add_argument(
"-c",
"--changes",
dest="changes_path",
default="./out/report",
help=
"path to output csv file with names of test that changed status, defaults to \"./out/report\""
)
args = parser.parse_args()
reportA = get_data(args.report_compare)
reportB = get_data(args.report_base)
summary = check_reports(reportA, reportB)
with open(args.changes_path + "/new_failures.csv", "w") as csv_file:
writer = csv.writer(csv_file)
for tool in summary["comparable_tools"]:
for test in summary["comparable_tools"][tool]["new_failures"]:
writer.writerow([tool, test])
with open(args.changes_path + "/new_passes.csv", "w") as csv_file:
writer = csv.writer(csv_file)
for tool in summary["comparable_tools"]:
for test in summary["comparable_tools"][tool]["new_passes"]:
writer.writerow([tool, test])
prepare_comment(summary, args.table_path)
with open(args.output_path, "w") as json_file:
json.dump(summary, json_file, indent=4)
if __name__ == "__main__":
main()