annotate contrib/testsuite-management/validate_failures.py @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 #!/usr/bin/python
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 # Script to compare testsuite failures against a list of known-to-fail
kono
parents:
diff changeset
4 # tests.
kono
parents:
diff changeset
5 #
kono
parents:
diff changeset
6 # NOTE: This script is used in installations that are running Python 2.4.
kono
parents:
diff changeset
7 # Please stick to syntax features available in 2.4 and earlier
kono
parents:
diff changeset
8 # versions.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 # Contributed by Diego Novillo <dnovillo@google.com>
kono
parents:
diff changeset
11 #
kono
parents:
diff changeset
12 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
kono
parents:
diff changeset
13 #
kono
parents:
diff changeset
14 # This file is part of GCC.
kono
parents:
diff changeset
15 #
kono
parents:
diff changeset
16 # GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
17 # it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
18 # the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
19 # any later version.
kono
parents:
diff changeset
20 #
kono
parents:
diff changeset
21 # GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
24 # GNU General Public License for more details.
kono
parents:
diff changeset
25 #
kono
parents:
diff changeset
26 # You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
27 # along with GCC; see the file COPYING. If not, write to
kono
parents:
diff changeset
28 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
kono
parents:
diff changeset
29 # Boston, MA 02110-1301, USA.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 """This script provides a coarser XFAILing mechanism that requires no
kono
parents:
diff changeset
32 detailed DejaGNU markings. This is useful in a variety of scenarios:
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 - Development branches with many known failures waiting to be fixed.
kono
parents:
diff changeset
35 - Release branches with known failures that are not considered
kono
parents:
diff changeset
36 important for the particular release criteria used in that branch.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 The script must be executed from the toplevel build directory. When
kono
parents:
diff changeset
39 executed it will:
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 1- Determine the target built: TARGET
kono
parents:
diff changeset
42 2- Determine the source directory: SRCDIR
kono
parents:
diff changeset
43 3- Look for a failure manifest file in
kono
parents:
diff changeset
44 <SRCDIR>/<MANIFEST_SUBDIR>/<MANIFEST_NAME>.xfail
kono
parents:
diff changeset
45 4- Collect all the <tool>.sum files from the build tree.
kono
parents:
diff changeset
46 5- Produce a report stating:
kono
parents:
diff changeset
47 a- Failures expected in the manifest but not present in the build.
kono
parents:
diff changeset
48 b- Failures in the build not expected in the manifest.
kono
parents:
diff changeset
49 6- If all the build failures are expected in the manifest, it exits
kono
parents:
diff changeset
50 with exit code 0. Otherwise, it exits with error code 1.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Manifest files contain expected DejaGNU results that are otherwise
kono
parents:
diff changeset
53 treated as failures.
kono
parents:
diff changeset
54 They may also contain additional text:
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 # This is a comment. - self explanatory
kono
parents:
diff changeset
57 @include file - the file is a path relative to the includer
kono
parents:
diff changeset
58 @remove result text - result text is removed from the expected set
kono
parents:
diff changeset
59 """
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 import datetime
kono
parents:
diff changeset
62 import optparse
kono
parents:
diff changeset
63 import os
kono
parents:
diff changeset
64 import re
kono
parents:
diff changeset
65 import sys
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 # Handled test results.
kono
parents:
diff changeset
68 _VALID_TEST_RESULTS = [ 'FAIL', 'UNRESOLVED', 'XPASS', 'ERROR' ]
kono
parents:
diff changeset
69 _VALID_TEST_RESULTS_REX = re.compile("%s" % "|".join(_VALID_TEST_RESULTS))
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 # Subdirectory of srcdir in which to find the manifest file.
kono
parents:
diff changeset
72 _MANIFEST_SUBDIR = 'contrib/testsuite-management'
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 # Pattern for naming manifest files.
kono
parents:
diff changeset
75 # The first argument should be the toplevel GCC(/GNU tool) source directory.
kono
parents:
diff changeset
76 # The second argument is the manifest subdir.
kono
parents:
diff changeset
77 # The third argument is the manifest target, which defaults to the target
kono
parents:
diff changeset
78 # triplet used during the build.
kono
parents:
diff changeset
79 _MANIFEST_PATH_PATTERN = '%s/%s/%s.xfail'
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 # The options passed to the program.
kono
parents:
diff changeset
82 _OPTIONS = None
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 def Error(msg):
kono
parents:
diff changeset
85 print >>sys.stderr, 'error: %s' % msg
kono
parents:
diff changeset
86 sys.exit(1)
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 class TestResult(object):
kono
parents:
diff changeset
90 """Describes a single DejaGNU test result as emitted in .sum files.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 We are only interested in representing unsuccessful tests. So, only
kono
parents:
diff changeset
93 a subset of all the tests are loaded.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 The summary line used to build the test result should have this format:
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 attrlist | XPASS: gcc.dg/unroll_1.c (test for excess errors)
kono
parents:
diff changeset
98 ^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
99 optional state name description
kono
parents:
diff changeset
100 attributes
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 Attributes:
kono
parents:
diff changeset
103 attrlist: A comma separated list of attributes.
kono
parents:
diff changeset
104 Valid values:
kono
parents:
diff changeset
105 flaky Indicates that this test may not always fail. These
kono
parents:
diff changeset
106 tests are reported, but their presence does not affect
kono
parents:
diff changeset
107 the results.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 expire=YYYYMMDD After this date, this test will produce an error
kono
parents:
diff changeset
110 whether it is in the manifest or not.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 state: One of UNRESOLVED, XPASS or FAIL.
kono
parents:
diff changeset
113 name: File name for the test.
kono
parents:
diff changeset
114 description: String describing the test (flags used, dejagnu message, etc)
kono
parents:
diff changeset
115 ordinal: Monotonically increasing integer.
kono
parents:
diff changeset
116 It is used to keep results for one .exp file sorted
kono
parents:
diff changeset
117 by the order the tests were run.
kono
parents:
diff changeset
118 """
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 def __init__(self, summary_line, ordinal=-1):
kono
parents:
diff changeset
121 try:
kono
parents:
diff changeset
122 (self.attrs, summary_line) = SplitAttributesFromSummaryLine(summary_line)
kono
parents:
diff changeset
123 try:
kono
parents:
diff changeset
124 (self.state,
kono
parents:
diff changeset
125 self.name,
kono
parents:
diff changeset
126 self.description) = re.match(r'([A-Z]+):\s*(\S+)\s*(.*)',
kono
parents:
diff changeset
127 summary_line).groups()
kono
parents:
diff changeset
128 except:
kono
parents:
diff changeset
129 print 'Failed to parse summary line: "%s"' % summary_line
kono
parents:
diff changeset
130 raise
kono
parents:
diff changeset
131 self.ordinal = ordinal
kono
parents:
diff changeset
132 except ValueError:
kono
parents:
diff changeset
133 Error('Cannot parse summary line "%s"' % summary_line)
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 if self.state not in _VALID_TEST_RESULTS:
kono
parents:
diff changeset
136 Error('Invalid test result %s in "%s" (parsed as "%s")' % (
kono
parents:
diff changeset
137 self.state, summary_line, self))
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 def __lt__(self, other):
kono
parents:
diff changeset
140 return (self.name < other.name or
kono
parents:
diff changeset
141 (self.name == other.name and self.ordinal < other.ordinal))
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 def __hash__(self):
kono
parents:
diff changeset
144 return hash(self.state) ^ hash(self.name) ^ hash(self.description)
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 def __eq__(self, other):
kono
parents:
diff changeset
147 return (self.state == other.state and
kono
parents:
diff changeset
148 self.name == other.name and
kono
parents:
diff changeset
149 self.description == other.description)
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 def __ne__(self, other):
kono
parents:
diff changeset
152 return not (self == other)
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 def __str__(self):
kono
parents:
diff changeset
155 attrs = ''
kono
parents:
diff changeset
156 if self.attrs:
kono
parents:
diff changeset
157 attrs = '%s | ' % self.attrs
kono
parents:
diff changeset
158 return '%s%s: %s %s' % (attrs, self.state, self.name, self.description)
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 def ExpirationDate(self):
kono
parents:
diff changeset
161 # Return a datetime.date object with the expiration date for this
kono
parents:
diff changeset
162 # test result. Return None, if no expiration has been set.
kono
parents:
diff changeset
163 if re.search(r'expire=', self.attrs):
kono
parents:
diff changeset
164 expiration = re.search(r'expire=(\d\d\d\d)(\d\d)(\d\d)', self.attrs)
kono
parents:
diff changeset
165 if not expiration:
kono
parents:
diff changeset
166 Error('Invalid expire= format in "%s". Must be of the form '
kono
parents:
diff changeset
167 '"expire=YYYYMMDD"' % self)
kono
parents:
diff changeset
168 return datetime.date(int(expiration.group(1)),
kono
parents:
diff changeset
169 int(expiration.group(2)),
kono
parents:
diff changeset
170 int(expiration.group(3)))
kono
parents:
diff changeset
171 return None
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 def HasExpired(self):
kono
parents:
diff changeset
174 # Return True if the expiration date of this result has passed.
kono
parents:
diff changeset
175 expiration_date = self.ExpirationDate()
kono
parents:
diff changeset
176 if expiration_date:
kono
parents:
diff changeset
177 now = datetime.date.today()
kono
parents:
diff changeset
178 return now > expiration_date
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 def GetMakefileValue(makefile_name, value_name):
kono
parents:
diff changeset
182 if os.path.exists(makefile_name):
kono
parents:
diff changeset
183 makefile = open(makefile_name)
kono
parents:
diff changeset
184 for line in makefile:
kono
parents:
diff changeset
185 if line.startswith(value_name):
kono
parents:
diff changeset
186 (_, value) = line.split('=', 1)
kono
parents:
diff changeset
187 value = value.strip()
kono
parents:
diff changeset
188 makefile.close()
kono
parents:
diff changeset
189 return value
kono
parents:
diff changeset
190 makefile.close()
kono
parents:
diff changeset
191 return None
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 def ValidBuildDirectory(builddir):
kono
parents:
diff changeset
195 if (not os.path.exists(builddir) or
kono
parents:
diff changeset
196 not os.path.exists('%s/Makefile' % builddir)):
kono
parents:
diff changeset
197 return False
kono
parents:
diff changeset
198 return True
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 def IsComment(line):
kono
parents:
diff changeset
202 """Return True if line is a comment."""
kono
parents:
diff changeset
203 return line.startswith('#')
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 def SplitAttributesFromSummaryLine(line):
kono
parents:
diff changeset
207 """Splits off attributes from a summary line, if present."""
kono
parents:
diff changeset
208 if '|' in line and not _VALID_TEST_RESULTS_REX.match(line):
kono
parents:
diff changeset
209 (attrs, line) = line.split('|', 1)
kono
parents:
diff changeset
210 attrs = attrs.strip()
kono
parents:
diff changeset
211 else:
kono
parents:
diff changeset
212 attrs = ''
kono
parents:
diff changeset
213 line = line.strip()
kono
parents:
diff changeset
214 return (attrs, line)
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 def IsInterestingResult(line):
kono
parents:
diff changeset
218 """Return True if line is one of the summary lines we care about."""
kono
parents:
diff changeset
219 (_, line) = SplitAttributesFromSummaryLine(line)
kono
parents:
diff changeset
220 return bool(_VALID_TEST_RESULTS_REX.match(line))
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 def IsInclude(line):
kono
parents:
diff changeset
224 """Return True if line is an include of another file."""
kono
parents:
diff changeset
225 return line.startswith("@include ")
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 def GetIncludeFile(line, includer):
kono
parents:
diff changeset
229 """Extract the name of the include file from line."""
kono
parents:
diff changeset
230 includer_dir = os.path.dirname(includer)
kono
parents:
diff changeset
231 include_file = line[len("@include "):]
kono
parents:
diff changeset
232 return os.path.join(includer_dir, include_file.strip())
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 def IsNegativeResult(line):
kono
parents:
diff changeset
236 """Return True if line should be removed from the expected results."""
kono
parents:
diff changeset
237 return line.startswith("@remove ")
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 def GetNegativeResult(line):
kono
parents:
diff changeset
241 """Extract the name of the negative result from line."""
kono
parents:
diff changeset
242 line = line[len("@remove "):]
kono
parents:
diff changeset
243 return line.strip()
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 def ParseManifestWorker(result_set, manifest_path):
kono
parents:
diff changeset
247 """Read manifest_path, adding the contents to result_set."""
kono
parents:
diff changeset
248 if _OPTIONS.verbosity >= 1:
kono
parents:
diff changeset
249 print 'Parsing manifest file %s.' % manifest_path
kono
parents:
diff changeset
250 manifest_file = open(manifest_path)
kono
parents:
diff changeset
251 for line in manifest_file:
kono
parents:
diff changeset
252 line = line.strip()
kono
parents:
diff changeset
253 if line == "":
kono
parents:
diff changeset
254 pass
kono
parents:
diff changeset
255 elif IsComment(line):
kono
parents:
diff changeset
256 pass
kono
parents:
diff changeset
257 elif IsNegativeResult(line):
kono
parents:
diff changeset
258 result_set.remove(TestResult(GetNegativeResult(line)))
kono
parents:
diff changeset
259 elif IsInclude(line):
kono
parents:
diff changeset
260 ParseManifestWorker(result_set, GetIncludeFile(line, manifest_path))
kono
parents:
diff changeset
261 elif IsInterestingResult(line):
kono
parents:
diff changeset
262 result_set.add(TestResult(line))
kono
parents:
diff changeset
263 else:
kono
parents:
diff changeset
264 Error('Unrecognized line in manifest file: %s' % line)
kono
parents:
diff changeset
265 manifest_file.close()
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 def ParseManifest(manifest_path):
kono
parents:
diff changeset
269 """Create a set of TestResult instances from the given manifest file."""
kono
parents:
diff changeset
270 result_set = set()
kono
parents:
diff changeset
271 ParseManifestWorker(result_set, manifest_path)
kono
parents:
diff changeset
272 return result_set
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 def ParseSummary(sum_fname):
kono
parents:
diff changeset
276 """Create a set of TestResult instances from the given summary file."""
kono
parents:
diff changeset
277 result_set = set()
kono
parents:
diff changeset
278 # ordinal is used when sorting the results so that tests within each
kono
parents:
diff changeset
279 # .exp file are kept sorted.
kono
parents:
diff changeset
280 ordinal=0
kono
parents:
diff changeset
281 sum_file = open(sum_fname)
kono
parents:
diff changeset
282 for line in sum_file:
kono
parents:
diff changeset
283 if IsInterestingResult(line):
kono
parents:
diff changeset
284 result = TestResult(line, ordinal)
kono
parents:
diff changeset
285 ordinal += 1
kono
parents:
diff changeset
286 if result.HasExpired():
kono
parents:
diff changeset
287 # Tests that have expired are not added to the set of expected
kono
parents:
diff changeset
288 # results. If they are still present in the set of actual results,
kono
parents:
diff changeset
289 # they will cause an error to be reported.
kono
parents:
diff changeset
290 print 'WARNING: Expected failure "%s" has expired.' % line.strip()
kono
parents:
diff changeset
291 continue
kono
parents:
diff changeset
292 result_set.add(result)
kono
parents:
diff changeset
293 sum_file.close()
kono
parents:
diff changeset
294 return result_set
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 def GetManifest(manifest_path):
kono
parents:
diff changeset
298 """Build a set of expected failures from the manifest file.
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 Each entry in the manifest file should have the format understood
kono
parents:
diff changeset
301 by the TestResult constructor.
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 If no manifest file exists for this target, it returns an empty set.
kono
parents:
diff changeset
304 """
kono
parents:
diff changeset
305 if os.path.exists(manifest_path):
kono
parents:
diff changeset
306 return ParseManifest(manifest_path)
kono
parents:
diff changeset
307 else:
kono
parents:
diff changeset
308 return set()
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 def CollectSumFiles(builddir):
kono
parents:
diff changeset
312 sum_files = []
kono
parents:
diff changeset
313 for root, dirs, files in os.walk(builddir):
kono
parents:
diff changeset
314 for ignored in ('.svn', '.git'):
kono
parents:
diff changeset
315 if ignored in dirs:
kono
parents:
diff changeset
316 dirs.remove(ignored)
kono
parents:
diff changeset
317 for fname in files:
kono
parents:
diff changeset
318 if fname.endswith('.sum'):
kono
parents:
diff changeset
319 sum_files.append(os.path.join(root, fname))
kono
parents:
diff changeset
320 return sum_files
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 def GetResults(sum_files):
kono
parents:
diff changeset
324 """Collect all the test results from the given .sum files."""
kono
parents:
diff changeset
325 build_results = set()
kono
parents:
diff changeset
326 for sum_fname in sum_files:
kono
parents:
diff changeset
327 print '\t%s' % sum_fname
kono
parents:
diff changeset
328 build_results |= ParseSummary(sum_fname)
kono
parents:
diff changeset
329 return build_results
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 def CompareResults(manifest, actual):
kono
parents:
diff changeset
333 """Compare sets of results and return two lists:
kono
parents:
diff changeset
334 - List of results present in ACTUAL but missing from MANIFEST.
kono
parents:
diff changeset
335 - List of results present in MANIFEST but missing from ACTUAL.
kono
parents:
diff changeset
336 """
kono
parents:
diff changeset
337 # Collect all the actual results not present in the manifest.
kono
parents:
diff changeset
338 # Results in this set will be reported as errors.
kono
parents:
diff changeset
339 actual_vs_manifest = set()
kono
parents:
diff changeset
340 for actual_result in actual:
kono
parents:
diff changeset
341 if actual_result not in manifest:
kono
parents:
diff changeset
342 actual_vs_manifest.add(actual_result)
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 # Collect all the tests in the manifest that were not found
kono
parents:
diff changeset
345 # in the actual results.
kono
parents:
diff changeset
346 # Results in this set will be reported as warnings (since
kono
parents:
diff changeset
347 # they are expected failures that are not failing anymore).
kono
parents:
diff changeset
348 manifest_vs_actual = set()
kono
parents:
diff changeset
349 for expected_result in manifest:
kono
parents:
diff changeset
350 # Ignore tests marked flaky.
kono
parents:
diff changeset
351 if 'flaky' in expected_result.attrs:
kono
parents:
diff changeset
352 continue
kono
parents:
diff changeset
353 if expected_result not in actual:
kono
parents:
diff changeset
354 manifest_vs_actual.add(expected_result)
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 return actual_vs_manifest, manifest_vs_actual
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 def GetManifestPath(srcdir, target, user_provided_must_exist):
kono
parents:
diff changeset
360 """Return the full path to the manifest file."""
kono
parents:
diff changeset
361 manifest_path = _OPTIONS.manifest
kono
parents:
diff changeset
362 if manifest_path:
kono
parents:
diff changeset
363 if user_provided_must_exist and not os.path.exists(manifest_path):
kono
parents:
diff changeset
364 Error('Manifest does not exist: %s' % manifest_path)
kono
parents:
diff changeset
365 return manifest_path
kono
parents:
diff changeset
366 else:
kono
parents:
diff changeset
367 if not srcdir:
kono
parents:
diff changeset
368 Error('Could not determine the location of GCC\'s source tree. '
kono
parents:
diff changeset
369 'The Makefile does not contain a definition for "srcdir".')
kono
parents:
diff changeset
370 if not target:
kono
parents:
diff changeset
371 Error('Could not determine the target triplet for this build. '
kono
parents:
diff changeset
372 'The Makefile does not contain a definition for "target_alias".')
kono
parents:
diff changeset
373 return _MANIFEST_PATH_PATTERN % (srcdir, _MANIFEST_SUBDIR, target)
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 def GetBuildData():
kono
parents:
diff changeset
377 if not ValidBuildDirectory(_OPTIONS.build_dir):
kono
parents:
diff changeset
378 # If we have been given a set of results to use, we may
kono
parents:
diff changeset
379 # not be inside a valid GCC build directory. In that case,
kono
parents:
diff changeset
380 # the user must provide both a manifest file and a set
kono
parents:
diff changeset
381 # of results to check against it.
kono
parents:
diff changeset
382 if not _OPTIONS.results or not _OPTIONS.manifest:
kono
parents:
diff changeset
383 Error('%s is not a valid GCC top level build directory. '
kono
parents:
diff changeset
384 'You must use --manifest and --results to do the validation.' %
kono
parents:
diff changeset
385 _OPTIONS.build_dir)
kono
parents:
diff changeset
386 else:
kono
parents:
diff changeset
387 return None, None
kono
parents:
diff changeset
388 srcdir = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'srcdir =')
kono
parents:
diff changeset
389 target = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'target_alias=')
kono
parents:
diff changeset
390 print 'Source directory: %s' % srcdir
kono
parents:
diff changeset
391 print 'Build target: %s' % target
kono
parents:
diff changeset
392 return srcdir, target
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 def PrintSummary(msg, summary):
kono
parents:
diff changeset
396 print '\n\n%s' % msg
kono
parents:
diff changeset
397 for result in sorted(summary):
kono
parents:
diff changeset
398 print result
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 def GetSumFiles(results, build_dir):
kono
parents:
diff changeset
402 if not results:
kono
parents:
diff changeset
403 print 'Getting actual results from build directory %s' % build_dir
kono
parents:
diff changeset
404 sum_files = CollectSumFiles(build_dir)
kono
parents:
diff changeset
405 else:
kono
parents:
diff changeset
406 print 'Getting actual results from user-provided results'
kono
parents:
diff changeset
407 sum_files = results.split()
kono
parents:
diff changeset
408 return sum_files
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 def PerformComparison(expected, actual, ignore_missing_failures):
kono
parents:
diff changeset
412 actual_vs_expected, expected_vs_actual = CompareResults(expected, actual)
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 tests_ok = True
kono
parents:
diff changeset
415 if len(actual_vs_expected) > 0:
kono
parents:
diff changeset
416 PrintSummary('Unexpected results in this build (new failures)',
kono
parents:
diff changeset
417 actual_vs_expected)
kono
parents:
diff changeset
418 tests_ok = False
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 if not ignore_missing_failures and len(expected_vs_actual) > 0:
kono
parents:
diff changeset
421 PrintSummary('Expected results not present in this build (fixed tests)'
kono
parents:
diff changeset
422 '\n\nNOTE: This is not a failure. It just means that these '
kono
parents:
diff changeset
423 'tests were expected\nto fail, but either they worked in '
kono
parents:
diff changeset
424 'this configuration or they were not\npresent at all.\n',
kono
parents:
diff changeset
425 expected_vs_actual)
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 if tests_ok:
kono
parents:
diff changeset
428 print '\nSUCCESS: No unexpected failures.'
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 return tests_ok
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 def CheckExpectedResults():
kono
parents:
diff changeset
434 srcdir, target = GetBuildData()
kono
parents:
diff changeset
435 manifest_path = GetManifestPath(srcdir, target, True)
kono
parents:
diff changeset
436 print 'Manifest: %s' % manifest_path
kono
parents:
diff changeset
437 manifest = GetManifest(manifest_path)
kono
parents:
diff changeset
438 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
kono
parents:
diff changeset
439 actual = GetResults(sum_files)
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 if _OPTIONS.verbosity >= 1:
kono
parents:
diff changeset
442 PrintSummary('Tests expected to fail', manifest)
kono
parents:
diff changeset
443 PrintSummary('\nActual test results', actual)
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 return PerformComparison(manifest, actual, _OPTIONS.ignore_missing_failures)
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 def ProduceManifest():
kono
parents:
diff changeset
449 (srcdir, target) = GetBuildData()
kono
parents:
diff changeset
450 manifest_path = GetManifestPath(srcdir, target, False)
kono
parents:
diff changeset
451 print 'Manifest: %s' % manifest_path
kono
parents:
diff changeset
452 if os.path.exists(manifest_path) and not _OPTIONS.force:
kono
parents:
diff changeset
453 Error('Manifest file %s already exists.\nUse --force to overwrite.' %
kono
parents:
diff changeset
454 manifest_path)
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
kono
parents:
diff changeset
457 actual = GetResults(sum_files)
kono
parents:
diff changeset
458 manifest_file = open(manifest_path, 'w')
kono
parents:
diff changeset
459 for result in sorted(actual):
kono
parents:
diff changeset
460 print result
kono
parents:
diff changeset
461 manifest_file.write('%s\n' % result)
kono
parents:
diff changeset
462 manifest_file.close()
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 return True
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 def CompareBuilds():
kono
parents:
diff changeset
468 (srcdir, target) = GetBuildData()
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
kono
parents:
diff changeset
471 actual = GetResults(sum_files)
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 clean_sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.clean_build)
kono
parents:
diff changeset
474 clean = GetResults(clean_sum_files)
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 return PerformComparison(clean, actual, _OPTIONS.ignore_missing_failures)
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 def Main(argv):
kono
parents:
diff changeset
480 parser = optparse.OptionParser(usage=__doc__)
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 # Keep the following list sorted by option name.
kono
parents:
diff changeset
483 parser.add_option('--build_dir', action='store', type='string',
kono
parents:
diff changeset
484 dest='build_dir', default='.',
kono
parents:
diff changeset
485 help='Build directory to check (default = .)')
kono
parents:
diff changeset
486 parser.add_option('--clean_build', action='store', type='string',
kono
parents:
diff changeset
487 dest='clean_build', default=None,
kono
parents:
diff changeset
488 help='Compare test results from this build against '
kono
parents:
diff changeset
489 'those of another (clean) build. Use this option '
kono
parents:
diff changeset
490 'when comparing the test results of your patch versus '
kono
parents:
diff changeset
491 'the test results of a clean build without your patch. '
kono
parents:
diff changeset
492 'You must provide the path to the top directory of your '
kono
parents:
diff changeset
493 'clean build.')
kono
parents:
diff changeset
494 parser.add_option('--force', action='store_true', dest='force',
kono
parents:
diff changeset
495 default=False, help='When used with --produce_manifest, '
kono
parents:
diff changeset
496 'it will overwrite an existing manifest file '
kono
parents:
diff changeset
497 '(default = False)')
kono
parents:
diff changeset
498 parser.add_option('--ignore_missing_failures', action='store_true',
kono
parents:
diff changeset
499 dest='ignore_missing_failures', default=False,
kono
parents:
diff changeset
500 help='When a failure is expected in the manifest but '
kono
parents:
diff changeset
501 'it is not found in the actual results, the script '
kono
parents:
diff changeset
502 'produces a note alerting to this fact. This means '
kono
parents:
diff changeset
503 'that the expected failure has been fixed, or '
kono
parents:
diff changeset
504 'it did not run, or it may simply be flaky '
kono
parents:
diff changeset
505 '(default = False)')
kono
parents:
diff changeset
506 parser.add_option('--manifest', action='store', type='string',
kono
parents:
diff changeset
507 dest='manifest', default=None,
kono
parents:
diff changeset
508 help='Name of the manifest file to use (default = '
kono
parents:
diff changeset
509 'taken from '
kono
parents:
diff changeset
510 'contrib/testsuite-managment/<target_alias>.xfail)')
kono
parents:
diff changeset
511 parser.add_option('--produce_manifest', action='store_true',
kono
parents:
diff changeset
512 dest='produce_manifest', default=False,
kono
parents:
diff changeset
513 help='Produce the manifest for the current '
kono
parents:
diff changeset
514 'build (default = False)')
kono
parents:
diff changeset
515 parser.add_option('--results', action='store', type='string',
kono
parents:
diff changeset
516 dest='results', default=None, help='Space-separated list '
kono
parents:
diff changeset
517 'of .sum files with the testing results to check. The '
kono
parents:
diff changeset
518 'only content needed from these files are the lines '
kono
parents:
diff changeset
519 'starting with FAIL, XPASS or UNRESOLVED (default = '
kono
parents:
diff changeset
520 '.sum files collected from the build directory).')
kono
parents:
diff changeset
521 parser.add_option('--verbosity', action='store', dest='verbosity',
kono
parents:
diff changeset
522 type='int', default=0, help='Verbosity level (default = 0)')
kono
parents:
diff changeset
523 global _OPTIONS
kono
parents:
diff changeset
524 (_OPTIONS, _) = parser.parse_args(argv[1:])
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 if _OPTIONS.produce_manifest:
kono
parents:
diff changeset
527 retval = ProduceManifest()
kono
parents:
diff changeset
528 elif _OPTIONS.clean_build:
kono
parents:
diff changeset
529 retval = CompareBuilds()
kono
parents:
diff changeset
530 else:
kono
parents:
diff changeset
531 retval = CheckExpectedResults()
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 if retval:
kono
parents:
diff changeset
534 return 0
kono
parents:
diff changeset
535 else:
kono
parents:
diff changeset
536 return 1
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 if __name__ == '__main__':
kono
parents:
diff changeset
540 retval = Main(sys.argv)
kono
parents:
diff changeset
541 sys.exit(retval)