Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
from __future__ import absolute_import
2015-10-20 07:45:41 +08:00
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
# System modules
2015-10-24 01:53:30 +08:00
import argparse
2015-05-19 03:40:54 +08:00
import sys
import os
import textwrap
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
# LLDB modules
2016-05-18 02:02:34 +08:00
from . import configuration
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
2016-09-07 04:57:50 +08:00
2015-05-23 03:49:23 +08:00
def create_parser ( ) :
2015-05-19 03:40:54 +08:00
parser = argparse . ArgumentParser (
description = ' description ' ,
prefix_chars = ' +- ' ,
add_help = False )
group = None
# Helper function for boolean options (group will point to the current
# group when executing X)
X = lambda optstr , helpstr , * * kwargs : group . add_argument (
optstr , help = helpstr , action = ' store_true ' , * * kwargs )
group = parser . add_argument_group ( ' Help ' )
group . add_argument (
' -h ' ,
' --help ' ,
dest = ' h ' ,
action = ' store_true ' ,
help = " Print this help message and exit. Add ' -v ' for more detailed help. " )
# C and Python toolchain options
group = parser . add_argument_group ( ' Toolchain options ' )
group . add_argument (
' -A ' ,
' --arch ' ,
metavar = ' arch ' ,
2017-03-15 16:51:59 +08:00
dest = ' arch ' ,
2015-05-19 03:40:54 +08:00
help = textwrap . dedent ( ''' Specify the architecture(s) to test. This option can be specified more than once ''' ) )
2017-03-15 16:51:59 +08:00
group . add_argument ( ' -C ' , ' --compiler ' , metavar = ' compiler ' , dest = ' compiler ' , help = textwrap . dedent (
2015-05-19 03:40:54 +08:00
''' Specify the compiler(s) used to build the inferior executables. The compiler path can be an executable basename or a full path to a compiler executable. This option can be specified multiple times. ''' ) )
if sys . platform == ' darwin ' :
2020-06-17 07:25:09 +08:00
group . add_argument ( ' --apple-sdk ' , metavar = ' apple_sdk ' , dest = ' apple_sdk ' , default = " " , help = textwrap . dedent (
2015-05-19 03:40:54 +08:00
''' Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK ' s toolchain. ''' ) )
# FIXME? This won't work for different extra flags according to each arch.
group . add_argument (
' -E ' ,
metavar = ' extra-flags ' ,
help = textwrap . dedent ( ''' Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged
suggestions : do not lump the " -A arch1 -A arch2 " together such that the - E option applies to only one of the architectures ''' ))
2018-04-12 17:35:17 +08:00
group . add_argument ( ' --dsymutil ' , metavar = ' dsymutil ' , dest = ' dsymutil ' , help = textwrap . dedent ( ' Specify which dsymutil to use. ' ) )
2021-01-23 04:48:17 +08:00
group . add_argument ( ' --llvm-tools-dir ' , metavar = ' dir ' , dest = ' llvm_tools_dir ' ,
help = textwrap . dedent ( ' The location of llvm tools used for testing (yaml2obj, FileCheck, etc.). ' ) )
2018-09-19 03:31:47 +08:00
2015-05-19 03:40:54 +08:00
# Test filtering options
group = parser . add_argument_group ( ' Test filtering options ' )
group . add_argument (
' -f ' ,
metavar = ' filterspec ' ,
action = ' append ' ,
2019-10-08 08:26:53 +08:00
help = ( ' Specify a filter, which looks like " TestModule.TestClass.test_name " . ' +
' You may also use shortened filters, such as ' +
' " TestModule.TestClass " , " TestClass.test_name " , or just " test_name " . ' ) )
2015-05-19 03:40:54 +08:00
group . add_argument (
' -p ' ,
metavar = ' pattern ' ,
help = ' Specify a regexp filename pattern for inclusion in the test suite ' )
2016-10-05 02:48:00 +08:00
group . add_argument ( ' --excluded ' , metavar = ' exclusion-file ' , action = ' append ' , help = textwrap . dedent (
2016-09-24 05:32:47 +08:00
''' Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods,
with each list under a matching header ( xfail files , xfail methods , skip files , skip methods ) ''' ))
2015-05-19 03:40:54 +08:00
group . add_argument (
' -G ' ,
' --category ' ,
metavar = ' category ' ,
action = ' append ' ,
2019-12-12 19:17:14 +08:00
dest = ' categories_list ' ,
2015-05-19 03:40:54 +08:00
help = textwrap . dedent ( ''' Specify categories of test cases of interest. Can be specified more than once. ''' ) )
group . add_argument (
' --skip-category ' ,
metavar = ' category ' ,
action = ' append ' ,
2019-12-12 19:17:14 +08:00
dest = ' skip_categories ' ,
2015-05-19 03:40:54 +08:00
help = textwrap . dedent ( ''' Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once. ''' ) )
2019-12-12 20:01:25 +08:00
group . add_argument (
' --xfail-category ' ,
metavar = ' category ' ,
action = ' append ' ,
dest = ' xfail_categories ' ,
help = textwrap . dedent ( ''' Specify categories of test cases that are expected to fail. Can be specified more than once. ''' ) )
2015-05-19 03:40:54 +08:00
# Configuration options
group = parser . add_argument_group ( ' Configuration options ' )
group . add_argument (
' --framework ' ,
metavar = ' framework-path ' ,
help = ' The path to LLDB.framework ' )
group . add_argument (
' --executable ' ,
metavar = ' executable-path ' ,
help = ' The path to the lldb executable ' )
2018-03-09 03:46:39 +08:00
group . add_argument (
' --out-of-tree-debugserver ' ,
dest = ' out_of_tree_debugserver ' ,
action = ' store_true ' ,
help = ' A flag to indicate an out-of-tree debug server is being used ' )
2019-08-20 00:04:21 +08:00
group . add_argument (
' --dwarf-version ' ,
metavar = ' dwarf_version ' ,
dest = ' dwarf_version ' ,
type = int ,
help = ' Override the DWARF version. ' )
2020-01-15 04:34:13 +08:00
group . add_argument (
' --setting ' ,
metavar = ' SETTING=VALUE ' ,
dest = ' settings ' ,
type = str ,
nargs = 1 ,
action = ' append ' ,
help = ' Run " setting set SETTING VALUE " before executing any test. ' )
2015-05-19 03:40:54 +08:00
group . add_argument (
' -y ' ,
type = int ,
metavar = ' count ' ,
help = " Specify the iteration count used to collect our benchmarks. An example is the number of times to do ' thread step-over ' to measure stepping speed. " )
group . add_argument (
' -# ' ,
type = int ,
metavar = ' sharp ' ,
dest = ' sharp ' ,
help = ' Repeat the test suite for a specified number of times ' )
group . add_argument ( ' --channel ' , metavar = ' channel ' , dest = ' channels ' , action = ' append ' , help = textwrap . dedent (
" Specify the log channels (and optional categories) e.g. ' lldb all ' or ' gdb-remote packets ' if no categories are specified, ' default ' is used " ) )
group . add_argument (
' --log-success ' ,
dest = ' log_success ' ,
action = ' store_true ' ,
help = " Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.) " )
2016-10-22 06:13:55 +08:00
group . add_argument (
' --codesign-identity ' ,
metavar = ' Codesigning identity ' ,
default = ' lldb_codesign ' ,
help = ' The codesigning identity to use ' )
2018-01-31 02:29:16 +08:00
group . add_argument (
' --build-dir ' ,
dest = ' test_build_dir ' ,
metavar = ' Test build directory ' ,
2018-02-03 02:32:29 +08:00
default = ' lldb-test-build.noindex ' ,
2018-01-31 02:29:16 +08:00
help = ' The root build directory for the tests. It will be removed before running. ' )
2019-08-30 02:37:05 +08:00
group . add_argument (
2019-10-11 01:27:09 +08:00
' --lldb-module-cache-dir ' ,
dest = ' lldb_module_cache_dir ' ,
2019-08-30 02:37:05 +08:00
metavar = ' The clang module cache directory used by LLDB ' ,
2019-10-11 01:27:09 +08:00
help = ' The clang module cache directory used by LLDB. Defaults to <test build directory>/module-cache-lldb. ' )
group . add_argument (
' --clang-module-cache-dir ' ,
dest = ' clang_module_cache_dir ' ,
metavar = ' The clang module cache directory used by Clang ' ,
help = ' The clang module cache directory used in the Make files by Clang while building tests. Defaults to <test build directory>/module-cache-clang. ' )
2020-01-31 16:35:34 +08:00
group . add_argument (
' --lldb-libs-dir ' ,
dest = ' lldb_libs_dir ' ,
metavar = ' path ' ,
help = ' The path to LLDB library directory (containing liblldb) ' )
2020-04-04 10:42:58 +08:00
group . add_argument (
' --enable-plugin ' ,
dest = ' enabled_plugins ' ,
action = ' append ' ,
type = str ,
metavar = ' A plugin whose tests will be enabled ' ,
help = ' A plugin whose tests will be enabled. The only currently supported plugin is intel-pt. ' )
2015-05-19 03:40:54 +08:00
# Configuration options
group = parser . add_argument_group ( ' Remote platform options ' )
group . add_argument (
' --platform-name ' ,
dest = ' lldb_platform_name ' ,
metavar = ' platform-name ' ,
help = ' The name of a remote platform to use ' )
group . add_argument (
' --platform-url ' ,
dest = ' lldb_platform_url ' ,
metavar = ' platform-url ' ,
help = ' A LLDB platform URL to use when connecting to a remote platform to run the test suite ' )
group . add_argument (
' --platform-working-dir ' ,
dest = ' lldb_platform_working_dir ' ,
metavar = ' platform-working-dir ' ,
help = ' The directory to use on the remote platform. ' )
# Test-suite behaviour
group = parser . add_argument_group ( ' Runtime behaviour options ' )
X ( ' -d ' , ' Suspend the process after launch to wait indefinitely for a debugger to attach ' )
X ( ' -t ' , ' Turn on tracing of lldb command and other detailed test executions ' )
group . add_argument (
' -u ' ,
dest = ' unset_env_varnames ' ,
metavar = ' variable ' ,
action = ' append ' ,
help = ' Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble ' )
group . add_argument (
' --env ' ,
dest = ' set_env_vars ' ,
metavar = ' variable ' ,
action = ' append ' ,
help = ' Specify an environment variable to set to the given value before running the test cases e.g.: --env CXXFLAGS=-O3 --env DYLD_INSERT_LIBRARIES ' )
2019-06-27 00:12:08 +08:00
group . add_argument (
' --inferior-env ' ,
dest = ' set_inferior_env_vars ' ,
metavar = ' variable ' ,
action = ' append ' ,
help = ' Specify an environment variable to set to the given value for the inferior. ' )
2015-05-19 03:40:54 +08:00
X ( ' -v ' , ' Do verbose mode of unittest framework (print out each test case invocation) ' )
group . add_argument (
' --enable-crash-dialog ' ,
dest = ' disable_crash_dialog ' ,
action = ' store_false ' ,
help = ' (Windows only) When LLDB crashes, display the Windows crash dialog. ' )
group . set_defaults ( disable_crash_dialog = True )
# Remove the reference to our helper function
del X
group = parser . add_argument_group ( ' Test directories ' )
group . add_argument (
' args ' ,
metavar = ' test-dir ' ,
nargs = ' * ' ,
help = ' Specify a list of directory names to search for test modules named after Test*.py (test discovery). If empty, search from the current working directory instead. ' )
2015-05-23 03:49:23 +08:00
return parser