blob: c3034bb1847af7aaad0579a927150f4751ef8092 [file] [log] [blame]
Johnny Chenc5fa0052011-07-29 22:54:56 +00001#!/usr/bin/env python
2
3"""
4A simple utility to redo the failed/errored tests.
5
6You need to specify the session directory in order for this script to locate the
7tests which need to be re-run.
8
9See also dotest.py, the test driver running the test suite.
10
11Type:
12
13./dotest.py -h
14
15for help.
16"""
17
18import os, sys
19import re
20
21# If True, redo with no '-t' option for the test driver.
22no_trace = False
23
24# To be filled with the filterspecs found in the session logs.
25redo_specs = []
26
27def usage():
28 print"""\
29Usage: redo.py [-n] session_dir
30where options:
31-n : when running the tests, do not turn on trace mode, i.e, no '-t' option
32 is passed to the test driver (this will run the tests faster)
33
34and session_dir specifies the session directory which contains previously
35recorded session infos for all the test cases which either failed or errored."""
36 sys.exit(0)
37
38def where(session_dir, test_dir):
39 """Returns the full path to the session directory; None if non-existent."""
40 abspath = os.path.abspath(session_dir)
41 if os.path.isdir(abspath):
42 return abspath
43
44 session_dir_path = os.path.join(test_dir, session_dir)
45 if os.path.isdir(session_dir_path):
46 return session_dir_path
47
48 return None
49
50# This is the pattern for the line from the log file to redo a test.
51# We want the filter spec.
52pattern = re.compile("^\./dotest\.py.*-f (.*)$")
53def redo(suffix, dir, names):
54 """Visitor function for os.path.walk(path, visit, arg)."""
55 global redo_specs
56
57 for name in names:
58 if name.endswith(suffix):
59 #print "Find a log file:", name
60 if name.startswith("Error") or name.startswith("Failure"):
61 with open(os.path.join(dir, name), 'r') as log:
62 content = log.read()
63 for line in content.splitlines():
64 match = pattern.match(line)
65 if match:
66 filterspec = match.group(1)
67 print "adding filterspec:", filterspec
68 redo_specs.append(filterspec)
69 else:
70 continue
71
72def main():
73 """Read the session directory and run the failed test cases one by one."""
74 global no_trace
75 global redo_specs
76
77 if len(sys.argv) < 2 or len(sys.argv) > 3:
78 usage()
79
80 index = 1
81 while index < len(sys.argv):
82 if sys.argv[index].startswith('-'):
83 # We should continue processing...
84 pass
85 else:
86 # End of option processing.
87 break
88
89 if sys.argv[index] == '-n':
90 no_trace = True
91 index += 1
92
93 session_dir = sys.argv[index]
94
95 test_dir = sys.path[0]
96 if not test_dir.endswith('test'):
97 print "This script expects to reside in lldb's test directory."
98 sys.exit(-1)
99
100 #print "The test directory:", test_dir
101 session_dir_path = where(session_dir, test_dir)
102
103 #print "Session dir path:", session_dir_path
104 os.chdir(test_dir)
105 os.path.walk(session_dir_path, redo, ".log")
106
107 command = "./dotest.py -v %s -f " % ("" if no_trace else "-t")
108 filters = " -f ".join(redo_specs)
109
110 print "Running %s" % (command + filters)
111 os.system(command + filters)
112
113if __name__ == '__main__':
114 main()