blob: 6abf1636b112c75bcc1d0b4719755cd8942e5765 [file] [log] [blame]
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001"""
2A simple testing framework for lldb using python's unit testing framework.
3
4Tests for lldb are written as python scripts which take advantage of the script
5bridging provided by LLDB.framework to interact with lldb core.
6
7A specific naming pattern is followed by the .py script to be recognized as
8a module which implements a test scenario, namely, Test*.py.
9
10To specify the directories where "Test*.py" python test scripts are located,
11you need to pass in a list of directory names. By default, the current
12working directory is searched if nothing is specified on the command line.
13
14Type:
15
16./dotest.py -h
17
18for available options.
19"""
20
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000021from __future__ import absolute_import
Zachary Turnerc432c8f2015-10-28 17:43:26 +000022from __future__ import print_function
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000023
24# System modules
Zachary Turnerc432c8f2015-10-28 17:43:26 +000025import atexit
Zachary Turnerc432c8f2015-10-28 17:43:26 +000026import os
Zachary Turnerc432c8f2015-10-28 17:43:26 +000027import errno
Tim Hammerquist84858212017-03-17 18:10:58 +000028import logging
Zachary Turnerc432c8f2015-10-28 17:43:26 +000029import platform
Francis Ricci69517072016-09-23 21:32:47 +000030import re
Zachary Turnerc432c8f2015-10-28 17:43:26 +000031import signal
32import socket
33import subprocess
34import sys
Zachary Turnerc432c8f2015-10-28 17:43:26 +000035
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000036# Third-party modules
Zachary Turnerc432c8f2015-10-28 17:43:26 +000037import six
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000038import unittest2
39
40# LLDB Modules
41import lldbsuite
Zachary Turner606e3a52015-12-08 01:15:30 +000042from . import configuration
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000043from . import dotest_args
44from . import lldbtest_config
45from . import test_categories
Todd Fiala49d3c152016-04-20 16:27:27 +000046from lldbsuite.test_event import formatter
Zachary Turnerb4733e62015-12-08 01:15:44 +000047from . import test_result
Todd Fiala49d3c152016-04-20 16:27:27 +000048from lldbsuite.test_event.event_builder import EventBuilder
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000049from ..support import seven
Zachary Turnerc432c8f2015-10-28 17:43:26 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051
Zachary Turnerc432c8f2015-10-28 17:43:26 +000052def is_exe(fpath):
Pavel Labathe3f6eb12017-10-24 16:07:50 +000053 """Returns true if fpath is an executable."""
Davide Italiano643b2b92018-01-26 21:46:10 +000054 if fpath == None:
55 return False
Zachary Turnerc432c8f2015-10-28 17:43:26 +000056 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
57
Kate Stoneb9c1b512016-09-06 20:57:50 +000058
Zachary Turnerc432c8f2015-10-28 17:43:26 +000059def which(program):
60 """Returns the full path to a program; None otherwise."""
61 fpath, fname = os.path.split(program)
62 if fpath:
63 if is_exe(program):
64 return program
65 else:
66 for path in os.environ["PATH"].split(os.pathsep):
67 exe_file = os.path.join(path, program)
68 if is_exe(exe_file):
69 return exe_file
70 return None
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072
Zachary Turnerc432c8f2015-10-28 17:43:26 +000073class _WritelnDecorator(object):
74 """Used to decorate file-like objects with a handy 'writeln' method"""
Kate Stoneb9c1b512016-09-06 20:57:50 +000075
76 def __init__(self, stream):
Zachary Turnerc432c8f2015-10-28 17:43:26 +000077 self.stream = stream
78
79 def __getattr__(self, attr):
80 if attr in ('stream', '__getstate__'):
81 raise AttributeError(attr)
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 return getattr(self.stream, attr)
Zachary Turnerc432c8f2015-10-28 17:43:26 +000083
84 def writeln(self, arg=None):
85 if arg:
86 self.write(arg)
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 self.write('\n') # text-mode streams translate to \r\n if needed
Zachary Turnerc432c8f2015-10-28 17:43:26 +000088
89#
90# Global variables:
91#
Kate Stoneb9c1b512016-09-06 20:57:50 +000092
93
Zachary Turnerc432c8f2015-10-28 17:43:26 +000094def usage(parser):
95 parser.print_help()
Zachary Turner606e3a52015-12-08 01:15:30 +000096 if configuration.verbose > 0:
Zachary Turnerc432c8f2015-10-28 17:43:26 +000097 print("""
98Examples:
99
100This is an example of using the -f option to pinpoint to a specific test class
101and test method to be run:
102
103$ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command
104----------------------------------------------------------------------
105Collected 1 test
106
107test_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase)
108Test 'frame variable this' when stopped on a class constructor. ... ok
109
110----------------------------------------------------------------------
111Ran 1 test in 1.396s
112
113OK
114
115And this is an example of using the -p option to run a single file (the filename
116matches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'):
117
118$ ./dotest.py -v -p ObjC
119----------------------------------------------------------------------
120Collected 4 tests
121
122test_break_with_dsym (TestObjCMethods.FoundationTestCase)
123Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok
124test_break_with_dwarf (TestObjCMethods.FoundationTestCase)
125Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok
126test_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase)
127Lookup objective-c data types and evaluate expressions. ... ok
128test_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase)
129Lookup objective-c data types and evaluate expressions. ... ok
130
131----------------------------------------------------------------------
132Ran 4 tests in 16.661s
133
134OK
135
136Running of this script also sets up the LLDB_TEST environment variable so that
137individual test cases can locate their supporting files correctly. The script
138tries to set up Python's search paths for modules by looking at the build tree
139relative to this script. See also the '-i' option in the following example.
140
141Finally, this is an example of using the lldb.py module distributed/installed by
142Xcode4 to run against the tests under the 'forward' directory, and with the '-w'
143option to add some delay between two tests. It uses ARCH=x86_64 to specify that
144as the architecture and CC=clang to specify the compiler used for the test run:
145
146$ PYTHONPATH=/Xcode4/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python ARCH=x86_64 CC=clang ./dotest.py -v -w -i forward
147
148Session logs for test failures/errors will go into directory '2010-11-11-13_56_16'
149----------------------------------------------------------------------
150Collected 2 tests
151
152test_with_dsym_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase)
153Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok
154test_with_dwarf_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase)
155Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok
156
157----------------------------------------------------------------------
158Ran 2 tests in 5.659s
159
160OK
161
162The 'Session ...' verbiage is recently introduced (see also the '-s' option) to
163notify the directory containing the session logs for test failures or errors.
164In case there is any test failure/error, a similar message is appended at the
165end of the stderr output for your convenience.
166
167ENABLING LOGS FROM TESTS
168
169Option 1:
170
171Writing logs into different files per test case::
172
173This option is particularly useful when multiple dotest instances are created
174by dosep.py
175
176$ ./dotest.py --channel "lldb all"
177
178$ ./dotest.py --channel "lldb all" --channel "gdb-remote packets"
179
180These log files are written to:
181
182<session-dir>/<test-id>-host.log (logs from lldb host process)
183<session-dir>/<test-id>-server.log (logs from debugserver/lldb-server)
184<session-dir>/<test-id>-<test-result>.log (console logs)
185
186By default, logs from successful runs are deleted. Use the --log-success flag
187to create reference logs for debugging.
188
189$ ./dotest.py --log-success
190
191Option 2: (DEPRECATED)
192
193The following options can only enable logs from the host lldb process.
194Only categories from the "lldb" or "gdb-remote" channels can be enabled
195They also do not automatically enable logs in locally running debug servers.
196Also, logs from all test case are written into each log file
197
198o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem
199 with a default option of 'event process' if LLDB_LOG_OPTION is not defined.
200
201o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the
202 'process.gdb-remote' subsystem with a default option of 'packets' if
203 GDB_REMOTE_LOG_OPTION is not defined.
204
205""")
206 sys.exit(0)
207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208
Francis Ricci69517072016-09-23 21:32:47 +0000209def parseExclusion(exclusion_file):
210 """Parse an exclusion file, of the following format, where
211 'skip files', 'skip methods', 'xfail files', and 'xfail methods'
212 are the possible list heading values:
213
214 skip files
215 <file name>
216 <file name>
217
218 xfail methods
219 <method name>
220 """
221 excl_type = None
Francis Ricci69517072016-09-23 21:32:47 +0000222
223 with open(exclusion_file) as f:
224 for line in f:
Francis Riccif833f172016-10-04 18:48:00 +0000225 line = line.strip()
Francis Ricci69517072016-09-23 21:32:47 +0000226 if not excl_type:
Francis Riccif833f172016-10-04 18:48:00 +0000227 excl_type = line
Francis Ricci69517072016-09-23 21:32:47 +0000228 continue
229
Francis Ricci69517072016-09-23 21:32:47 +0000230 if not line:
231 excl_type = None
Francis Riccif833f172016-10-04 18:48:00 +0000232 elif excl_type == 'skip':
233 if not configuration.skip_tests:
234 configuration.skip_tests = []
235 configuration.skip_tests.append(line)
236 elif excl_type == 'xfail':
237 if not configuration.xfail_tests:
238 configuration.xfail_tests = []
239 configuration.xfail_tests.append(line)
Francis Ricci69517072016-09-23 21:32:47 +0000240
241
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000242def parseOptionsAndInitTestdirs():
243 """Initialize the list of directories containing our unittest scripts.
244
245 '-h/--help as the first option prints out usage info and exit the program.
246 """
247
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000248 do_help = False
249
250 platform_system = platform.system()
251 platform_machine = platform.machine()
252
253 parser = dotest_args.create_parser()
254 args = dotest_args.parse_args(parser, sys.argv[1:])
255
256 if args.unset_env_varnames:
257 for env_var in args.unset_env_varnames:
258 if env_var in os.environ:
259 # From Python Doc: When unsetenv() is supported, deletion of items in os.environ
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260 # is automatically translated into a corresponding call to
261 # unsetenv().
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000262 del os.environ[env_var]
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 # os.unsetenv(env_var)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000264
265 if args.set_env_vars:
266 for env_var in args.set_env_vars:
267 parts = env_var.split('=', 1)
268 if len(parts) == 1:
269 os.environ[parts[0]] = ""
270 else:
271 os.environ[parts[0]] = parts[1]
272
273 # only print the args if being verbose (and parsable is off)
274 if args.v and not args.q:
275 print(sys.argv)
276
277 if args.h:
278 do_help = True
279
Pavel Labath6de25ec2017-03-15 08:51:59 +0000280 if args.compiler:
Tim Hammerquist84858212017-03-17 18:10:58 +0000281 configuration.compiler = os.path.realpath(args.compiler)
282 if not is_exe(configuration.compiler):
Tim Hammerquistf73c6c72017-03-17 21:00:35 +0000283 configuration.compiler = which(args.compiler)
284 if not is_exe(configuration.compiler):
Tim Hammerquist84858212017-03-17 18:10:58 +0000285 logging.error(
286 '%s is not a valid compiler executable; aborting...',
287 args.compiler)
288 sys.exit(-1)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000289 else:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000290 # Use a compiler appropriate appropriate for the Apple SDK if one was
291 # specified
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000292 if platform_system == 'Darwin' and args.apple_sdk:
Pavel Labath6de25ec2017-03-15 08:51:59 +0000293 configuration.compiler = seven.get_command_output(
294 'xcrun -sdk "%s" -find clang 2> /dev/null' %
295 (args.apple_sdk))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000296 else:
297 # 'clang' on ubuntu 14.04 is 3.4 so we try clang-3.5 first
298 candidateCompilers = ['clang-3.5', 'clang', 'gcc']
299 for candidate in candidateCompilers:
300 if which(candidate):
Pavel Labath6de25ec2017-03-15 08:51:59 +0000301 configuration.compiler = candidate
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000302 break
303
Jonas Devlieghere1bf22e72018-04-12 09:25:32 +0000304 if args.dsymutil:
305 os.environ['DSYMUTIL'] = args.dsymutil
306 else if platform_system == 'Darwin':
307 os.environ['DSYMUTIL'] = seven.get_command_output(
308 'xcrun -find -toolchain default dsymutil')
309
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000310 if args.channels:
311 lldbtest_config.channels = args.channels
312
313 if args.log_success:
314 lldbtest_config.log_success = args.log_success
315
Vedant Kumar45ae11c2018-03-08 19:46:39 +0000316 if args.out_of_tree_debugserver:
317 lldbtest_config.out_of_tree_debugserver = args.out_of_tree_debugserver
318
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000319 # Set SDKROOT if we are using an Apple SDK
320 if platform_system == 'Darwin' and args.apple_sdk:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 os.environ['SDKROOT'] = seven.get_command_output(
322 'xcrun --sdk "%s" --show-sdk-path 2> /dev/null' %
323 (args.apple_sdk))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000324
Pavel Labath6de25ec2017-03-15 08:51:59 +0000325 if args.arch:
326 configuration.arch = args.arch
327 if configuration.arch.startswith(
328 'arm') and platform_system == 'Darwin' and not args.apple_sdk:
329 os.environ['SDKROOT'] = seven.get_command_output(
330 'xcrun --sdk iphoneos.internal --show-sdk-path 2> /dev/null')
331 if not os.path.exists(os.environ['SDKROOT']):
Kate Stoneb9c1b512016-09-06 20:57:50 +0000332 os.environ['SDKROOT'] = seven.get_command_output(
Pavel Labath6de25ec2017-03-15 08:51:59 +0000333 'xcrun --sdk iphoneos --show-sdk-path 2> /dev/null')
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000334 else:
Pavel Labath6de25ec2017-03-15 08:51:59 +0000335 configuration.arch = platform_machine
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000336
337 if args.categoriesList:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338 configuration.categoriesList = set(
339 test_categories.validate(
340 args.categoriesList, False))
Zachary Turner606e3a52015-12-08 01:15:30 +0000341 configuration.useCategories = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000342 else:
Zachary Turner606e3a52015-12-08 01:15:30 +0000343 configuration.categoriesList = []
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000344
345 if args.skipCategories:
Davide Italiano5f969602018-04-05 22:46:39 +0000346 configuration.skipCategories += test_categories.validate(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 args.skipCategories, False)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000348
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000349 if args.E:
350 cflags_extras = args.E
351 os.environ['CFLAGS_EXTRAS'] = cflags_extras
352
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000353 if args.d:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000354 sys.stdout.write(
355 "Suspending the process %d to wait for debugger to attach...\n" %
356 os.getpid())
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000357 sys.stdout.flush()
358 os.kill(os.getpid(), signal.SIGSTOP)
359
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000360 if args.f:
361 if any([x.startswith('-') for x in args.f]):
362 usage(parser)
Zachary Turner606e3a52015-12-08 01:15:30 +0000363 configuration.filters.extend(args.f)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000364 # Shut off multiprocessing mode when additional filters are specified.
365 # The rational is that the user is probably going after a very specific
366 # test and doesn't need a bunch of parallel test runners all looking for
367 # it in a frenzy. Also, '-v' now spits out all test run output even
368 # on success, so the standard recipe for redoing a failing test (with -v
369 # and a -f to filter to the specific test) now causes all test scanning
370 # (in parallel) to print results for do-nothing runs in a very distracting
371 # manner. If we really need filtered parallel runs in the future, consider
372 # adding a --no-output-on-success that prevents -v from setting
373 # output-on-success.
Zachary Turner606e3a52015-12-08 01:15:30 +0000374 configuration.no_multiprocess_test_runner = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000375
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000376 if args.l:
Zachary Turner606e3a52015-12-08 01:15:30 +0000377 configuration.skip_long_running_test = False
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000378
379 if args.framework:
Zachary Turner606e3a52015-12-08 01:15:30 +0000380 configuration.lldbFrameworkPath = args.framework
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000381
382 if args.executable:
Tim Hammerquist84858212017-03-17 18:10:58 +0000383 # lldb executable is passed explicitly
Francis Riccicef04a22016-04-25 20:36:22 +0000384 lldbtest_config.lldbExec = os.path.realpath(args.executable)
Tim Hammerquist84858212017-03-17 18:10:58 +0000385 if not is_exe(lldbtest_config.lldbExec):
Tim Hammerquistf73c6c72017-03-17 21:00:35 +0000386 lldbtest_config.lldbExec = which(args.executable)
387 if not is_exe(lldbtest_config.lldbExec):
Tim Hammerquist84858212017-03-17 18:10:58 +0000388 logging.error(
389 '%s is not a valid executable to test; aborting...',
390 args.executable)
391 sys.exit(-1)
392
Chris Bieneman265ca532017-03-14 20:04:46 +0000393 if args.server:
394 os.environ['LLDB_DEBUGSERVER_PATH'] = args.server
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000395
Francis Ricci69517072016-09-23 21:32:47 +0000396 if args.excluded:
Francis Riccif833f172016-10-04 18:48:00 +0000397 for excl_file in args.excluded:
398 parseExclusion(excl_file)
Francis Ricci69517072016-09-23 21:32:47 +0000399
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000400 if args.p:
401 if args.p.startswith('-'):
402 usage(parser)
Zachary Turner606e3a52015-12-08 01:15:30 +0000403 configuration.regexp = args.p
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000404
405 if args.q:
Zachary Turner606e3a52015-12-08 01:15:30 +0000406 configuration.parsable = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000407
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000408 if args.s:
409 if args.s.startswith('-'):
410 usage(parser)
Zachary Turner606e3a52015-12-08 01:15:30 +0000411 configuration.sdir_name = args.s
Zachary Turner8d4d1512016-05-17 18:02:34 +0000412 configuration.session_file_format = args.session_file_format
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000413
414 if args.t:
415 os.environ['LLDB_COMMAND_TRACE'] = 'YES'
416
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000417 if args.v:
Zachary Turner606e3a52015-12-08 01:15:30 +0000418 configuration.verbose = 2
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000419
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000420 # argparse makes sure we have a number
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000421 if args.sharp:
Zachary Turner606e3a52015-12-08 01:15:30 +0000422 configuration.count = args.sharp
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000423
424 if sys.platform.startswith('win32'):
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 os.environ['LLDB_DISABLE_CRASH_DIALOG'] = str(
426 args.disable_crash_dialog)
Zachary Turner80310c22015-12-10 18:51:02 +0000427 os.environ['LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE'] = str(True)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000428
Kate Stoneb9c1b512016-09-06 20:57:50 +0000429 if do_help:
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000430 usage(parser)
431
432 if args.no_multiprocess:
Zachary Turner606e3a52015-12-08 01:15:30 +0000433 configuration.no_multiprocess_test_runner = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000434
435 if args.inferior:
Zachary Turner606e3a52015-12-08 01:15:30 +0000436 configuration.is_inferior_test_runner = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000437
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000438 if args.num_threads:
Zachary Turner606e3a52015-12-08 01:15:30 +0000439 configuration.num_threads = args.num_threads
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000440
441 if args.test_subdir:
Zachary Turner606e3a52015-12-08 01:15:30 +0000442 configuration.multiprocess_test_subdir = args.test_subdir
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000443
444 if args.test_runner_name:
Zachary Turner606e3a52015-12-08 01:15:30 +0000445 configuration.test_runner_name = args.test_runner_name
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000446
447 # Capture test results-related args.
Todd Fialacee6a6a2015-11-09 18:51:04 +0000448 if args.curses and not args.inferior:
449 # Act as if the following args were set.
Todd Fiala49d3c152016-04-20 16:27:27 +0000450 args.results_formatter = "lldbsuite.test_event.formatter.curses.Curses"
Todd Fialacee6a6a2015-11-09 18:51:04 +0000451 args.results_file = "stdout"
452
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000453 if args.results_file:
Zachary Turner606e3a52015-12-08 01:15:30 +0000454 configuration.results_filename = args.results_file
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000455
456 if args.results_port:
Zachary Turner606e3a52015-12-08 01:15:30 +0000457 configuration.results_port = args.results_port
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000458
459 if args.results_file and args.results_port:
460 sys.stderr.write(
461 "only one of --results-file and --results-port should "
462 "be specified\n")
463 usage(args)
464
465 if args.results_formatter:
Zachary Turner606e3a52015-12-08 01:15:30 +0000466 configuration.results_formatter_name = args.results_formatter
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000467 if args.results_formatter_options:
Zachary Turner606e3a52015-12-08 01:15:30 +0000468 configuration.results_formatter_options = args.results_formatter_options
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000469
Todd Fialab68dbfa22015-12-11 22:29:34 +0000470 # Default to using the BasicResultsFormatter if no formatter is specified
471 # and we're not a test inferior.
472 if not args.inferior and configuration.results_formatter_name is None:
473 configuration.results_formatter_name = (
Todd Fiala49d3c152016-04-20 16:27:27 +0000474 "lldbsuite.test_event.formatter.results_formatter.ResultsFormatter")
Todd Fialab68dbfa22015-12-11 22:29:34 +0000475
Todd Fiala93153922015-12-12 19:26:56 +0000476 # rerun-related arguments
477 configuration.rerun_all_issues = args.rerun_all_issues
Todd Fiala685a7572015-12-14 21:28:46 +0000478 configuration.rerun_max_file_threshold = args.rerun_max_file_threshold
Todd Fiala93153922015-12-12 19:26:56 +0000479
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000480 if args.lldb_platform_name:
Zachary Turner606e3a52015-12-08 01:15:30 +0000481 configuration.lldb_platform_name = args.lldb_platform_name
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000482 if args.lldb_platform_url:
Zachary Turner606e3a52015-12-08 01:15:30 +0000483 configuration.lldb_platform_url = args.lldb_platform_url
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000484 if args.lldb_platform_working_dir:
Zachary Turner606e3a52015-12-08 01:15:30 +0000485 configuration.lldb_platform_working_dir = args.lldb_platform_working_dir
Adrian Prantl5ec76fe2018-01-30 18:29:16 +0000486 if args.test_build_dir:
487 configuration.test_build_dir = args.test_build_dir
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000488
489 if args.event_add_entries and len(args.event_add_entries) > 0:
490 entries = {}
491 # Parse out key=val pairs, separated by comma
492 for keyval in args.event_add_entries.split(","):
493 key_val_entry = keyval.split("=")
494 if len(key_val_entry) == 2:
495 (key, val) = key_val_entry
496 val_parts = val.split(':')
497 if len(val_parts) > 1:
498 (val, val_type) = val_parts
499 if val_type == 'int':
500 val = int(val)
501 entries[key] = val
502 # Tell the event builder to create all events with these
503 # key/val pairs in them.
504 if len(entries) > 0:
Todd Fiala49d3c152016-04-20 16:27:27 +0000505 EventBuilder.add_entries_to_all_events(entries)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000506
507 # Gather all the dirs passed on the command line.
508 if len(args.args) > 0:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000509 configuration.testdirs = list(
510 map(lambda x: os.path.realpath(os.path.abspath(x)), args.args))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000511 # Shut off multiprocessing mode when test directories are specified.
Zachary Turner606e3a52015-12-08 01:15:30 +0000512 configuration.no_multiprocess_test_runner = True
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000513
Chris Bieneman7ba55812016-10-21 22:13:55 +0000514 lldbtest_config.codesign_identity = args.codesign_identity
515
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000516 #print("testdirs:", testdirs)
517
Kate Stoneb9c1b512016-09-06 20:57:50 +0000518
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000519def getXcodeOutputPaths(lldbRootDirectory):
520 result = []
521
522 # These are for xcode build directories.
523 xcode3_build_dir = ['build']
524 xcode4_build_dir = ['build', 'lldb', 'Build', 'Products']
525
Kate Stoneb9c1b512016-09-06 20:57:50 +0000526 configurations = [
527 ['Debug'],
528 ['DebugClang'],
529 ['Release'],
530 ['BuildAndIntegration']]
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000531 xcode_build_dirs = [xcode3_build_dir, xcode4_build_dir]
532 for configuration in configurations:
533 for xcode_build_dir in xcode_build_dirs:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000534 outputPath = os.path.join(
535 lldbRootDirectory, *(xcode_build_dir + configuration))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000536 result.append(outputPath)
537
538 return result
539
540
541def createSocketToLocalPort(port):
542 def socket_closer(s):
543 """Close down an opened socket properly."""
544 s.shutdown(socket.SHUT_RDWR)
545 s.close()
546
547 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
548 sock.connect(("localhost", port))
549 return (sock, lambda: socket_closer(sock))
550
551
552def setupTestResults():
553 """Sets up test results-related objects based on arg settings."""
Todd Fiala51831472015-12-09 06:45:43 +0000554 # Setup the results formatter configuration.
Todd Fiala49d3c152016-04-20 16:27:27 +0000555 formatter_config = formatter.FormatterConfig()
Todd Fiala51831472015-12-09 06:45:43 +0000556 formatter_config.filename = configuration.results_filename
557 formatter_config.formatter_name = configuration.results_formatter_name
558 formatter_config.formatter_options = (
559 configuration.results_formatter_options)
560 formatter_config.port = configuration.results_port
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000561
Todd Fialade029392015-12-08 00:53:56 +0000562 # Create the results formatter.
Todd Fiala49d3c152016-04-20 16:27:27 +0000563 formatter_spec = formatter.create_results_formatter(
Todd Fiala51831472015-12-09 06:45:43 +0000564 formatter_config)
Todd Fialade029392015-12-08 00:53:56 +0000565 if formatter_spec is not None and formatter_spec.formatter is not None:
Zachary Turner606e3a52015-12-08 01:15:30 +0000566 configuration.results_formatter_object = formatter_spec.formatter
Todd Fiala194913f2015-12-02 21:12:17 +0000567
Todd Fiala49d3c152016-04-20 16:27:27 +0000568 # Send an initialize message to the formatter.
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000569 initialize_event = EventBuilder.bare_event("initialize")
570 if isMultiprocessTestRunner():
Todd Fiala51831472015-12-09 06:45:43 +0000571 if (configuration.test_runner_name is not None and
572 configuration.test_runner_name == "serial"):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000573 # Only one worker queue here.
574 worker_count = 1
575 else:
576 # Workers will be the number of threads specified.
Zachary Turner606e3a52015-12-08 01:15:30 +0000577 worker_count = configuration.num_threads
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000578 else:
579 worker_count = 1
580 initialize_event["worker_count"] = worker_count
581
Todd Fialade029392015-12-08 00:53:56 +0000582 formatter_spec.formatter.handle_event(initialize_event)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000583
Todd Fialade029392015-12-08 00:53:56 +0000584 # Make sure we clean up the formatter on shutdown.
585 if formatter_spec.cleanup_func is not None:
586 atexit.register(formatter_spec.cleanup_func)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000587
588
589def getOutputPaths(lldbRootDirectory):
590 """
591 Returns typical build output paths for the lldb executable
592
593 lldbDirectory - path to the root of the lldb svn/git repo
594 """
595 result = []
596
597 if sys.platform == 'darwin':
598 result.extend(getXcodeOutputPaths(lldbRootDirectory))
599
600 # cmake builds? look for build or build/host folder next to llvm directory
601 # lldb is located in llvm/tools/lldb so we need to go up three levels
Kate Stoneb9c1b512016-09-06 20:57:50 +0000602 llvmParentDir = os.path.abspath(
603 os.path.join(
604 lldbRootDirectory,
605 os.pardir,
606 os.pardir,
607 os.pardir))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000608 result.append(os.path.join(llvmParentDir, 'build', 'bin'))
609 result.append(os.path.join(llvmParentDir, 'build', 'host', 'bin'))
610
Kate Stoneb9c1b512016-09-06 20:57:50 +0000611 # some cmake developers keep their build directory beside their lldb
612 # directory
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000613 lldbParentDir = os.path.abspath(os.path.join(lldbRootDirectory, os.pardir))
614 result.append(os.path.join(lldbParentDir, 'build', 'bin'))
615 result.append(os.path.join(lldbParentDir, 'build', 'host', 'bin'))
616
617 return result
618
Kate Stoneb9c1b512016-09-06 20:57:50 +0000619
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000620def setupSysPath():
621 """
622 Add LLDB.framework/Resources/Python to the search paths for modules.
623 As a side effect, we also discover the 'lldb' executable and export it here.
624 """
625
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000626 # Get the directory containing the current script.
627 if "DOTEST_PROFILE" in os.environ and "DOTEST_SCRIPT_DIR" in os.environ:
628 scriptPath = os.environ["DOTEST_SCRIPT_DIR"]
629 else:
630 scriptPath = os.path.dirname(os.path.realpath(__file__))
631 if not scriptPath.endswith('test'):
632 print("This script expects to reside in lldb's test directory.")
633 sys.exit(-1)
634
Zachary Turner6a188e62015-12-11 19:21:34 +0000635 os.environ["LLDB_TEST"] = scriptPath
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000636
Adrian Prantl5ec76fe2018-01-30 18:29:16 +0000637 # Set up the root build directory.
638 builddir = configuration.test_build_dir
639 if not configuration.test_build_dir:
640 raise Exception("test_build_dir is not set")
641 os.environ["LLDB_BUILD"] = os.path.abspath(configuration.test_build_dir)
642
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000643 # Set up the LLDB_SRC environment variable, so that the tests can locate
644 # the LLDB source code.
645 os.environ["LLDB_SRC"] = lldbsuite.lldb_root
646
647 pluginPath = os.path.join(scriptPath, 'plugins')
648 toolsLLDBMIPath = os.path.join(scriptPath, 'tools', 'lldb-mi')
649 toolsLLDBServerPath = os.path.join(scriptPath, 'tools', 'lldb-server')
650
Kate Stoneb9c1b512016-09-06 20:57:50 +0000651 # Insert script dir, plugin dir, lldb-mi dir and lldb-server dir to the
652 # sys.path.
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000653 sys.path.insert(0, pluginPath)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000654 # Adding test/tools/lldb-mi to the path makes it easy
655 sys.path.insert(0, toolsLLDBMIPath)
656 # to "import lldbmi_testcase" from the MI tests
657 # Adding test/tools/lldb-server to the path makes it easy
658 sys.path.insert(0, toolsLLDBServerPath)
659 # to "import lldbgdbserverutils" from the lldb-server tests
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000660
661 # This is the root of the lldb git/svn checkout
662 # When this changes over to a package instead of a standalone script, this
663 # will be `lldbsuite.lldb_root`
664 lldbRootDirectory = lldbsuite.lldb_root
665
666 # Some of the tests can invoke the 'lldb' command directly.
667 # We'll try to locate the appropriate executable right here.
668
669 # The lldb executable can be set from the command line
670 # if it's not set, we try to find it now
671 # first, we try the environment
672 if not lldbtest_config.lldbExec:
673 # First, you can define an environment variable LLDB_EXEC specifying the
674 # full pathname of the lldb executable.
675 if "LLDB_EXEC" in os.environ:
676 lldbtest_config.lldbExec = os.environ["LLDB_EXEC"]
677
678 if not lldbtest_config.lldbExec:
679 outputPaths = getOutputPaths(lldbRootDirectory)
680 for outputPath in outputPaths:
681 candidatePath = os.path.join(outputPath, 'lldb')
682 if is_exe(candidatePath):
683 lldbtest_config.lldbExec = candidatePath
684 break
685
686 if not lldbtest_config.lldbExec:
687 # Last, check the path
688 lldbtest_config.lldbExec = which('lldb')
689
690 if lldbtest_config.lldbExec and not is_exe(lldbtest_config.lldbExec):
Kate Stoneb9c1b512016-09-06 20:57:50 +0000691 print(
692 "'{}' is not a path to a valid executable".format(
693 lldbtest_config.lldbExec))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000694 lldbtest_config.lldbExec = None
695
696 if not lldbtest_config.lldbExec:
697 print("The 'lldb' executable cannot be located. Some of the tests may not be run as a result.")
698 sys.exit(-1)
699
Kate Stoneb9c1b512016-09-06 20:57:50 +0000700 # confusingly, this is the "bin" directory
701 lldbLibDir = os.path.dirname(lldbtest_config.lldbExec)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000702 os.environ["LLDB_LIB_DIR"] = lldbLibDir
Kate Stoneb9c1b512016-09-06 20:57:50 +0000703 lldbImpLibDir = os.path.join(
704 lldbLibDir,
705 '..',
706 'lib') if sys.platform.startswith('win32') else lldbLibDir
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000707 os.environ["LLDB_IMPLIB_DIR"] = lldbImpLibDir
Zachary Turner35a76102015-12-09 20:48:42 +0000708 print("LLDB library dir:", os.environ["LLDB_LIB_DIR"])
709 print("LLDB import library dir:", os.environ["LLDB_IMPLIB_DIR"])
710 os.system('%s -v' % lldbtest_config.lldbExec)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000711
712 # Assume lldb-mi is in same place as lldb
713 # If not found, disable the lldb-mi tests
Chris Bieneman35e54572016-10-12 20:15:46 +0000714 # TODO: Append .exe on Windows
715 # - this will be in a separate commit in case the mi tests fail horribly
716 lldbDir = os.path.dirname(lldbtest_config.lldbExec)
717 lldbMiExec = os.path.join(lldbDir, "lldb-mi")
718 if is_exe(lldbMiExec):
719 os.environ["LLDBMI_EXEC"] = lldbMiExec
720 else:
Zachary Turnerb4733e62015-12-08 01:15:44 +0000721 if not configuration.shouldSkipBecauseOfCategories(["lldb-mi"]):
Kate Stoneb9c1b512016-09-06 20:57:50 +0000722 print(
723 "The 'lldb-mi' executable cannot be located. The lldb-mi tests can not be run as a result.")
Zachary Turner606e3a52015-12-08 01:15:30 +0000724 configuration.skipCategories.append("lldb-mi")
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000725
Kate Stoneb9c1b512016-09-06 20:57:50 +0000726 lldbPythonDir = None # The directory that contains 'lldb/__init__.py'
Chris Bieneman5d51a762016-10-31 22:06:52 +0000727 if not configuration.lldbFrameworkPath and os.path.exists(os.path.join(lldbLibDir, "LLDB.framework")):
728 configuration.lldbFrameworkPath = os.path.join(lldbLibDir, "LLDB.framework")
Zachary Turner606e3a52015-12-08 01:15:30 +0000729 if configuration.lldbFrameworkPath:
Chris Bienemanbd6d6992016-10-31 04:48:10 +0000730 lldbtest_config.lldbFrameworkPath = configuration.lldbFrameworkPath
Kate Stoneb9c1b512016-09-06 20:57:50 +0000731 candidatePath = os.path.join(
732 configuration.lldbFrameworkPath, 'Resources', 'Python')
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000733 if os.path.isfile(os.path.join(candidatePath, 'lldb/__init__.py')):
734 lldbPythonDir = candidatePath
735 if not lldbPythonDir:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000736 print(
737 'Resources/Python/lldb/__init__.py was not found in ' +
738 configuration.lldbFrameworkPath)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000739 sys.exit(-1)
740 else:
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000741 # If our lldb supports the -P option, use it to find the python path:
742 init_in_python_dir = os.path.join('lldb', '__init__.py')
743
Kate Stoneb9c1b512016-09-06 20:57:50 +0000744 lldb_dash_p_result = subprocess.check_output(
745 [lldbtest_config.lldbExec, "-P"], stderr=subprocess.STDOUT, universal_newlines=True)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000746
Kate Stoneb9c1b512016-09-06 20:57:50 +0000747 if lldb_dash_p_result and not lldb_dash_p_result.startswith(
748 ("<", "lldb: invalid option:")) and not lldb_dash_p_result.startswith("Traceback"):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000749 lines = lldb_dash_p_result.splitlines()
750
751 # Workaround for readline vs libedit issue on FreeBSD. If stdout
752 # is not a terminal Python executes
753 # rl_variable_bind ("enable-meta-key", "off");
754 # This produces a warning with FreeBSD's libedit because the
755 # enable-meta-key variable is unknown. Not an issue on Apple
756 # because cpython commit f0ab6f9f0603 added a #ifndef __APPLE__
757 # around the call. See http://bugs.python.org/issue19884 for more
758 # information. For now we just discard the warning output.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000759 if len(lines) >= 1 and lines[0].startswith(
760 "bind: Invalid command"):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000761 lines.pop(0)
762
763 # Taking the last line because lldb outputs
764 # 'Cannot read termcap database;\nusing dumb terminal settings.\n'
765 # before the path
Kate Stoneb9c1b512016-09-06 20:57:50 +0000766 if len(lines) >= 1 and os.path.isfile(
767 os.path.join(lines[-1], init_in_python_dir)):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000768 lldbPythonDir = lines[-1]
769 if "freebsd" in sys.platform or "linux" in sys.platform:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000770 os.environ['LLDB_LIB_DIR'] = os.path.join(
771 lldbPythonDir, '..', '..')
772
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000773 if not lldbPythonDir:
774 if platform.system() == "Darwin":
775 python_resource_dir = ['LLDB.framework', 'Resources', 'Python']
Saleem Abdulrasool81eadde2016-05-16 03:13:05 +0000776 outputPaths = getXcodeOutputPaths(lldbRootDirectory)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000777 for outputPath in outputPaths:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000778 candidatePath = os.path.join(
779 outputPath, *python_resource_dir)
780 if os.path.isfile(
781 os.path.join(
782 candidatePath,
783 init_in_python_dir)):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000784 lldbPythonDir = candidatePath
785 break
786
787 if not lldbPythonDir:
Saleem Abdulrasool0eadc532016-05-16 03:13:12 +0000788 print("lldb.py is not found, some tests may fail.")
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000789 else:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000790 print(
791 "Unable to load lldb extension module. Possible reasons for this include:")
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000792 print(" 1) LLDB was built with LLDB_DISABLE_PYTHON=1")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000793 print(
794 " 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to")
795 print(
796 " the version of Python that LLDB built and linked against, and PYTHONPATH")
797 print(
798 " should contain the Lib directory for the same python distro, as well as the")
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000799 print(" location of LLDB\'s site-packages folder.")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000800 print(
801 " 3) A different version of Python than that which was built against is exported in")
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000802 print(" the system\'s PATH environment variable, causing conflicts.")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000803 print(
804 " 4) The executable '%s' could not be found. Please check " %
805 lldbtest_config.lldbExec)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000806 print(" that it exists and is executable.")
807
808 if lldbPythonDir:
809 lldbPythonDir = os.path.normpath(lldbPythonDir)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000810 # Some of the code that uses this path assumes it hasn't resolved the Versions... link.
811 # If the path we've constructed looks like that, then we'll strip out
812 # the Versions/A part.
813 (before, frameWithVersion, after) = lldbPythonDir.rpartition(
814 "LLDB.framework/Versions/A")
815 if frameWithVersion != "":
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000816 lldbPythonDir = before + "LLDB.framework" + after
817
818 lldbPythonDir = os.path.abspath(lldbPythonDir)
819
820 # If tests need to find LLDB_FRAMEWORK, now they can do it
Kate Stoneb9c1b512016-09-06 20:57:50 +0000821 os.environ["LLDB_FRAMEWORK"] = os.path.dirname(
822 os.path.dirname(lldbPythonDir))
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000823
Kate Stoneb9c1b512016-09-06 20:57:50 +0000824 # This is to locate the lldb.py module. Insert it right after
825 # sys.path[0].
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000826 sys.path[1:1] = [lldbPythonDir]
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000827
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000828
829def visit_file(dir, name):
830 # Try to match the regexp pattern, if specified.
831 if configuration.regexp:
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000832 if not re.search(configuration.regexp, name):
833 # We didn't match the regex, we're done.
834 return
835
Francis Riccif833f172016-10-04 18:48:00 +0000836 if configuration.skip_tests:
837 for file_regexp in configuration.skip_tests:
Francis Ricci69517072016-09-23 21:32:47 +0000838 if re.search(file_regexp, name):
839 return
840
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000841 # We found a match for our test. Add it to the suite.
842
843 # Update the sys.path first.
844 if not sys.path.count(dir):
845 sys.path.insert(0, dir)
846 base = os.path.splitext(name)[0]
847
848 # Thoroughly check the filterspec against the base module and admit
849 # the (base, filterspec) combination only when it makes sense.
850 filterspec = None
851 for filterspec in configuration.filters:
852 # Optimistically set the flag to True.
853 filtered = True
854 module = __import__(base)
855 parts = filterspec.split('.')
856 obj = module
857 for part in parts:
858 try:
859 parent, obj = obj, getattr(obj, part)
860 except AttributeError:
861 # The filterspec has failed.
862 filtered = False
863 break
864
865 # If filtered, we have a good filterspec. Add it.
866 if filtered:
867 # print("adding filter spec %s to module %s" % (filterspec, module))
868 configuration.suite.addTests(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000869 unittest2.defaultTestLoader.loadTestsFromName(
870 filterspec, module))
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000871 continue
872
873 # Forgo this module if the (base, filterspec) combo is invalid
874 if configuration.filters and not filtered:
875 return
876
877 if not filterspec or not filtered:
878 # Add the entire file's worth of tests since we're not filtered.
879 # Also the fail-over case when the filterspec branch
880 # (base, filterspec) combo doesn't make sense.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000881 configuration.suite.addTests(
882 unittest2.defaultTestLoader.loadTestsFromName(base))
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000883
884
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000885def visit(prefix, dir, names):
886 """Visitor function for os.path.walk(path, visit, arg)."""
887
Zachary Turner50671582015-12-08 20:36:22 +0000888 dir_components = set(dir.split(os.sep))
889 excluded_components = set(['.svn', '.git'])
890 if dir_components.intersection(excluded_components):
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000891 return
892
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000893 # Gather all the Python test file names that follow the Test*.py pattern.
894 python_test_files = [
895 name
896 for name in names
897 if name.endswith('.py') and name.startswith(prefix)]
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000898
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000899 # Visit all the python test files.
900 for name in python_test_files:
901 try:
902 # Ensure we error out if we have multiple tests with the same
903 # base name.
904 # Future improvement: find all the places where we work with base
905 # names and convert to full paths. We have directory structure
906 # to disambiguate these, so we shouldn't need this constraint.
Zachary Turner606e3a52015-12-08 01:15:30 +0000907 if name in configuration.all_tests:
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000908 raise Exception("Found multiple tests with the name %s" % name)
Zachary Turner606e3a52015-12-08 01:15:30 +0000909 configuration.all_tests.add(name)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000910
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000911 # Run the relevant tests in the python file.
912 visit_file(dir, name)
913 except Exception as ex:
914 # Convert this exception to a test event error for the file.
915 test_filename = os.path.abspath(os.path.join(dir, name))
916 if configuration.results_formatter_object is not None:
917 # Grab the backtrace for the exception.
918 import traceback
919 backtrace = traceback.format_exc()
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000920
Todd Fiala7c5f7ca2016-05-13 21:36:26 +0000921 # Generate the test event.
922 configuration.results_formatter_object.handle_event(
923 EventBuilder.event_for_job_test_add_error(
924 test_filename, ex, backtrace))
925 raise
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000926
927
928def disabledynamics():
929 import lldb
930 ci = lldb.DBG.GetCommandInterpreter()
931 res = lldb.SBCommandReturnObject()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000932 ci.HandleCommand(
933 "setting set target.prefer-dynamic-value no-dynamic-values",
934 res,
935 False)
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000936 if not res.Succeeded():
937 raise Exception('disabling dynamic type support failed')
938
Kate Stoneb9c1b512016-09-06 20:57:50 +0000939
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000940def lldbLoggings():
941 import lldb
942 """Check and do lldb loggings if necessary."""
943
944 # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is
945 # defined. Use ${LLDB_LOG} to specify the log file.
946 ci = lldb.DBG.GetCommandInterpreter()
947 res = lldb.SBCommandReturnObject()
948 if ("LLDB_LOG" in os.environ):
949 open(os.environ["LLDB_LOG"], 'w').close()
950 if ("LLDB_LOG_OPTION" in os.environ):
951 lldb_log_option = os.environ["LLDB_LOG_OPTION"]
952 else:
953 lldb_log_option = "event process expr state api"
954 ci.HandleCommand(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000955 "log enable -n -f " +
956 os.environ["LLDB_LOG"] +
957 " lldb " +
958 lldb_log_option,
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000959 res)
960 if not res.Succeeded():
961 raise Exception('log enable failed (check LLDB_LOG env variable)')
962
963 if ("LLDB_LINUX_LOG" in os.environ):
964 open(os.environ["LLDB_LINUX_LOG"], 'w').close()
965 if ("LLDB_LINUX_LOG_OPTION" in os.environ):
966 lldb_log_option = os.environ["LLDB_LINUX_LOG_OPTION"]
967 else:
968 lldb_log_option = "event process expr state api"
969 ci.HandleCommand(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000970 "log enable -n -f " +
971 os.environ["LLDB_LINUX_LOG"] +
972 " linux " +
973 lldb_log_option,
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000974 res)
975 if not res.Succeeded():
Kate Stoneb9c1b512016-09-06 20:57:50 +0000976 raise Exception(
977 'log enable failed (check LLDB_LINUX_LOG env variable)')
978
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000979 # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined.
980 # Use ${GDB_REMOTE_LOG} to specify the log file.
981 if ("GDB_REMOTE_LOG" in os.environ):
982 if ("GDB_REMOTE_LOG_OPTION" in os.environ):
983 gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"]
984 else:
985 gdb_remote_log_option = "packets process"
986 ci.HandleCommand(
987 "log enable -n -f " + os.environ["GDB_REMOTE_LOG"] + " gdb-remote "
988 + gdb_remote_log_option,
989 res)
990 if not res.Succeeded():
Kate Stoneb9c1b512016-09-06 20:57:50 +0000991 raise Exception(
992 'log enable failed (check GDB_REMOTE_LOG env variable)')
993
Zachary Turnerc432c8f2015-10-28 17:43:26 +0000994
995def getMyCommandLine():
996 return ' '.join(sys.argv)
997
998# ======================================== #
999# #
1000# Execution of the test driver starts here #
1001# #
1002# ======================================== #
1003
Kate Stoneb9c1b512016-09-06 20:57:50 +00001004
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001005def checkDsymForUUIDIsNotOn():
1006 cmd = ["defaults", "read", "com.apple.DebugSymbols"]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001007 pipe = subprocess.Popen(
1008 cmd,
1009 stdout=subprocess.PIPE,
1010 stderr=subprocess.STDOUT)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001011 cmd_output = pipe.stdout.read()
1012 if cmd_output and "DBGFileMappedPaths = " in cmd_output:
1013 print("%s =>" % ' '.join(cmd))
1014 print(cmd_output)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001015 print(
1016 "Disable automatic lookup and caching of dSYMs before running the test suite!")
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001017 print("Exiting...")
1018 sys.exit(0)
1019
Kate Stoneb9c1b512016-09-06 20:57:50 +00001020
1021def exitTestSuite(exitCode=None):
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001022 import lldb
1023 lldb.SBDebugger.Terminate()
1024 if exitCode:
1025 sys.exit(exitCode)
1026
1027
1028def isMultiprocessTestRunner():
1029 # We're not multiprocess when we're either explicitly
1030 # the inferior (as specified by the multiprocess test
1031 # runner) OR we've been told to skip using the multiprocess
1032 # test runner
Kate Stoneb9c1b512016-09-06 20:57:50 +00001033 return not (
1034 configuration.is_inferior_test_runner or configuration.no_multiprocess_test_runner)
1035
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001036
Enrico Granata5f92a132015-11-05 00:46:25 +00001037def getVersionForSDK(sdk):
1038 sdk = str.lower(sdk)
1039 full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
1040 basename = os.path.basename(full_path)
1041 basename = os.path.splitext(basename)[0]
1042 basename = str.lower(basename)
1043 ver = basename.replace(sdk, '')
1044 return ver
1045
Kate Stoneb9c1b512016-09-06 20:57:50 +00001046
Enrico Granata5f92a132015-11-05 00:46:25 +00001047def getPathForSDK(sdk):
1048 sdk = str.lower(sdk)
1049 full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001050 if os.path.exists(full_path):
1051 return full_path
Enrico Granata5f92a132015-11-05 00:46:25 +00001052 return None
1053
Kate Stoneb9c1b512016-09-06 20:57:50 +00001054
Enrico Granata5f92a132015-11-05 00:46:25 +00001055def setDefaultTripleForPlatform():
Zachary Turner606e3a52015-12-08 01:15:30 +00001056 if configuration.lldb_platform_name == 'ios-simulator':
Kate Stoneb9c1b512016-09-06 20:57:50 +00001057 triple_str = 'x86_64-apple-ios%s' % (
1058 getVersionForSDK('iphonesimulator'))
Enrico Granata5f92a132015-11-05 00:46:25 +00001059 os.environ['TRIPLE'] = triple_str
Kate Stoneb9c1b512016-09-06 20:57:50 +00001060 return {'TRIPLE': triple_str}
Enrico Granata5f92a132015-11-05 00:46:25 +00001061 return {}
1062
Kate Stoneb9c1b512016-09-06 20:57:50 +00001063
Pavel Labath6de25ec2017-03-15 08:51:59 +00001064def checkCompiler():
1065 # Add some intervention here to sanity check that the compiler requested is sane.
1066 # If found not to be an executable program, we abort.
1067 c = configuration.compiler
1068 if which(c):
1069 return
1070
1071 if not sys.platform.startswith("darwin"):
1072 raise Exception(c + " is not a valid compiler")
1073
1074 pipe = subprocess.Popen(
1075 ['xcrun', '-find', c], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
1076 cmd_output = pipe.stdout.read()
1077 if not cmd_output or "not found" in cmd_output:
1078 raise Exception(c + " is not a valid compiler")
1079
1080 configuration.compiler = cmd_output.split('\n')[0]
1081 print("'xcrun -find %s' returning %s" % (c, configuration.compiler))
1082
Pavel Labath01a28ca2017-03-29 21:01:14 +00001083def canRunLibcxxTests():
1084 from lldbsuite.test import lldbplatformutil
1085
1086 platform = lldbplatformutil.getPlatform()
1087
1088 if lldbplatformutil.target_is_android() or lldbplatformutil.platformIsDarwin():
1089 return True, "libc++ always present"
1090
1091 if platform == "linux":
1092 if not os.path.isdir("/usr/include/c++/v1"):
1093 return False, "Unable to find libc++ installation"
1094 return True, "Headers found, let's hope they work"
1095
1096 return False, "Don't know how to build with libc++ on %s" % platform
1097
1098def checkLibcxxSupport():
1099 result, reason = canRunLibcxxTests()
1100 if result:
1101 return # libc++ supported
1102 if "libc++" in configuration.categoriesList:
1103 return # libc++ category explicitly requested, let it run.
1104 print("Libc++ tests will not be run because: " + reason)
1105 configuration.skipCategories.append("libc++")
Pavel Labath6de25ec2017-03-15 08:51:59 +00001106
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001107def run_suite():
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001108 # On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults
1109 # does not exist before proceeding to running the test suite.
1110 if sys.platform.startswith("darwin"):
1111 checkDsymForUUIDIsNotOn()
1112
1113 #
1114 # Start the actions by first parsing the options while setting up the test
1115 # directories, followed by setting up the search paths for lldb utilities;
1116 # then, we walk the directory trees and collect the tests into our test suite.
1117 #
1118 parseOptionsAndInitTestdirs()
1119
1120 # Setup test results (test results formatter and output handling).
1121 setupTestResults()
1122
1123 # If we are running as the multiprocess test runner, kick off the
1124 # multiprocess test runner here.
1125 if isMultiprocessTestRunner():
Zachary Turnerc1b7cd72015-11-05 19:22:28 +00001126 from . import dosep
Kate Stoneb9c1b512016-09-06 20:57:50 +00001127 dosep.main(
1128 configuration.num_threads,
1129 configuration.multiprocess_test_subdir,
1130 configuration.test_runner_name,
1131 configuration.results_formatter_object)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001132 raise Exception("should never get here")
Zachary Turner606e3a52015-12-08 01:15:30 +00001133 elif configuration.is_inferior_test_runner:
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001134 # Shut off Ctrl-C processing in inferiors. The parallel
1135 # test runner handles this more holistically.
1136 signal.signal(signal.SIGINT, signal.SIG_IGN)
1137
1138 setupSysPath()
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001139
1140 #
1141 # If '-l' is specified, do not skip the long running tests.
Zachary Turner606e3a52015-12-08 01:15:30 +00001142 if not configuration.skip_long_running_test:
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001143 os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO"
1144
1145 # For the time being, let's bracket the test runner within the
1146 # lldb.SBDebugger.Initialize()/Terminate() pair.
1147 import lldb
1148
1149 # Create a singleton SBDebugger in the lldb namespace.
1150 lldb.DBG = lldb.SBDebugger.Create()
1151
Zachary Turner606e3a52015-12-08 01:15:30 +00001152 if configuration.lldb_platform_name:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001153 print("Setting up remote platform '%s'" %
1154 (configuration.lldb_platform_name))
1155 lldb.remote_platform = lldb.SBPlatform(
1156 configuration.lldb_platform_name)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001157 if not lldb.remote_platform.IsValid():
Kate Stoneb9c1b512016-09-06 20:57:50 +00001158 print(
1159 "error: unable to create the LLDB platform named '%s'." %
1160 (configuration.lldb_platform_name))
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001161 exitTestSuite(1)
Zachary Turner606e3a52015-12-08 01:15:30 +00001162 if configuration.lldb_platform_url:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001163 # We must connect to a remote platform if a LLDB platform URL was
1164 # specified
1165 print(
1166 "Connecting to remote platform '%s' at '%s'..." %
1167 (configuration.lldb_platform_name, configuration.lldb_platform_url))
1168 platform_connect_options = lldb.SBPlatformConnectOptions(
1169 configuration.lldb_platform_url)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001170 err = lldb.remote_platform.ConnectRemote(platform_connect_options)
1171 if err.Success():
1172 print("Connected.")
1173 else:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001174 print("error: failed to connect to remote platform using URL '%s': %s" % (
1175 configuration.lldb_platform_url, err))
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001176 exitTestSuite(1)
1177 else:
Zachary Turner606e3a52015-12-08 01:15:30 +00001178 configuration.lldb_platform_url = None
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001179
Enrico Granata5f92a132015-11-05 00:46:25 +00001180 platform_changes = setDefaultTripleForPlatform()
1181 first = True
1182 for key in platform_changes:
1183 if first:
1184 print("Environment variables setup for platform support:")
1185 first = False
Kate Stoneb9c1b512016-09-06 20:57:50 +00001186 print("%s = %s" % (key, platform_changes[key]))
Enrico Granata5f92a132015-11-05 00:46:25 +00001187
Zachary Turner606e3a52015-12-08 01:15:30 +00001188 if configuration.lldb_platform_working_dir:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001189 print("Setting remote platform working directory to '%s'..." %
1190 (configuration.lldb_platform_working_dir))
Pavel Labath6b42b3b2017-03-20 16:07:17 +00001191 error = lldb.remote_platform.MakeDirectory(
1192 configuration.lldb_platform_working_dir, 448) # 448 = 0o700
1193 if error.Fail():
1194 raise Exception("making remote directory '%s': %s" % (
1195 remote_test_dir, error))
1196
1197 if not lldb.remote_platform.SetWorkingDirectory(
1198 configuration.lldb_platform_working_dir):
1199 raise Exception("failed to set working directory '%s'" % remote_test_dir)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001200 lldb.DBG.SetSelectedPlatform(lldb.remote_platform)
1201 else:
1202 lldb.remote_platform = None
Zachary Turner606e3a52015-12-08 01:15:30 +00001203 configuration.lldb_platform_working_dir = None
1204 configuration.lldb_platform_url = None
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001205
Adrian Prantl5ec76fe2018-01-30 18:29:16 +00001206 # Set up the working directory.
1207 # Note that it's not dotest's job to clean this directory.
Adrian Prantle8857682018-02-01 22:18:02 +00001208 import lldbsuite.test.lldbutil as lldbutil
1209 build_dir = configuration.test_build_dir
1210 lldbutil.mkdir_p(build_dir)
1211
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001212 target_platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2]
1213
Pavel Labath01a28ca2017-03-29 21:01:14 +00001214 checkLibcxxSupport()
1215
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001216 # Don't do debugserver tests on everything except OS X.
Zachary Turner606e3a52015-12-08 01:15:30 +00001217 configuration.dont_do_debugserver_test = "linux" in target_platform or "freebsd" in target_platform or "windows" in target_platform
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001218
1219 # Don't do lldb-server (llgs) tests on anything except Linux.
Zachary Turner606e3a52015-12-08 01:15:30 +00001220 configuration.dont_do_llgs_test = not ("linux" in target_platform)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001221
1222 #
1223 # Walk through the testdirs while collecting tests.
1224 #
Zachary Turner606e3a52015-12-08 01:15:30 +00001225 for testdir in configuration.testdirs:
Zachary Turnere6ba0532015-11-05 01:33:54 +00001226 for (dirpath, dirnames, filenames) in os.walk(testdir):
1227 visit('Test', dirpath, filenames)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001228
1229 #
1230 # Now that we have loaded all the test cases, run the whole test suite.
1231 #
1232
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001233 # Turn on lldb loggings if necessary.
1234 lldbLoggings()
1235
1236 # Disable default dynamic types for testing purposes
1237 disabledynamics()
1238
1239 # Install the control-c handler.
1240 unittest2.signals.installHandler()
1241
1242 # If sdir_name is not specified through the '-s sdir_name' option, get a
1243 # timestamp string and export it as LLDB_SESSION_DIR environment var. This will
1244 # be used when/if we want to dump the session info of individual test cases
1245 # later on.
1246 #
1247 # See also TestBase.dumpSessionInfo() in lldbtest.py.
1248 import datetime
1249 # The windows platforms don't like ':' in the pathname.
1250 timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
Zachary Turner606e3a52015-12-08 01:15:30 +00001251 if not configuration.sdir_name:
1252 configuration.sdir_name = timestamp_started
Kate Stoneb9c1b512016-09-06 20:57:50 +00001253 os.environ["LLDB_SESSION_DIRNAME"] = os.path.join(
1254 os.getcwd(), configuration.sdir_name)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001255
Kate Stoneb9c1b512016-09-06 20:57:50 +00001256 sys.stderr.write(
1257 "\nSession logs for test failures/errors/unexpected successes"
1258 " will go into directory '%s'\n" %
1259 configuration.sdir_name)
Zachary Turner35a76102015-12-09 20:48:42 +00001260 sys.stderr.write("Command invoked: %s\n" % getMyCommandLine())
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001261
Zachary Turner606e3a52015-12-08 01:15:30 +00001262 if not os.path.isdir(configuration.sdir_name):
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001263 try:
Zachary Turner606e3a52015-12-08 01:15:30 +00001264 os.mkdir(configuration.sdir_name)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001265 except OSError as exception:
1266 if exception.errno != errno.EEXIST:
1267 raise
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001268
1269 #
Pavel Labath6de25ec2017-03-15 08:51:59 +00001270 # Invoke the default TextTestRunner to run the test suite
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001271 #
Pavel Labath6de25ec2017-03-15 08:51:59 +00001272 checkCompiler()
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001273
Zachary Turner606e3a52015-12-08 01:15:30 +00001274 if not configuration.parsable:
Pavel Labath6de25ec2017-03-15 08:51:59 +00001275 print("compiler=%s" % configuration.compiler)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001276
1277 # Iterating over all possible architecture and compiler combinations.
Pavel Labath6de25ec2017-03-15 08:51:59 +00001278 os.environ["ARCH"] = configuration.arch
1279 os.environ["CC"] = configuration.compiler
1280 configString = "arch=%s compiler=%s" % (configuration.arch,
1281 configuration.compiler)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001282
Pavel Labath6de25ec2017-03-15 08:51:59 +00001283 # Translate ' ' to '-' for pathname component.
1284 if six.PY2:
1285 import string
1286 tbl = string.maketrans(' ', '-')
1287 else:
1288 tbl = str.maketrans(' ', '-')
1289 configPostfix = configString.translate(tbl)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001290
Pavel Labath6de25ec2017-03-15 08:51:59 +00001291 # Output the configuration.
1292 if not configuration.parsable:
1293 sys.stderr.write("\nConfiguration: " + configString + "\n")
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001294
Pavel Labath6de25ec2017-03-15 08:51:59 +00001295 # First, write out the number of collected test cases.
1296 if not configuration.parsable:
1297 sys.stderr.write(configuration.separator + "\n")
1298 sys.stderr.write(
1299 "Collected %d test%s\n\n" %
1300 (configuration.suite.countTestCases(),
1301 configuration.suite.countTestCases() != 1 and "s" or ""))
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001302
Pavel Labath6de25ec2017-03-15 08:51:59 +00001303 if configuration.parsable:
1304 v = 0
1305 else:
1306 v = configuration.verbose
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001307
Pavel Labath6de25ec2017-03-15 08:51:59 +00001308 # Invoke the test runner.
1309 if configuration.count == 1:
1310 result = unittest2.TextTestRunner(
1311 stream=sys.stderr,
1312 verbosity=v,
1313 resultclass=test_result.LLDBTestResult).run(
1314 configuration.suite)
1315 else:
1316 # We are invoking the same test suite more than once. In this case,
1317 # mark __ignore_singleton__ flag as True so the signleton pattern is
1318 # not enforced.
1319 test_result.LLDBTestResult.__ignore_singleton__ = True
1320 for i in range(configuration.count):
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001321
Pavel Labath6de25ec2017-03-15 08:51:59 +00001322 result = unittest2.TextTestRunner(
1323 stream=sys.stderr,
1324 verbosity=v,
1325 resultclass=test_result.LLDBTestResult).run(
1326 configuration.suite)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001327
Pavel Labath6de25ec2017-03-15 08:51:59 +00001328 configuration.failed = not result.wasSuccessful()
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001329
Zachary Turner606e3a52015-12-08 01:15:30 +00001330 if configuration.sdir_has_content and not configuration.parsable:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001331 sys.stderr.write(
1332 "Session logs for test failures/errors/unexpected successes"
1333 " can be found in directory '%s'\n" %
1334 configuration.sdir_name)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001335
Kate Stoneb9c1b512016-09-06 20:57:50 +00001336 if configuration.useCategories and len(
1337 configuration.failuresPerCategory) > 0:
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001338 sys.stderr.write("Failures per category:\n")
Zachary Turner606e3a52015-12-08 01:15:30 +00001339 for category in configuration.failuresPerCategory:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001340 sys.stderr.write(
1341 "%s - %d\n" %
1342 (category, configuration.failuresPerCategory[category]))
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001343
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001344 # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined.
1345 # This should not be necessary now.
1346 if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ):
1347 print("Terminating Test suite...")
1348 subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())])
1349
1350 # Exiting.
Zachary Turner606e3a52015-12-08 01:15:30 +00001351 exitTestSuite(configuration.failed)
Zachary Turnerc432c8f2015-10-28 17:43:26 +00001352
1353if __name__ == "__main__":
Kate Stoneb9c1b512016-09-06 20:57:50 +00001354 print(
1355 __file__ +
1356 " is for use as a module only. It should not be run as a standalone script.")
Zachary Turner7d564542015-11-02 19:19:49 +00001357 sys.exit(-1)