blob: 05c63083eafb981ecc9d10df371062e993b4cc9c [file] [log] [blame]
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +00001#!/usr/bin/python3
Maxim Kuvyrkov59877482021-07-07 11:22:26 +00002
3# Script to compare testsuite failures against a list of known-to-fail
4# tests.
5#
Maxim Kuvyrkov59877482021-07-07 11:22:26 +00006# Contributed by Diego Novillo <dnovillo@google.com>
7#
8# Copyright (C) 2011-2013 Free Software Foundation, Inc.
9#
10# This file is part of GCC.
11#
12# GCC is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 3, or (at your option)
15# any later version.
16#
17# GCC is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with GCC; see the file COPYING. If not, write to
24# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25# Boston, MA 02110-1301, USA.
26
27"""This script provides a coarser XFAILing mechanism that requires no
28detailed DejaGNU markings. This is useful in a variety of scenarios:
29
30- Development branches with many known failures waiting to be fixed.
31- Release branches with known failures that are not considered
32 important for the particular release criteria used in that branch.
33
34The script must be executed from the toplevel build directory. When
35executed it will:
36
371- Determine the target built: TARGET
382- Determine the source directory: SRCDIR
393- Look for a failure manifest file in
40 <SRCDIR>/<MANIFEST_SUBDIR>/<MANIFEST_NAME>.xfail
414- Collect all the <tool>.sum files from the build tree.
425- Produce a report stating:
43 a- Failures expected in the manifest but not present in the build.
44 b- Failures in the build not expected in the manifest.
456- If all the build failures are expected in the manifest, it exits
46 with exit code 0. Otherwise, it exits with error code 1.
47
48Manifest files contain expected DejaGNU results that are otherwise
49treated as failures.
50They may also contain additional text:
51
52# This is a comment. - self explanatory
53@include file - the file is a path relative to the includer
54@remove result text - result text is removed from the expected set
55"""
56
57import datetime
58import optparse
59import os
60import re
61import sys
62
63# Handled test results.
64_VALID_TEST_RESULTS = [ 'FAIL', 'UNRESOLVED', 'XPASS', 'ERROR' ]
65_VALID_TEST_RESULTS_REX = re.compile("%s" % "|".join(_VALID_TEST_RESULTS))
66
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +000067# Formats of .sum file sections
68_TOOL_LINE_FORMAT = '\t\t=== %s tests ===\n'
69_EXP_LINE_FORMAT = '\nRunning %s ...\n'
70_SUMMARY_LINE_FORMAT = '\n\t\t=== %s Summary ===\n'
71
72# ... and their compiled regexs.
73_TOOL_LINE_REX = re.compile('^\t\t=== (.*) tests ===\n')
74_EXP_LINE_REX = re.compile('^Running .*(?:/testsuite/)?(.*\.exp) \.\.\.\n')
75_SUMMARY_LINE_REX = re.compile('^\t\t=== (.*) Summary ===\n')
76
Maxim Kuvyrkov59877482021-07-07 11:22:26 +000077# Subdirectory of srcdir in which to find the manifest file.
78_MANIFEST_SUBDIR = 'contrib/testsuite-management'
79
80# Pattern for naming manifest files.
81# The first argument should be the toplevel GCC(/GNU tool) source directory.
82# The second argument is the manifest subdir.
83# The third argument is the manifest target, which defaults to the target
84# triplet used during the build.
85_MANIFEST_PATH_PATTERN = '%s/%s/%s.xfail'
86
87# The options passed to the program.
88_OPTIONS = None
89
90def Error(msg):
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +000091 print('error: %s' % msg, file=sys.stderr)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +000092 sys.exit(1)
93
94
95class TestResult(object):
96 """Describes a single DejaGNU test result as emitted in .sum files.
97
98 We are only interested in representing unsuccessful tests. So, only
99 a subset of all the tests are loaded.
100
101 The summary line used to build the test result should have this format:
102
103 attrlist | XPASS: gcc.dg/unroll_1.c (test for excess errors)
104 ^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
105 optional state name description
106 attributes
107
108 Attributes:
109 attrlist: A comma separated list of attributes.
110 Valid values:
111 flaky Indicates that this test may not always fail. These
112 tests are reported, but their presence does not affect
113 the results.
114
115 expire=YYYYMMDD After this date, this test will produce an error
116 whether it is in the manifest or not.
117
118 state: One of UNRESOLVED, XPASS or FAIL.
119 name: File name for the test.
120 description: String describing the test (flags used, dejagnu message, etc)
121 ordinal: Monotonically increasing integer.
122 It is used to keep results for one .exp file sorted
123 by the order the tests were run.
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000124 tool: Top-level testsuite name (aka "tool" in DejaGnu parlance) of the test.
125 exp: Name of .exp testsuite file.
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000126 """
127
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000128 def __init__(self, summary_line, ordinal, tool, exp):
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000129 try:
130 (self.attrs, summary_line) = SplitAttributesFromSummaryLine(summary_line)
131 try:
132 (self.state,
133 self.name,
134 self.description) = re.match(r'([A-Z]+):\s*(\S+)\s*(.*)',
135 summary_line).groups()
136 except:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000137 print('Failed to parse summary line: "%s"' % summary_line)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000138 raise
139 self.ordinal = ordinal
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000140 self.tool = tool
141 self.exp = exp
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000142 except ValueError:
143 Error('Cannot parse summary line "%s"' % summary_line)
144
145 if self.state not in _VALID_TEST_RESULTS:
146 Error('Invalid test result %s in "%s" (parsed as "%s")' % (
147 self.state, summary_line, self))
148
149 def __lt__(self, other):
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000150 if (self.tool != other.tool):
151 return self.tool < other.tool
152 if (self.exp != other.exp):
153 return self.exp < other.exp
154 if (self.name != other.name):
155 return self.name < other.name
156 return self.ordinal < other.ordinal
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000157
158 def __hash__(self):
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000159 return (hash(self.state) ^ hash(self.tool) ^ hash(self.exp)
160 ^ hash(self.name) ^ hash(self.description))
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000161
162 def __eq__(self, other):
163 return (self.state == other.state and
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000164 self.tool == other.tool and
165 self.exp == other.exp and
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000166 self.name == other.name and
167 self.description == other.description)
168
169 def __ne__(self, other):
170 return not (self == other)
171
172 def __str__(self):
173 attrs = ''
174 if self.attrs:
175 attrs = '%s | ' % self.attrs
176 return '%s%s: %s %s' % (attrs, self.state, self.name, self.description)
177
178 def ExpirationDate(self):
179 # Return a datetime.date object with the expiration date for this
180 # test result. Return None, if no expiration has been set.
181 if re.search(r'expire=', self.attrs):
182 expiration = re.search(r'expire=(\d\d\d\d)(\d\d)(\d\d)', self.attrs)
183 if not expiration:
184 Error('Invalid expire= format in "%s". Must be of the form '
185 '"expire=YYYYMMDD"' % self)
186 return datetime.date(int(expiration.group(1)),
187 int(expiration.group(2)),
188 int(expiration.group(3)))
189 return None
190
191 def HasExpired(self):
192 # Return True if the expiration date of this result has passed.
193 expiration_date = self.ExpirationDate()
194 if expiration_date:
195 now = datetime.date.today()
196 return now > expiration_date
197
198
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000199class ResultSet(set):
200 """Describes a set of DejaGNU test results.
201 This set can be read in from .sum files or emitted as a manifest.
202
203 Attributes:
204 current_tool: Name of the current top-level DejaGnu testsuite.
205 current_exp: Name of the current .exp testsuite file.
206 """
207
208 def __init__(self):
209 super().__init__()
210 self.ResetToolExp()
211
212 def ResetToolExp(self):
213 self.current_tool = None
214 self.current_exp = None
215
216 def MakeTestResult(self, summary_line, ordinal=-1):
217 return TestResult(summary_line, ordinal,
218 self.current_tool, self.current_exp)
219
220 def Print(self, outfile=sys.stdout):
221 current_tool = None
222 current_exp = None
223
224 for result in sorted(self):
225 if current_tool != result.tool:
226 current_tool = result.tool
227 outfile.write(_TOOL_LINE_FORMAT % current_tool)
228 if current_exp != result.exp:
229 current_exp = result.exp
230 outfile.write(_EXP_LINE_FORMAT % current_exp)
231 outfile.write('%s\n' % result)
232
233 outfile.write(_SUMMARY_LINE_FORMAT % 'Results')
234
235
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000236def GetMakefileValue(makefile_name, value_name):
237 if os.path.exists(makefile_name):
238 makefile = open(makefile_name)
239 for line in makefile:
240 if line.startswith(value_name):
241 (_, value) = line.split('=', 1)
242 value = value.strip()
243 makefile.close()
244 return value
245 makefile.close()
246 return None
247
248
249def ValidBuildDirectory(builddir):
250 if (not os.path.exists(builddir) or
251 not os.path.exists('%s/Makefile' % builddir)):
252 return False
253 return True
254
255
256def IsComment(line):
257 """Return True if line is a comment."""
258 return line.startswith('#')
259
260
261def SplitAttributesFromSummaryLine(line):
262 """Splits off attributes from a summary line, if present."""
263 if '|' in line and not _VALID_TEST_RESULTS_REX.match(line):
264 (attrs, line) = line.split('|', 1)
265 attrs = attrs.strip()
266 else:
267 attrs = ''
268 line = line.strip()
269 return (attrs, line)
270
271
272def IsInterestingResult(line):
273 """Return True if line is one of the summary lines we care about."""
274 (_, line) = SplitAttributesFromSummaryLine(line)
275 return bool(_VALID_TEST_RESULTS_REX.match(line))
276
277
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000278def IsToolLine(line):
279 """Return True if line mentions the tool (in DejaGnu terms) for the following tests."""
280 return bool(_TOOL_LINE_REX.match(line))
281
282
283def IsExpLine(line):
284 """Return True if line mentions the .exp file for the following tests."""
285 return bool(_EXP_LINE_REX.match(line))
286
287
288def IsSummaryLine(line):
289 """Return True if line starts .sum footer."""
290 return bool(_SUMMARY_LINE_REX.match(line))
291
292
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000293def IsInclude(line):
294 """Return True if line is an include of another file."""
295 return line.startswith("@include ")
296
297
298def GetIncludeFile(line, includer):
299 """Extract the name of the include file from line."""
300 includer_dir = os.path.dirname(includer)
301 include_file = line[len("@include "):]
302 return os.path.join(includer_dir, include_file.strip())
303
304
305def IsNegativeResult(line):
306 """Return True if line should be removed from the expected results."""
307 return line.startswith("@remove ")
308
309
310def GetNegativeResult(line):
311 """Extract the name of the negative result from line."""
312 line = line[len("@remove "):]
313 return line.strip()
314
315
316def ParseManifestWorker(result_set, manifest_path):
317 """Read manifest_path, adding the contents to result_set."""
318 if _OPTIONS.verbosity >= 1:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000319 print('Parsing manifest file %s.' % manifest_path)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000320 manifest_file = open(manifest_path)
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000321 for orig_line in manifest_file:
322 line = orig_line.strip()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000323 if line == "":
324 pass
325 elif IsComment(line):
326 pass
327 elif IsNegativeResult(line):
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000328 result_set.remove(result_set.MakeTestResult(GetNegativeResult(line)))
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000329 elif IsInclude(line):
330 ParseManifestWorker(result_set, GetIncludeFile(line, manifest_path))
331 elif IsInterestingResult(line):
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000332 result_set.add(result_set.MakeTestResult(line))
333 elif IsExpLine(orig_line):
334 result_set.current_exp = _EXP_LINE_REX.match(orig_line).groups()[0]
335 elif IsToolLine(orig_line):
336 result_set.current_tool = _TOOL_LINE_REX.match(orig_line).groups()[0]
337 elif IsSummaryLine(orig_line):
338 result_set.ResetToolExp()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000339 else:
340 Error('Unrecognized line in manifest file: %s' % line)
341 manifest_file.close()
342
343
344def ParseManifest(manifest_path):
345 """Create a set of TestResult instances from the given manifest file."""
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000346 result_set = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000347 ParseManifestWorker(result_set, manifest_path)
348 return result_set
349
350
351def ParseSummary(sum_fname):
352 """Create a set of TestResult instances from the given summary file."""
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000353 result_set = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000354 # ordinal is used when sorting the results so that tests within each
355 # .exp file are kept sorted.
356 ordinal=0
357 sum_file = open(sum_fname)
358 for line in sum_file:
359 if IsInterestingResult(line):
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000360 result = result_set.MakeTestResult(line, ordinal)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000361 ordinal += 1
362 if result.HasExpired():
363 # Tests that have expired are not added to the set of expected
364 # results. If they are still present in the set of actual results,
365 # they will cause an error to be reported.
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000366 print('WARNING: Expected failure "%s" has expired.' % line.strip())
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000367 continue
368 result_set.add(result)
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000369 elif IsExpLine(line):
370 result_set.current_exp = _EXP_LINE_REX.match(line).groups()[0]
371 elif IsToolLine(line):
372 result_set.current_tool = _TOOL_LINE_REX.match(line).groups()[0]
373 elif IsSummaryLine(line):
374 result_set.ResetToolExp()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000375 sum_file.close()
376 return result_set
377
378
379def GetManifest(manifest_path):
380 """Build a set of expected failures from the manifest file.
381
382 Each entry in the manifest file should have the format understood
383 by the TestResult constructor.
384
385 If no manifest file exists for this target, it returns an empty set.
386 """
387 if os.path.exists(manifest_path):
388 return ParseManifest(manifest_path)
389 else:
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000390 return ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000391
392
393def CollectSumFiles(builddir):
394 sum_files = []
395 for root, dirs, files in os.walk(builddir):
396 for ignored in ('.svn', '.git'):
397 if ignored in dirs:
398 dirs.remove(ignored)
399 for fname in files:
400 if fname.endswith('.sum'):
401 sum_files.append(os.path.join(root, fname))
402 return sum_files
403
404
405def GetResults(sum_files):
406 """Collect all the test results from the given .sum files."""
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000407 build_results = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000408 for sum_fname in sum_files:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000409 print('\t%s' % sum_fname)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000410 build_results |= ParseSummary(sum_fname)
411 return build_results
412
413
414def CompareResults(manifest, actual):
415 """Compare sets of results and return two lists:
416 - List of results present in ACTUAL but missing from MANIFEST.
417 - List of results present in MANIFEST but missing from ACTUAL.
418 """
419 # Collect all the actual results not present in the manifest.
420 # Results in this set will be reported as errors.
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000421 actual_vs_manifest = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000422 for actual_result in actual:
423 if actual_result not in manifest:
424 actual_vs_manifest.add(actual_result)
425
426 # Collect all the tests in the manifest that were not found
427 # in the actual results.
428 # Results in this set will be reported as warnings (since
429 # they are expected failures that are not failing anymore).
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000430 manifest_vs_actual = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000431 for expected_result in manifest:
432 # Ignore tests marked flaky.
433 if 'flaky' in expected_result.attrs:
434 continue
435 if expected_result not in actual:
436 manifest_vs_actual.add(expected_result)
437
438 return actual_vs_manifest, manifest_vs_actual
439
440
441def GetManifestPath(srcdir, target, user_provided_must_exist):
442 """Return the full path to the manifest file."""
443 manifest_path = _OPTIONS.manifest
444 if manifest_path:
445 if user_provided_must_exist and not os.path.exists(manifest_path):
446 Error('Manifest does not exist: %s' % manifest_path)
447 return manifest_path
448 else:
449 if not srcdir:
450 Error('Could not determine the location of GCC\'s source tree. '
451 'The Makefile does not contain a definition for "srcdir".')
452 if not target:
453 Error('Could not determine the target triplet for this build. '
454 'The Makefile does not contain a definition for "target_alias".')
455 return _MANIFEST_PATH_PATTERN % (srcdir, _MANIFEST_SUBDIR, target)
456
457
458def GetBuildData():
459 if not ValidBuildDirectory(_OPTIONS.build_dir):
460 # If we have been given a set of results to use, we may
461 # not be inside a valid GCC build directory. In that case,
462 # the user must provide both a manifest file and a set
463 # of results to check against it.
464 if not _OPTIONS.results or not _OPTIONS.manifest:
465 Error('%s is not a valid GCC top level build directory. '
466 'You must use --manifest and --results to do the validation.' %
467 _OPTIONS.build_dir)
468 else:
469 return None, None
470 srcdir = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'srcdir =')
471 target = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'target_alias=')
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000472 print('Source directory: %s' % srcdir)
473 print('Build target: %s' % target)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000474 return srcdir, target
475
476
477def PrintSummary(msg, summary):
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000478 print('\n\n%s' % msg)
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000479 summary.Print()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000480
481def GetSumFiles(results, build_dir):
482 if not results:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000483 print('Getting actual results from build directory %s' % build_dir)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000484 sum_files = CollectSumFiles(build_dir)
485 else:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000486 print('Getting actual results from user-provided results')
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000487 sum_files = results.split()
488 return sum_files
489
490
491def PerformComparison(expected, actual, ignore_missing_failures):
492 actual_vs_expected, expected_vs_actual = CompareResults(expected, actual)
493
494 tests_ok = True
495 if len(actual_vs_expected) > 0:
496 PrintSummary('Unexpected results in this build (new failures)',
497 actual_vs_expected)
498 tests_ok = False
499
500 if not ignore_missing_failures and len(expected_vs_actual) > 0:
501 PrintSummary('Expected results not present in this build (fixed tests)'
502 '\n\nNOTE: This is not a failure. It just means that these '
503 'tests were expected\nto fail, but either they worked in '
504 'this configuration or they were not\npresent at all.\n',
505 expected_vs_actual)
506
507 if tests_ok:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000508 print('\nSUCCESS: No unexpected failures.')
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000509
510 return tests_ok
511
512
513def CheckExpectedResults():
514 srcdir, target = GetBuildData()
515 manifest_path = GetManifestPath(srcdir, target, True)
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000516 print('Manifest: %s' % manifest_path)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000517 manifest = GetManifest(manifest_path)
518 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
519 actual = GetResults(sum_files)
520
521 if _OPTIONS.verbosity >= 1:
522 PrintSummary('Tests expected to fail', manifest)
523 PrintSummary('\nActual test results', actual)
524
525 return PerformComparison(manifest, actual, _OPTIONS.ignore_missing_failures)
526
527
528def ProduceManifest():
529 (srcdir, target) = GetBuildData()
530 manifest_path = GetManifestPath(srcdir, target, False)
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000531 print('Manifest: %s' % manifest_path)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000532 if os.path.exists(manifest_path) and not _OPTIONS.force:
533 Error('Manifest file %s already exists.\nUse --force to overwrite.' %
534 manifest_path)
535
536 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
537 actual = GetResults(sum_files)
538 manifest_file = open(manifest_path, 'w')
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000539 actual.Print(manifest_file)
540 actual.Print()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000541 manifest_file.close()
542
543 return True
544
545
546def CompareBuilds():
547 (srcdir, target) = GetBuildData()
548
549 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
550 actual = GetResults(sum_files)
551
552 clean_sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.clean_build)
553 clean = GetResults(clean_sum_files)
554
555 return PerformComparison(clean, actual, _OPTIONS.ignore_missing_failures)
556
557
558def Main(argv):
559 parser = optparse.OptionParser(usage=__doc__)
560
561 # Keep the following list sorted by option name.
562 parser.add_option('--build_dir', action='store', type='string',
563 dest='build_dir', default='.',
564 help='Build directory to check (default = .)')
565 parser.add_option('--clean_build', action='store', type='string',
566 dest='clean_build', default=None,
567 help='Compare test results from this build against '
568 'those of another (clean) build. Use this option '
569 'when comparing the test results of your patch versus '
570 'the test results of a clean build without your patch. '
571 'You must provide the path to the top directory of your '
572 'clean build.')
573 parser.add_option('--force', action='store_true', dest='force',
574 default=False, help='When used with --produce_manifest, '
575 'it will overwrite an existing manifest file '
576 '(default = False)')
577 parser.add_option('--ignore_missing_failures', action='store_true',
578 dest='ignore_missing_failures', default=False,
579 help='When a failure is expected in the manifest but '
580 'it is not found in the actual results, the script '
581 'produces a note alerting to this fact. This means '
582 'that the expected failure has been fixed, or '
583 'it did not run, or it may simply be flaky '
584 '(default = False)')
585 parser.add_option('--manifest', action='store', type='string',
586 dest='manifest', default=None,
587 help='Name of the manifest file to use (default = '
588 'taken from '
589 'contrib/testsuite-managment/<target_alias>.xfail)')
590 parser.add_option('--produce_manifest', action='store_true',
591 dest='produce_manifest', default=False,
592 help='Produce the manifest for the current '
593 'build (default = False)')
594 parser.add_option('--results', action='store', type='string',
595 dest='results', default=None, help='Space-separated list '
596 'of .sum files with the testing results to check. The '
597 'only content needed from these files are the lines '
598 'starting with FAIL, XPASS or UNRESOLVED (default = '
599 '.sum files collected from the build directory).')
600 parser.add_option('--verbosity', action='store', dest='verbosity',
601 type='int', default=0, help='Verbosity level (default = 0)')
602 global _OPTIONS
603 (_OPTIONS, _) = parser.parse_args(argv[1:])
604
605 if _OPTIONS.produce_manifest:
606 retval = ProduceManifest()
607 elif _OPTIONS.clean_build:
608 retval = CompareBuilds()
609 else:
610 retval = CheckExpectedResults()
611
612 if retval:
613 return 0
614 else:
615 return 1
616
617
618if __name__ == '__main__':
619 retval = Main(sys.argv)
620 sys.exit(retval)