Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | A simple testing framework for lldb using python's unit testing framework. |
| 5 | |
| 6 | Tests for lldb are written as python scripts which take advantage of the script |
| 7 | bridging provided by LLDB.framework to interact with lldb core. |
| 8 | |
| 9 | A specific naming pattern is followed by the .py script to be recognized as |
| 10 | a module which implements a test scenario, namely, Test*.py. |
| 11 | |
| 12 | To specify the directories where "Test*.py" python test scripts are located, |
| 13 | you need to pass in a list of directory names. By default, the current |
| 14 | working directory is searched if nothing is specified on the command line. |
Johnny Chen | 872aee1 | 2010-09-16 15:44:23 +0000 | [diff] [blame] | 15 | |
| 16 | Type: |
| 17 | |
| 18 | ./dotest.py -h |
| 19 | |
| 20 | for available options. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 21 | """ |
| 22 | |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 23 | import os, signal, sys, time |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 24 | import unittest2 |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 25 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 26 | class _WritelnDecorator(object): |
| 27 | """Used to decorate file-like objects with a handy 'writeln' method""" |
| 28 | def __init__(self,stream): |
| 29 | self.stream = stream |
| 30 | |
| 31 | def __getattr__(self, attr): |
| 32 | if attr in ('stream', '__getstate__'): |
| 33 | raise AttributeError(attr) |
| 34 | return getattr(self.stream,attr) |
| 35 | |
| 36 | def writeln(self, arg=None): |
| 37 | if arg: |
| 38 | self.write(arg) |
| 39 | self.write('\n') # text-mode streams translate to \r\n if needed |
| 40 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 41 | # |
| 42 | # Global variables: |
| 43 | # |
| 44 | |
| 45 | # The test suite. |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 46 | suite = unittest2.TestSuite() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 47 | |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 48 | # The config file is optional. |
| 49 | configFile = None |
| 50 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 51 | # The dictionary as a result of sourcing configFile. |
| 52 | config = {} |
| 53 | |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 54 | # Delay startup in order for the debugger to attach. |
| 55 | delay = False |
| 56 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 57 | # Ignore the build search path relative to this script to locate the lldb.py module. |
| 58 | ignore = False |
| 59 | |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 60 | # The regular expression pattern to match against eligible filenames as our test cases. |
| 61 | regexp = None |
| 62 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 63 | # Default verbosity is 0. |
| 64 | verbose = 0 |
| 65 | |
| 66 | # By default, search from the current working directory. |
| 67 | testdirs = [ os.getcwd() ] |
| 68 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 69 | # Separator string. |
| 70 | separator = '-' * 70 |
| 71 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 72 | |
| 73 | def usage(): |
| 74 | print """ |
| 75 | Usage: dotest.py [option] [args] |
| 76 | where options: |
| 77 | -h : print this help message and exit (also --help) |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 78 | -c : read a config file specified after this option |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 79 | (see also lldb-trunk/example/test/usage-config) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 80 | -d : delay startup for 10 seconds (in order for the debugger to attach) |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 81 | -i : ignore (don't bailout) if 'lldb.py' module cannot be located in the build |
| 82 | tree relative to this script; use PYTHONPATH to locate the module |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 83 | -p : specify a regexp filename pattern for inclusion in the test suite |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 84 | -t : trace lldb command execution and result |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 85 | -v : do verbose mode of unittest framework |
| 86 | |
| 87 | and: |
| 88 | args : specify a list of directory names to search for python Test*.py scripts |
| 89 | if empty, search from the curret working directory, instead |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 90 | |
| 91 | Running of this script also sets up the LLDB_TEST environment variable so that |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 92 | individual test cases can locate their supporting files correctly. The script |
| 93 | tries to set up Python's search paths for modules by looking at the build tree |
| 94 | relative to this script. See also the '-i' option. |
Johnny Chen | fde69bc | 2010-09-14 22:01:40 +0000 | [diff] [blame] | 95 | |
| 96 | Environment variables related to loggings: |
| 97 | |
| 98 | o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem |
| 99 | with a default option of 'event process' if LLDB_LOG_OPTION is not defined. |
| 100 | |
| 101 | o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the |
| 102 | 'process.gdb-remote' subsystem with a default option of 'packets' if |
| 103 | GDB_REMOTE_LOG_OPTION is not defined. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 104 | """ |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 105 | sys.exit(0) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 106 | |
| 107 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 108 | def parseOptionsAndInitTestdirs(): |
| 109 | """Initialize the list of directories containing our unittest scripts. |
| 110 | |
| 111 | '-h/--help as the first option prints out usage info and exit the program. |
| 112 | """ |
| 113 | |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 114 | global configFile |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 115 | global delay |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 116 | global ignore |
| 117 | global regexp |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 118 | global verbose |
| 119 | global testdirs |
| 120 | |
| 121 | if len(sys.argv) == 1: |
| 122 | return |
| 123 | |
| 124 | # Process possible trace and/or verbose flag, among other things. |
| 125 | index = 1 |
| 126 | for i in range(1, len(sys.argv)): |
| 127 | if not sys.argv[index].startswith('-'): |
| 128 | # End of option processing. |
| 129 | break |
| 130 | |
| 131 | if sys.argv[index].find('-h') != -1: |
| 132 | usage() |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 133 | elif sys.argv[index].startswith('-c'): |
| 134 | # Increment by 1 to fetch the config file name option argument. |
| 135 | index += 1 |
| 136 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 137 | usage() |
| 138 | configFile = sys.argv[index] |
| 139 | if not os.path.isfile(configFile): |
| 140 | print "Config file:", configFile, "does not exist!" |
| 141 | usage() |
| 142 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 143 | elif sys.argv[index].startswith('-d'): |
| 144 | delay = True |
| 145 | index += 1 |
| 146 | elif sys.argv[index].startswith('-i'): |
| 147 | ignore = True |
| 148 | index += 1 |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 149 | elif sys.argv[index].startswith('-p'): |
| 150 | # Increment by 1 to fetch the reg exp pattern argument. |
| 151 | index += 1 |
| 152 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 153 | usage() |
| 154 | regexp = sys.argv[index] |
| 155 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 156 | elif sys.argv[index].startswith('-t'): |
| 157 | os.environ["LLDB_COMMAND_TRACE"] = "YES" |
| 158 | index += 1 |
| 159 | elif sys.argv[index].startswith('-v'): |
| 160 | verbose = 2 |
| 161 | index += 1 |
| 162 | else: |
| 163 | print "Unknown option: ", sys.argv[index] |
| 164 | usage() |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 165 | |
| 166 | # Gather all the dirs passed on the command line. |
| 167 | if len(sys.argv) > index: |
| 168 | testdirs = map(os.path.abspath, sys.argv[index:]) |
| 169 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 170 | # Source the configFile if specified. |
| 171 | # The side effect, if any, will be felt from this point on. An example |
| 172 | # config file may be these simple two lines: |
| 173 | # |
| 174 | # sys.stderr = open("/tmp/lldbtest-stderr", "w") |
| 175 | # sys.stdout = open("/tmp/lldbtest-stdout", "w") |
| 176 | # |
| 177 | # which will reassign the two file objects to sys.stderr and sys.stdout, |
| 178 | # respectively. |
| 179 | # |
| 180 | # See also lldb-trunk/example/test/usage-config. |
| 181 | global config |
| 182 | if configFile: |
| 183 | # Pass config (a dictionary) as the locals namespace for side-effect. |
| 184 | execfile(configFile, globals(), config) |
| 185 | #print "config:", config |
| 186 | #print "sys.stderr:", sys.stderr |
| 187 | #print "sys.stdout:", sys.stdout |
| 188 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 189 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 190 | def setupSysPath(): |
| 191 | """Add LLDB.framework/Resources/Python to the search paths for modules.""" |
| 192 | |
| 193 | # Get the directory containing the current script. |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 194 | scriptPath = sys.path[0] |
| 195 | if not scriptPath.endswith('test'): |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 196 | print "This script expects to reside in lldb's test directory." |
| 197 | sys.exit(-1) |
| 198 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 199 | os.environ["LLDB_TEST"] = scriptPath |
Johnny Chen | 9de4ede | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 200 | pluginPath = os.path.join(scriptPath, 'plugins') |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 201 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 202 | # Append script dir and plugin dir to the sys.path. |
| 203 | sys.path.append(scriptPath) |
| 204 | sys.path.append(pluginPath) |
| 205 | |
| 206 | global ignore |
| 207 | |
| 208 | # The '-i' option is used to skip looking for lldb.py in the build tree. |
| 209 | if ignore: |
| 210 | return |
| 211 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 212 | base = os.path.abspath(os.path.join(scriptPath, os.pardir)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 213 | dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework', |
| 214 | 'Resources', 'Python') |
| 215 | relPath = os.path.join(base, 'build', 'Release', 'LLDB.framework', |
| 216 | 'Resources', 'Python') |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 217 | baiPath = os.path.join(base, 'build', 'BuildAndIntegration', |
| 218 | 'LLDB.framework', 'Resources', 'Python') |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 219 | |
| 220 | lldbPath = None |
| 221 | if os.path.isfile(os.path.join(dbgPath, 'lldb.py')): |
| 222 | lldbPath = dbgPath |
| 223 | elif os.path.isfile(os.path.join(relPath, 'lldb.py')): |
| 224 | lldbPath = relPath |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 225 | elif os.path.isfile(os.path.join(baiPath, 'lldb.py')): |
| 226 | lldbPath = baiPath |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 227 | |
| 228 | if not lldbPath: |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 229 | print 'This script requires lldb.py to be in either ' + dbgPath + ',', |
| 230 | print relPath + ', or ' + baiPath |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 231 | sys.exit(-1) |
| 232 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 233 | # This is to locate the lldb.py module. Insert it right after sys.path[0]. |
| 234 | sys.path[1:1] = [lldbPath] |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 235 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 236 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 237 | def doDelay(delta): |
| 238 | """Delaying startup for delta-seconds to facilitate debugger attachment.""" |
| 239 | def alarm_handler(*args): |
| 240 | raise Exception("timeout") |
| 241 | |
| 242 | signal.signal(signal.SIGALRM, alarm_handler) |
| 243 | signal.alarm(delta) |
| 244 | sys.stdout.write("pid=%d\n" % os.getpid()) |
| 245 | sys.stdout.write("Enter RET to proceed (or timeout after %d seconds):" % |
| 246 | delta) |
| 247 | sys.stdout.flush() |
| 248 | try: |
| 249 | text = sys.stdin.readline() |
| 250 | except: |
| 251 | text = "" |
| 252 | signal.alarm(0) |
| 253 | sys.stdout.write("proceeding...\n") |
| 254 | pass |
| 255 | |
| 256 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 257 | def visit(prefix, dir, names): |
| 258 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 259 | |
| 260 | global suite |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 261 | global regexp |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 262 | |
| 263 | for name in names: |
| 264 | if os.path.isdir(os.path.join(dir, name)): |
| 265 | continue |
| 266 | |
| 267 | if '.py' == os.path.splitext(name)[1] and name.startswith(prefix): |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame^] | 268 | # Try to match the regexp pattern, if specified. |
| 269 | if regexp: |
| 270 | import re |
| 271 | if re.search(regexp, name): |
| 272 | #print "Filename: '%s' matches pattern: '%s'" % (name, regexp) |
| 273 | pass |
| 274 | else: |
| 275 | #print "Filename: '%s' does not match pattern: '%s'" % (name, regexp) |
| 276 | continue |
| 277 | |
| 278 | # We found a match for our test case. Add it to the suite. |
Johnny Chen | a85d7ee | 2010-06-26 00:19:32 +0000 | [diff] [blame] | 279 | if not sys.path.count(dir): |
| 280 | sys.path.append(dir) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 281 | base = os.path.splitext(name)[0] |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 282 | suite.addTests(unittest2.defaultTestLoader.loadTestsFromName(base)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 283 | |
| 284 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 285 | def lldbLoggings(): |
| 286 | """Check and do lldb loggings if necessary.""" |
| 287 | |
| 288 | # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is |
| 289 | # defined. Use ${LLDB_LOG} to specify the log file. |
| 290 | ci = lldb.DBG.GetCommandInterpreter() |
| 291 | res = lldb.SBCommandReturnObject() |
| 292 | if ("LLDB_LOG" in os.environ): |
| 293 | if ("LLDB_LOG_OPTION" in os.environ): |
| 294 | lldb_log_option = os.environ["LLDB_LOG_OPTION"] |
| 295 | else: |
| 296 | lldb_log_option = "event process" |
| 297 | ci.HandleCommand( |
| 298 | "log enable -f " + os.environ["LLDB_LOG"] + " lldb " + lldb_log_option, |
| 299 | res) |
| 300 | if not res.Succeeded(): |
| 301 | raise Exception('log enable failed (check LLDB_LOG env variable.') |
| 302 | # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined. |
| 303 | # Use ${GDB_REMOTE_LOG} to specify the log file. |
| 304 | if ("GDB_REMOTE_LOG" in os.environ): |
| 305 | if ("GDB_REMOTE_LOG_OPTION" in os.environ): |
| 306 | gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"] |
| 307 | else: |
| 308 | gdb_remote_log_option = "packets" |
| 309 | ci.HandleCommand( |
| 310 | "log enable -f " + os.environ["GDB_REMOTE_LOG"] + " process.gdb-remote " |
| 311 | + gdb_remote_log_option, |
| 312 | res) |
| 313 | if not res.Succeeded(): |
| 314 | raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') |
| 315 | |
| 316 | |
| 317 | ############################################ |
| 318 | # # |
| 319 | # Execution of the test driver starts here # |
| 320 | # # |
| 321 | ############################################ |
| 322 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 323 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 324 | # Start the actions by first parsing the options while setting up the test |
| 325 | # directories, followed by setting up the search paths for lldb utilities; |
| 326 | # then, we walk the directory trees and collect the tests into our test suite. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 327 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 328 | parseOptionsAndInitTestdirs() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 329 | setupSysPath() |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 330 | |
| 331 | # |
| 332 | # If '-d' is specified, do a delay of 10 seconds for the debugger to attach. |
| 333 | # |
| 334 | if delay: |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 335 | doDelay(10) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 336 | |
Johnny Chen | 49f2f7a | 2010-09-20 17:25:45 +0000 | [diff] [blame] | 337 | # |
| 338 | # Walk through the testdirs while collecting test cases. |
| 339 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 340 | for testdir in testdirs: |
| 341 | os.path.walk(testdir, visit, 'Test') |
| 342 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 343 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 344 | # Now that we have loaded all the test cases, run the whole test suite. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 345 | # |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 346 | |
| 347 | # First, write out the number of collected test cases. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 348 | sys.stderr.write(separator + "\n") |
| 349 | sys.stderr.write("Collected %d test%s\n\n" |
| 350 | % (suite.countTestCases(), |
| 351 | suite.countTestCases() != 1 and "s" or "")) |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 352 | |
| 353 | # For the time being, let's bracket the test runner within the |
| 354 | # lldb.SBDebugger.Initialize()/Terminate() pair. |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 355 | import lldb, atexit |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 356 | lldb.SBDebugger.Initialize() |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 357 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 358 | |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 359 | # Create a singleton SBDebugger in the lldb namespace. |
| 360 | lldb.DBG = lldb.SBDebugger.Create() |
| 361 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 362 | # Turn on lldb loggings if necessary. |
| 363 | lldbLoggings() |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 364 | |
Johnny Chen | 7987ac9 | 2010-08-09 20:40:52 +0000 | [diff] [blame] | 365 | # Install the control-c handler. |
| 366 | unittest2.signals.installHandler() |
| 367 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 368 | # |
| 369 | # Invoke the default TextTestRunner to run the test suite, possibly iterating |
| 370 | # over different configurations. |
| 371 | # |
| 372 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 373 | iterArchs = False |
Johnny Chen | f032d90 | 2010-09-21 00:16:09 +0000 | [diff] [blame] | 374 | iterCompilers = False |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 375 | |
| 376 | from types import * |
| 377 | if "archs" in config: |
| 378 | archs = config["archs"] |
| 379 | if type(archs) is ListType and len(archs) >= 1: |
| 380 | iterArchs = True |
| 381 | if "compilers" in config: |
| 382 | compilers = config["compilers"] |
| 383 | if type(compilers) is ListType and len(compilers) >= 1: |
| 384 | iterCompilers = True |
| 385 | |
| 386 | for ia in range(len(archs) if iterArchs else 1): |
| 387 | archConfig = "" |
| 388 | if iterArchs: |
| 389 | os.environ["LLDB_ARCH"] = archs[ia] |
| 390 | archConfig = "arch=%s" % archs[ia] |
| 391 | for ic in range(len(compilers) if iterCompilers else 1): |
| 392 | if iterCompilers: |
| 393 | os.environ["LLDB_CC"] = compilers[ic] |
| 394 | configString = "%s compiler=%s" % (archConfig, compilers[ic]) |
| 395 | else: |
| 396 | configString = archConfig |
| 397 | |
| 398 | # Invoke the test runner. |
| 399 | if iterArchs or iterCompilers: |
| 400 | sys.stderr.write("\nConfiguration: " + configString + "\n") |
| 401 | result = unittest2.TextTestRunner(stream=sys.stderr, verbosity=verbose).run(suite) |
| 402 | |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 403 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 404 | # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. |
| 405 | # This should not be necessary now. |
Johnny Chen | 83f6e51 | 2010-08-13 22:58:44 +0000 | [diff] [blame] | 406 | if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): |
| 407 | import subprocess |
| 408 | print "Terminating Test suite..." |
| 409 | subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) |
| 410 | |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 411 | # Exiting. |
| 412 | sys.exit(not result.wasSuccessful) |