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