blob: cd9576ff6a1aa967e271a1cca0b857bc3a3fe044 [file] [log] [blame]
Johnny Chen9707bb62010-06-25 21:14:08 +00001#!/usr/bin/env python
2
3"""
4A simple testing framework for lldb using python's unit testing framework.
5
6Tests for lldb are written as python scripts which take advantage of the script
7bridging provided by LLDB.framework to interact with lldb core.
8
9A specific naming pattern is followed by the .py script to be recognized as
10a module which implements a test scenario, namely, Test*.py.
11
12To specify the directories where "Test*.py" python test scripts are located,
13you need to pass in a list of directory names. By default, the current
14working directory is searched if nothing is specified on the command line.
Johnny Chen872aee12010-09-16 15:44:23 +000015
16Type:
17
18./dotest.py -h
19
20for available options.
Johnny Chen9707bb62010-06-25 21:14:08 +000021"""
22
Johnny Chen91960d32010-09-08 20:56:16 +000023import os, signal, sys, time
Johnny Chen2891bb02011-09-16 01:04:26 +000024import subprocess
Johnny Chen75e28f92010-08-05 23:42:46 +000025import unittest2
Johnny Chen9707bb62010-06-25 21:14:08 +000026
Johnny Chen26901c82011-03-11 19:47:23 +000027def is_exe(fpath):
Johnny Chenf2c7b282011-04-26 23:10:51 +000028 """Returns true if fpath is an executable."""
Johnny Chen26901c82011-03-11 19:47:23 +000029 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
30
Johnny Chen26901c82011-03-11 19:47:23 +000031def which(program):
Johnny Chenf2c7b282011-04-26 23:10:51 +000032 """Returns the full path to a program; None otherwise."""
Johnny Chen26901c82011-03-11 19:47:23 +000033 fpath, fname = os.path.split(program)
34 if fpath:
35 if is_exe(program):
36 return program
37 else:
38 for path in os.environ["PATH"].split(os.pathsep):
39 exe_file = os.path.join(path, program)
40 if is_exe(exe_file):
41 return exe_file
42 return None
43
Johnny Chen877c7e42010-08-07 00:16:07 +000044class _WritelnDecorator(object):
45 """Used to decorate file-like objects with a handy 'writeln' method"""
46 def __init__(self,stream):
47 self.stream = stream
48
49 def __getattr__(self, attr):
50 if attr in ('stream', '__getstate__'):
51 raise AttributeError(attr)
52 return getattr(self.stream,attr)
53
54 def writeln(self, arg=None):
55 if arg:
56 self.write(arg)
57 self.write('\n') # text-mode streams translate to \r\n if needed
58
Johnny Chen9707bb62010-06-25 21:14:08 +000059#
60# Global variables:
61#
62
63# The test suite.
Johnny Chen75e28f92010-08-05 23:42:46 +000064suite = unittest2.TestSuite()
Johnny Chen9707bb62010-06-25 21:14:08 +000065
Johnny Chen4f93bf12010-12-10 00:51:23 +000066# By default, both command line and Python API tests are performed.
Johnny Chen3ebdacc2010-12-10 18:52:10 +000067# Use @python_api_test decorator, defined in lldbtest.py, to mark a test as
68# a Python API test.
Johnny Chen4f93bf12010-12-10 00:51:23 +000069dont_do_python_api_test = False
70
71# By default, both command line and Python API tests are performed.
Johnny Chen4f93bf12010-12-10 00:51:23 +000072just_do_python_api_test = False
73
Johnny Chen82ccf402011-07-30 01:39:58 +000074# By default, benchmarks tests are not run.
75just_do_benchmarks_test = False
76
Johnny Chena3ed7d82012-04-06 00:56:05 +000077# By default, both dsym and dwarf tests are performed.
78# Use @dsym_test or @dwarf_test decorators, defined in lldbtest.py, to mark a test
79# as a dsym or dwarf test. Use '-N dsym' or '-N dwarf' to exclude dsym or dwarf
80# tests from running.
81dont_do_dsym_test = False
82dont_do_dwarf_test = False
83
Johnny Chen82e6b1e2010-12-01 22:47:54 +000084# The blacklist is optional (-b blacklistFile) and allows a central place to skip
85# testclass's and/or testclass.testmethod's.
86blacklist = None
87
88# The dictionary as a result of sourcing blacklistFile.
89blacklistConfig = {}
90
Johnny Chen9fdb0a92010-09-18 00:16:47 +000091# The config file is optional.
92configFile = None
93
Johnny Chend2acdb32010-11-16 22:42:58 +000094# Test suite repeat count. Can be overwritten with '-# count'.
95count = 1
96
Johnny Chenb40056b2010-09-21 00:09:27 +000097# The dictionary as a result of sourcing configFile.
98config = {}
Johnny Chenac97a6b2012-04-16 18:55:15 +000099# The pre_flight and post_flight functions come from reading a config file.
100pre_flight = None
101post_flight = None
Johnny Chenb40056b2010-09-21 00:09:27 +0000102
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000103# The 'archs' and 'compilers' can be specified via either command line or configFile,
104# with the command line overriding the configFile. When specified, they should be
105# of the list type. For example, "-A x86_64^i386" => archs=['x86_64', 'i386'] and
106# "-C gcc^clang" => compilers=['gcc', 'clang'].
Johnny Chenbb4800e2012-04-12 00:55:57 +0000107archs = ['x86_64', 'i386']
Johnny Chen92693b52012-03-09 02:11:37 +0000108compilers = ['clang']
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000109
Johnny Chen1abe4c02012-03-20 00:33:51 +0000110# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
111# the inferior programs. The global variable cflags_extras provides a hook to do
112# just that.
113cflags_extras = ''
114
Johnny Chen91960d32010-09-08 20:56:16 +0000115# Delay startup in order for the debugger to attach.
116delay = False
117
Johnny Chend5362332011-01-29 01:21:04 +0000118# Dump the Python sys.path variable. Use '-D' to dump sys.path.
Johnny Chen50bc6382011-01-29 01:16:52 +0000119dumpSysPath = False
120
Johnny Chene00c9302011-10-10 22:03:44 +0000121# Full path of the benchmark executable, as specified by the '-e' option.
122bmExecutable = None
123# The breakpoint specification of bmExecutable, as specified by the '-x' option.
124bmBreakpointSpec = None
Johnny Chen5f2ed172011-10-20 18:43:28 +0000125# The benchamrk iteration count, as specified by the '-y' option.
126bmIterationCount = -1
Johnny Chene00c9302011-10-10 22:03:44 +0000127
Johnny Chene9eae812012-01-18 05:15:00 +0000128# By default, don't exclude any directories. Use '-X' to add one excluded directory.
129excluded = set(['.svn', '.git'])
130
Johnny Chen7d6d8442010-12-03 19:59:35 +0000131# By default, failfast is False. Use '-F' to overwrite it.
132failfast = False
133
Johnny Chenc5fa0052011-07-29 22:54:56 +0000134# The filters (testclass.testmethod) used to admit tests into our test suite.
135filters = []
Johnny Chenb62436b2010-10-06 20:40:56 +0000136
Johnny Chen38f823c2011-10-11 01:30:27 +0000137# The runhooks is a list of lldb commands specifically for the debugger.
138# Use '-k' to specify a runhook.
139runHooks = []
140
Johnny Chena224cd12010-11-08 01:21:03 +0000141# If '-g' is specified, the filterspec is not exclusive. If a test module does
142# not contain testclass.testmethod which matches the filterspec, the whole test
143# module is still admitted into our test suite. fs4all flag defaults to True.
144fs4all = True
Johnny Chenb62436b2010-10-06 20:40:56 +0000145
Johnny Chenaf149a02010-09-16 17:11:30 +0000146# Ignore the build search path relative to this script to locate the lldb.py module.
147ignore = False
148
Johnny Chen028d8eb2011-11-17 19:57:27 +0000149# By default, we do not skip build and cleanup. Use '-S' option to override.
150skip_build_and_cleanup = False
151
Johnny Chen548aefd2010-10-11 22:25:46 +0000152# By default, we skip long running test case. Use '-l' option to override.
Johnny Chen028d8eb2011-11-17 19:57:27 +0000153skip_long_running_test = True
Johnny Chen41998192010-10-01 22:59:49 +0000154
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000155# By default, we print the build dir, lldb version, and svn info. Use '-n' option to
156# turn it off.
157noHeaders = False
158
Johnny Chen7c52ff12010-09-27 23:29:54 +0000159# The regular expression pattern to match against eligible filenames as our test cases.
160regexp = None
161
Johnny Chen548aefd2010-10-11 22:25:46 +0000162# By default, tests are executed in place and cleanups are performed afterwards.
163# Use '-r dir' option to relocate the tests and their intermediate files to a
164# different directory and to forgo any cleanups. The directory specified must
165# not exist yet.
166rdir = None
167
Johnny Chen125fc2b2010-10-21 16:55:35 +0000168# By default, recorded session info for errored/failed test are dumped into its
169# own file under a session directory named after the timestamp of the test suite
170# run. Use '-s session-dir-name' to specify a specific dir name.
171sdir_name = None
172
Johnny Chen63c2cba2010-10-29 22:20:36 +0000173# Set this flag if there is any session info dumped during the test run.
174sdir_has_content = False
175
Johnny Chenb5fe80c2011-05-17 22:58:50 +0000176# svn_info stores the output from 'svn info lldb.base.dir'.
177svn_info = ''
178
Johnny Chen0f907b82012-01-31 00:38:03 +0000179# The environment variables to unset before running the test cases.
180unsets = []
181
Johnny Chen9707bb62010-06-25 21:14:08 +0000182# Default verbosity is 0.
183verbose = 0
184
Johnny Chen08967192011-11-18 00:19:29 +0000185# Set to True only if verbose is 0 and LLDB trace mode is off.
186progress_bar = False
187
Peter Collingbourne61aca482011-06-20 19:06:29 +0000188# By default, search from the script directory.
189testdirs = [ sys.path[0] ]
Johnny Chen9707bb62010-06-25 21:14:08 +0000190
Johnny Chen877c7e42010-08-07 00:16:07 +0000191# Separator string.
192separator = '-' * 70
193
Johnny Chen9707bb62010-06-25 21:14:08 +0000194
195def usage():
196 print """
197Usage: dotest.py [option] [args]
198where options:
Jim Ingham4f347cb2011-04-13 21:11:41 +0000199-h : print this help message and exit. Add '-v' for more detailed help.
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000200-A : specify the architecture(s) to launch for the inferior process
201 -A i386 => launch inferior with i386 architecture
202 -A x86_64^i386 => launch inferior with x86_64 and i386 architectures
203-C : specify the compiler(s) used to build the inferior executable
204 -C clang => build debuggee using clang compiler
Johnny Chence9cf4e2012-01-17 01:26:06 +0000205 -C /my/full/path/to/clang => specify a full path to the clang binary
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000206 -C clang^gcc => build debuggee using clang and gcc compilers
Johnny Chen50bc6382011-01-29 01:16:52 +0000207-D : dump the Python sys.path variable
Johnny Chen1abe4c02012-03-20 00:33:51 +0000208-E : specify the extra flags to be passed to the toolchain when building the
209 inferior programs to be debugged
210 suggestions: do not lump the -A arch1^arch2 together such that the -E
211 option applies to only one of the architectures
Johnny Chena3ed7d82012-04-06 00:56:05 +0000212-N : don't do test cases marked with the @dsym decorator by passing 'dsym' as the option arg, or
213 don't do test cases marked with the @dwarf decorator by passing 'dwarf' as the option arg
Johnny Chen4f93bf12010-12-10 00:51:23 +0000214-a : don't do lldb Python API tests
215 use @python_api_test to decorate a test case as lldb Python API test
Johnny Chen3ebdacc2010-12-10 18:52:10 +0000216+a : just do lldb Python API tests
Johnny Chencc659ad2010-12-10 19:02:23 +0000217 do not specify both '-a' and '+a' at the same time
Johnny Chen82ccf402011-07-30 01:39:58 +0000218+b : just do benchmark tests
219 use @benchmark_test to decorate a test case as such
Johnny Chen82e6b1e2010-12-01 22:47:54 +0000220-b : read a blacklist file specified after this option
Johnny Chen9fdb0a92010-09-18 00:16:47 +0000221-c : read a config file specified after this option
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000222 the architectures and compilers (note the plurals) specified via '-A' and '-C'
223 will override those specified via a config file
Johnny Chenb40056b2010-09-21 00:09:27 +0000224 (see also lldb-trunk/example/test/usage-config)
Johnny Chen91960d32010-09-08 20:56:16 +0000225-d : delay startup for 10 seconds (in order for the debugger to attach)
Johnny Chene00c9302011-10-10 22:03:44 +0000226-e : specify the full path of an executable used for benchmark purpose;
227 see also '-x', which provides the breakpoint sepcification
Johnny Chen7d6d8442010-12-03 19:59:35 +0000228-F : failfast, stop the test suite on the first error/failure
Johnny Chen46be75d2010-10-11 16:19:48 +0000229-f : specify a filter, which consists of the test class name, a dot, followed by
Johnny Chen1a6e92a2010-11-08 20:17:04 +0000230 the test method, to only admit such test into the test suite
Johnny Chenb62436b2010-10-06 20:40:56 +0000231 e.g., -f 'ClassTypesTestCase.test_with_dwarf_and_python_api'
Johnny Chena224cd12010-11-08 01:21:03 +0000232-g : if specified, the filterspec by -f is not exclusive, i.e., if a test module
233 does not match the filterspec (testclass.testmethod), the whole module is
234 still admitted to the test suite
Johnny Chenaf149a02010-09-16 17:11:30 +0000235-i : ignore (don't bailout) if 'lldb.py' module cannot be located in the build
236 tree relative to this script; use PYTHONPATH to locate the module
Johnny Chen38f823c2011-10-11 01:30:27 +0000237-k : specify a runhook, which is an lldb command to be executed by the debugger;
238 '-k' option can occur multiple times, the commands are executed one after the
239 other to bring the debugger to a desired state, so that, for example, further
240 benchmarking can be done
Johnny Chen41998192010-10-01 22:59:49 +0000241-l : don't skip long running test
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000242-n : don't print the headers like build dir, lldb version, and svn info at all
Johnny Chen7c52ff12010-09-27 23:29:54 +0000243-p : specify a regexp filename pattern for inclusion in the test suite
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000244-R : specify a dir to relocate the tests and their intermediate files to;
245 BE WARNED THAT the directory, if exists, will be deleted before running this test driver;
Johnny Chen548aefd2010-10-11 22:25:46 +0000246 no cleanup of intermediate test files is performed in this case
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000247-r : similar to '-R',
248 except that the directory must not exist before running this test driver
Johnny Chen028d8eb2011-11-17 19:57:27 +0000249-S : skip the build and cleanup while running the test
250 use this option with care as you would need to build the inferior(s) by hand
251 and build the executable(s) with the correct name(s)
252 this can be used with '-# n' to stress test certain test cases for n number of
253 times
Johnny Chen125fc2b2010-10-21 16:55:35 +0000254-s : specify the name of the dir created to store the session files of tests
255 with errored or failed status; if not specified, the test driver uses the
256 timestamp as the session dir name
Johnny Chena2486f22011-04-21 20:48:32 +0000257-t : turn on tracing of lldb command and other detailed test executions
Johnny Chen0f907b82012-01-31 00:38:03 +0000258-u : specify an environment variable to unset before running the test cases
259 e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble'
Johnny Chena2486f22011-04-21 20:48:32 +0000260-v : do verbose mode of unittest framework (print out each test case invocation)
Johnny Chene9eae812012-01-18 05:15:00 +0000261-X : exclude a directory from consideration for test discovery
262 -X types => if 'types' appear in the pathname components of a potential testfile
263 it will be ignored
Johnny Chene00c9302011-10-10 22:03:44 +0000264-x : specify the breakpoint specification for the benchmark executable;
265 see also '-e', which provides the full path of the executable
Johnny Chen5f2ed172011-10-20 18:43:28 +0000266-y : specify the iteration count used to collect our benchmarks; an example is
267 the number of times to do 'thread step-over' to measure stepping speed
268 see also '-e' and '-x' options
Johnny Chene47649c2010-10-07 02:04:14 +0000269-w : insert some wait time (currently 0.5 sec) between consecutive test cases
Johnny Chend2acdb32010-11-16 22:42:58 +0000270-# : Repeat the test suite for a specified number of times
Johnny Chen9707bb62010-06-25 21:14:08 +0000271
272and:
Johnny Chen9656ab22010-10-22 19:00:18 +0000273args : specify a list of directory names to search for test modules named after
274 Test*.py (test discovery)
Peter Collingbourne5f2b5d62011-06-14 03:55:45 +0000275 if empty, search from the current working directory, instead
Jim Ingham4f347cb2011-04-13 21:11:41 +0000276"""
Johnny Chen58f93922010-06-29 23:10:39 +0000277
Jim Ingham4f347cb2011-04-13 21:11:41 +0000278 if verbose > 0:
279 print """
Johnny Chen9656ab22010-10-22 19:00:18 +0000280Examples:
281
Johnny Chena224cd12010-11-08 01:21:03 +0000282This is an example of using the -f option to pinpoint to a specfic test class
283and test method to be run:
Johnny Chen6ad7e5e2010-10-21 00:47:52 +0000284
Johnny Chena224cd12010-11-08 01:21:03 +0000285$ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command
Johnny Chen6ad7e5e2010-10-21 00:47:52 +0000286----------------------------------------------------------------------
287Collected 1 test
288
289test_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase)
290Test 'frame variable this' when stopped on a class constructor. ... ok
291
292----------------------------------------------------------------------
293Ran 1 test in 1.396s
294
295OK
Johnny Chen9656ab22010-10-22 19:00:18 +0000296
297And this is an example of using the -p option to run a single file (the filename
298matches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'):
299
300$ ./dotest.py -v -p ObjC
301----------------------------------------------------------------------
302Collected 4 tests
303
304test_break_with_dsym (TestObjCMethods.FoundationTestCase)
Greg Claytonb72d0f02011-04-12 05:54:46 +0000305Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok
Johnny Chen9656ab22010-10-22 19:00:18 +0000306test_break_with_dwarf (TestObjCMethods.FoundationTestCase)
Greg Claytonb72d0f02011-04-12 05:54:46 +0000307Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok
Johnny Chen9656ab22010-10-22 19:00:18 +0000308test_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase)
309Lookup objective-c data types and evaluate expressions. ... ok
310test_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase)
311Lookup objective-c data types and evaluate expressions. ... ok
312
313----------------------------------------------------------------------
314Ran 4 tests in 16.661s
315
316OK
Johnny Chen6ad7e5e2010-10-21 00:47:52 +0000317
Johnny Chen58f93922010-06-29 23:10:39 +0000318Running of this script also sets up the LLDB_TEST environment variable so that
Johnny Chenaf149a02010-09-16 17:11:30 +0000319individual test cases can locate their supporting files correctly. The script
320tries to set up Python's search paths for modules by looking at the build tree
Johnny Chena85859f2010-11-11 22:14:56 +0000321relative to this script. See also the '-i' option in the following example.
322
323Finally, this is an example of using the lldb.py module distributed/installed by
324Xcode4 to run against the tests under the 'forward' directory, and with the '-w'
325option to add some delay between two tests. It uses ARCH=x86_64 to specify that
326as the architecture and CC=clang to specify the compiler used for the test run:
327
328$ PYTHONPATH=/Xcode4/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python ARCH=x86_64 CC=clang ./dotest.py -v -w -i forward
329
330Session logs for test failures/errors will go into directory '2010-11-11-13_56_16'
331----------------------------------------------------------------------
332Collected 2 tests
333
334test_with_dsym_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase)
335Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok
336test_with_dwarf_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase)
337Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok
338
339----------------------------------------------------------------------
340Ran 2 tests in 5.659s
341
342OK
343
344The 'Session ...' verbiage is recently introduced (see also the '-s' option) to
345notify the directory containing the session logs for test failures or errors.
346In case there is any test failure/error, a similar message is appended at the
347end of the stderr output for your convenience.
Johnny Chenfde69bc2010-09-14 22:01:40 +0000348
349Environment variables related to loggings:
350
351o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem
352 with a default option of 'event process' if LLDB_LOG_OPTION is not defined.
353
354o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the
355 'process.gdb-remote' subsystem with a default option of 'packets' if
356 GDB_REMOTE_LOG_OPTION is not defined.
Johnny Chen9707bb62010-06-25 21:14:08 +0000357"""
Johnny Chen9fdb0a92010-09-18 00:16:47 +0000358 sys.exit(0)
Johnny Chen9707bb62010-06-25 21:14:08 +0000359
360
Johnny Chenaf149a02010-09-16 17:11:30 +0000361def parseOptionsAndInitTestdirs():
362 """Initialize the list of directories containing our unittest scripts.
363
364 '-h/--help as the first option prints out usage info and exit the program.
365 """
366
Johnny Chen4f93bf12010-12-10 00:51:23 +0000367 global dont_do_python_api_test
368 global just_do_python_api_test
Johnny Chen82ccf402011-07-30 01:39:58 +0000369 global just_do_benchmarks_test
Johnny Chena3ed7d82012-04-06 00:56:05 +0000370 global dont_do_dsym_test
371 global dont_do_dwarf_test
Johnny Chen82e6b1e2010-12-01 22:47:54 +0000372 global blacklist
373 global blacklistConfig
Johnny Chen9fdb0a92010-09-18 00:16:47 +0000374 global configFile
Johnny Chen1a4d5e72011-03-04 01:35:22 +0000375 global archs
376 global compilers
Johnny Chend2acdb32010-11-16 22:42:58 +0000377 global count
Johnny Chenaf149a02010-09-16 17:11:30 +0000378 global delay
Johnny Chen50bc6382011-01-29 01:16:52 +0000379 global dumpSysPath
Johnny Chene00c9302011-10-10 22:03:44 +0000380 global bmExecutable
381 global bmBreakpointSpec
Johnny Chen5f2ed172011-10-20 18:43:28 +0000382 global bmIterationCount
Johnny Chen7d6d8442010-12-03 19:59:35 +0000383 global failfast
Johnny Chenc5fa0052011-07-29 22:54:56 +0000384 global filters
Johnny Chenb62436b2010-10-06 20:40:56 +0000385 global fs4all
Johnny Chen7c52ff12010-09-27 23:29:54 +0000386 global ignore
Johnny Chen08967192011-11-18 00:19:29 +0000387 global progress_bar
Johnny Chen38f823c2011-10-11 01:30:27 +0000388 global runHooks
Johnny Chen028d8eb2011-11-17 19:57:27 +0000389 global skip_build_and_cleanup
390 global skip_long_running_test
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000391 global noHeaders
Johnny Chen7c52ff12010-09-27 23:29:54 +0000392 global regexp
Johnny Chen548aefd2010-10-11 22:25:46 +0000393 global rdir
Johnny Chen125fc2b2010-10-21 16:55:35 +0000394 global sdir_name
Johnny Chen0f907b82012-01-31 00:38:03 +0000395 global unsets
Johnny Chenaf149a02010-09-16 17:11:30 +0000396 global verbose
397 global testdirs
398
Jim Ingham4f347cb2011-04-13 21:11:41 +0000399 do_help = False
400
Johnny Chenaf149a02010-09-16 17:11:30 +0000401 if len(sys.argv) == 1:
402 return
403
404 # Process possible trace and/or verbose flag, among other things.
405 index = 1
Johnny Chence2212c2010-10-07 15:41:55 +0000406 while index < len(sys.argv):
Johnny Chen4f93bf12010-12-10 00:51:23 +0000407 if sys.argv[index].startswith('-') or sys.argv[index].startswith('+'):
408 # We should continue processing...
409 pass
410 else:
Johnny Chenaf149a02010-09-16 17:11:30 +0000411 # End of option processing.
412 break
413
414 if sys.argv[index].find('-h') != -1:
Jim Ingham4f347cb2011-04-13 21:11:41 +0000415 index += 1
416 do_help = True
Johnny Chen012cba12011-01-26 19:07:42 +0000417 elif sys.argv[index].startswith('-A'):
418 # Increment by 1 to fetch the ARCH spec.
419 index += 1
420 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
421 usage()
Johnny Cheneee9b862011-04-26 20:45:00 +0000422 archs = sys.argv[index].split('^')
Johnny Chen012cba12011-01-26 19:07:42 +0000423 index += 1
424 elif sys.argv[index].startswith('-C'):
425 # Increment by 1 to fetch the CC spec.
426 index += 1
427 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
428 usage()
Johnny Cheneee9b862011-04-26 20:45:00 +0000429 compilers = sys.argv[index].split('^')
Johnny Chen012cba12011-01-26 19:07:42 +0000430 index += 1
Johnny Chen50bc6382011-01-29 01:16:52 +0000431 elif sys.argv[index].startswith('-D'):
432 dumpSysPath = True
433 index += 1
Johnny Chen1abe4c02012-03-20 00:33:51 +0000434 elif sys.argv[index].startswith('-E'):
435 # Increment by 1 to fetch the CFLAGS_EXTRAS spec.
436 index += 1
437 if index >= len(sys.argv):
438 usage()
439 cflags_extras = sys.argv[index]
440 os.environ["CFLAGS_EXTRAS"] = cflags_extras
441 index += 1
Johnny Chena3ed7d82012-04-06 00:56:05 +0000442 elif sys.argv[index].startswith('-N'):
443 # Increment by 1 to fetch 'dsym' or 'dwarf'.
444 index += 1
445 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
446 usage()
447 dont_do = sys.argv[index]
448 if dont_do.lower() == 'dsym':
449 dont_do_dsym_test = True
450 elif dont_do.lower() == 'dwarf':
451 dont_do_dwarf_test = True
452 else:
453 print "!!!"
454 print "Warning: -N only accepts either 'dsym' or 'dwarf' as the option arg; you passed in '%s'?" % dont_do
455 print "!!!"
456 index += 1
Johnny Chen4f93bf12010-12-10 00:51:23 +0000457 elif sys.argv[index].startswith('-a'):
458 dont_do_python_api_test = True
459 index += 1
460 elif sys.argv[index].startswith('+a'):
461 just_do_python_api_test = True
462 index += 1
Johnny Chen82ccf402011-07-30 01:39:58 +0000463 elif sys.argv[index].startswith('+b'):
464 just_do_benchmarks_test = True
465 index += 1
Johnny Chen82e6b1e2010-12-01 22:47:54 +0000466 elif sys.argv[index].startswith('-b'):
467 # Increment by 1 to fetch the blacklist file name option argument.
468 index += 1
469 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
470 usage()
471 blacklistFile = sys.argv[index]
472 if not os.path.isfile(blacklistFile):
473 print "Blacklist file:", blacklistFile, "does not exist!"
474 usage()
475 index += 1
476 # Now read the blacklist contents and assign it to blacklist.
477 execfile(blacklistFile, globals(), blacklistConfig)
478 blacklist = blacklistConfig.get('blacklist')
Johnny Chen9fdb0a92010-09-18 00:16:47 +0000479 elif sys.argv[index].startswith('-c'):
480 # Increment by 1 to fetch the config file name option argument.
481 index += 1
482 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
483 usage()
484 configFile = sys.argv[index]
485 if not os.path.isfile(configFile):
486 print "Config file:", configFile, "does not exist!"
487 usage()
488 index += 1
Johnny Chenaf149a02010-09-16 17:11:30 +0000489 elif sys.argv[index].startswith('-d'):
490 delay = True
491 index += 1
Johnny Chene00c9302011-10-10 22:03:44 +0000492 elif sys.argv[index].startswith('-e'):
493 # Increment by 1 to fetch the full path of the benchmark executable.
494 index += 1
495 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
496 usage()
497 bmExecutable = sys.argv[index]
498 if not is_exe(bmExecutable):
499 usage()
500 index += 1
Johnny Chen7d6d8442010-12-03 19:59:35 +0000501 elif sys.argv[index].startswith('-F'):
502 failfast = True
503 index += 1
Johnny Chenb62436b2010-10-06 20:40:56 +0000504 elif sys.argv[index].startswith('-f'):
505 # Increment by 1 to fetch the filter spec.
506 index += 1
507 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
508 usage()
Johnny Chenc5fa0052011-07-29 22:54:56 +0000509 filters.append(sys.argv[index])
Johnny Chenb62436b2010-10-06 20:40:56 +0000510 index += 1
511 elif sys.argv[index].startswith('-g'):
Johnny Chena224cd12010-11-08 01:21:03 +0000512 fs4all = False
Johnny Chenb62436b2010-10-06 20:40:56 +0000513 index += 1
Johnny Chenaf149a02010-09-16 17:11:30 +0000514 elif sys.argv[index].startswith('-i'):
515 ignore = True
516 index += 1
Johnny Chen38f823c2011-10-11 01:30:27 +0000517 elif sys.argv[index].startswith('-k'):
518 # Increment by 1 to fetch the runhook lldb command.
519 index += 1
520 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
521 usage()
522 runHooks.append(sys.argv[index])
523 index += 1
Johnny Chen41998192010-10-01 22:59:49 +0000524 elif sys.argv[index].startswith('-l'):
Johnny Chen028d8eb2011-11-17 19:57:27 +0000525 skip_long_running_test = False
Johnny Chen41998192010-10-01 22:59:49 +0000526 index += 1
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000527 elif sys.argv[index].startswith('-n'):
528 noHeaders = True
529 index += 1
Johnny Chen7c52ff12010-09-27 23:29:54 +0000530 elif sys.argv[index].startswith('-p'):
531 # Increment by 1 to fetch the reg exp pattern argument.
532 index += 1
533 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
534 usage()
535 regexp = sys.argv[index]
536 index += 1
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000537 elif sys.argv[index].startswith('-R'):
538 # Increment by 1 to fetch the relocated directory argument.
539 index += 1
540 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
541 usage()
542 rdir = os.path.abspath(sys.argv[index])
543 if os.path.exists(rdir):
544 import shutil
545 print "Removing tree:", rdir
546 shutil.rmtree(rdir)
547 index += 1
Johnny Chen548aefd2010-10-11 22:25:46 +0000548 elif sys.argv[index].startswith('-r'):
549 # Increment by 1 to fetch the relocated directory argument.
550 index += 1
551 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
552 usage()
553 rdir = os.path.abspath(sys.argv[index])
554 if os.path.exists(rdir):
555 print "Relocated directory:", rdir, "must not exist!"
556 usage()
557 index += 1
Johnny Chen028d8eb2011-11-17 19:57:27 +0000558 elif sys.argv[index].startswith('-S'):
559 skip_build_and_cleanup = True
560 index += 1
Johnny Chen125fc2b2010-10-21 16:55:35 +0000561 elif sys.argv[index].startswith('-s'):
562 # Increment by 1 to fetch the session dir name.
563 index += 1
564 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
565 usage()
566 sdir_name = sys.argv[index]
567 index += 1
Johnny Chenaf149a02010-09-16 17:11:30 +0000568 elif sys.argv[index].startswith('-t'):
569 os.environ["LLDB_COMMAND_TRACE"] = "YES"
570 index += 1
Johnny Chen0f907b82012-01-31 00:38:03 +0000571 elif sys.argv[index].startswith('-u'):
572 # Increment by 1 to fetch the environment variable to unset.
573 index += 1
574 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
575 usage()
576 unsets.append(sys.argv[index])
577 index += 1
Johnny Chenaf149a02010-09-16 17:11:30 +0000578 elif sys.argv[index].startswith('-v'):
579 verbose = 2
580 index += 1
Johnny Chene47649c2010-10-07 02:04:14 +0000581 elif sys.argv[index].startswith('-w'):
582 os.environ["LLDB_WAIT_BETWEEN_TEST_CASES"] = 'YES'
583 index += 1
Johnny Chene9eae812012-01-18 05:15:00 +0000584 elif sys.argv[index].startswith('-X'):
585 # Increment by 1 to fetch an excluded directory.
586 index += 1
587 if index >= len(sys.argv):
588 usage()
589 excluded.add(sys.argv[index])
590 index += 1
Johnny Chene00c9302011-10-10 22:03:44 +0000591 elif sys.argv[index].startswith('-x'):
592 # Increment by 1 to fetch the breakpoint specification of the benchmark executable.
593 index += 1
Johnny Chen8a1b1222011-10-20 22:16:24 +0000594 if index >= len(sys.argv):
Johnny Chene00c9302011-10-10 22:03:44 +0000595 usage()
596 bmBreakpointSpec = sys.argv[index]
597 index += 1
Johnny Chen5f2ed172011-10-20 18:43:28 +0000598 elif sys.argv[index].startswith('-y'):
599 # Increment by 1 to fetch the the benchmark iteration count.
600 index += 1
601 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
602 usage()
603 bmIterationCount = int(sys.argv[index])
604 index += 1
Johnny Chend2acdb32010-11-16 22:42:58 +0000605 elif sys.argv[index].startswith('-#'):
606 # Increment by 1 to fetch the repeat count argument.
607 index += 1
608 if index >= len(sys.argv) or sys.argv[index].startswith('-'):
609 usage()
610 count = int(sys.argv[index])
611 index += 1
Johnny Chenaf149a02010-09-16 17:11:30 +0000612 else:
613 print "Unknown option: ", sys.argv[index]
614 usage()
Johnny Chenaf149a02010-09-16 17:11:30 +0000615
Jim Ingham4f347cb2011-04-13 21:11:41 +0000616 if do_help == True:
617 usage()
618
Johnny Chencc659ad2010-12-10 19:02:23 +0000619 # Do not specify both '-a' and '+a' at the same time.
620 if dont_do_python_api_test and just_do_python_api_test:
621 usage()
622
Johnny Chen08967192011-11-18 00:19:29 +0000623 # The simple progress bar is turned on only if verbose == 0 and LLDB_COMMAND_TRACE is not 'YES'
624 if ("LLDB_COMMAND_TRACE" not in os.environ or os.environ["LLDB_COMMAND_TRACE"]!="YES") and verbose==0:
625 progress_bar = True
626
Johnny Chenaf149a02010-09-16 17:11:30 +0000627 # Gather all the dirs passed on the command line.
628 if len(sys.argv) > index:
629 testdirs = map(os.path.abspath, sys.argv[index:])
630
Johnny Chen548aefd2010-10-11 22:25:46 +0000631 # If '-r dir' is specified, the tests should be run under the relocated
632 # directory. Let's copy the testdirs over.
633 if rdir:
634 from shutil import copytree, ignore_patterns
635
636 tmpdirs = []
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000637 orig_testdirs = testdirs[:]
Johnny Chen548aefd2010-10-11 22:25:46 +0000638 for srcdir in testdirs:
Johnny Chen1abe4c02012-03-20 00:33:51 +0000639 # For example, /Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/hello_watchpoint
640 # shall be split into ['/Volumes/data/lldb/svn/ToT/', 'functionalities/watchpoint/hello_watchpoint'].
641 # Utilize the relative path to the 'test' directory to make our destination dir path.
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000642 if ("test"+os.sep) in srcdir:
643 to_split_on = "test"+os.sep
644 else:
645 to_split_on = "test"
646 dstdir = os.path.join(rdir, srcdir.split(to_split_on)[1])
647 dstdir = dstdir.rstrip(os.sep)
Johnny Chen548aefd2010-10-11 22:25:46 +0000648 # Don't copy the *.pyc and .svn stuffs.
649 copytree(srcdir, dstdir, ignore=ignore_patterns('*.pyc', '.svn'))
650 tmpdirs.append(dstdir)
651
652 # This will be our modified testdirs.
653 testdirs = tmpdirs
654
655 # With '-r dir' specified, there's no cleanup of intermediate test files.
656 os.environ["LLDB_DO_CLEANUP"] = 'NO'
657
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000658 # If the original testdirs is ['test'], the make directory has already been copied
Johnny Chen548aefd2010-10-11 22:25:46 +0000659 # recursively and is contained within the rdir/test dir. For anything
660 # else, we would need to copy over the make directory and its contents,
661 # so that, os.listdir(rdir) looks like, for example:
662 #
663 # array_types conditional_break make
664 #
665 # where the make directory contains the Makefile.rules file.
Johnny Chen3bc7e5e2012-04-24 21:44:10 +0000666 if len(testdirs) != 1 or os.path.basename(orig_testdirs[0]) != 'test':
Johnny Chen548aefd2010-10-11 22:25:46 +0000667 # Don't copy the .svn stuffs.
668 copytree('make', os.path.join(rdir, 'make'),
669 ignore=ignore_patterns('.svn'))
670
671 #print "testdirs:", testdirs
672
Johnny Chenb40056b2010-09-21 00:09:27 +0000673 # Source the configFile if specified.
674 # The side effect, if any, will be felt from this point on. An example
675 # config file may be these simple two lines:
676 #
677 # sys.stderr = open("/tmp/lldbtest-stderr", "w")
678 # sys.stdout = open("/tmp/lldbtest-stdout", "w")
679 #
680 # which will reassign the two file objects to sys.stderr and sys.stdout,
681 # respectively.
682 #
683 # See also lldb-trunk/example/test/usage-config.
Johnny Chenac97a6b2012-04-16 18:55:15 +0000684 global config, pre_flight, post_flight
Johnny Chenb40056b2010-09-21 00:09:27 +0000685 if configFile:
686 # Pass config (a dictionary) as the locals namespace for side-effect.
687 execfile(configFile, globals(), config)
Johnny Chenac97a6b2012-04-16 18:55:15 +0000688 print "config:", config
689 if "pre_flight" in config:
690 pre_flight = config["pre_flight"]
691 if not callable(pre_flight):
692 print "fatal error: pre_flight is not callable, exiting."
693 sys.exit(1)
694 if "post_flight" in config:
695 post_flight = config["post_flight"]
696 if not callable(post_flight):
697 print "fatal error: post_flight is not callable, exiting."
698 sys.exit(1)
Johnny Chenb40056b2010-09-21 00:09:27 +0000699 #print "sys.stderr:", sys.stderr
700 #print "sys.stdout:", sys.stdout
701
Johnny Chenaf149a02010-09-16 17:11:30 +0000702
Johnny Chen9707bb62010-06-25 21:14:08 +0000703def setupSysPath():
Johnny Chen8a3c0432011-03-11 20:13:06 +0000704 """
705 Add LLDB.framework/Resources/Python to the search paths for modules.
706 As a side effect, we also discover the 'lldb' executable and export it here.
707 """
Johnny Chen9707bb62010-06-25 21:14:08 +0000708
Johnny Chen548aefd2010-10-11 22:25:46 +0000709 global rdir
710 global testdirs
Johnny Chen50bc6382011-01-29 01:16:52 +0000711 global dumpSysPath
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000712 global noHeaders
Johnny Chenb5fe80c2011-05-17 22:58:50 +0000713 global svn_info
Johnny Chen548aefd2010-10-11 22:25:46 +0000714
Johnny Chen9707bb62010-06-25 21:14:08 +0000715 # Get the directory containing the current script.
Johnny Chen4d162e52011-08-12 18:54:11 +0000716 if ("DOTEST_PROFILE" in os.environ or "DOTEST_PDB" in os.environ) and "DOTEST_SCRIPT_DIR" in os.environ:
Johnny Chen0de6ab52011-01-19 02:10:40 +0000717 scriptPath = os.environ["DOTEST_SCRIPT_DIR"]
718 else:
719 scriptPath = sys.path[0]
Johnny Chena1affab2010-07-03 03:41:59 +0000720 if not scriptPath.endswith('test'):
Johnny Chen9707bb62010-06-25 21:14:08 +0000721 print "This script expects to reside in lldb's test directory."
722 sys.exit(-1)
723
Johnny Chen548aefd2010-10-11 22:25:46 +0000724 if rdir:
725 # Set up the LLDB_TEST environment variable appropriately, so that the
726 # individual tests can be located relatively.
727 #
728 # See also lldbtest.TestBase.setUpClass(cls).
729 if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test':
730 os.environ["LLDB_TEST"] = os.path.join(rdir, 'test')
731 else:
732 os.environ["LLDB_TEST"] = rdir
733 else:
734 os.environ["LLDB_TEST"] = scriptPath
Peter Collingbournef6c3de82011-06-20 19:06:45 +0000735
736 # Set up the LLDB_SRC environment variable, so that the tests can locate
737 # the LLDB source code.
738 os.environ["LLDB_SRC"] = os.path.join(sys.path[0], os.pardir)
739
Johnny Chen9de4ede2010-08-31 17:42:54 +0000740 pluginPath = os.path.join(scriptPath, 'plugins')
Johnny Chen8a3c0432011-03-11 20:13:06 +0000741 pexpectPath = os.path.join(scriptPath, 'pexpect-2.4')
Johnny Chen58f93922010-06-29 23:10:39 +0000742
Johnny Chen8a3c0432011-03-11 20:13:06 +0000743 # Append script dir, plugin dir, and pexpect dir to the sys.path.
Johnny Chenaf149a02010-09-16 17:11:30 +0000744 sys.path.append(scriptPath)
745 sys.path.append(pluginPath)
Johnny Chen8a3c0432011-03-11 20:13:06 +0000746 sys.path.append(pexpectPath)
Johnny Chenaf149a02010-09-16 17:11:30 +0000747
Johnny Chen26901c82011-03-11 19:47:23 +0000748 # This is our base name component.
Johnny Chena1affab2010-07-03 03:41:59 +0000749 base = os.path.abspath(os.path.join(scriptPath, os.pardir))
Johnny Chen6a564a42011-02-15 18:50:19 +0000750
Johnny Chen26901c82011-03-11 19:47:23 +0000751 # These are for xcode build directories.
Johnny Chen6a564a42011-02-15 18:50:19 +0000752 xcode3_build_dir = ['build']
753 xcode4_build_dir = ['build', 'lldb', 'Build', 'Products']
754 dbg = ['Debug']
755 rel = ['Release']
756 bai = ['BuildAndIntegration']
757 python_resource_dir = ['LLDB.framework', 'Resources', 'Python']
Johnny Chen26901c82011-03-11 19:47:23 +0000758
759 # Some of the tests can invoke the 'lldb' command directly.
760 # We'll try to locate the appropriate executable right here.
761
Johnny Chen6033bed2011-08-26 00:00:01 +0000762 # First, you can define an environment variable LLDB_EXEC specifying the
763 # full pathname of the lldb executable.
764 if "LLDB_EXEC" in os.environ and is_exe(os.environ["LLDB_EXEC"]):
765 lldbExec = os.environ["LLDB_EXEC"]
766 else:
767 lldbExec = None
768
Johnny Chen26901c82011-03-11 19:47:23 +0000769 executable = ['lldb']
770 dbgExec = os.path.join(base, *(xcode3_build_dir + dbg + executable))
771 dbgExec2 = os.path.join(base, *(xcode4_build_dir + dbg + executable))
772 relExec = os.path.join(base, *(xcode3_build_dir + rel + executable))
773 relExec2 = os.path.join(base, *(xcode4_build_dir + rel + executable))
774 baiExec = os.path.join(base, *(xcode3_build_dir + bai + executable))
775 baiExec2 = os.path.join(base, *(xcode4_build_dir + bai + executable))
776
Johnny Chen6033bed2011-08-26 00:00:01 +0000777 # The 'lldb' executable built here in the source tree.
778 lldbHere = None
Johnny Chen26901c82011-03-11 19:47:23 +0000779 if is_exe(dbgExec):
Johnny Chen6033bed2011-08-26 00:00:01 +0000780 lldbHere = dbgExec
Johnny Chen26901c82011-03-11 19:47:23 +0000781 elif is_exe(dbgExec2):
Johnny Chen6033bed2011-08-26 00:00:01 +0000782 lldbHere = dbgExec2
Johnny Chen26901c82011-03-11 19:47:23 +0000783 elif is_exe(relExec):
Johnny Chen6033bed2011-08-26 00:00:01 +0000784 lldbHere = relExec
Johnny Chen26901c82011-03-11 19:47:23 +0000785 elif is_exe(relExec2):
Johnny Chen6033bed2011-08-26 00:00:01 +0000786 lldbHere = relExec2
Johnny Chen26901c82011-03-11 19:47:23 +0000787 elif is_exe(baiExec):
Johnny Chen6033bed2011-08-26 00:00:01 +0000788 lldbHere = baiExec
Johnny Chen26901c82011-03-11 19:47:23 +0000789 elif is_exe(baiExec2):
Johnny Chen6033bed2011-08-26 00:00:01 +0000790 lldbHere = baiExec2
Daniel Dunbar2bd310c2011-10-31 23:27:06 +0000791 elif lldbExec:
792 lldbHere = lldbExec
Johnny Chen26901c82011-03-11 19:47:23 +0000793
Johnny Chen6033bed2011-08-26 00:00:01 +0000794 if lldbHere:
795 os.environ["LLDB_HERE"] = lldbHere
Johnny Chen0409d992011-10-25 20:08:03 +0000796 os.environ["LLDB_BUILD_DIR"] = os.path.split(lldbHere)[0]
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000797 if not noHeaders:
798 print "LLDB build dir:", os.environ["LLDB_BUILD_DIR"]
Johnny Chen91da0052011-10-28 17:56:02 +0000799 os.system('%s -v' % lldbHere)
Johnny Chen62d527e2011-08-04 18:17:16 +0000800
Johnny Chen6033bed2011-08-26 00:00:01 +0000801 # One last chance to locate the 'lldb' executable.
Johnny Chen26901c82011-03-11 19:47:23 +0000802 if not lldbExec:
Johnny Chen0409d992011-10-25 20:08:03 +0000803 lldbExec = which('lldb')
804 if lldbHere and not lldbExec:
Johnny Chen6033bed2011-08-26 00:00:01 +0000805 lldbExec = lldbHere
Johnny Chen0409d992011-10-25 20:08:03 +0000806
Johnny Chen26901c82011-03-11 19:47:23 +0000807
808 if not lldbExec:
809 print "The 'lldb' executable cannot be located. Some of the tests may not be run as a result."
810 else:
811 os.environ["LLDB_EXEC"] = lldbExec
Johnny Chen8904eb02011-10-28 00:59:00 +0000812 #print "The 'lldb' from PATH env variable", lldbExec
Johnny Chend7931462011-03-17 00:38:22 +0000813
Johnny Chenb264c9b2011-06-24 22:52:05 +0000814 if os.path.isdir(os.path.join(base, '.svn')):
815 pipe = subprocess.Popen(["svn", "info", base], stdout = subprocess.PIPE)
816 svn_info = pipe.stdout.read()
817 elif os.path.isdir(os.path.join(base, '.git')):
818 pipe = subprocess.Popen(["git", "svn", "info", base], stdout = subprocess.PIPE)
819 svn_info = pipe.stdout.read()
Johnny Chenfe5f1ed2011-10-21 18:33:27 +0000820 if not noHeaders:
821 print svn_info
Johnny Chen26901c82011-03-11 19:47:23 +0000822
823 global ignore
824
825 # The '-i' option is used to skip looking for lldb.py in the build tree.
826 if ignore:
827 return
828
Johnny Chen6a564a42011-02-15 18:50:19 +0000829 dbgPath = os.path.join(base, *(xcode3_build_dir + dbg + python_resource_dir))
830 dbgPath2 = os.path.join(base, *(xcode4_build_dir + dbg + python_resource_dir))
831 relPath = os.path.join(base, *(xcode3_build_dir + rel + python_resource_dir))
832 relPath2 = os.path.join(base, *(xcode4_build_dir + rel + python_resource_dir))
833 baiPath = os.path.join(base, *(xcode3_build_dir + bai + python_resource_dir))
834 baiPath2 = os.path.join(base, *(xcode4_build_dir + bai + python_resource_dir))
Johnny Chen9707bb62010-06-25 21:14:08 +0000835
836 lldbPath = None
837 if os.path.isfile(os.path.join(dbgPath, 'lldb.py')):
838 lldbPath = dbgPath
Greg Claytond9846b02011-02-14 21:17:06 +0000839 elif os.path.isfile(os.path.join(dbgPath2, 'lldb.py')):
840 lldbPath = dbgPath2
Johnny Chen9707bb62010-06-25 21:14:08 +0000841 elif os.path.isfile(os.path.join(relPath, 'lldb.py')):
842 lldbPath = relPath
Greg Claytond9846b02011-02-14 21:17:06 +0000843 elif os.path.isfile(os.path.join(relPath2, 'lldb.py')):
844 lldbPath = relPath2
Johnny Chenc202c462010-09-15 18:11:19 +0000845 elif os.path.isfile(os.path.join(baiPath, 'lldb.py')):
846 lldbPath = baiPath
Greg Claytond9846b02011-02-14 21:17:06 +0000847 elif os.path.isfile(os.path.join(baiPath2, 'lldb.py')):
848 lldbPath = baiPath2
Johnny Chen9707bb62010-06-25 21:14:08 +0000849
850 if not lldbPath:
Johnny Chenc202c462010-09-15 18:11:19 +0000851 print 'This script requires lldb.py to be in either ' + dbgPath + ',',
852 print relPath + ', or ' + baiPath
Johnny Chen9707bb62010-06-25 21:14:08 +0000853 sys.exit(-1)
854
Johnny Chenaf149a02010-09-16 17:11:30 +0000855 # This is to locate the lldb.py module. Insert it right after sys.path[0].
856 sys.path[1:1] = [lldbPath]
Johnny Chen50bc6382011-01-29 01:16:52 +0000857 if dumpSysPath:
858 print "sys.path:", sys.path
Johnny Chen9707bb62010-06-25 21:14:08 +0000859
Johnny Chen9707bb62010-06-25 21:14:08 +0000860
Johnny Chencd0279d2010-09-20 18:07:50 +0000861def doDelay(delta):
862 """Delaying startup for delta-seconds to facilitate debugger attachment."""
863 def alarm_handler(*args):
864 raise Exception("timeout")
865
866 signal.signal(signal.SIGALRM, alarm_handler)
867 signal.alarm(delta)
868 sys.stdout.write("pid=%d\n" % os.getpid())
869 sys.stdout.write("Enter RET to proceed (or timeout after %d seconds):" %
870 delta)
871 sys.stdout.flush()
872 try:
873 text = sys.stdin.readline()
874 except:
875 text = ""
876 signal.alarm(0)
877 sys.stdout.write("proceeding...\n")
878 pass
879
880
Johnny Chen9707bb62010-06-25 21:14:08 +0000881def visit(prefix, dir, names):
882 """Visitor function for os.path.walk(path, visit, arg)."""
883
884 global suite
Johnny Chen7c52ff12010-09-27 23:29:54 +0000885 global regexp
Johnny Chenc5fa0052011-07-29 22:54:56 +0000886 global filters
Johnny Chenb62436b2010-10-06 20:40:56 +0000887 global fs4all
Johnny Chene9eae812012-01-18 05:15:00 +0000888 global excluded
889
890 if set(dir.split(os.sep)).intersection(excluded):
891 #print "Detected an excluded dir component: %s" % dir
892 return
Johnny Chen9707bb62010-06-25 21:14:08 +0000893
894 for name in names:
895 if os.path.isdir(os.path.join(dir, name)):
896 continue
897
898 if '.py' == os.path.splitext(name)[1] and name.startswith(prefix):
Johnny Chen7c52ff12010-09-27 23:29:54 +0000899 # Try to match the regexp pattern, if specified.
900 if regexp:
901 import re
902 if re.search(regexp, name):
903 #print "Filename: '%s' matches pattern: '%s'" % (name, regexp)
904 pass
905 else:
906 #print "Filename: '%s' does not match pattern: '%s'" % (name, regexp)
907 continue
908
Johnny Chen953864a2010-10-12 21:35:54 +0000909 # We found a match for our test. Add it to the suite.
Johnny Chen79723352010-10-12 15:53:22 +0000910
911 # Update the sys.path first.
Johnny Chena85d7ee2010-06-26 00:19:32 +0000912 if not sys.path.count(dir):
Johnny Chen548aefd2010-10-11 22:25:46 +0000913 sys.path.insert(0, dir)
Johnny Chen9707bb62010-06-25 21:14:08 +0000914 base = os.path.splitext(name)[0]
Johnny Chenb62436b2010-10-06 20:40:56 +0000915
916 # Thoroughly check the filterspec against the base module and admit
917 # the (base, filterspec) combination only when it makes sense.
Johnny Chenc5fa0052011-07-29 22:54:56 +0000918 filterspec = None
919 for filterspec in filters:
Johnny Chenb62436b2010-10-06 20:40:56 +0000920 # Optimistically set the flag to True.
921 filtered = True
922 module = __import__(base)
923 parts = filterspec.split('.')
924 obj = module
925 for part in parts:
926 try:
927 parent, obj = obj, getattr(obj, part)
928 except AttributeError:
929 # The filterspec has failed.
930 filtered = False
931 break
Johnny Chenc5fa0052011-07-29 22:54:56 +0000932
Johnny Chendb4be602011-08-12 23:55:07 +0000933 # If filtered, we have a good filterspec. Add it.
Johnny Chenc5fa0052011-07-29 22:54:56 +0000934 if filtered:
Johnny Chendb4be602011-08-12 23:55:07 +0000935 #print "adding filter spec %s to module %s" % (filterspec, module)
936 suite.addTests(
937 unittest2.defaultTestLoader.loadTestsFromName(filterspec, module))
938 continue
Johnny Chenc5fa0052011-07-29 22:54:56 +0000939
940 # Forgo this module if the (base, filterspec) combo is invalid
941 # and no '-g' option is specified
942 if filters and fs4all and not filtered:
943 continue
Johnny Chenb62436b2010-10-06 20:40:56 +0000944
Johnny Chendb4be602011-08-12 23:55:07 +0000945 # Add either the filtered test case(s) (which is done before) or the entire test class.
946 if not filterspec or not filtered:
Johnny Chenb62436b2010-10-06 20:40:56 +0000947 # A simple case of just the module name. Also the failover case
948 # from the filterspec branch when the (base, filterspec) combo
949 # doesn't make sense.
950 suite.addTests(unittest2.defaultTestLoader.loadTestsFromName(base))
Johnny Chen9707bb62010-06-25 21:14:08 +0000951
952
Johnny Chencd0279d2010-09-20 18:07:50 +0000953def lldbLoggings():
954 """Check and do lldb loggings if necessary."""
955
956 # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is
957 # defined. Use ${LLDB_LOG} to specify the log file.
958 ci = lldb.DBG.GetCommandInterpreter()
959 res = lldb.SBCommandReturnObject()
960 if ("LLDB_LOG" in os.environ):
961 if ("LLDB_LOG_OPTION" in os.environ):
962 lldb_log_option = os.environ["LLDB_LOG_OPTION"]
963 else:
Johnny Chen8fd886c2010-12-08 01:25:21 +0000964 lldb_log_option = "event process expr state api"
Johnny Chencd0279d2010-09-20 18:07:50 +0000965 ci.HandleCommand(
Greg Clayton940b1032011-02-23 00:35:02 +0000966 "log enable -n -f " + os.environ["LLDB_LOG"] + " lldb " + lldb_log_option,
Johnny Chencd0279d2010-09-20 18:07:50 +0000967 res)
968 if not res.Succeeded():
969 raise Exception('log enable failed (check LLDB_LOG env variable.')
970 # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined.
971 # Use ${GDB_REMOTE_LOG} to specify the log file.
972 if ("GDB_REMOTE_LOG" in os.environ):
973 if ("GDB_REMOTE_LOG_OPTION" in os.environ):
974 gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"]
975 else:
Johnny Chen7ab8c852010-12-02 18:35:13 +0000976 gdb_remote_log_option = "packets process"
Johnny Chencd0279d2010-09-20 18:07:50 +0000977 ci.HandleCommand(
Johnny Chenc935a892011-06-21 19:25:45 +0000978 "log enable -n -f " + os.environ["GDB_REMOTE_LOG"] + " gdb-remote "
Johnny Chencd0279d2010-09-20 18:07:50 +0000979 + gdb_remote_log_option,
980 res)
981 if not res.Succeeded():
982 raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.')
983
Johnny Chen067022b2011-01-19 19:31:46 +0000984def getMyCommandLine():
Johnny Chen067022b2011-01-19 19:31:46 +0000985 ps = subprocess.Popen(['ps', '-o', "command=CMD", str(os.getpid())], stdout=subprocess.PIPE).communicate()[0]
986 lines = ps.split('\n')
987 cmd_line = lines[1]
988 return cmd_line
Johnny Chencd0279d2010-09-20 18:07:50 +0000989
Johnny Chend96b5682010-11-05 17:30:53 +0000990# ======================================== #
Johnny Chencd0279d2010-09-20 18:07:50 +0000991# #
992# Execution of the test driver starts here #
993# #
Johnny Chend96b5682010-11-05 17:30:53 +0000994# ======================================== #
Johnny Chencd0279d2010-09-20 18:07:50 +0000995
Johnny Chen2891bb02011-09-16 01:04:26 +0000996def checkDsymForUUIDIsNotOn():
Johnny Chen6a4e0872011-09-16 17:50:44 +0000997 cmd = ["defaults", "read", "com.apple.DebugSymbols"]
998 pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
999 cmd_output = pipe.stdout.read()
Johnny Chen178c8d92011-09-16 18:03:19 +00001000 if cmd_output and "DBGFileMappedPaths = " in cmd_output:
Johnny Chen6a451482011-09-16 18:09:45 +00001001 print "%s =>" % ' '.join(cmd)
Johnny Chen6a4e0872011-09-16 17:50:44 +00001002 print cmd_output
Johnny Chen2891bb02011-09-16 01:04:26 +00001003 print "Disable automatic lookup and caching of dSYMs before running the test suite!"
1004 print "Exiting..."
1005 sys.exit(0)
1006
1007# On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults
1008# does not exist before proceeding to running the test suite.
1009if sys.platform.startswith("darwin"):
1010 checkDsymForUUIDIsNotOn()
1011
Johnny Chen9707bb62010-06-25 21:14:08 +00001012#
Johnny Chenaf149a02010-09-16 17:11:30 +00001013# Start the actions by first parsing the options while setting up the test
1014# directories, followed by setting up the search paths for lldb utilities;
1015# then, we walk the directory trees and collect the tests into our test suite.
Johnny Chen9707bb62010-06-25 21:14:08 +00001016#
Johnny Chenaf149a02010-09-16 17:11:30 +00001017parseOptionsAndInitTestdirs()
Johnny Chen9707bb62010-06-25 21:14:08 +00001018setupSysPath()
Johnny Chen91960d32010-09-08 20:56:16 +00001019
1020#
1021# If '-d' is specified, do a delay of 10 seconds for the debugger to attach.
1022#
1023if delay:
Johnny Chencd0279d2010-09-20 18:07:50 +00001024 doDelay(10)
Johnny Chen91960d32010-09-08 20:56:16 +00001025
Johnny Chen49f2f7a2010-09-20 17:25:45 +00001026#
Johnny Chen41998192010-10-01 22:59:49 +00001027# If '-l' is specified, do not skip the long running tests.
Johnny Chen028d8eb2011-11-17 19:57:27 +00001028if not skip_long_running_test:
Johnny Chen41998192010-10-01 22:59:49 +00001029 os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO"
1030
1031#
Johnny Chen79723352010-10-12 15:53:22 +00001032# Walk through the testdirs while collecting tests.
Johnny Chen49f2f7a2010-09-20 17:25:45 +00001033#
Johnny Chen9707bb62010-06-25 21:14:08 +00001034for testdir in testdirs:
1035 os.path.walk(testdir, visit, 'Test')
1036
Johnny Chenb40056b2010-09-21 00:09:27 +00001037#
Johnny Chen9707bb62010-06-25 21:14:08 +00001038# Now that we have loaded all the test cases, run the whole test suite.
Johnny Chenb40056b2010-09-21 00:09:27 +00001039#
Johnny Chencd0279d2010-09-20 18:07:50 +00001040
Johnny Chen1bfbd412010-06-29 19:44:16 +00001041# For the time being, let's bracket the test runner within the
1042# lldb.SBDebugger.Initialize()/Terminate() pair.
Johnny Chen01f2a6a2010-08-10 20:23:55 +00001043import lldb, atexit
Johnny Chen6b6f5ba2010-10-14 16:36:49 +00001044# Update: the act of importing lldb now executes lldb.SBDebugger.Initialize(),
1045# there's no need to call it a second time.
1046#lldb.SBDebugger.Initialize()
Johnny Chen01f2a6a2010-08-10 20:23:55 +00001047atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen1bfbd412010-06-29 19:44:16 +00001048
Johnny Chen909e5a62010-07-01 22:52:57 +00001049# Create a singleton SBDebugger in the lldb namespace.
1050lldb.DBG = lldb.SBDebugger.Create()
1051
Johnny Chen4f93bf12010-12-10 00:51:23 +00001052# Put the blacklist in the lldb namespace, to be used by lldb.TestBase.
Johnny Chen82e6b1e2010-12-01 22:47:54 +00001053lldb.blacklist = blacklist
1054
Johnny Chenac97a6b2012-04-16 18:55:15 +00001055# The pre_flight and post_flight come from reading a config file.
1056lldb.pre_flight = pre_flight
1057lldb.post_flight = post_flight
1058def getsource_if_available(obj):
1059 """
1060 Return the text of the source code for an object if available. Otherwise,
1061 a print representation is returned.
1062 """
1063 import inspect
1064 try:
1065 return inspect.getsource(obj)
1066 except:
1067 return repr(obj)
1068
1069print "lldb.pre_flight:", getsource_if_available(lldb.pre_flight)
1070print "lldb.post_flight:", getsource_if_available(lldb.post_flight)
1071
Johnny Chena3ed7d82012-04-06 00:56:05 +00001072# Put all these test decorators in the lldb namespace.
Johnny Chen4f93bf12010-12-10 00:51:23 +00001073lldb.dont_do_python_api_test = dont_do_python_api_test
1074lldb.just_do_python_api_test = just_do_python_api_test
Johnny Chen82ccf402011-07-30 01:39:58 +00001075lldb.just_do_benchmarks_test = just_do_benchmarks_test
Johnny Chena3ed7d82012-04-06 00:56:05 +00001076lldb.dont_do_dsym_test = dont_do_dsym_test
1077lldb.dont_do_dwarf_test = dont_do_dwarf_test
Johnny Chen4f93bf12010-12-10 00:51:23 +00001078
Johnny Chen028d8eb2011-11-17 19:57:27 +00001079# Do we need to skip build and cleanup?
1080lldb.skip_build_and_cleanup = skip_build_and_cleanup
1081
Johnny Chen5f2ed172011-10-20 18:43:28 +00001082# Put bmExecutable, bmBreakpointSpec, and bmIterationCount into the lldb namespace, too.
Johnny Chene00c9302011-10-10 22:03:44 +00001083lldb.bmExecutable = bmExecutable
1084lldb.bmBreakpointSpec = bmBreakpointSpec
Johnny Chen5f2ed172011-10-20 18:43:28 +00001085lldb.bmIterationCount = bmIterationCount
Johnny Chene00c9302011-10-10 22:03:44 +00001086
Johnny Chen38f823c2011-10-11 01:30:27 +00001087# And don't forget the runHooks!
1088lldb.runHooks = runHooks
1089
Johnny Chencd0279d2010-09-20 18:07:50 +00001090# Turn on lldb loggings if necessary.
1091lldbLoggings()
Johnny Chen909e5a62010-07-01 22:52:57 +00001092
Johnny Chen7987ac92010-08-09 20:40:52 +00001093# Install the control-c handler.
1094unittest2.signals.installHandler()
1095
Johnny Chen125fc2b2010-10-21 16:55:35 +00001096# If sdir_name is not specified through the '-s sdir_name' option, get a
1097# timestamp string and export it as LLDB_SESSION_DIR environment var. This will
1098# be used when/if we want to dump the session info of individual test cases
1099# later on.
Johnny Chence681462010-10-19 00:25:01 +00001100#
1101# See also TestBase.dumpSessionInfo() in lldbtest.py.
Johnny Chen125fc2b2010-10-21 16:55:35 +00001102if not sdir_name:
1103 import datetime
Johnny Chen41fae812010-10-29 22:26:38 +00001104 # The windows platforms don't like ':' in the pathname.
Johnny Chen76bd0102010-10-28 16:32:13 +00001105 timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
Johnny Chen125fc2b2010-10-21 16:55:35 +00001106 sdir_name = timestamp
Peter Collingbourne132476f2011-06-20 23:55:53 +00001107os.environ["LLDB_SESSION_DIRNAME"] = os.path.join(os.getcwd(), sdir_name)
Johnny Chen067022b2011-01-19 19:31:46 +00001108
Johnny Chenfe5f1ed2011-10-21 18:33:27 +00001109if not noHeaders:
1110 sys.stderr.write("\nSession logs for test failures/errors/unexpected successes"
1111 " will go into directory '%s'\n" % sdir_name)
1112 sys.stderr.write("Command invoked: %s\n" % getMyCommandLine())
Johnny Chence681462010-10-19 00:25:01 +00001113
Johnny Chenb5fe80c2011-05-17 22:58:50 +00001114if not os.path.isdir(sdir_name):
1115 os.mkdir(sdir_name)
1116fname = os.path.join(sdir_name, "svn-info")
1117with open(fname, "w") as f:
1118 print >> f, svn_info
1119 print >> f, "Command invoked: %s\n" % getMyCommandLine()
1120
Johnny Chenb40056b2010-09-21 00:09:27 +00001121#
Johnny Chen0f907b82012-01-31 00:38:03 +00001122# If we have environment variables to unset, do it here before we invoke the test runner.
1123#
1124for env_var in unsets :
1125 if env_var in os.environ:
1126 # From Python Doc: When unsetenv() is supported, deletion of items in os.environ
Johnny Chen6346a292012-01-31 00:48:02 +00001127 # is automatically translated into a corresponding call to unsetenv().
Johnny Chen0f907b82012-01-31 00:38:03 +00001128 del os.environ[env_var]
1129 #os.unsetenv(env_var)
1130
1131#
Johnny Chenb40056b2010-09-21 00:09:27 +00001132# Invoke the default TextTestRunner to run the test suite, possibly iterating
1133# over different configurations.
1134#
1135
Johnny Chenb40056b2010-09-21 00:09:27 +00001136iterArchs = False
Johnny Chenf032d902010-09-21 00:16:09 +00001137iterCompilers = False
Johnny Chenb40056b2010-09-21 00:09:27 +00001138
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001139if not archs and "archs" in config:
Johnny Chenb40056b2010-09-21 00:09:27 +00001140 archs = config["archs"]
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001141
1142if isinstance(archs, list) and len(archs) >= 1:
1143 iterArchs = True
1144
1145if not compilers and "compilers" in config:
Johnny Chenb40056b2010-09-21 00:09:27 +00001146 compilers = config["compilers"]
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001147
Johnny Chen92693b52012-03-09 02:11:37 +00001148#
1149# Add some intervention here to sanity check that the compilers requested are sane.
1150# If found not to be an executable program, the invalid one is dropped from the list.
1151for i in range(len(compilers)):
1152 c = compilers[i]
1153 if which(c):
1154 continue
1155 else:
1156 if sys.platform.startswith("darwin"):
1157 pipe = subprocess.Popen(['xcrun', '-find', c], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
1158 cmd_output = pipe.stdout.read()
1159 if cmd_output:
1160 if "not found" in cmd_output:
1161 print "dropping %s from the compilers used" % c
1162 compilers.remove(i)
1163 else:
1164 compilers[i] = cmd_output.split('\n')[0]
1165 print "'xcrun -find %s' returning %s" % (c, compilers[i])
1166
1167print "compilers=%s" % str(compilers)
1168
1169if not compilers or len(compilers) == 0:
1170 print "No eligible compiler found, exiting."
1171 sys.exit(1)
1172
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001173if isinstance(compilers, list) and len(compilers) >= 1:
1174 iterCompilers = True
Johnny Chenb40056b2010-09-21 00:09:27 +00001175
Johnny Chen953864a2010-10-12 21:35:54 +00001176# Make a shallow copy of sys.path, we need to manipulate the search paths later.
1177# This is only necessary if we are relocated and with different configurations.
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001178if rdir:
Johnny Chen953864a2010-10-12 21:35:54 +00001179 old_sys_path = sys.path[:]
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001180# If we iterate on archs or compilers, there is a chance we want to split stderr/stdout.
1181if iterArchs or iterCompilers:
Johnny Chen953864a2010-10-12 21:35:54 +00001182 old_stderr = sys.stderr
1183 old_stdout = sys.stdout
1184 new_stderr = None
1185 new_stdout = None
1186
Johnny Chend96b5682010-11-05 17:30:53 +00001187# Iterating over all possible architecture and compiler combinations.
Johnny Chenb40056b2010-09-21 00:09:27 +00001188for ia in range(len(archs) if iterArchs else 1):
1189 archConfig = ""
1190 if iterArchs:
Johnny Chen18a921f2010-09-30 17:11:58 +00001191 os.environ["ARCH"] = archs[ia]
Johnny Chenb40056b2010-09-21 00:09:27 +00001192 archConfig = "arch=%s" % archs[ia]
1193 for ic in range(len(compilers) if iterCompilers else 1):
1194 if iterCompilers:
Johnny Chen18a921f2010-09-30 17:11:58 +00001195 os.environ["CC"] = compilers[ic]
Johnny Chenb40056b2010-09-21 00:09:27 +00001196 configString = "%s compiler=%s" % (archConfig, compilers[ic])
1197 else:
1198 configString = archConfig
1199
Johnny Chenb40056b2010-09-21 00:09:27 +00001200 if iterArchs or iterCompilers:
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001201 # Translate ' ' to '-' for pathname component.
1202 from string import maketrans
1203 tbl = maketrans(' ', '-')
1204 configPostfix = configString.translate(tbl)
1205
1206 # Check whether we need to split stderr/stdout into configuration
1207 # specific files.
1208 if old_stderr.name != '<stderr>' and config.get('split_stderr'):
1209 if new_stderr:
1210 new_stderr.close()
1211 new_stderr = open("%s.%s" % (old_stderr.name, configPostfix), "w")
1212 sys.stderr = new_stderr
1213 if old_stdout.name != '<stdout>' and config.get('split_stdout'):
1214 if new_stdout:
1215 new_stdout.close()
1216 new_stdout = open("%s.%s" % (old_stdout.name, configPostfix), "w")
1217 sys.stdout = new_stdout
1218
Johnny Chen953864a2010-10-12 21:35:54 +00001219 # If we specified a relocated directory to run the test suite, do
1220 # the extra housekeeping to copy the testdirs to a configStringified
1221 # directory and to update sys.path before invoking the test runner.
1222 # The purpose is to separate the configuration-specific directories
1223 # from each other.
1224 if rdir:
Johnny Chen3bc7e5e2012-04-24 21:44:10 +00001225 from shutil import copytree, rmtree, ignore_patterns
Johnny Chen953864a2010-10-12 21:35:54 +00001226
Johnny Chen953864a2010-10-12 21:35:54 +00001227 newrdir = "%s.%s" % (rdir, configPostfix)
1228
1229 # Copy the tree to a new directory with postfix name configPostfix.
Johnny Chen3bc7e5e2012-04-24 21:44:10 +00001230 if os.path.exists(newrdir):
1231 rmtree(newrdir)
Johnny Chen953864a2010-10-12 21:35:54 +00001232 copytree(rdir, newrdir, ignore=ignore_patterns('*.pyc', '*.o', '*.d'))
1233
Johnny Chen1a4d5e72011-03-04 01:35:22 +00001234 # Update the LLDB_TEST environment variable to reflect new top
Johnny Chen953864a2010-10-12 21:35:54 +00001235 # level test directory.
1236 #
1237 # See also lldbtest.TestBase.setUpClass(cls).
1238 if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test':
1239 os.environ["LLDB_TEST"] = os.path.join(newrdir, 'test')
1240 else:
1241 os.environ["LLDB_TEST"] = newrdir
1242
1243 # And update the Python search paths for modules.
1244 sys.path = [x.replace(rdir, newrdir, 1) for x in old_sys_path]
1245
1246 # Output the configuration.
Johnny Chenb40056b2010-09-21 00:09:27 +00001247 sys.stderr.write("\nConfiguration: " + configString + "\n")
Johnny Chen953864a2010-10-12 21:35:54 +00001248
1249 #print "sys.stderr name is", sys.stderr.name
1250 #print "sys.stdout name is", sys.stdout.name
1251
1252 # First, write out the number of collected test cases.
Johnny Chen08967192011-11-18 00:19:29 +00001253 sys.stderr.write(separator + "\n")
1254 sys.stderr.write("Collected %d test%s\n\n"
1255 % (suite.countTestCases(),
1256 suite.countTestCases() != 1 and "s" or ""))
Johnny Chen953864a2010-10-12 21:35:54 +00001257
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001258 class LLDBTestResult(unittest2.TextTestResult):
1259 """
Johnny Chen26be4532010-11-09 23:56:14 +00001260 Enforce a singleton pattern to allow introspection of test progress.
1261
1262 Overwrite addError(), addFailure(), and addExpectedFailure() methods
1263 to enable each test instance to track its failure/error status. It
1264 is used in the LLDB test framework to emit detailed trace messages
1265 to a log file for easier human inspection of test failres/errors.
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001266 """
1267 __singleton__ = None
Johnny Chen360dd372010-11-29 17:50:10 +00001268 __ignore_singleton__ = False
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001269
1270 def __init__(self, *args):
Johnny Chen360dd372010-11-29 17:50:10 +00001271 if not LLDBTestResult.__ignore_singleton__ and LLDBTestResult.__singleton__:
Johnny Chend2acdb32010-11-16 22:42:58 +00001272 raise Exception("LLDBTestResult instantiated more than once")
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001273 super(LLDBTestResult, self).__init__(*args)
1274 LLDBTestResult.__singleton__ = self
1275 # Now put this singleton into the lldb module namespace.
1276 lldb.test_result = self
Johnny Chen810042e2011-01-05 20:24:11 +00001277 # Computes the format string for displaying the counter.
1278 global suite
1279 counterWidth = len(str(suite.countTestCases()))
1280 self.fmt = "%" + str(counterWidth) + "d: "
Johnny Chenc87fd492011-01-05 22:50:11 +00001281 self.indentation = ' ' * (counterWidth + 2)
Johnny Chen810042e2011-01-05 20:24:11 +00001282 # This counts from 1 .. suite.countTestCases().
1283 self.counter = 0
1284
Johnny Chenbe452272012-04-19 21:33:55 +00001285 def _exc_info_to_string(self, err, test):
1286 """Overrides superclass TestResult's method in order to append
1287 our test config info string to the exception info string."""
1288 modified_exc_string = '%sConfig=%s-%s' % (super(LLDBTestResult, self)._exc_info_to_string(err, test),
1289 test.getArchitecture(),
1290 test.getCompiler())
1291 return modified_exc_string
1292
Johnny Chenc87fd492011-01-05 22:50:11 +00001293 def getDescription(self, test):
1294 doc_first_line = test.shortDescription()
1295 if self.descriptions and doc_first_line:
1296 return '\n'.join((str(test), self.indentation + doc_first_line))
1297 else:
1298 return str(test)
1299
Johnny Chen810042e2011-01-05 20:24:11 +00001300 def startTest(self, test):
1301 self.counter += 1
1302 if self.showAll:
1303 self.stream.write(self.fmt % self.counter)
1304 super(LLDBTestResult, self).startTest(test)
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001305
Johnny Chence681462010-10-19 00:25:01 +00001306 def addError(self, test, err):
Johnny Chen63c2cba2010-10-29 22:20:36 +00001307 global sdir_has_content
1308 sdir_has_content = True
Johnny Chence681462010-10-19 00:25:01 +00001309 super(LLDBTestResult, self).addError(test, err)
1310 method = getattr(test, "markError", None)
1311 if method:
1312 method()
1313
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001314 def addFailure(self, test, err):
Johnny Chen63c2cba2010-10-29 22:20:36 +00001315 global sdir_has_content
1316 sdir_has_content = True
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001317 super(LLDBTestResult, self).addFailure(test, err)
1318 method = getattr(test, "markFailure", None)
1319 if method:
1320 method()
Johnny Chen84a6d6f2010-10-15 01:18:29 +00001321
Johnny Chendd2bb2c2010-11-03 18:17:03 +00001322 def addExpectedFailure(self, test, err):
1323 global sdir_has_content
1324 sdir_has_content = True
1325 super(LLDBTestResult, self).addExpectedFailure(test, err)
1326 method = getattr(test, "markExpectedFailure", None)
1327 if method:
1328 method()
1329
Johnny Chenf5b89092011-08-15 23:09:08 +00001330 def addSkip(self, test, reason):
1331 global sdir_has_content
1332 sdir_has_content = True
1333 super(LLDBTestResult, self).addSkip(test, reason)
1334 method = getattr(test, "markSkippedTest", None)
1335 if method:
1336 method()
1337
Johnny Chenab2f0662011-05-06 20:30:22 +00001338 def addUnexpectedSuccess(self, test):
1339 global sdir_has_content
1340 sdir_has_content = True
1341 super(LLDBTestResult, self).addUnexpectedSuccess(test)
1342 method = getattr(test, "markUnexpectedSuccess", None)
1343 if method:
1344 method()
1345
Johnny Chen26be4532010-11-09 23:56:14 +00001346 # Invoke the test runner.
Johnny Chend2acdb32010-11-16 22:42:58 +00001347 if count == 1:
Johnny Chen7d6d8442010-12-03 19:59:35 +00001348 result = unittest2.TextTestRunner(stream=sys.stderr,
Johnny Chene6d88a82012-04-19 20:09:44 +00001349 verbosity=(1 if progress_bar else verbose),
Johnny Chen7d6d8442010-12-03 19:59:35 +00001350 failfast=failfast,
Johnny Chend2acdb32010-11-16 22:42:58 +00001351 resultclass=LLDBTestResult).run(suite)
1352 else:
Johnny Chend6e7ca22010-11-29 17:52:43 +00001353 # We are invoking the same test suite more than once. In this case,
1354 # mark __ignore_singleton__ flag as True so the signleton pattern is
1355 # not enforced.
Johnny Chen360dd372010-11-29 17:50:10 +00001356 LLDBTestResult.__ignore_singleton__ = True
Johnny Chend2acdb32010-11-16 22:42:58 +00001357 for i in range(count):
Johnny Chen7d6d8442010-12-03 19:59:35 +00001358 result = unittest2.TextTestRunner(stream=sys.stderr,
Johnny Chene6d88a82012-04-19 20:09:44 +00001359 verbosity=(1 if progress_bar else verbose),
Johnny Chen7d6d8442010-12-03 19:59:35 +00001360 failfast=failfast,
Johnny Chen360dd372010-11-29 17:50:10 +00001361 resultclass=LLDBTestResult).run(suite)
Johnny Chenb40056b2010-09-21 00:09:27 +00001362
Johnny Chen1bfbd412010-06-29 19:44:16 +00001363
Johnny Chen63c2cba2010-10-29 22:20:36 +00001364if sdir_has_content:
Johnny Chenab2f0662011-05-06 20:30:22 +00001365 sys.stderr.write("Session logs for test failures/errors/unexpected successes"
1366 " can be found in directory '%s'\n" % sdir_name)
Johnny Chen63c2cba2010-10-29 22:20:36 +00001367
Johnny Chencd0279d2010-09-20 18:07:50 +00001368# Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined.
1369# This should not be necessary now.
Johnny Chen83f6e512010-08-13 22:58:44 +00001370if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ):
Johnny Chen83f6e512010-08-13 22:58:44 +00001371 print "Terminating Test suite..."
1372 subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())])
1373
Johnny Chen01f2a6a2010-08-10 20:23:55 +00001374# Exiting.
1375sys.exit(not result.wasSuccessful)