teak-llvm/lldb/packages/Python/lldbsuite/test/functionalities/thread/jump/TestThreadJump.py
Zachary Turner 95c453a221 Tighten up sys.path, and use absolute imports everywhere.
For convenience, we had added the folder that dotest.py was in
to sys.path, so that we could easily write things like
`import lldbutil` from anywhere and any test.  This introduces
a subtle problem when using Python's package system, because when
unittest2 imports a particular test suite, the test suite is detached
from the package.  Thus, writing "import lldbutil" from dotest imports
it as part of the package, and writing the same line from a test
does a fresh import since the importing module was not part of
the same package.

The real way to fix this is to use absolute imports everywhere.  Instead
of writing "import lldbutil", we need to write "import
lldbsuite.test.util".  This patch fixes up that and all other similar
cases, and additionally removes the script directory from sys.path
to ensure that this can't happen again.

llvm-svn: 251886
2015-11-03 02:06:18 +00:00

61 lines
2.6 KiB
Python

"""
Test jumping to different places.
"""
from __future__ import print_function
import use_lldb_suite
import os, time
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class ThreadJumpTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def test(self):
"""Test thread jump handling."""
self.build(dictionary=self.getBuildFlags())
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Find the line numbers for our breakpoints.
self.mark1 = line_number('main.cpp', '// 1st marker')
self.mark2 = line_number('main.cpp', '// 2nd marker')
self.mark3 = line_number('main.cpp', '// 3rd marker')
self.mark4 = line_number('main.cpp', '// 4th marker')
self.mark5 = line_number('other.cpp', '// other marker')
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.mark3, num_expected_locations=1)
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint 1.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1",
substrs = ['stopped',
'* thread #1',
'stop reason = breakpoint 1'])
self.do_min_test(self.mark3, self.mark1, "i", "4"); # Try the int path, force it to return 'a'
self.do_min_test(self.mark3, self.mark2, "i", "5"); # Try the int path, force it to return 'b'
self.do_min_test(self.mark4, self.mark1, "j", "7"); # Try the double path, force it to return 'a'
self.do_min_test(self.mark4, self.mark2, "j", "8"); # Try the double path, force it to return 'b'
# Try jumping to another function in a different file.
self.runCmd("thread jump --file other.cpp --line %i --force" % self.mark5)
self.expect("process status",
substrs = ["at other.cpp:%i" % self.mark5])
# Try jumping to another function (without forcing)
self.expect("j main.cpp:%i" % self.mark1, COMMAND_FAILED_AS_EXPECTED, error = True,
substrs = ["error"])
def do_min_test(self, start, jump, var, value):
self.runCmd("j %i" % start) # jump to the start marker
self.runCmd("thread step-in") # step into the min fn
self.runCmd("j %i" % jump) # jump to the branch we're interested in
self.runCmd("thread step-out") # return out
self.runCmd("thread step-over") # assign to the global
self.expect("expr %s" % var, substrs = [value]) # check it