blob: 8dbf8f0d092ceb0cbdc51fbbe823b9049b50929e [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')
Maxim Kuvyrkovd8951a22021-07-08 08:20:28 +000074_EXP_LINE_REX = re.compile('^Running (?:.*/testsuite/)?(.*\.exp) \.\.\.\n')
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +000075_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]
Maxim Kuvyrkovd8951a22021-07-08 08:20:28 +0000373 result_set.current_exp = None
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000374 elif IsSummaryLine(line):
375 result_set.ResetToolExp()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000376 sum_file.close()
377 return result_set
378
379
380def GetManifest(manifest_path):
381 """Build a set of expected failures from the manifest file.
382
383 Each entry in the manifest file should have the format understood
384 by the TestResult constructor.
385
386 If no manifest file exists for this target, it returns an empty set.
387 """
388 if os.path.exists(manifest_path):
389 return ParseManifest(manifest_path)
390 else:
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000391 return ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000392
393
394def CollectSumFiles(builddir):
395 sum_files = []
396 for root, dirs, files in os.walk(builddir):
397 for ignored in ('.svn', '.git'):
398 if ignored in dirs:
399 dirs.remove(ignored)
400 for fname in files:
401 if fname.endswith('.sum'):
402 sum_files.append(os.path.join(root, fname))
403 return sum_files
404
405
Maxim Kuvyrkov8ef7c852021-07-08 08:21:18 +0000406def GetResults(sum_files, build_results = None):
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000407 """Collect all the test results from the given .sum files."""
Maxim Kuvyrkov8ef7c852021-07-08 08:21:18 +0000408 if build_results == None:
409 build_results = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000410 for sum_fname in sum_files:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000411 print('\t%s' % sum_fname)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000412 build_results |= ParseSummary(sum_fname)
413 return build_results
414
415
416def CompareResults(manifest, actual):
417 """Compare sets of results and return two lists:
418 - List of results present in ACTUAL but missing from MANIFEST.
419 - List of results present in MANIFEST but missing from ACTUAL.
420 """
421 # Collect all the actual results not present in the manifest.
422 # Results in this set will be reported as errors.
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000423 actual_vs_manifest = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000424 for actual_result in actual:
425 if actual_result not in manifest:
426 actual_vs_manifest.add(actual_result)
427
428 # Collect all the tests in the manifest that were not found
429 # in the actual results.
430 # Results in this set will be reported as warnings (since
431 # they are expected failures that are not failing anymore).
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000432 manifest_vs_actual = ResultSet()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000433 for expected_result in manifest:
434 # Ignore tests marked flaky.
435 if 'flaky' in expected_result.attrs:
436 continue
437 if expected_result not in actual:
438 manifest_vs_actual.add(expected_result)
439
440 return actual_vs_manifest, manifest_vs_actual
441
442
Maxim Kuvyrkov918bc262021-07-08 08:27:39 +0000443def GetManifestPath(user_provided_must_exist):
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000444 """Return the full path to the manifest file."""
445 manifest_path = _OPTIONS.manifest
446 if manifest_path:
447 if user_provided_must_exist and not os.path.exists(manifest_path):
448 Error('Manifest does not exist: %s' % manifest_path)
449 return manifest_path
450 else:
Maxim Kuvyrkov918bc262021-07-08 08:27:39 +0000451 (srcdir, target) = GetBuildData()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000452 if not srcdir:
453 Error('Could not determine the location of GCC\'s source tree. '
454 'The Makefile does not contain a definition for "srcdir".')
455 if not target:
456 Error('Could not determine the target triplet for this build. '
457 'The Makefile does not contain a definition for "target_alias".')
458 return _MANIFEST_PATH_PATTERN % (srcdir, _MANIFEST_SUBDIR, target)
459
460
461def GetBuildData():
462 if not ValidBuildDirectory(_OPTIONS.build_dir):
463 # If we have been given a set of results to use, we may
464 # not be inside a valid GCC build directory. In that case,
465 # the user must provide both a manifest file and a set
466 # of results to check against it.
467 if not _OPTIONS.results or not _OPTIONS.manifest:
468 Error('%s is not a valid GCC top level build directory. '
469 'You must use --manifest and --results to do the validation.' %
470 _OPTIONS.build_dir)
471 else:
472 return None, None
473 srcdir = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'srcdir =')
474 target = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'target_alias=')
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000475 print('Source directory: %s' % srcdir)
476 print('Build target: %s' % target)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000477 return srcdir, target
478
479
480def PrintSummary(msg, summary):
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000481 print('\n\n%s' % msg)
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000482 summary.Print()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000483
484def GetSumFiles(results, build_dir):
485 if not results:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000486 print('Getting actual results from build directory %s' % build_dir)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000487 sum_files = CollectSumFiles(build_dir)
488 else:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000489 print('Getting actual results from user-provided results')
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000490 sum_files = results.split()
491 return sum_files
492
493
494def PerformComparison(expected, actual, ignore_missing_failures):
495 actual_vs_expected, expected_vs_actual = CompareResults(expected, actual)
496
497 tests_ok = True
498 if len(actual_vs_expected) > 0:
499 PrintSummary('Unexpected results in this build (new failures)',
500 actual_vs_expected)
501 tests_ok = False
502
503 if not ignore_missing_failures and len(expected_vs_actual) > 0:
504 PrintSummary('Expected results not present in this build (fixed tests)'
505 '\n\nNOTE: This is not a failure. It just means that these '
506 'tests were expected\nto fail, but either they worked in '
507 'this configuration or they were not\npresent at all.\n',
508 expected_vs_actual)
509
510 if tests_ok:
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000511 print('\nSUCCESS: No unexpected failures.')
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000512
513 return tests_ok
514
515
516def CheckExpectedResults():
Maxim Kuvyrkov918bc262021-07-08 08:27:39 +0000517 manifest_path = GetManifestPath(True)
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000518 print('Manifest: %s' % manifest_path)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000519 manifest = GetManifest(manifest_path)
520 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
521 actual = GetResults(sum_files)
522
523 if _OPTIONS.verbosity >= 1:
524 PrintSummary('Tests expected to fail', manifest)
525 PrintSummary('\nActual test results', actual)
526
527 return PerformComparison(manifest, actual, _OPTIONS.ignore_missing_failures)
528
529
530def ProduceManifest():
Maxim Kuvyrkov918bc262021-07-08 08:27:39 +0000531 manifest_path = GetManifestPath(False)
Maxim Kuvyrkov63ad5352021-07-04 07:38:22 +0000532 print('Manifest: %s' % manifest_path)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000533 if os.path.exists(manifest_path) and not _OPTIONS.force:
534 Error('Manifest file %s already exists.\nUse --force to overwrite.' %
535 manifest_path)
536
537 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
538 actual = GetResults(sum_files)
539 manifest_file = open(manifest_path, 'w')
Maxim Kuvyrkov51e3fa12021-07-04 10:58:53 +0000540 actual.Print(manifest_file)
541 actual.Print()
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000542 manifest_file.close()
543
544 return True
545
546
547def CompareBuilds():
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000548 sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir)
549 actual = GetResults(sum_files)
550
Maxim Kuvyrkov8ef7c852021-07-08 08:21:18 +0000551 clean = ResultSet()
552
553 if _OPTIONS.manifest:
Maxim Kuvyrkov918bc262021-07-08 08:27:39 +0000554 manifest_path = GetManifestPath(True)
Maxim Kuvyrkov8ef7c852021-07-08 08:21:18 +0000555 print('Manifest: %s' % manifest_path)
556 clean = GetManifest(manifest_path)
557
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000558 clean_sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.clean_build)
Maxim Kuvyrkov8ef7c852021-07-08 08:21:18 +0000559 clean = GetResults(clean_sum_files, clean)
Maxim Kuvyrkov59877482021-07-07 11:22:26 +0000560
561 return PerformComparison(clean, actual, _OPTIONS.ignore_missing_failures)
562
563
564def Main(argv):
565 parser = optparse.OptionParser(usage=__doc__)
566
567 # Keep the following list sorted by option name.
568 parser.add_option('--build_dir', action='store', type='string',
569 dest='build_dir', default='.',
570 help='Build directory to check (default = .)')
571 parser.add_option('--clean_build', action='store', type='string',
572 dest='clean_build', default=None,
573 help='Compare test results from this build against '
574 'those of another (clean) build. Use this option '
575 'when comparing the test results of your patch versus '
576 'the test results of a clean build without your patch. '
577 'You must provide the path to the top directory of your '
578 'clean build.')
579 parser.add_option('--force', action='store_true', dest='force',
580 default=False, help='When used with --produce_manifest, '
581 'it will overwrite an existing manifest file '
582 '(default = False)')
583 parser.add_option('--ignore_missing_failures', action='store_true',
584 dest='ignore_missing_failures', default=False,
585 help='When a failure is expected in the manifest but '
586 'it is not found in the actual results, the script '
587 'produces a note alerting to this fact. This means '
588 'that the expected failure has been fixed, or '
589 'it did not run, or it may simply be flaky '
590 '(default = False)')
591 parser.add_option('--manifest', action='store', type='string',
592 dest='manifest', default=None,
593 help='Name of the manifest file to use (default = '
594 'taken from '
595 'contrib/testsuite-managment/<target_alias>.xfail)')
596 parser.add_option('--produce_manifest', action='store_true',
597 dest='produce_manifest', default=False,
598 help='Produce the manifest for the current '
599 'build (default = False)')
600 parser.add_option('--results', action='store', type='string',
601 dest='results', default=None, help='Space-separated list '
602 'of .sum files with the testing results to check. The '
603 'only content needed from these files are the lines '
604 'starting with FAIL, XPASS or UNRESOLVED (default = '
605 '.sum files collected from the build directory).')
606 parser.add_option('--verbosity', action='store', dest='verbosity',
607 type='int', default=0, help='Verbosity level (default = 0)')
608 global _OPTIONS
609 (_OPTIONS, _) = parser.parse_args(argv[1:])
610
611 if _OPTIONS.produce_manifest:
612 retval = ProduceManifest()
613 elif _OPTIONS.clean_build:
614 retval = CompareBuilds()
615 else:
616 retval = CheckExpectedResults()
617
618 if retval:
619 return 0
620 else:
621 return 1
622
623
624if __name__ == '__main__':
625 retval = Main(sys.argv)
626 sys.exit(retval)