blob: 2518f076e1cf1a53de18487831b0356b3780d710 [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 = []
Johnny Chen13fb6572011-08-16 20:02:59 +000026comp_specs = set()
27arch_specs = set()
Johnny Chenc5fa0052011-07-29 22:54:56 +000028
29def usage():
30 print"""\
31Usage: redo.py [-n] session_dir
32where 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
36and session_dir specifies the session directory which contains previously
37recorded session infos for all the test cases which either failed or errored."""
38 sys.exit(0)
39
40def 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 Chen13fb6572011-08-16 20:02:59 +000054filter_pattern = re.compile("^\./dotest\.py.*-f (.*)$")
55comp_pattern = re.compile(" -C ([^ ]+) ")
56arch_pattern = re.compile(" -A ([^ ]+) ")
Johnny Chenc5fa0052011-07-29 22:54:56 +000057def redo(suffix, dir, names):
58 """Visitor function for os.path.walk(path, visit, arg)."""
59 global redo_specs
Johnny Chen13fb6572011-08-16 20:02:59 +000060 global comp_specs
61 global arch_specs
62 global filter_pattern
63 global comp_pattern
64 global arch_pattern
Johnny Chenc5fa0052011-07-29 22:54:56 +000065
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 Chen13fb6572011-08-16 20:02:59 +000073 match = filter_pattern.match(line)
Johnny Chenc5fa0052011-07-29 22:54:56 +000074 if match:
75 filterspec = match.group(1)
76 print "adding filterspec:", filterspec
77 redo_specs.append(filterspec)
Johnny Chen13fb6572011-08-16 20:02:59 +000078 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 Chenc5fa0052011-07-29 22:54:56 +000084 else:
85 continue
86
87def 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 Chenc5fa0052011-07-29 22:54:56 +0000122 filters = " -f ".join(redo_specs)
Johnny Chen13fb6572011-08-16 20:02:59 +0000123 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 Chenc5fa0052011-07-29 22:54:56 +0000130
131 print "Running %s" % (command + filters)
132 os.system(command + filters)
133
134if __name__ == '__main__':
135 main()