2015-10-24 01:04:29 +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-24 01:04:29 +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-02-03 06:12:39 +08:00
|
|
|
import os
|
|
|
|
import sys
|
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
|
2016-01-28 02:49:25 +08:00
|
|
|
import six
|
2015-02-03 06:12:39 +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
|
|
|
# LLDB Modules
|
|
|
|
import lldb
|
|
|
|
from .lldbtest import *
|
|
|
|
from . import lldbutil
|
|
|
|
|
2016-01-28 02:49:25 +08:00
|
|
|
if sys.platform.startswith('win32'):
|
|
|
|
class PExpectTest(TestBase):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
import pexpect
|
|
|
|
|
|
|
|
class PExpectTest(TestBase):
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-01-28 02:49:25 +08:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2016-01-28 02:49:25 +08:00
|
|
|
def setUp(self):
|
|
|
|
TestBase.setUp(self)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2016-01-28 02:49:25 +08:00
|
|
|
def launchArgs(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def launch(self, timeout=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
if timeout is None:
|
|
|
|
timeout = 30
|
2016-01-28 02:49:25 +08:00
|
|
|
logfile = sys.stdout if self.TraceOn() else None
|
2016-09-07 04:57:50 +08:00
|
|
|
self.child = pexpect.spawn(
|
|
|
|
'%s --no-use-colors %s' %
|
|
|
|
(lldbtest_config.lldbExec, self.launchArgs()), logfile=logfile)
|
2016-01-28 02:49:25 +08:00
|
|
|
self.child.timeout = timeout
|
|
|
|
self.timeout = timeout
|
|
|
|
|
|
|
|
def expect(self, patterns=None, timeout=None, exact=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
if patterns is None:
|
|
|
|
return None
|
|
|
|
if timeout is None:
|
|
|
|
timeout = self.timeout
|
|
|
|
if exact is None:
|
|
|
|
exact = False
|
2016-01-28 02:49:25 +08:00
|
|
|
if exact:
|
|
|
|
return self.child.expect_exact(patterns, timeout=timeout)
|
|
|
|
else:
|
|
|
|
return self.child.expect(patterns, timeout=timeout)
|
|
|
|
|
|
|
|
def expectall(self, patterns=None, timeout=None, exact=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
if patterns is None:
|
|
|
|
return None
|
|
|
|
if timeout is None:
|
|
|
|
timeout = self.timeout
|
|
|
|
if exact is None:
|
|
|
|
exact = False
|
2016-01-28 02:49:25 +08:00
|
|
|
for pattern in patterns:
|
|
|
|
self.expect(pattern, timeout=timeout, exact=exact)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
def sendimpl(
|
|
|
|
self,
|
|
|
|
sender,
|
|
|
|
command,
|
|
|
|
patterns=None,
|
|
|
|
timeout=None,
|
|
|
|
exact=None):
|
2016-01-28 02:49:25 +08:00
|
|
|
sender(command)
|
|
|
|
return self.expect(patterns=patterns, timeout=timeout, exact=exact)
|
|
|
|
|
|
|
|
def send(self, command, patterns=None, timeout=None, exact=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
return self.sendimpl(
|
|
|
|
self.child.send,
|
|
|
|
command,
|
|
|
|
patterns,
|
|
|
|
timeout,
|
|
|
|
exact)
|
2016-01-28 02:49:25 +08:00
|
|
|
|
|
|
|
def sendline(self, command, patterns=None, timeout=None, exact=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
return self.sendimpl(
|
|
|
|
self.child.sendline,
|
|
|
|
command,
|
|
|
|
patterns,
|
|
|
|
timeout,
|
|
|
|
exact)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2016-01-28 02:49:25 +08:00
|
|
|
def quit(self, gracefully=None):
|
2016-09-07 04:57:50 +08:00
|
|
|
if gracefully is None:
|
|
|
|
gracefully = True
|
2016-01-28 02:49:25 +08:00
|
|
|
self.child.sendeof()
|
|
|
|
self.child.close(force=not gracefully)
|
|
|
|
self.child = None
|