2015-10-20 07:45:41 +08:00
|
|
|
from __future__ import print_function
|
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
|
2014-10-17 07:15:22 +08:00
|
|
|
import os
|
|
|
|
|
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
|
|
|
# Third-party modules
|
2019-02-20 08:54:07 +08:00
|
|
|
import io
|
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
|
|
|
|
import lldb
|
|
|
|
from .lldbtest import *
|
2016-05-26 21:57:03 +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
|
|
|
from . import lldbutil
|
2016-02-05 07:04:17 +08:00
|
|
|
from .decorators import *
|
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
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
def source_type(filename):
|
|
|
|
_, extension = os.path.splitext(filename)
|
|
|
|
return {
|
|
|
|
'.c': 'C_SOURCES',
|
|
|
|
'.cpp': 'CXX_SOURCES',
|
|
|
|
'.cxx': 'CXX_SOURCES',
|
|
|
|
'.cc': 'CXX_SOURCES',
|
|
|
|
'.m': 'OBJC_SOURCES',
|
|
|
|
'.mm': 'OBJCXX_SOURCES'
|
|
|
|
}.get(extension, None)
|
|
|
|
|
2016-01-07 03:16:45 +08:00
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
class CommandParser:
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.breakpoints = []
|
|
|
|
|
|
|
|
def parse_one_command(self, line):
|
|
|
|
parts = line.split('//%')
|
2014-10-17 08:39:37 +08:00
|
|
|
|
|
|
|
command = None
|
|
|
|
new_breakpoint = True
|
|
|
|
|
|
|
|
if len(parts) == 2:
|
2016-01-07 03:16:45 +08:00
|
|
|
command = parts[1].strip() # take off whitespace
|
2014-10-17 08:39:37 +08:00
|
|
|
new_breakpoint = parts[0].strip() != ""
|
|
|
|
|
|
|
|
return (command, new_breakpoint)
|
2014-10-17 07:15:22 +08:00
|
|
|
|
|
|
|
def parse_source_files(self, source_files):
|
|
|
|
for source_file in source_files:
|
2019-02-20 08:54:07 +08:00
|
|
|
file_handle = io.open(source_file, encoding='utf-8')
|
2014-10-17 07:15:22 +08:00
|
|
|
lines = file_handle.readlines()
|
|
|
|
line_number = 0
|
2014-10-17 08:39:37 +08:00
|
|
|
# non-NULL means we're looking through whitespace to find
|
|
|
|
# additional commands
|
|
|
|
current_breakpoint = None
|
2014-10-17 07:15:22 +08:00
|
|
|
for line in lines:
|
|
|
|
line_number = line_number + 1 # 1-based, so we do this first
|
2014-10-17 08:39:37 +08:00
|
|
|
(command, new_breakpoint) = self.parse_one_command(line)
|
|
|
|
|
|
|
|
if new_breakpoint:
|
|
|
|
current_breakpoint = None
|
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
if command is not None:
|
2014-10-17 08:39:37 +08:00
|
|
|
if current_breakpoint is None:
|
|
|
|
current_breakpoint = {}
|
|
|
|
current_breakpoint['file_name'] = source_file
|
|
|
|
current_breakpoint['line_number'] = line_number
|
|
|
|
current_breakpoint['command'] = command
|
|
|
|
self.breakpoints.append(current_breakpoint)
|
|
|
|
else:
|
|
|
|
current_breakpoint['command'] = current_breakpoint[
|
|
|
|
'command'] + "\n" + command
|
2014-10-17 07:15:22 +08:00
|
|
|
|
|
|
|
def set_breakpoints(self, target):
|
|
|
|
for breakpoint in self.breakpoints:
|
|
|
|
breakpoint['breakpoint'] = target.BreakpointCreateByLocation(
|
|
|
|
breakpoint['file_name'], breakpoint['line_number'])
|
|
|
|
|
|
|
|
def handle_breakpoint(self, test, breakpoint_id):
|
|
|
|
for breakpoint in self.breakpoints:
|
|
|
|
if breakpoint['breakpoint'].GetID() == breakpoint_id:
|
|
|
|
test.execute_user_command(breakpoint['command'])
|
|
|
|
return
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-01-08 06:25:50 +08:00
|
|
|
class InlineTest(TestBase):
|
|
|
|
# Internal implementation
|
2014-12-20 02:26:33 +08:00
|
|
|
|
2015-01-08 06:25:50 +08:00
|
|
|
def BuildMakefile(self):
|
2018-01-31 02:29:16 +08:00
|
|
|
makefilePath = self.getBuildArtifact("Makefile")
|
|
|
|
if os.path.exists(makefilePath):
|
2016-06-08 05:29:46 +08:00
|
|
|
return
|
|
|
|
|
2015-01-08 06:25:50 +08:00
|
|
|
categories = {}
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2018-01-31 02:29:16 +08:00
|
|
|
for f in os.listdir(self.getSourceDir()):
|
2015-01-08 06:25:50 +08:00
|
|
|
t = source_type(f)
|
|
|
|
if t:
|
2015-10-24 01:53:51 +08:00
|
|
|
if t in list(categories.keys()):
|
2015-01-08 06:25:50 +08:00
|
|
|
categories[t].append(f)
|
|
|
|
else:
|
|
|
|
categories[t] = [f]
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2018-01-31 02:29:16 +08:00
|
|
|
makefile = open(makefilePath, 'w+')
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2015-10-24 01:53:51 +08:00
|
|
|
for t in list(categories.keys()):
|
2015-01-08 06:25:50 +08:00
|
|
|
line = t + " := " + " ".join(categories[t])
|
|
|
|
makefile.write(line + "\n")
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2015-10-24 01:53:51 +08:00
|
|
|
if ('OBJCXX_SOURCES' in list(categories.keys())) or (
|
|
|
|
'OBJC_SOURCES' in list(categories.keys())):
|
2015-01-08 06:25:50 +08:00
|
|
|
makefile.write(
|
|
|
|
"LDFLAGS = $(CFLAGS) -lobjc -framework Foundation\n")
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2015-10-24 01:53:51 +08:00
|
|
|
if ('CXX_SOURCES' in list(categories.keys())):
|
2015-01-08 06:25:50 +08:00
|
|
|
makefile.write("CXXFLAGS += -std=c++11\n")
|
2014-10-17 07:15:22 +08:00
|
|
|
|
[dotest] Avoid the need for LEVEL= makefile boilerplate
Summary:
Instead of each test case knowing its depth relative to the test root,
we can just have dotest add the folder containing Makefile.rules to the
include path.
This was motivated by r370616, though I have been wanting to do this
ever since we moved to building tests out-of-tree.
The only manually modified files in this patch are lldbinline.py and
plugins/builder_base.py. The rest of the patch has been produced by this
shell command:
find . \( -name Makefile -o -name '*.mk' \) -exec sed --in-place -e '/LEVEL *:\?=/d' -e '1,2{/^$/d}' -e 's,\$(LEVEL)/,,' {} +
Reviewers: teemperor, aprantl, espindola, jfb
Subscribers: emaste, javed.absar, arichardson, christof, arphaman, lldb-commits
Differential Revision: https://reviews.llvm.org/D67083
llvm-svn: 370845
2019-09-04 15:46:25 +08:00
|
|
|
makefile.write("include Makefile.rules\n")
|
2016-01-26 09:15:57 +08:00
|
|
|
makefile.write("\ncleanup:\n\trm -f Makefile *.d\n\n")
|
2015-01-08 06:25:50 +08:00
|
|
|
makefile.flush()
|
|
|
|
makefile.close()
|
2014-10-17 07:15:22 +08:00
|
|
|
|
2018-06-05 18:58:44 +08:00
|
|
|
def _test(self):
|
2015-01-08 06:25:50 +08:00
|
|
|
self.BuildMakefile()
|
2018-01-31 02:29:16 +08:00
|
|
|
self.build()
|
2014-10-17 07:15:22 +08:00
|
|
|
self.do_test()
|
2016-05-26 21:57:03 +08:00
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
def execute_user_command(self, __command):
|
2015-11-07 05:37:21 +08:00
|
|
|
exec(__command, globals(), locals())
|
2014-10-17 07:15:22 +08:00
|
|
|
|
|
|
|
def do_test(self):
|
2018-01-20 07:24:35 +08:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2018-01-31 02:29:16 +08:00
|
|
|
source_files = [f for f in os.listdir(self.getSourceDir())
|
|
|
|
if source_type(f)]
|
2014-10-17 07:15:22 +08:00
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
|
|
|
|
|
|
parser = CommandParser()
|
|
|
|
parser.parse_source_files(source_files)
|
|
|
|
parser.set_breakpoints(target)
|
|
|
|
|
2018-02-28 06:45:49 +08:00
|
|
|
process = target.LaunchSimple(None, None, self.get_process_working_directory())
|
2020-03-26 20:03:27 +08:00
|
|
|
self.assertIsNotNone(process, PROCESS_IS_VALID)
|
|
|
|
|
2018-02-27 06:40:20 +08:00
|
|
|
hit_breakpoints = 0
|
2014-10-17 07:15:22 +08:00
|
|
|
|
|
|
|
while lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint):
|
2018-02-27 06:40:20 +08:00
|
|
|
hit_breakpoints += 1
|
2014-10-17 07:15:22 +08:00
|
|
|
thread = lldbutil.get_stopped_thread(
|
|
|
|
process, lldb.eStopReasonBreakpoint)
|
|
|
|
breakpoint_id = thread.GetStopReasonDataAtIndex(0)
|
|
|
|
parser.handle_breakpoint(self, breakpoint_id)
|
|
|
|
process.Continue()
|
|
|
|
|
2018-02-27 06:40:20 +08:00
|
|
|
self.assertTrue(hit_breakpoints > 0,
|
|
|
|
"inline test did not hit a single breakpoint")
|
|
|
|
# Either the process exited or the stepping plan is complete.
|
|
|
|
self.assertTrue(process.GetState() in [lldb.eStateStopped,
|
|
|
|
lldb.eStateExited],
|
|
|
|
PROCESS_EXITED)
|
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
# Utilities for testcases
|
|
|
|
|
|
|
|
def check_expression(self, expression, expected_result, use_summary=True):
|
|
|
|
value = self.frame().EvaluateExpression(expression)
|
|
|
|
self.assertTrue(value.IsValid(), expression + "returned a valid value")
|
|
|
|
if self.TraceOn():
|
2015-10-20 07:45:41 +08:00
|
|
|
print(value.GetSummary())
|
|
|
|
print(value.GetValue())
|
2014-10-17 07:15:22 +08:00
|
|
|
if use_summary:
|
|
|
|
answer = value.GetSummary()
|
|
|
|
else:
|
|
|
|
answer = value.GetValue()
|
|
|
|
report_str = "%s expected: %s got: %s" % (
|
|
|
|
expression, expected_result, answer)
|
|
|
|
self.assertTrue(answer == expected_result, report_str)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-29 04:23:20 +08:00
|
|
|
def ApplyDecoratorsToFunction(func, decorators):
|
|
|
|
tmp = func
|
|
|
|
if isinstance(decorators, list):
|
|
|
|
for decorator in decorators:
|
|
|
|
tmp = decorator(tmp)
|
|
|
|
elif hasattr(decorators, '__call__'):
|
|
|
|
tmp = decorators(tmp)
|
|
|
|
return tmp
|
2016-05-05 07:32:35 +08:00
|
|
|
|
2014-10-29 04:23:20 +08:00
|
|
|
|
|
|
|
def MakeInlineTest(__file, __globals, decorators=None):
|
2016-04-19 04:26:56 +08:00
|
|
|
# Adjust the filename if it ends in .pyc. We want filenames to
|
|
|
|
# reflect the source python file, not the compiled variant.
|
|
|
|
if __file is not None and __file.endswith(".pyc"):
|
|
|
|
# Strip the trailing "c"
|
|
|
|
__file = __file[0:-1]
|
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
# Derive the test name from the current file name
|
|
|
|
file_basename = os.path.basename(__file)
|
|
|
|
|
|
|
|
test_name, _ = os.path.splitext(file_basename)
|
2018-06-05 18:58:44 +08:00
|
|
|
|
|
|
|
test_func = ApplyDecoratorsToFunction(InlineTest._test, decorators)
|
2016-05-05 07:32:35 +08:00
|
|
|
# Build the test case
|
2018-06-05 18:58:44 +08:00
|
|
|
test_class = type(test_name, (InlineTest,), dict(test=test_func, name=test_name))
|
2014-10-29 04:23:20 +08:00
|
|
|
|
2014-10-17 07:15:22 +08:00
|
|
|
# Add the test case to the globals, and hide InlineTest
|
2018-06-05 18:58:44 +08:00
|
|
|
__globals.update({test_name: test_class})
|
2015-12-23 01:14:47 +08:00
|
|
|
|
2016-04-19 04:26:56 +08:00
|
|
|
# Keep track of the original test filename so we report it
|
|
|
|
# correctly in test results.
|
2018-06-05 18:58:44 +08:00
|
|
|
test_class.test_filename = __file
|
2018-09-26 04:20:13 +08:00
|
|
|
test_class.mydir = TestBase.compute_mydir(__file)
|
2018-06-05 18:58:44 +08:00
|
|
|
return test_class
|