Skip to content

Commit 93e794e

Browse files
authored
Merge pull request riscv-collab#468 from riscv/new-testsuite-filter
New testsuite filter scheme
2 parents 23a0388 + 39e3a17 commit 93e794e

25 files changed

+385
-2345
lines changed

Makefile.in

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -785,26 +785,14 @@ stamps/check-gdb-linux: stamps/build-gcc-linux-stage2 stamps/build-gdb-linux sta
785785

786786
.PHONY: report-gcc-newlib report-gcc-newlib-nano
787787
report-gcc-newlib: stamps/check-gcc-newlib
788-
stat $(patsubst %,$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)) || exit 1
789-
# Fail if there are blank lines in the log file used as input for grep below.
790-
if grep '^$$' $(patsubst %,$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then exit 1; fi
791-
if find build-gcc-newlib-stage2/gcc/testsuite/ -iname '*.sum' | xargs grep ^FAIL | sort | grep -F -v $(patsubst %,--file=$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then false; else true; fi
792-
if test "$$(find build-gcc-newlib-stage2/gcc/testsuite/ -iname '*.sum' | xargs cat | wc -l)" -lt 100; then false; else true; fi
788+
$(srcdir)/scripts/testsuite-filter gcc newlib $(srcdir)/test/whitelist `find build-gcc-newlib-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -`
793789

794790
report-gcc-newlib-nano: stamps/check-gcc-newlib-nano
795-
stat $(patsubst %,$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)) || exit 1
796-
# Fail if there are blank lines in the log file used as input for grep below.
797-
if grep '^$$' $(patsubst %,$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then exit 1; fi
798-
if find build-gcc-newlib-stage2/gcc/testsuite/ -iname '*.sum' | xargs grep ^FAIL | sort | grep -F -v $(patsubst %,--file=$(srcdir)/test/gcc-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then false; else true; fi
799-
if test "$$(find build-gcc-newlib-stage2/gcc/testsuite/ -iname '*.sum' | xargs cat | wc -l)" -lt 100; then false; else true; fi
791+
$(srcdir)/scripts/testsuite-filter gcc newlib-nano $(srcdir)/test/whitelist `find build-gcc-newlib-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -`
800792

801793
.PHONY: report-gcc-linux
802794
report-gcc-linux: stamps/check-gcc-linux
803-
stat $(patsubst %,$(srcdir)/test/gcc-linux/%.log,$(GLIBC_MULTILIB_NAMES)) || exit 1
804-
# Fail if there are blank lines in the log file used as input for grep below.
805-
if grep '^$$' $(patsubst %,$(srcdir)/test/gcc-linux/%.log,$(GLIBC_MULTILIB_NAMES)); then exit 1; fi
806-
if find build-gcc-linux-stage2/gcc/testsuite/ -iname '*.sum' | xargs grep ^FAIL | sort | grep -F -v $(patsubst %,--file=$(srcdir)/test/gcc-linux/%.log,$(GLIBC_MULTILIB_NAMES)); then false; else true; fi
807-
if test "$$(find build-gcc-linux-stage2/gcc/testsuite/ -iname '*.sum' | xargs cat | wc -l)" -lt 100; then false; else true; fi
795+
$(srcdir)/scripts/testsuite-filter gcc glibc $(srcdir)/test/whitelist `find build-gcc-linux-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -`
808796

809797
.PHONY: report-dhrystone-newlib report-dhrystone-newlib-nano
810798
report-dhrystone-newlib: $(patsubst %,stamps/check-dhrystone-newlib-%,$(NEWLIB_MULTILIB_NAMES))

scripts/testsuite-filter

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
#!/usr/bin/env python
2+
3+
4+
from __future__ import print_function
5+
import sys
6+
import os
7+
import re
8+
import collections
9+
10+
debug = False
11+
12+
13+
class Arch:
14+
def __init__(self, arch):
15+
arch = re.sub("^rv(32|64|128)g", 'rv\\1imafd', arch)
16+
m = re.match('rv(32|64|128)', arch)
17+
self.base_arch = m.group(0)
18+
self.ext = []
19+
i = len(self.base_arch)
20+
21+
while i < len(arch):
22+
ext = arch[i]
23+
if ext in ['x', 's', 'z']:
24+
extlen = 1
25+
while (i+extlen) < len(arch) and arch[i+extlen] != '_':
26+
extlen += 1
27+
self.ext.append(arch[i:i + extlen])
28+
i += extlen
29+
elif ext == '_':
30+
i += 1
31+
else:
32+
self.ext.append(ext)
33+
i += 1
34+
35+
36+
def usage():
37+
print("%s <toolname> <libc>" \
38+
" <white-list-base-dir> <testsuite.sum>" % sys.argv[0])
39+
40+
41+
def get_white_list_files(raw_arch, abi, libc, white_list_base_dir):
42+
""" Return white file list according the arch, abi, libc name and component.
43+
"""
44+
white_list_files = []
45+
arch = Arch(raw_arch)
46+
47+
def append_if_exist(filename):
48+
if debug:
49+
print ("Try append: %s" % filename)
50+
filepath = os.path.join(white_list_base_dir, filename)
51+
if os.path.exists(filepath):
52+
white_list_files.append(filepath)
53+
54+
libc_filename = "common.log"
55+
append_if_exist(libc_filename)
56+
57+
libc_filename = "%s.log" % (libc)
58+
append_if_exist(libc_filename)
59+
60+
filename = "%s.log" % (arch.base_arch)
61+
append_if_exist(filename)
62+
63+
filename = "%s.log" % (abi)
64+
append_if_exist(filename)
65+
66+
filename = "%s.%s.log" % (arch.base_arch, abi)
67+
append_if_exist(filename)
68+
69+
filename = "%s.%s.log" % (libc, arch.base_arch)
70+
append_if_exist(filename)
71+
72+
filename = "%s.%s.log" % (libc, abi)
73+
append_if_exist(filename)
74+
75+
filename = "%s.%s.%s.log" % (libc, arch.base_arch, abi)
76+
append_if_exist(filename)
77+
78+
for ext in arch.ext:
79+
filename = "%s.log" % (ext)
80+
append_if_exist(filename)
81+
82+
filename = "%s.%s.log" % (arch.base_arch, ext)
83+
append_if_exist(filename)
84+
85+
filename = "%s.%s.log" % (ext, abi)
86+
append_if_exist(filename)
87+
88+
filename = "%s.%s.%s.log" % (arch.base_arch, ext, abi)
89+
append_if_exist(filename)
90+
91+
filename = "%s.%s.log" % (libc, ext)
92+
append_if_exist(filename)
93+
94+
filename = "%s.%s.%s.log" % (libc, arch.base_arch, ext)
95+
append_if_exist(filename)
96+
97+
filename = "%s.%s.%s.log" % (libc, ext, abi)
98+
append_if_exist(filename)
99+
100+
filename = "%s.%s.%s.%s.log" % (libc, arch.base_arch, ext, abi)
101+
append_if_exist(filename)
102+
103+
return white_list_files
104+
105+
106+
def read_white_lists(white_list_files):
107+
white_lists = dict()
108+
for fname in white_list_files:
109+
with open(fname) as f:
110+
content = f.readlines()
111+
for l in content:
112+
l = l.strip()
113+
if len(l) == 0:
114+
continue
115+
if l[0] == '#':
116+
continue
117+
try:
118+
key = l.split(' ')[1]
119+
except:
120+
print ("Corrupt whitelist file?")
121+
print ("Each line must contail <STATUS>: .*")
122+
print ("e.g. FAIL: g++.dg/pr83239.C")
123+
print ("Or starts with # for comment")
124+
white_lists[key] = l
125+
return white_lists
126+
127+
128+
def read_gcc_sum(sum_files):
129+
unexpected_results = dict()
130+
for sum_file in sum_files:
131+
with open(sum_file) as f:
132+
content = f.readlines()
133+
current_target = None
134+
variations = []
135+
scan_variations = False
136+
unexpected_result = dict()
137+
tool = os.path.basename(sum_file).split(".")[0]
138+
for l in content:
139+
if l.startswith("Schedule of variations"):
140+
scan_variations = True
141+
continue
142+
if scan_variations and l.startswith(" "):
143+
variations.append(l.strip())
144+
continue
145+
scan_variations = False
146+
147+
if l.startswith("Running target"):
148+
# Parsing current running target.
149+
current_target = l.split(" ")[-1].strip()
150+
unexpected_result[current_target] = list()
151+
elif l.startswith("FAIL") or l.startswith("XPASS"):
152+
unexpected_result[current_target].append(l.strip())
153+
unexpected_results[tool] = unexpected_result
154+
# tool -> variation(target) -> list of unexpected result
155+
return unexpected_results
156+
157+
158+
def get_white_list(arch, abi, libc, white_list_base_dir):
159+
white_list_files = \
160+
get_white_list_files(arch, abi, libc, white_list_base_dir)
161+
white_list = read_white_lists(white_list_files)
162+
return white_list
163+
164+
165+
166+
def filter_result(tool, libc, white_list_base_dir, unexpected_results):
167+
summary = dict()
168+
any_fail = False
169+
# Filter with white list.
170+
for testtool, variation_unexpected_result in unexpected_results.iteritems():
171+
for variation, unexpected_result in variation_unexpected_result.iteritems():
172+
# Extract variation to arch/abi
173+
arch = ""
174+
abi = ""
175+
cmodel = ""
176+
for info in variation.split('/'):
177+
if info.startswith('-march'):
178+
arch = info[7:]
179+
elif info.startswith('-mabi'):
180+
abi = info[6:]
181+
elif info.startswith('-mcmodel'):
182+
cmodel = info[9:]
183+
184+
white_list = \
185+
get_white_list(arch, abi, libc,
186+
os.path.join(white_list_base_dir, tool))
187+
# filter!
188+
config = (arch, abi, cmodel)
189+
fail_count = 0
190+
case_count = set()
191+
unexpected_result_list = []
192+
for ur in unexpected_result:
193+
key = ur.split(' ')[1]
194+
if key in white_list and \
195+
ur.startswith(white_list[key]):
196+
# This item can be ignored
197+
continue
198+
else:
199+
unexpected_result_list.append(ur)
200+
fail_count += 1
201+
case_count.add(key)
202+
any_fail = True
203+
if config not in summary:
204+
summary[config] = dict()
205+
summary[config][testtool] = (fail_count, len(case_count))
206+
207+
if len(unexpected_result_list) != 0:
208+
print ("\t\t=== %s: Unexpected fails for %s %s %s ===" \
209+
% (testtool, arch, abi, cmodel))
210+
for ur in unexpected_result_list:
211+
print (ur)
212+
213+
214+
# Generate summary report.
215+
if tool == 'gcc':
216+
toollist = ['gcc', 'g++', 'gfortran']
217+
else:
218+
raise Exception("Unsupported tool `%s`" % tool)
219+
220+
bar_item = map(lambda x: "%13s" % x, toollist)
221+
bar = " |".join(bar_item)
222+
print ("\n ========= Summary of gcc testsuite =========")
223+
print (" | # of unexpected case / # of unique unexpected case")
224+
print (" |%s |" % bar)
225+
for config, result in summary.iteritems():
226+
arch, abi, cmodel = config
227+
print (" %10s/ %6s/ %6s |" % (arch, abi, cmodel), end='')
228+
for tool in toollist:
229+
if tool not in summary[config]:
230+
print ("%13s |" % '-', end='')
231+
continue
232+
233+
fail_count, case_count = summary[config][tool]
234+
print ("%5d / %5d |" % (fail_count, case_count), end='')
235+
print ("")
236+
if any_fail:
237+
return 1
238+
else:
239+
return 0
240+
241+
242+
def main():
243+
if len(sys.argv) < 5:
244+
usage()
245+
sys.exit()
246+
tool, libc, white_list_base_dir, sum_files = sys.argv[1:5]
247+
248+
rv = 0
249+
250+
sum_files = sum_files.split(',')
251+
unexpected_results = read_gcc_sum(sum_files)
252+
if tool in ['gcc']:
253+
rv = filter_result(tool, libc, white_list_base_dir,
254+
unexpected_results)
255+
else:
256+
print ("Unsupported tool: `%s`" % tool)
257+
rv = 1
258+
259+
sys.exit(rv)
260+
261+
262+
if __name__ == '__main__':
263+
main()

0 commit comments

Comments
 (0)