Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | A simple utility to redo the failed/errored tests. |
| 5 | |
| 6 | You need to specify the session directory in order for this script to locate the |
| 7 | tests which need to be re-run. |
| 8 | |
| 9 | See also dotest.py, the test driver running the test suite. |
| 10 | |
| 11 | Type: |
| 12 | |
| 13 | ./dotest.py -h |
| 14 | |
| 15 | for help. |
| 16 | """ |
| 17 | |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 18 | from __future__ import print_function |
| 19 | |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 20 | import os, sys, datetime |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 21 | import re |
| 22 | |
| 23 | # If True, redo with no '-t' option for the test driver. |
| 24 | no_trace = False |
| 25 | |
| 26 | # To be filled with the filterspecs found in the session logs. |
| 27 | redo_specs = [] |
Johnny Chen | 4d9d968 | 2011-08-16 20:56:10 +0000 | [diff] [blame] | 28 | |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 29 | # The filename components to match for. Only files with the contained component names |
| 30 | # will be considered for re-run. Examples: ['X86_64', 'clang']. |
| 31 | filename_components = [] |
| 32 | |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 33 | do_delay = False |
| 34 | |
Johnny Chen | 4d9d968 | 2011-08-16 20:56:10 +0000 | [diff] [blame] | 35 | # There is a known bug with respect to comp_specs and arch_specs, in that if we |
| 36 | # encountered "-C clang" and "-C gcc" when visiting the session files, both |
| 37 | # compilers will end up in the invocation of the test driver when rerunning. |
| 38 | # That is: ./dotest -v -C clang^gcc ... -f ...". Ditto for "-A" flags. |
Johnny Chen | b7e62d0 | 2011-08-16 20:57:05 +0000 | [diff] [blame] | 39 | |
Johnny Chen | 4d9d968 | 2011-08-16 20:56:10 +0000 | [diff] [blame] | 40 | # The "-C compiler" for comp_specs. |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 41 | comp_specs = set() |
Johnny Chen | 4d9d968 | 2011-08-16 20:56:10 +0000 | [diff] [blame] | 42 | # The "-A arch" for arch_specs. |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 43 | arch_specs = set() |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 44 | |
| 45 | def usage(): |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 46 | print("""\ |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 47 | Usage: redo.py [-F filename_component] [-n] [session_dir] [-d] |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 48 | where options: |
Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 49 | -F : only consider the test for re-run if the session filename contains the filename component |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 50 | for example: -F x86_64 |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 51 | -n : when running the tests, do not turn on trace mode, i.e, no '-t' option |
| 52 | is passed to the test driver (this will run the tests faster) |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 53 | -d : pass -d down to the test driver (introduces a delay so you can attach with a debugger) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 54 | |
| 55 | and session_dir specifies the session directory which contains previously |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 56 | recorded session infos for all the test cases which either failed or errored. |
| 57 | |
| 58 | If sessin_dir is left unspecified, this script uses the heuristic to find the |
| 59 | possible session directories with names starting with %Y-%m-%d- (for example, |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 60 | 2012-01-23-) and employs the one with the latest timestamp.""") |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 61 | sys.exit(0) |
| 62 | |
| 63 | def where(session_dir, test_dir): |
| 64 | """Returns the full path to the session directory; None if non-existent.""" |
| 65 | abspath = os.path.abspath(session_dir) |
| 66 | if os.path.isdir(abspath): |
| 67 | return abspath |
| 68 | |
| 69 | session_dir_path = os.path.join(test_dir, session_dir) |
| 70 | if os.path.isdir(session_dir_path): |
| 71 | return session_dir_path |
| 72 | |
| 73 | return None |
| 74 | |
| 75 | # This is the pattern for the line from the log file to redo a test. |
| 76 | # We want the filter spec. |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 77 | filter_pattern = re.compile("^\./dotest\.py.*-f (.*)$") |
| 78 | comp_pattern = re.compile(" -C ([^ ]+) ") |
| 79 | arch_pattern = re.compile(" -A ([^ ]+) ") |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 80 | def redo(suffix, dir, names): |
| 81 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 82 | global redo_specs |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 83 | global comp_specs |
| 84 | global arch_specs |
| 85 | global filter_pattern |
| 86 | global comp_pattern |
| 87 | global arch_pattern |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 88 | global filename_components |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 89 | global do_delay |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 90 | |
| 91 | for name in names: |
| 92 | if name.endswith(suffix): |
Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame] | 93 | #print("Find a log file:", name) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 94 | if name.startswith("Error") or name.startswith("Failure"): |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 95 | if filename_components: |
| 96 | if not all([comp in name for comp in filename_components]): |
| 97 | continue |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 98 | with open(os.path.join(dir, name), 'r') as log: |
| 99 | content = log.read() |
| 100 | for line in content.splitlines(): |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 101 | match = filter_pattern.match(line) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 102 | if match: |
| 103 | filterspec = match.group(1) |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 104 | print("adding filterspec:", filterspec) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 105 | redo_specs.append(filterspec) |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 106 | comp = comp_pattern.search(line) |
| 107 | if comp: |
| 108 | comp_specs.add(comp.group(1)) |
| 109 | arch = arch_pattern.search(line) |
| 110 | if arch: |
| 111 | arch_specs.add(arch.group(1)) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 112 | else: |
| 113 | continue |
| 114 | |
| 115 | def main(): |
| 116 | """Read the session directory and run the failed test cases one by one.""" |
| 117 | global no_trace |
| 118 | global redo_specs |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 119 | global filename_components |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 120 | global do_delay |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 121 | |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 122 | test_dir = sys.path[0] |
Johnny Chen | b8684b3 | 2012-05-16 19:43:14 +0000 | [diff] [blame] | 123 | if not test_dir: |
| 124 | test_dir = os.getcwd() |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 125 | if not test_dir.endswith('test'): |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 126 | print("This script expects to reside in lldb's test directory.") |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 127 | sys.exit(-1) |
| 128 | |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 129 | index = 1 |
| 130 | while index < len(sys.argv): |
Johnny Chen | 039330c | 2012-08-23 23:45:26 +0000 | [diff] [blame] | 131 | if sys.argv[index].startswith('-h') or sys.argv[index].startswith('--help'): |
Johnny Chen | 442b57c | 2011-11-30 19:46:37 +0000 | [diff] [blame] | 132 | usage() |
| 133 | |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 134 | if sys.argv[index].startswith('-'): |
| 135 | # We should continue processing... |
| 136 | pass |
| 137 | else: |
| 138 | # End of option processing. |
| 139 | break |
| 140 | |
Johnny Chen | a21bd40 | 2012-05-09 21:00:03 +0000 | [diff] [blame] | 141 | if sys.argv[index] == '-F': |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 142 | # Increment by 1 to fetch the filename component spec. |
| 143 | index += 1 |
| 144 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 145 | usage() |
| 146 | filename_components.append(sys.argv[index]) |
Johnny Chen | ddb1490 | 2012-05-07 22:59:00 +0000 | [diff] [blame] | 147 | elif sys.argv[index] == '-n': |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 148 | no_trace = True |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 149 | elif sys.argv[index] == '-d': |
| 150 | do_delay = True |
Filipe Cabecinhas | 3a9b6e7 | 2012-05-09 19:02:19 +0000 | [diff] [blame] | 151 | |
| 152 | index += 1 |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 153 | |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 154 | if index < len(sys.argv): |
| 155 | # Get the specified session directory. |
| 156 | session_dir = sys.argv[index] |
| 157 | else: |
| 158 | # Use heuristic to find the latest session directory. |
| 159 | name = datetime.datetime.now().strftime("%Y-%m-%d-") |
| 160 | dirs = [d for d in os.listdir(os.getcwd()) if d.startswith(name)] |
Filipe Cabecinhas | 3a9b6e7 | 2012-05-09 19:02:19 +0000 | [diff] [blame] | 161 | if len(dirs) == 0: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 162 | print("No default session directory found, please specify it explicitly.") |
Filipe Cabecinhas | 3a9b6e7 | 2012-05-09 19:02:19 +0000 | [diff] [blame] | 163 | usage() |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 164 | session_dir = max(dirs, key=os.path.getmtime) |
| 165 | if not session_dir or not os.path.exists(session_dir): |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 166 | print("No default session directory found, please specify it explicitly.") |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 167 | usage() |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 168 | |
Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame] | 169 | #print("The test directory:", test_dir) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 170 | session_dir_path = where(session_dir, test_dir) |
| 171 | |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 172 | print("Using session dir path:", session_dir_path) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 173 | os.chdir(test_dir) |
| 174 | os.path.walk(session_dir_path, redo, ".log") |
| 175 | |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 176 | if not redo_specs: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 177 | print("No failures/errors recorded within the session directory, please specify a different session directory.\n") |
Johnny Chen | d007790 | 2012-01-24 01:53:02 +0000 | [diff] [blame] | 178 | usage() |
| 179 | |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 180 | filters = " -f ".join(redo_specs) |
Greg Clayton | 85c2a72 | 2012-10-09 16:54:55 +0000 | [diff] [blame] | 181 | compilers = '' |
| 182 | for comp in comp_specs: |
| 183 | compilers += " -C %s" % (comp) |
| 184 | archs = '' |
| 185 | for arch in arch_specs: |
| 186 | archs += "--arch %s " % (arch) |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 187 | |
Enrico Granata | 5676839 | 2013-04-23 20:05:05 +0000 | [diff] [blame] | 188 | command = "./dotest.py %s %s -v %s %s -f " % (compilers, archs, "" if no_trace else "-t", "-d" if do_delay else "") |
Johnny Chen | 9fd6bbb | 2011-08-16 20:02:59 +0000 | [diff] [blame] | 189 | |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 190 | |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 191 | print("Running %s" % (command + filters)) |
Johnny Chen | 4a57d12 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 192 | os.system(command + filters) |
| 193 | |
| 194 | if __name__ == '__main__': |
| 195 | main() |