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