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 | |
| 18 | import os, sys |
| 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 | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 26 | comp_specs = set() |
| 27 | arch_specs = set() |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 28 | |
| 29 | def usage(): |
| 30 | print"""\ |
| 31 | Usage: redo.py [-n] session_dir |
| 32 | where options: |
| 33 | -n : when running the tests, do not turn on trace mode, i.e, no '-t' option |
| 34 | is passed to the test driver (this will run the tests faster) |
| 35 | |
| 36 | and session_dir specifies the session directory which contains previously |
| 37 | recorded session infos for all the test cases which either failed or errored.""" |
| 38 | sys.exit(0) |
| 39 | |
| 40 | def where(session_dir, test_dir): |
| 41 | """Returns the full path to the session directory; None if non-existent.""" |
| 42 | abspath = os.path.abspath(session_dir) |
| 43 | if os.path.isdir(abspath): |
| 44 | return abspath |
| 45 | |
| 46 | session_dir_path = os.path.join(test_dir, session_dir) |
| 47 | if os.path.isdir(session_dir_path): |
| 48 | return session_dir_path |
| 49 | |
| 50 | return None |
| 51 | |
| 52 | # This is the pattern for the line from the log file to redo a test. |
| 53 | # We want the filter spec. |
Johnny Chen | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 54 | filter_pattern = re.compile("^\./dotest\.py.*-f (.*)$") |
| 55 | comp_pattern = re.compile(" -C ([^ ]+) ") |
| 56 | arch_pattern = re.compile(" -A ([^ ]+) ") |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 57 | def redo(suffix, dir, names): |
| 58 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 59 | global redo_specs |
Johnny Chen | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 60 | global comp_specs |
| 61 | global arch_specs |
| 62 | global filter_pattern |
| 63 | global comp_pattern |
| 64 | global arch_pattern |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 65 | |
| 66 | for name in names: |
| 67 | if name.endswith(suffix): |
| 68 | #print "Find a log file:", name |
| 69 | if name.startswith("Error") or name.startswith("Failure"): |
| 70 | with open(os.path.join(dir, name), 'r') as log: |
| 71 | content = log.read() |
| 72 | for line in content.splitlines(): |
Johnny Chen | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 73 | match = filter_pattern.match(line) |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 74 | if match: |
| 75 | filterspec = match.group(1) |
| 76 | print "adding filterspec:", filterspec |
| 77 | redo_specs.append(filterspec) |
Johnny Chen | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 78 | comp = comp_pattern.search(line) |
| 79 | if comp: |
| 80 | comp_specs.add(comp.group(1)) |
| 81 | arch = arch_pattern.search(line) |
| 82 | if arch: |
| 83 | arch_specs.add(arch.group(1)) |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 84 | else: |
| 85 | continue |
| 86 | |
| 87 | def main(): |
| 88 | """Read the session directory and run the failed test cases one by one.""" |
| 89 | global no_trace |
| 90 | global redo_specs |
| 91 | |
| 92 | if len(sys.argv) < 2 or len(sys.argv) > 3: |
| 93 | usage() |
| 94 | |
| 95 | index = 1 |
| 96 | while index < len(sys.argv): |
| 97 | if sys.argv[index].startswith('-'): |
| 98 | # We should continue processing... |
| 99 | pass |
| 100 | else: |
| 101 | # End of option processing. |
| 102 | break |
| 103 | |
| 104 | if sys.argv[index] == '-n': |
| 105 | no_trace = True |
| 106 | index += 1 |
| 107 | |
| 108 | session_dir = sys.argv[index] |
| 109 | |
| 110 | test_dir = sys.path[0] |
| 111 | if not test_dir.endswith('test'): |
| 112 | print "This script expects to reside in lldb's test directory." |
| 113 | sys.exit(-1) |
| 114 | |
| 115 | #print "The test directory:", test_dir |
| 116 | session_dir_path = where(session_dir, test_dir) |
| 117 | |
| 118 | #print "Session dir path:", session_dir_path |
| 119 | os.chdir(test_dir) |
| 120 | os.path.walk(session_dir_path, redo, ".log") |
| 121 | |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 122 | filters = " -f ".join(redo_specs) |
Johnny Chen | 13fb657 | 2011-08-16 20:02:59 +0000 | [diff] [blame^] | 123 | compilers = (" -C %s" % "^".join(comp_specs)) if comp_specs else None |
| 124 | archs = (" -A %s" % "^".join(arch_specs)) if arch_specs else None |
| 125 | |
| 126 | command = "./dotest.py %s %s -v %s -f " % (compilers if compilers else "", |
| 127 | archs if archs else "", |
| 128 | "" if no_trace else "-t") |
| 129 | |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 130 | |
| 131 | print "Running %s" % (command + filters) |
| 132 | os.system(command + filters) |
| 133 | |
| 134 | if __name__ == '__main__': |
| 135 | main() |