Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 2 | |
| 3 | # Script to compare testsuite failures against a list of known-to-fail |
| 4 | # tests. |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 5 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 6 | # Contributed by Diego Novillo <dnovillo@google.com> |
| 7 | # |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 8 | # Copyright (C) 2011-2023 Free Software Foundation, Inc. |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 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 |
| 28 | detailed 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 | |
| 34 | The script must be executed from the toplevel build directory. When |
| 35 | executed it will: |
| 36 | |
| 37 | 1- Determine the target built: TARGET |
| 38 | 2- Determine the source directory: SRCDIR |
| 39 | 3- Look for a failure manifest file in |
| 40 | <SRCDIR>/<MANIFEST_SUBDIR>/<MANIFEST_NAME>.xfail |
| 41 | 4- Collect all the <tool>.sum files from the build tree. |
| 42 | 5- 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. |
| 45 | 6- 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 | |
| 48 | Manifest files contain expected DejaGNU results that are otherwise |
| 49 | treated as failures. |
| 50 | They 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 | |
| 57 | import datetime |
| 58 | import optparse |
| 59 | import os |
| 60 | import re |
| 61 | import sys |
| 62 | |
Maxim Kuvyrkov | 8704bc1 | 2023-05-03 15:03:34 +0000 | [diff] [blame] | 63 | _VALID_TEST_RESULTS = [ 'FAIL', 'UNRESOLVED', 'XPASS', 'ERROR' ] |
| 64 | # <STATE>: <NAME> <DESCRIPTION" |
| 65 | _VALID_TEST_RESULTS_REX = re.compile('(%s):\s*(\S+)\s*(.*)' |
| 66 | % "|".join(_VALID_TEST_RESULTS)) |
| 67 | |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 68 | # Formats of .sum file sections |
| 69 | _TOOL_LINE_FORMAT = '\t\t=== %s tests ===\n' |
Christophe Lyon | a7d8c4c | 2023-04-14 12:01:23 +0000 | [diff] [blame] | 70 | _EXP_LINE_FORMAT = '\nRunning %s:%s ...\n' |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 71 | _SUMMARY_LINE_FORMAT = '\n\t\t=== %s Summary ===\n' |
| 72 | |
| 73 | # ... and their compiled regexs. |
| 74 | _TOOL_LINE_REX = re.compile('^\t\t=== (.*) tests ===\n') |
Christophe Lyon | a7d8c4c | 2023-04-14 12:01:23 +0000 | [diff] [blame] | 75 | # Match .exp file name, optionally prefixed by a "tool:" name and a |
| 76 | # path ending with "testsuite/" |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 77 | _EXP_LINE_REX = re.compile('^Running (?:.*:)?(.*) \.\.\.\n') |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 78 | _SUMMARY_LINE_REX = re.compile('^\t\t=== (.*) Summary ===\n') |
| 79 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 80 | # Subdirectory of srcdir in which to find the manifest file. |
| 81 | _MANIFEST_SUBDIR = 'contrib/testsuite-management' |
| 82 | |
| 83 | # Pattern for naming manifest files. |
| 84 | # The first argument should be the toplevel GCC(/GNU tool) source directory. |
| 85 | # The second argument is the manifest subdir. |
| 86 | # The third argument is the manifest target, which defaults to the target |
| 87 | # triplet used during the build. |
| 88 | _MANIFEST_PATH_PATTERN = '%s/%s/%s.xfail' |
| 89 | |
| 90 | # The options passed to the program. |
| 91 | _OPTIONS = None |
| 92 | |
| 93 | def Error(msg): |
Maxim Kuvyrkov | 63ad535 | 2021-07-04 07:38:22 +0000 | [diff] [blame] | 94 | print('error: %s' % msg, file=sys.stderr) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 95 | sys.exit(1) |
| 96 | |
| 97 | |
| 98 | class TestResult(object): |
| 99 | """Describes a single DejaGNU test result as emitted in .sum files. |
| 100 | |
| 101 | We are only interested in representing unsuccessful tests. So, only |
| 102 | a subset of all the tests are loaded. |
| 103 | |
| 104 | The summary line used to build the test result should have this format: |
| 105 | |
| 106 | attrlist | XPASS: gcc.dg/unroll_1.c (test for excess errors) |
| 107 | ^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 108 | optional state name description |
| 109 | attributes |
| 110 | |
| 111 | Attributes: |
| 112 | attrlist: A comma separated list of attributes. |
| 113 | Valid values: |
| 114 | flaky Indicates that this test may not always fail. These |
| 115 | tests are reported, but their presence does not affect |
| 116 | the results. |
| 117 | |
| 118 | expire=YYYYMMDD After this date, this test will produce an error |
| 119 | whether it is in the manifest or not. |
| 120 | |
| 121 | state: One of UNRESOLVED, XPASS or FAIL. |
| 122 | name: File name for the test. |
| 123 | description: String describing the test (flags used, dejagnu message, etc) |
| 124 | ordinal: Monotonically increasing integer. |
| 125 | It is used to keep results for one .exp file sorted |
| 126 | by the order the tests were run. |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 127 | tool: Top-level testsuite name (aka "tool" in DejaGnu parlance) of the test. |
| 128 | exp: Name of .exp testsuite file. |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 129 | """ |
| 130 | |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 131 | def __init__(self, summary_line, ordinal, tool, exp): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 132 | try: |
| 133 | (self.attrs, summary_line) = SplitAttributesFromSummaryLine(summary_line) |
| 134 | try: |
| 135 | (self.state, |
| 136 | self.name, |
Maxim Kuvyrkov | 56734ff | 2021-08-30 14:24:25 +0000 | [diff] [blame] | 137 | self.description) = _VALID_TEST_RESULTS_REX.match(summary_line).groups() |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 138 | if _OPTIONS.srcpath_regex and _OPTIONS.srcpath_regex != '': |
| 139 | self.description = re.sub(_OPTIONS.srcpath_regex, '', |
| 140 | self.description) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 141 | except: |
Thiago Jung Bauermann | 7b82a59 | 2023-04-22 14:12:06 +0000 | [diff] [blame] | 142 | print('Failed to parse summary line: "%s"' % summary_line, |
| 143 | file=sys.stderr) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 144 | raise |
| 145 | self.ordinal = ordinal |
Maxim Kuvyrkov | f09ab0e | 2021-08-30 14:19:04 +0000 | [diff] [blame] | 146 | if tool == None or exp == None: |
| 147 | # .sum file seem to be broken. There was no "tool" and/or "exp" |
| 148 | # lines preceding this result. |
Thiago Jung Bauermann | 7b82a59 | 2023-04-22 14:12:06 +0000 | [diff] [blame] | 149 | print(f'.sum file seems to be broken: tool="{tool}", exp="{exp}", summary_line="{summary_line}"', |
| 150 | file=sys.stderr) |
Maxim Kuvyrkov | f09ab0e | 2021-08-30 14:19:04 +0000 | [diff] [blame] | 151 | raise |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 152 | self.tool = tool |
| 153 | self.exp = exp |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 154 | except ValueError: |
| 155 | Error('Cannot parse summary line "%s"' % summary_line) |
| 156 | |
| 157 | if self.state not in _VALID_TEST_RESULTS: |
| 158 | Error('Invalid test result %s in "%s" (parsed as "%s")' % ( |
| 159 | self.state, summary_line, self)) |
| 160 | |
| 161 | def __lt__(self, other): |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 162 | if (self.tool != other.tool): |
| 163 | return self.tool < other.tool |
| 164 | if (self.exp != other.exp): |
| 165 | return self.exp < other.exp |
| 166 | if (self.name != other.name): |
| 167 | return self.name < other.name |
| 168 | return self.ordinal < other.ordinal |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 169 | |
| 170 | def __hash__(self): |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 171 | return (hash(self.state) ^ hash(self.tool) ^ hash(self.exp) |
| 172 | ^ hash(self.name) ^ hash(self.description)) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 173 | |
Maxim Kuvyrkov | 7df8178 | 2023-05-25 06:42:06 +0000 | [diff] [blame] | 174 | # Note that we don't include "attrs" in this comparison. This means that |
| 175 | # result entries "FAIL: test" and "flaky | FAIL: test" are considered |
| 176 | # the same. Therefore the ResultSet will preserve only the first occurence. |
| 177 | # In practice this means that flaky entries should preceed expected fails |
| 178 | # entries. |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 179 | def __eq__(self, other): |
| 180 | return (self.state == other.state and |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 181 | self.tool == other.tool and |
| 182 | self.exp == other.exp and |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 183 | self.name == other.name and |
| 184 | self.description == other.description) |
| 185 | |
| 186 | def __ne__(self, other): |
| 187 | return not (self == other) |
| 188 | |
| 189 | def __str__(self): |
| 190 | attrs = '' |
| 191 | if self.attrs: |
| 192 | attrs = '%s | ' % self.attrs |
| 193 | return '%s%s: %s %s' % (attrs, self.state, self.name, self.description) |
| 194 | |
| 195 | def ExpirationDate(self): |
| 196 | # Return a datetime.date object with the expiration date for this |
| 197 | # test result. Return None, if no expiration has been set. |
| 198 | if re.search(r'expire=', self.attrs): |
| 199 | expiration = re.search(r'expire=(\d\d\d\d)(\d\d)(\d\d)', self.attrs) |
| 200 | if not expiration: |
| 201 | Error('Invalid expire= format in "%s". Must be of the form ' |
| 202 | '"expire=YYYYMMDD"' % self) |
| 203 | return datetime.date(int(expiration.group(1)), |
| 204 | int(expiration.group(2)), |
| 205 | int(expiration.group(3))) |
| 206 | return None |
| 207 | |
| 208 | def HasExpired(self): |
| 209 | # Return True if the expiration date of this result has passed. |
| 210 | expiration_date = self.ExpirationDate() |
| 211 | if expiration_date: |
Maxim Kuvyrkov | 158e61d | 2023-05-25 12:18:30 +0000 | [diff] [blame] | 212 | return _OPTIONS.expiry_today_date > expiration_date |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 213 | |
| 214 | |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 215 | class ResultSet(set): |
| 216 | """Describes a set of DejaGNU test results. |
| 217 | This set can be read in from .sum files or emitted as a manifest. |
| 218 | |
| 219 | Attributes: |
| 220 | current_tool: Name of the current top-level DejaGnu testsuite. |
| 221 | current_exp: Name of the current .exp testsuite file. |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 222 | testsuites: A set of (tool, exp) tuples representing encountered testsuites. |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 223 | """ |
| 224 | |
| 225 | def __init__(self): |
| 226 | super().__init__() |
| 227 | self.ResetToolExp() |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 228 | self.testsuites=set() |
| 229 | |
| 230 | def update(self, other): |
| 231 | super().update(other) |
| 232 | self.testsuites.update(other.testsuites) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 233 | |
| 234 | def ResetToolExp(self): |
| 235 | self.current_tool = None |
| 236 | self.current_exp = None |
| 237 | |
| 238 | def MakeTestResult(self, summary_line, ordinal=-1): |
| 239 | return TestResult(summary_line, ordinal, |
| 240 | self.current_tool, self.current_exp) |
| 241 | |
| 242 | def Print(self, outfile=sys.stdout): |
| 243 | current_tool = None |
| 244 | current_exp = None |
| 245 | |
| 246 | for result in sorted(self): |
| 247 | if current_tool != result.tool: |
| 248 | current_tool = result.tool |
| 249 | outfile.write(_TOOL_LINE_FORMAT % current_tool) |
| 250 | if current_exp != result.exp: |
| 251 | current_exp = result.exp |
Christophe Lyon | a7d8c4c | 2023-04-14 12:01:23 +0000 | [diff] [blame] | 252 | outfile.write(_EXP_LINE_FORMAT % (current_tool, current_exp)) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 253 | outfile.write('%s\n' % result) |
| 254 | |
| 255 | outfile.write(_SUMMARY_LINE_FORMAT % 'Results') |
| 256 | |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 257 | # Check if testsuite of expected_result is present in current results. |
| 258 | # This is used to compare partial test results against a full manifest. |
| 259 | def HasTestsuite(self, expected_result): |
| 260 | return (expected_result.tool, expected_result.exp) in self.testsuites |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 261 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 262 | def GetMakefileValue(makefile_name, value_name): |
| 263 | if os.path.exists(makefile_name): |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 264 | makefile = open(makefile_name, encoding='latin-1', mode='r') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 265 | for line in makefile: |
| 266 | if line.startswith(value_name): |
| 267 | (_, value) = line.split('=', 1) |
| 268 | value = value.strip() |
| 269 | makefile.close() |
| 270 | return value |
| 271 | makefile.close() |
| 272 | return None |
| 273 | |
| 274 | |
| 275 | def ValidBuildDirectory(builddir): |
| 276 | if (not os.path.exists(builddir) or |
| 277 | not os.path.exists('%s/Makefile' % builddir)): |
| 278 | return False |
| 279 | return True |
| 280 | |
| 281 | |
| 282 | def IsComment(line): |
| 283 | """Return True if line is a comment.""" |
| 284 | return line.startswith('#') |
| 285 | |
| 286 | |
| 287 | def SplitAttributesFromSummaryLine(line): |
| 288 | """Splits off attributes from a summary line, if present.""" |
| 289 | if '|' in line and not _VALID_TEST_RESULTS_REX.match(line): |
| 290 | (attrs, line) = line.split('|', 1) |
| 291 | attrs = attrs.strip() |
| 292 | else: |
| 293 | attrs = '' |
| 294 | line = line.strip() |
| 295 | return (attrs, line) |
| 296 | |
| 297 | |
| 298 | def IsInterestingResult(line): |
| 299 | """Return True if line is one of the summary lines we care about.""" |
| 300 | (_, line) = SplitAttributesFromSummaryLine(line) |
| 301 | return bool(_VALID_TEST_RESULTS_REX.match(line)) |
| 302 | |
| 303 | |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 304 | def IsToolLine(line): |
| 305 | """Return True if line mentions the tool (in DejaGnu terms) for the following tests.""" |
| 306 | return bool(_TOOL_LINE_REX.match(line)) |
| 307 | |
| 308 | |
| 309 | def IsExpLine(line): |
| 310 | """Return True if line mentions the .exp file for the following tests.""" |
| 311 | return bool(_EXP_LINE_REX.match(line)) |
| 312 | |
| 313 | |
| 314 | def IsSummaryLine(line): |
| 315 | """Return True if line starts .sum footer.""" |
| 316 | return bool(_SUMMARY_LINE_REX.match(line)) |
| 317 | |
| 318 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 319 | def IsInclude(line): |
| 320 | """Return True if line is an include of another file.""" |
| 321 | return line.startswith("@include ") |
| 322 | |
| 323 | |
| 324 | def GetIncludeFile(line, includer): |
| 325 | """Extract the name of the include file from line.""" |
| 326 | includer_dir = os.path.dirname(includer) |
| 327 | include_file = line[len("@include "):] |
| 328 | return os.path.join(includer_dir, include_file.strip()) |
| 329 | |
| 330 | |
| 331 | def IsNegativeResult(line): |
| 332 | """Return True if line should be removed from the expected results.""" |
| 333 | return line.startswith("@remove ") |
| 334 | |
| 335 | |
| 336 | def GetNegativeResult(line): |
| 337 | """Extract the name of the negative result from line.""" |
| 338 | line = line[len("@remove "):] |
| 339 | return line.strip() |
| 340 | |
| 341 | |
| 342 | def ParseManifestWorker(result_set, manifest_path): |
| 343 | """Read manifest_path, adding the contents to result_set.""" |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 344 | if _OPTIONS.verbosity >= 5: |
Maxim Kuvyrkov | 63ad535 | 2021-07-04 07:38:22 +0000 | [diff] [blame] | 345 | print('Parsing manifest file %s.' % manifest_path) |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 346 | manifest_file = open(manifest_path, encoding='latin-1', mode='r') |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 347 | for orig_line in manifest_file: |
| 348 | line = orig_line.strip() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 349 | if line == "": |
| 350 | pass |
| 351 | elif IsComment(line): |
| 352 | pass |
| 353 | elif IsNegativeResult(line): |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 354 | result_set.remove(result_set.MakeTestResult(GetNegativeResult(line))) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 355 | elif IsInclude(line): |
| 356 | ParseManifestWorker(result_set, GetIncludeFile(line, manifest_path)) |
| 357 | elif IsInterestingResult(line): |
Maxim Kuvyrkov | a6b29dd | 2023-04-12 14:35:39 +0000 | [diff] [blame] | 358 | result = result_set.MakeTestResult(line) |
| 359 | if result.HasExpired(): |
| 360 | # Ignore expired manifest entries. |
Maxim Kuvyrkov | 7df8178 | 2023-05-25 06:42:06 +0000 | [diff] [blame] | 361 | if _OPTIONS.verbosity >= 4: |
Maxim Kuvyrkov | a6b29dd | 2023-04-12 14:35:39 +0000 | [diff] [blame] | 362 | print('WARNING: Expected failure "%s" has expired.' % line.strip()) |
| 363 | continue |
| 364 | result_set.add(result) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 365 | elif IsExpLine(orig_line): |
| 366 | result_set.current_exp = _EXP_LINE_REX.match(orig_line).groups()[0] |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 367 | if _OPTIONS.srcpath_regex and _OPTIONS.srcpath_regex != '': |
| 368 | result_set.current_exp = re.sub(_OPTIONS.srcpath_regex, '', |
| 369 | result_set.current_exp) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 370 | elif IsToolLine(orig_line): |
| 371 | result_set.current_tool = _TOOL_LINE_REX.match(orig_line).groups()[0] |
| 372 | elif IsSummaryLine(orig_line): |
| 373 | result_set.ResetToolExp() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 374 | else: |
| 375 | Error('Unrecognized line in manifest file: %s' % line) |
| 376 | manifest_file.close() |
| 377 | |
| 378 | |
| 379 | def ParseManifest(manifest_path): |
| 380 | """Create a set of TestResult instances from the given manifest file.""" |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 381 | result_set = ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 382 | ParseManifestWorker(result_set, manifest_path) |
| 383 | return result_set |
| 384 | |
| 385 | |
| 386 | def ParseSummary(sum_fname): |
| 387 | """Create a set of TestResult instances from the given summary file.""" |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 388 | result_set = ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 389 | # ordinal is used when sorting the results so that tests within each |
| 390 | # .exp file are kept sorted. |
| 391 | ordinal=0 |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 392 | sum_file = open(sum_fname, encoding='latin-1', mode='r') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 393 | for line in sum_file: |
| 394 | if IsInterestingResult(line): |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 395 | result = result_set.MakeTestResult(line, ordinal) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 396 | ordinal += 1 |
| 397 | if result.HasExpired(): |
Maxim Kuvyrkov | a6b29dd | 2023-04-12 14:35:39 +0000 | [diff] [blame] | 398 | # ??? What is the use-case for this? How "expiry" annotations are |
| 399 | # ??? supposed to be added to .sum results? |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 400 | # Tests that have expired are not added to the set of expected |
| 401 | # results. If they are still present in the set of actual results, |
| 402 | # they will cause an error to be reported. |
Maxim Kuvyrkov | 7df8178 | 2023-05-25 06:42:06 +0000 | [diff] [blame] | 403 | if _OPTIONS.verbosity >= 4: |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 404 | print('WARNING: Expected failure "%s" has expired.' % line.strip()) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 405 | continue |
| 406 | result_set.add(result) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 407 | elif IsExpLine(line): |
| 408 | result_set.current_exp = _EXP_LINE_REX.match(line).groups()[0] |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 409 | if _OPTIONS.srcpath_regex and _OPTIONS.srcpath_regex != '': |
| 410 | result_set.current_exp = re.sub(_OPTIONS.srcpath_regex, '', |
| 411 | result_set.current_exp) |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 412 | result_set.testsuites.add((result_set.current_tool, |
| 413 | result_set.current_exp)) |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 414 | elif IsToolLine(line): |
| 415 | result_set.current_tool = _TOOL_LINE_REX.match(line).groups()[0] |
Maxim Kuvyrkov | d8951a2 | 2021-07-08 08:20:28 +0000 | [diff] [blame] | 416 | result_set.current_exp = None |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 417 | elif IsSummaryLine(line): |
| 418 | result_set.ResetToolExp() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 419 | sum_file.close() |
| 420 | return result_set |
| 421 | |
| 422 | |
| 423 | def GetManifest(manifest_path): |
| 424 | """Build a set of expected failures from the manifest file. |
| 425 | |
| 426 | Each entry in the manifest file should have the format understood |
| 427 | by the TestResult constructor. |
| 428 | |
| 429 | If no manifest file exists for this target, it returns an empty set. |
| 430 | """ |
| 431 | if os.path.exists(manifest_path): |
| 432 | return ParseManifest(manifest_path) |
| 433 | else: |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 434 | return ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 435 | |
| 436 | |
| 437 | def CollectSumFiles(builddir): |
| 438 | sum_files = [] |
| 439 | for root, dirs, files in os.walk(builddir): |
| 440 | for ignored in ('.svn', '.git'): |
| 441 | if ignored in dirs: |
| 442 | dirs.remove(ignored) |
| 443 | for fname in files: |
| 444 | if fname.endswith('.sum'): |
| 445 | sum_files.append(os.path.join(root, fname)) |
| 446 | return sum_files |
| 447 | |
| 448 | |
Maxim Kuvyrkov | 8ef7c85 | 2021-07-08 08:21:18 +0000 | [diff] [blame] | 449 | def GetResults(sum_files, build_results = None): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 450 | """Collect all the test results from the given .sum files.""" |
Maxim Kuvyrkov | 8ef7c85 | 2021-07-08 08:21:18 +0000 | [diff] [blame] | 451 | if build_results == None: |
| 452 | build_results = ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 453 | for sum_fname in sum_files: |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 454 | if _OPTIONS.verbosity >= 3: |
| 455 | print('\t%s' % sum_fname) |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 456 | build_results.update(ParseSummary(sum_fname)) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 457 | return build_results |
| 458 | |
| 459 | |
| 460 | def CompareResults(manifest, actual): |
| 461 | """Compare sets of results and return two lists: |
| 462 | - List of results present in ACTUAL but missing from MANIFEST. |
| 463 | - List of results present in MANIFEST but missing from ACTUAL. |
| 464 | """ |
| 465 | # Collect all the actual results not present in the manifest. |
| 466 | # Results in this set will be reported as errors. |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 467 | actual_vs_manifest = ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 468 | for actual_result in actual: |
| 469 | if actual_result not in manifest: |
| 470 | actual_vs_manifest.add(actual_result) |
| 471 | |
| 472 | # Collect all the tests in the manifest that were not found |
| 473 | # in the actual results. |
| 474 | # Results in this set will be reported as warnings (since |
| 475 | # they are expected failures that are not failing anymore). |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 476 | manifest_vs_actual = ResultSet() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 477 | for expected_result in manifest: |
| 478 | # Ignore tests marked flaky. |
| 479 | if 'flaky' in expected_result.attrs: |
| 480 | continue |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 481 | # We try to support comparing partial results vs full manifest |
| 482 | # (e.g., manifest has failures for gcc, g++, gfortran, but we ran only |
| 483 | # g++ testsuite). To achieve this we record encountered testsuites in |
| 484 | # actual.testsuites set, and then we check it here using HasTestsuite(). |
| 485 | if expected_result not in actual and actual.HasTestsuite(expected_result): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 486 | manifest_vs_actual.add(expected_result) |
| 487 | |
| 488 | return actual_vs_manifest, manifest_vs_actual |
| 489 | |
| 490 | |
Maxim Kuvyrkov | 918bc26 | 2021-07-08 08:27:39 +0000 | [diff] [blame] | 491 | def GetManifestPath(user_provided_must_exist): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 492 | """Return the full path to the manifest file.""" |
| 493 | manifest_path = _OPTIONS.manifest |
| 494 | if manifest_path: |
| 495 | if user_provided_must_exist and not os.path.exists(manifest_path): |
| 496 | Error('Manifest does not exist: %s' % manifest_path) |
| 497 | return manifest_path |
| 498 | else: |
Maxim Kuvyrkov | 918bc26 | 2021-07-08 08:27:39 +0000 | [diff] [blame] | 499 | (srcdir, target) = GetBuildData() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 500 | if not srcdir: |
| 501 | Error('Could not determine the location of GCC\'s source tree. ' |
| 502 | 'The Makefile does not contain a definition for "srcdir".') |
| 503 | if not target: |
| 504 | Error('Could not determine the target triplet for this build. ' |
| 505 | 'The Makefile does not contain a definition for "target_alias".') |
| 506 | return _MANIFEST_PATH_PATTERN % (srcdir, _MANIFEST_SUBDIR, target) |
| 507 | |
| 508 | |
| 509 | def GetBuildData(): |
| 510 | if not ValidBuildDirectory(_OPTIONS.build_dir): |
| 511 | # If we have been given a set of results to use, we may |
| 512 | # not be inside a valid GCC build directory. In that case, |
| 513 | # the user must provide both a manifest file and a set |
| 514 | # of results to check against it. |
| 515 | if not _OPTIONS.results or not _OPTIONS.manifest: |
| 516 | Error('%s is not a valid GCC top level build directory. ' |
| 517 | 'You must use --manifest and --results to do the validation.' % |
| 518 | _OPTIONS.build_dir) |
| 519 | else: |
| 520 | return None, None |
| 521 | srcdir = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'srcdir =') |
| 522 | target = GetMakefileValue('%s/Makefile' % _OPTIONS.build_dir, 'target_alias=') |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 523 | if _OPTIONS.verbosity >= 3: |
| 524 | print('Source directory: %s' % srcdir) |
| 525 | print('Build target: %s' % target) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 526 | return srcdir, target |
| 527 | |
| 528 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 529 | def PrintSummary(summary): |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 530 | summary.Print() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 531 | |
| 532 | def GetSumFiles(results, build_dir): |
| 533 | if not results: |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 534 | if _OPTIONS.verbosity >= 3: |
| 535 | print('Getting actual results from build directory %s' % build_dir) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 536 | sum_files = CollectSumFiles(build_dir) |
| 537 | else: |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 538 | if _OPTIONS.verbosity >= 3: |
| 539 | print('Getting actual results from user-provided results') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 540 | sum_files = results.split() |
| 541 | return sum_files |
| 542 | |
| 543 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 544 | def PerformComparison(expected, actual): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 545 | actual_vs_expected, expected_vs_actual = CompareResults(expected, actual) |
| 546 | |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 547 | if _OPTIONS.inverse_match: |
| 548 | # Switch results if inverse comparison is requested. |
| 549 | # This is useful in detecting flaky tests that FAILed in expected set, |
| 550 | # but PASSed in actual set. |
| 551 | actual_vs_expected, expected_vs_actual \ |
Maxim Kuvyrkov | 7df8178 | 2023-05-25 06:42:06 +0000 | [diff] [blame] | 552 | = expected_vs_actual, actual_vs_expected |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 553 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 554 | tests_ok = True |
| 555 | if len(actual_vs_expected) > 0: |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 556 | if _OPTIONS.verbosity >= 3: |
| 557 | print('\n\nUnexpected results in this build (new failures)') |
| 558 | if _OPTIONS.verbosity >= 1: |
| 559 | PrintSummary(actual_vs_expected) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 560 | tests_ok = False |
| 561 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 562 | if _OPTIONS.verbosity >= 2 and len(expected_vs_actual) > 0: |
| 563 | print('\n\nExpected results not present in this build (fixed tests)' |
| 564 | '\n\nNOTE: This is not a failure. It just means that these ' |
| 565 | 'tests were expected\nto fail, but either they worked in ' |
| 566 | 'this configuration or they were not\npresent at all.\n') |
| 567 | PrintSummary(expected_vs_actual) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 568 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 569 | if tests_ok and _OPTIONS.verbosity >= 3: |
Maxim Kuvyrkov | 63ad535 | 2021-07-04 07:38:22 +0000 | [diff] [blame] | 570 | print('\nSUCCESS: No unexpected failures.') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 571 | |
| 572 | return tests_ok |
| 573 | |
| 574 | |
| 575 | def CheckExpectedResults(): |
Maxim Kuvyrkov | 918bc26 | 2021-07-08 08:27:39 +0000 | [diff] [blame] | 576 | manifest_path = GetManifestPath(True) |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 577 | if _OPTIONS.verbosity >= 3: |
| 578 | print('Manifest: %s' % manifest_path) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 579 | manifest = GetManifest(manifest_path) |
| 580 | sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir) |
| 581 | actual = GetResults(sum_files) |
| 582 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 583 | if _OPTIONS.verbosity >= 5: |
| 584 | print('\n\nTests expected to fail') |
| 585 | PrintSummary(manifest) |
| 586 | print('\n\nActual test results') |
| 587 | PrintSummary(actual) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 588 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 589 | return PerformComparison(manifest, actual) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 590 | |
| 591 | |
| 592 | def ProduceManifest(): |
Maxim Kuvyrkov | 918bc26 | 2021-07-08 08:27:39 +0000 | [diff] [blame] | 593 | manifest_path = GetManifestPath(False) |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 594 | if _OPTIONS.verbosity >= 3: |
| 595 | print('Manifest: %s' % manifest_path) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 596 | if os.path.exists(manifest_path) and not _OPTIONS.force: |
| 597 | Error('Manifest file %s already exists.\nUse --force to overwrite.' % |
| 598 | manifest_path) |
| 599 | |
| 600 | sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir) |
| 601 | actual = GetResults(sum_files) |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 602 | manifest_file = open(manifest_path, encoding='latin-1', mode='w') |
Maxim Kuvyrkov | 51e3fa1 | 2021-07-04 10:58:53 +0000 | [diff] [blame] | 603 | actual.Print(manifest_file) |
| 604 | actual.Print() |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 605 | manifest_file.close() |
| 606 | |
| 607 | return True |
| 608 | |
| 609 | |
| 610 | def CompareBuilds(): |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 611 | sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.build_dir) |
| 612 | actual = GetResults(sum_files) |
| 613 | |
Maxim Kuvyrkov | 8ef7c85 | 2021-07-08 08:21:18 +0000 | [diff] [blame] | 614 | clean = ResultSet() |
| 615 | |
| 616 | if _OPTIONS.manifest: |
Maxim Kuvyrkov | 918bc26 | 2021-07-08 08:27:39 +0000 | [diff] [blame] | 617 | manifest_path = GetManifestPath(True) |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 618 | if _OPTIONS.verbosity >= 3: |
| 619 | print('Manifest: %s' % manifest_path) |
Maxim Kuvyrkov | 8ef7c85 | 2021-07-08 08:21:18 +0000 | [diff] [blame] | 620 | clean = GetManifest(manifest_path) |
| 621 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 622 | clean_sum_files = GetSumFiles(_OPTIONS.results, _OPTIONS.clean_build) |
Maxim Kuvyrkov | 8ef7c85 | 2021-07-08 08:21:18 +0000 | [diff] [blame] | 623 | clean = GetResults(clean_sum_files, clean) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 624 | |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 625 | return PerformComparison(clean, actual) |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 626 | |
| 627 | |
| 628 | def Main(argv): |
| 629 | parser = optparse.OptionParser(usage=__doc__) |
| 630 | |
| 631 | # Keep the following list sorted by option name. |
| 632 | parser.add_option('--build_dir', action='store', type='string', |
| 633 | dest='build_dir', default='.', |
| 634 | help='Build directory to check (default = .)') |
| 635 | parser.add_option('--clean_build', action='store', type='string', |
| 636 | dest='clean_build', default=None, |
| 637 | help='Compare test results from this build against ' |
| 638 | 'those of another (clean) build. Use this option ' |
| 639 | 'when comparing the test results of your patch versus ' |
| 640 | 'the test results of a clean build without your patch. ' |
| 641 | 'You must provide the path to the top directory of your ' |
| 642 | 'clean build.') |
| 643 | parser.add_option('--force', action='store_true', dest='force', |
| 644 | default=False, help='When used with --produce_manifest, ' |
| 645 | 'it will overwrite an existing manifest file ' |
| 646 | '(default = False)') |
Maxim Kuvyrkov | 158e61d | 2023-05-25 12:18:30 +0000 | [diff] [blame] | 647 | parser.add_option('--expiry_date', action='store', |
| 648 | dest='expiry_today_date', default=None, |
| 649 | help='Use provided date YYYYMMDD to decide whether ' |
| 650 | 'manifest entries with expiry settings have expired ' |
| 651 | 'or not. (default = Use today date)') |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 652 | parser.add_option('--srcpath', action='store', type='string', |
| 653 | dest='srcpath_regex', default='[^ ]+/testsuite/', |
| 654 | help='Remove provided path (can be a regex) from ' |
| 655 | 'the result entries. This is useful to remove ' |
| 656 | 'occasional filesystem path from the results. ' |
| 657 | '(default = "[^ ]+/testsuite/")') |
Maxim Kuvyrkov | d8d6c47 | 2023-05-03 15:53:17 +0000 | [diff] [blame] | 658 | parser.add_option('--inverse_match', action='store_true', |
| 659 | dest='inverse_match', default=False, |
| 660 | help='Inverse result sets in comparison. ' |
| 661 | 'Output unexpected passes as unexpected failures and ' |
| 662 | 'unexpected failures as unexpected passes. ' |
| 663 | 'This is used to catch FAIL->PASS flaky tests. ' |
| 664 | '(default = False)') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 665 | parser.add_option('--manifest', action='store', type='string', |
| 666 | dest='manifest', default=None, |
| 667 | help='Name of the manifest file to use (default = ' |
| 668 | 'taken from ' |
| 669 | 'contrib/testsuite-managment/<target_alias>.xfail)') |
| 670 | parser.add_option('--produce_manifest', action='store_true', |
| 671 | dest='produce_manifest', default=False, |
| 672 | help='Produce the manifest for the current ' |
| 673 | 'build (default = False)') |
| 674 | parser.add_option('--results', action='store', type='string', |
| 675 | dest='results', default=None, help='Space-separated list ' |
| 676 | 'of .sum files with the testing results to check. The ' |
| 677 | 'only content needed from these files are the lines ' |
| 678 | 'starting with FAIL, XPASS or UNRESOLVED (default = ' |
| 679 | '.sum files collected from the build directory).') |
| 680 | parser.add_option('--verbosity', action='store', dest='verbosity', |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 681 | type='int', default=3, help='Verbosity level ' |
| 682 | '(default = 3). Level 0: only error output, this is ' |
| 683 | 'useful in scripting when only the exit code is used. ' |
| 684 | 'Level 1: output unexpected failures. ' |
| 685 | 'Level 2: output unexpected passes. ' |
| 686 | 'Level 3: output helpful information. ' |
Maxim Kuvyrkov | 8396bb3 | 2023-06-14 14:32:38 +0000 | [diff] [blame^] | 687 | 'Level 4: output notification on expired entries. ' |
Maxim Kuvyrkov | 4020538 | 2021-07-12 15:41:47 +0000 | [diff] [blame] | 688 | 'Level 5: output debug information.') |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 689 | global _OPTIONS |
| 690 | (_OPTIONS, _) = parser.parse_args(argv[1:]) |
| 691 | |
Maxim Kuvyrkov | 158e61d | 2023-05-25 12:18:30 +0000 | [diff] [blame] | 692 | # Set "today" date to compare expiration entries against. |
| 693 | # Setting expiration date into the future allows re-detection of flaky |
| 694 | # tests and creating fresh entries for them before the current flaky entries |
| 695 | # expire. |
| 696 | if _OPTIONS.expiry_today_date: |
| 697 | today_date = re.search(r'(\d\d\d\d)(\d\d)(\d\d)', |
| 698 | _OPTIONS.expiry_today_date) |
| 699 | if not today_date: |
| 700 | Error('Invalid --expiry_today_date format "%s". Must be of the form ' |
| 701 | '"expire=YYYYMMDD"' % _OPTIONS.expiry_today_date) |
| 702 | _OPTIONS.expiry_today_date=datetime.date(int(today_date.group(1)), |
| 703 | int(today_date.group(2)), |
| 704 | int(today_date.group(3))) |
| 705 | else: |
| 706 | _OPTIONS.expiry_today_date = datetime.date.today() |
| 707 | |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 708 | if _OPTIONS.produce_manifest: |
| 709 | retval = ProduceManifest() |
| 710 | elif _OPTIONS.clean_build: |
| 711 | retval = CompareBuilds() |
| 712 | else: |
| 713 | retval = CheckExpectedResults() |
| 714 | |
| 715 | if retval: |
| 716 | return 0 |
| 717 | else: |
Maxim Kuvyrkov | 972bb81 | 2021-08-30 14:18:09 +0000 | [diff] [blame] | 718 | return 2 |
Maxim Kuvyrkov | 5987748 | 2021-07-07 11:22:26 +0000 | [diff] [blame] | 719 | |
| 720 | |
| 721 | if __name__ == '__main__': |
| 722 | retval = Main(sys.argv) |
| 723 | sys.exit(retval) |