[Lldb-commits] [lldb] 54c2687 - [lldb] Introduce createTestTarget for creating a valid target in API tests

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon May 24 07:19:26 PDT 2021


Author: Raphael Isemann
Date: 2021-05-24T16:18:44+02:00
New Revision: 54c2687292da54a2d7964a47b0e334155385f084

URL: https://github.com/llvm/llvm-project/commit/54c2687292da54a2d7964a47b0e334155385f084
DIFF: https://github.com/llvm/llvm-project/commit/54c2687292da54a2d7964a47b0e334155385f084.diff

LOG: [lldb] Introduce createTestTarget for creating a valid target in API tests

At the moment nearly every test calls something similar to
`self.dbg.CreateTarget(self.getBuildArtifact("a.out"))` and them sometimes
checks if the created target is actually valid with something like
`self.assertTrue(target.IsValid(), "some useless text")`.

Beside being really verbose the error messages generated by this pattern are
always just indicating that the target failed to be created but now why.

This patch introduces a helper function `createTestTarget` to our Test class
that creates the target with the much more verbose `CreateTarget` overload that
gives us back an SBError (with a fancy error). If the target couldn't be created
the function prints out the SBError that LLDB returned and asserts for us. It
also defaults to the "a.out" build artifact path that nearly all tests are using
to avoid to hardcode "a.out" in every test.

I converted a bunch of tests to the new function but I'll do the rest of the
test suite as follow ups.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D102771

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/test/API/android/platform/TestDefaultCacheLineSize.py
    lldb/test/API/api/listeners/TestListener.py
    lldb/test/API/assert_messages_test/TestAssertMessages.py
    lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py
    lldb/test/API/commands/expression/call-function/TestCallBuiltinFunction.py
    lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py
    lldb/test/API/commands/expression/completion/TestExprCompletion.py
    lldb/test/API/commands/expression/error-limit/TestExprErrorLimit.py
    lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py
    lldb/test/API/commands/expression/no-deadlock/TestExprDoesntBlock.py
    lldb/test/API/commands/expression/test/TestExprs.py
    lldb/test/API/commands/frame/language/TestGuessLanguage.py
    lldb/test/API/commands/frame/var/TestFrameVar.py
    lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
    lldb/test/API/commands/process/launch/TestProcessLaunch.py
    lldb/test/API/commands/register/register/register_command/TestRegisters.py
    lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
    lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py
    lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
    lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
    lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
    lldb/test/API/functionalities/asan/TestMemoryHistory.py
    lldb/test/API/functionalities/asan/TestReportData.py
    lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
    lldb/test/API/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
    lldb/test/API/functionalities/breakpoint/breakpoint_by_file_colon_line/TestBreakpointByFileColonLine.py
    lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
    lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
    lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
    lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
    lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
    lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py
    lldb/test/API/sample_test/TestSampleTest.py
    lldb/test/API/sample_test/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 77b1eb3a1567a..7c0f01add8f07 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2654,6 +2654,31 @@ def assertSuccess(self, obj, msg=None):
             self.fail(self._formatMessage(msg,
                 "'{}' is not success".format(error)))
 
+    def createTestTarget(self, file_path=None, msg=None):
+        """
+        Creates a target from the file found at the given file path.
+        Asserts that the resulting target is valid.
+        :param file_path: The file path that should be used to create the target.
+                          The default argument opens the current default test
+                          executable in the current test directory.
+        :param msg: A custom error message.
+        """
+        if file_path is None:
+            file_path = self.getBuildArtifact("a.out")
+        error = lldb.SBError()
+        triple = ""
+        platform = ""
+        load_dependent_modules = True
+        target = self.dbg.CreateTarget(file_path, triple, platform,
+                                       load_dependent_modules, error)
+        if error.Fail():
+            err = "Couldn't create target for path '{}': {}".format(file_path,
+                                                                    str(error))
+            self.fail(self._formatMessage(msg, err))
+
+        self.assertTrue(target.IsValid(), "Got invalid target without error")
+        return target
+
     # =================================================
     # Misc. helper methods for debugging test execution
     # =================================================

diff  --git a/lldb/test/API/android/platform/TestDefaultCacheLineSize.py b/lldb/test/API/android/platform/TestDefaultCacheLineSize.py
index 0a5475c6749ff..eccc002f1d559 100644
--- a/lldb/test/API/android/platform/TestDefaultCacheLineSize.py
+++ b/lldb/test/API/android/platform/TestDefaultCacheLineSize.py
@@ -17,8 +17,7 @@ class DefaultCacheLineSizeTestCase(TestBase):
     @skipUnlessTargetAndroid
     def test_cache_line_size(self):
         self.build(dictionary=self.getBuildFlags())
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
         self.assertTrue(target and target.IsValid(), "Target is valid")
 
         breakpoint = target.BreakpointCreateByName("main")

diff  --git a/lldb/test/API/api/listeners/TestListener.py b/lldb/test/API/api/listeners/TestListener.py
index 2bd60fe00ecc8..2f77ea2c44f9f 100644
--- a/lldb/test/API/api/listeners/TestListener.py
+++ b/lldb/test/API/api/listeners/TestListener.py
@@ -35,11 +35,9 @@ def test_clearing_listener(self):
             lldb.SBTarget.GetBroadcasterClassName(),
             lldb.SBTarget.eBroadcastBitModulesUnloaded)
 
-        exe = self.getBuildArtifact("a.out")
-
         my_listener.Clear()
 
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
 
         bkpt = target.BreakpointCreateByName("main")
 
@@ -58,9 +56,7 @@ def test_receiving_breakpoint_added_from_debugger(self):
             lldb.SBTarget.GetBroadcasterClassName(),
             lldb.SBTarget.eBroadcastBitBreakpointChanged)
 
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
 
         bkpt = target.BreakpointCreateByName("main")
 
@@ -100,9 +96,7 @@ def test_recieving_breakpoint_added_from_target(self):
             lldb.SBTarget.GetBroadcasterClassName(),
             lldb.SBTarget.eBroadcastBitBreakpointChanged)
 
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
         result = target.GetBroadcaster().AddListener(my_listener,
                                                      lldb.SBTarget.eBroadcastBitBreakpointChanged)
         self.assertEqual(result, lldb.SBTarget.eBroadcastBitBreakpointChanged,"Got our bit")

diff  --git a/lldb/test/API/assert_messages_test/TestAssertMessages.py b/lldb/test/API/assert_messages_test/TestAssertMessages.py
index f8b6b33f297c3..93b4087aab2a4 100644
--- a/lldb/test/API/assert_messages_test/TestAssertMessages.py
+++ b/lldb/test/API/assert_messages_test/TestAssertMessages.py
@@ -24,6 +24,15 @@ def assert_expect_fails_with(self, cmd, expect_args, expected_msg):
         else:
             self.fail("Initial expect should have raised AssertionError!")
 
+    def test_createTestTarget(self):
+        try:
+           self.createTestTarget("doesnt_exist")
+        except AssertionError as e:
+           self.assertIn("Couldn't create target for path 'doesnt_exist': "
+                         "error: unable to find executable for 'doesnt_exist'",
+                         str(e))
+
+
     def test_expect(self):
         """Test format of messages produced by expect(...)"""
 

diff  --git a/lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py b/lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py
index c915c752bf51c..e76cbd8d61380 100644
--- a/lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py
+++ b/lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py
@@ -22,11 +22,8 @@ def test_frame_disassemble(self):
 
     def frame_disassemble_test(self):
         """Sample test to ensure SBFrame::Disassemble produces SOME output"""
-        exe = self.getBuildArtifact("a.out")
-
         # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint in main.c at the source matching
         # "Set a breakpoint here"

diff  --git a/lldb/test/API/commands/expression/call-function/TestCallBuiltinFunction.py b/lldb/test/API/commands/expression/call-function/TestCallBuiltinFunction.py
index 55ba2717c013b..4fd5cd6eddd5a 100644
--- a/lldb/test/API/commands/expression/call-function/TestCallBuiltinFunction.py
+++ b/lldb/test/API/commands/expression/call-function/TestCallBuiltinFunction.py
@@ -20,7 +20,7 @@ class ExprCommandCallBuiltinFunction(TestBase):
     def test(self):
         self.build()
 
-        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        target = self.createTestTarget()
 
         self.expect_expr("__builtin_isinf(0.0f)", result_type="int", result_value="0")
         self.expect_expr("__builtin_isnormal(0.0f)", result_type="int", result_value="0")

diff  --git a/lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py b/lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py
index 999a15cd42f36..18897e5cd2026 100644
--- a/lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py
+++ b/lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py
@@ -10,8 +10,7 @@ class TestCase(TestBase):
     @skipIf # rdar://problem/53931074
     def test(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
         callee_break = target.BreakpointCreateByName(
             "SomeClass::SomeClass(ParamClass)", None)
         self.assertTrue(callee_break.GetNumLocations() > 0)

diff  --git a/lldb/test/API/commands/expression/completion/TestExprCompletion.py b/lldb/test/API/commands/expression/completion/TestExprCompletion.py
index 9ff9052bb3fc2..7c5fb4cffa235 100644
--- a/lldb/test/API/commands/expression/completion/TestExprCompletion.py
+++ b/lldb/test/API/commands/expression/completion/TestExprCompletion.py
@@ -19,7 +19,7 @@ def test_expr_completion(self):
         self.build()
         self.main_source = "main.cpp"
         self.main_source_spec = lldb.SBFileSpec(self.main_source)
-        self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        self.createTestTarget()
 
         # Try the completion before we have a context to complete on.
         self.assume_no_completions('expr some_expr')
@@ -195,7 +195,7 @@ def test_expr_completion_with_descriptions(self):
         self.build()
         self.main_source = "main.cpp"
         self.main_source_spec = lldb.SBFileSpec(self.main_source)
-        self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        self.createTestTarget()
 
         (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
                                           '// Break here', self.main_source_spec)

diff  --git a/lldb/test/API/commands/expression/error-limit/TestExprErrorLimit.py b/lldb/test/API/commands/expression/error-limit/TestExprErrorLimit.py
index 30e003787ec5d..c940edbb90c53 100644
--- a/lldb/test/API/commands/expression/error-limit/TestExprErrorLimit.py
+++ b/lldb/test/API/commands/expression/error-limit/TestExprErrorLimit.py
@@ -17,7 +17,7 @@ def test(self):
         # FIXME: The only reason this test needs to create a real target is because
         # the settings of the dummy target can't be changed with `settings set`.
         self.build()
-        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+        target = self.createTestTarget()
 
         # Our test expression that is just several lines of malformed
         # integer literals (with a 'yerror' integer suffix). Every error

diff  --git a/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py b/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py
index a8ed94791463a..9083c51376f1b 100644
--- a/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py
+++ b/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py
@@ -20,11 +20,8 @@ def test_setpgid(self):
         self.expr_syscall()
 
     def expr_syscall(self):
-        exe = self.getBuildArtifact("a.out")
-
         # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         listener = lldb.SBListener("my listener")
 

diff  --git a/lldb/test/API/commands/expression/no-deadlock/TestExprDoesntBlock.py b/lldb/test/API/commands/expression/no-deadlock/TestExprDoesntBlock.py
index 7c8f2c1f39f66..5cf39d304da84 100644
--- a/lldb/test/API/commands/expression/no-deadlock/TestExprDoesntBlock.py
+++ b/lldb/test/API/commands/expression/no-deadlock/TestExprDoesntBlock.py
@@ -20,11 +20,7 @@ class ExprDoesntDeadlockTestCase(TestBase):
     def test_with_run_command(self):
         """Test that expr will time out and allow other threads to run if it blocks."""
         self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint at source line before call_me_to_get_lock
         # gets called.

diff  --git a/lldb/test/API/commands/expression/test/TestExprs.py b/lldb/test/API/commands/expression/test/TestExprs.py
index e9f6ec1d3659b..caa1d66a1c78d 100644
--- a/lldb/test/API/commands/expression/test/TestExprs.py
+++ b/lldb/test/API/commands/expression/test/TestExprs.py
@@ -80,11 +80,7 @@ def test_many_expr_commands(self):
     def test_evaluate_expression_python(self):
         """Test SBFrame.EvaluateExpression() API for evaluating an expression."""
         self.build()
-
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Create the breakpoint.
         filespec = lldb.SBFileSpec("main.cpp", False)

diff  --git a/lldb/test/API/commands/frame/language/TestGuessLanguage.py b/lldb/test/API/commands/frame/language/TestGuessLanguage.py
index 0974a0e1f858b..f20f184e3910b 100644
--- a/lldb/test/API/commands/frame/language/TestGuessLanguage.py
+++ b/lldb/test/API/commands/frame/language/TestGuessLanguage.py
@@ -34,11 +34,7 @@ def check_language(self, thread, frame_no, test_lang):
 
     def do_test(self):
         """Test GuessLanguage for C & C++."""
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint in main.c at the source matching
         # "Set a breakpoint here"

diff  --git a/lldb/test/API/commands/frame/var/TestFrameVar.py b/lldb/test/API/commands/frame/var/TestFrameVar.py
index 6b67e41ab74c4..c325c65ca155e 100644
--- a/lldb/test/API/commands/frame/var/TestFrameVar.py
+++ b/lldb/test/API/commands/frame/var/TestFrameVar.py
@@ -23,11 +23,7 @@ def test_frame_var(self):
         self.do_test()
 
     def do_test(self):
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint in main.c at the source matching
         # "Set a breakpoint here"

diff  --git a/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py b/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
index cd7ca139f1355..dd7120326ca63 100644
--- a/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
+++ b/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
@@ -25,12 +25,7 @@ class LaunchWithShellExpandTestCase(TestBase):
     @expectedFailureNetBSD
     def test(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        self.runCmd("target create %s" % exe)
-
-        # Create the target
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
 
         # Create any breakpoints we need
         breakpoint = target.BreakpointCreateBySourceRegex(

diff  --git a/lldb/test/API/commands/process/launch/TestProcessLaunch.py b/lldb/test/API/commands/process/launch/TestProcessLaunch.py
index 7a1a9a1469995..b36a137557477 100644
--- a/lldb/test/API/commands/process/launch/TestProcessLaunch.py
+++ b/lldb/test/API/commands/process/launch/TestProcessLaunch.py
@@ -180,11 +180,10 @@ def test_environment_with_special_char(self):
         d = {'CXX_SOURCES': source}
         self.build(dictionary=d)
         self.setTearDownCleanup(d)
-        exe = self.getBuildArtifact("a.out")
 
         evil_var = 'INIT*MIDDLE}TAIL'
 
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
         main_source_spec = lldb.SBFileSpec(source)
         breakpoint = target.BreakpointCreateBySourceRegex(
             '// Set breakpoint here.', main_source_spec)

diff  --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index e91e2c5a42de8..5ec46c175e621 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -197,11 +197,7 @@ def write_and_read(self, frame, register, new_value, must_exist=True):
     # lldb/test/Shell/Register/x86*-fp-read.test.
     @skipUnlessDarwin
     def fp_special_purpose_register_read(self):
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Launch the process and stop.
         self.expect("run", PROCESS_STOPPED, substrs=['stopped'])
@@ -278,11 +274,7 @@ def fp_special_purpose_register_read(self):
                 1 << fstat_top_pointer_initial)
 
     def fp_register_write(self):
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Launch the process, stop at the entry point.
         error = lldb.SBError()

diff  --git a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
index d3fdb47605bd6..ce215b081ba51 100644
--- a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
+++ b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
@@ -18,8 +18,7 @@ def setUp(self):
     @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
     def testStartMultipleLiveThreads(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
 
         self.expect("b main")
         self.expect("b 6")
@@ -40,8 +39,7 @@ def testStartMultipleLiveThreads(self):
     @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
     def testStartMultipleLiveThreadsWithStops(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
+        target = self.createTestTarget()
 
         self.expect("b main")
         self.expect("b 6")

diff  --git a/lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py b/lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py
index 2186dd0a42ce2..7232070f6dd45 100644
--- a/lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py
+++ b/lldb/test/API/commands/watchpoints/multiple_hits/TestMultipleHits.py
@@ -19,9 +19,7 @@ class MultipleHitsTestCase(TestBase):
     @skipIfwatchOS
     def test(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target and target.IsValid(), VALID_TARGET)
+        target = self.createTestTarget()
 
         bp = target.BreakpointCreateByName("main")
         self.assertTrue(bp and bp.IsValid(), "Breakpoint is valid")

diff  --git a/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py b/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
index 4b59263147902..c602dafb2bebd 100644
--- a/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
+++ b/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
@@ -26,10 +26,7 @@ class TestStepOverWatchpoint(TestBase):
     def test(self):
         """Test stepping over watchpoints."""
         self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(self.target, VALID_TARGET)
+        target = self.createTestTarget()
 
         lldbutil.run_break_set_by_symbol(self, 'main')
 

diff  --git a/lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py b/lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
index bf8bc7af29aeb..9ba3cf362d863 100644
--- a/lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
+++ b/lldb/test/API/commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
@@ -25,12 +25,9 @@ def test_disable_enable_works (self):
     def do_test(self, test_enable):
         """Set a watchpoint, disable it and make sure it doesn't get hit."""
 
-        exe = self.getBuildArtifact("a.out")
         main_file_spec = lldb.SBFileSpec("main.c")
 
-        # Create a target by the debugger.
-        self.target = self.dbg.CreateTarget(exe)
-        self.assertTrue(self.target, VALID_TARGET)
+        self.target = self.createTestTarget()
 
         bkpt_before = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", main_file_spec)
         self.assertEqual(bkpt_before.GetNumLocations(),  1, "Failed setting the before breakpoint.")

diff  --git a/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py b/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
index dddac1db3dc5a..4698716d074b9 100644
--- a/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
+++ b/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
@@ -24,11 +24,7 @@ def setUp(self):
     def test_with_python_api(self):
         """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
         self.build()
-
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         self.main_source_spec = lldb.SBFileSpec(self.main_source)
 

diff  --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index 37c34984f43b2..2ba3a92c9b553 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -31,9 +31,7 @@ def setUp(self):
         self.line_breakpoint = line_number('main.c', '// break line')
 
     def asan_tests(self):
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         self.registerSanitizerLibrariesWithTarget(target)
 

diff  --git a/lldb/test/API/functionalities/asan/TestReportData.py b/lldb/test/API/functionalities/asan/TestReportData.py
index 70084592cc865..de51fb1724c84 100644
--- a/lldb/test/API/functionalities/asan/TestReportData.py
+++ b/lldb/test/API/functionalities/asan/TestReportData.py
@@ -34,9 +34,7 @@ def setUp(self):
         self.col_crash = 16
 
     def asan_tests(self):
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         self.registerSanitizerLibrariesWithTarget(target)
 

diff  --git a/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py b/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
index a7430700d4811..76842671571b2 100644
--- a/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
+++ b/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
@@ -22,11 +22,7 @@ def test_address_breakpoints(self):
 
     def address_breakpoints(self):
         """Test address breakpoints set with shared library of SBAddress work correctly."""
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateBySourceRegex(

diff  --git a/lldb/test/API/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py b/lldb/test/API/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
index 956bd03f386cf..797708a15a57a 100644
--- a/lldb/test/API/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
+++ b/lldb/test/API/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
@@ -32,9 +32,7 @@ def test_auto_continue_on_location(self):
 
     def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
                              pattern="Set a breakpoint here"):
-        exe = self.getBuildArtifact("a.out")
-        self.target = self.dbg.CreateTarget(exe)
-        self.assertTrue(self.target.IsValid(), "Target is not valid")
+        self.target = self.createTestTarget()
 
         extra_options_txt = "--auto-continue 1 "
         if additional_options:

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_by_file_colon_line/TestBreakpointByFileColonLine.py b/lldb/test/API/functionalities/breakpoint/breakpoint_by_file_colon_line/TestBreakpointByFileColonLine.py
index 011fcdce8da46..fa32a4de4b0e0 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_by_file_colon_line/TestBreakpointByFileColonLine.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_by_file_colon_line/TestBreakpointByFileColonLine.py
@@ -16,10 +16,7 @@ class BreakpointByLineAndColumnTestCase(TestBase):
 
     def testBreakpointSpecWithLine(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
         
         # This one should work:
         lldbutil.run_break_set_by_file_colon_line(self, "main.c:11", "main.c", 11, num_expected_locations = 1)
@@ -32,10 +29,7 @@ def testBreakpointSpecWithLine(self):
     @skipIf(compiler="gcc", compiler_version=['<', '7.1'])
     def testBreakpointByLine(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         main_c = lldb.SBFileSpec("main.c")
         lldbutil.run_break_set_by_file_colon_line(self, "main.c:11:50", "main.c", 11, num_expected_locations = 1)

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py b/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
index b9238480d5ae2..a419e5d650d0a 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
@@ -52,7 +52,6 @@ def testBreakpointByLine(self):
     @skipIf(compiler="gcc", compiler_version=['<', '7.1'])
     def testBreakpointByLineAndColumnNearestCode(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
 
         patterns = [
             "In the middle of a function name (col:42)",
@@ -67,10 +66,7 @@ def testBreakpointByLineAndColumnNearestCode(self):
             column = int(re.search('\(col:([0-9]+)\)', pattern).group(1))
             source_loc.append({'line':line, 'column':column})
 
-        # Create a target from the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
-
+        target = self.createTestTarget()
 
         for loc in source_loc:
             src_file = lldb.SBFileSpec("main.cpp")

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
index 69e8862808394..d7872ff71ce75 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
@@ -270,9 +270,7 @@ def breakpoint_command_script_parameters(self):
 
     def breakpoint_commands_on_creation(self):
         """Test that setting breakpoint commands when creating the breakpoint works"""
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target.IsValid(), "Created an invalid target.")
+        target = self.createTestTarget()
 
         # Add a breakpoint.
         lldbutil.run_break_set_by_file_and_line(
@@ -291,9 +289,7 @@ def breakpoint_commands_on_creation(self):
     def test_breakpoint_delete_disabled(self):
         """Test 'break delete --disabled' works"""
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target.IsValid(), "Created an invalid target.")
+        target = self.createTestTarget()
 
         bp_1 = target.BreakpointCreateByName("main")
         bp_2 = target.BreakpointCreateByName("not_here")

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
index 5a6e94da594d8..f8575cf9f04ab 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
@@ -36,11 +36,9 @@ def setUp(self):
         self.main_source_spec = lldb.SBFileSpec(self.main_source)
 
     def do_set_python_command_from_python(self):
-        exe = self.getBuildArtifact("a.out")
         error = lldb.SBError()
 
-        self.target = self.dbg.CreateTarget(exe)
-        self.assertTrue(self.target, VALID_TARGET)
+        self.target = self.createTestTarget()
 
         body_bkpt = self.target.BreakpointCreateBySourceRegex(
             "Set break point at this line.", self.main_source_spec)
@@ -144,12 +142,9 @@ def do_set_python_command_from_python(self):
         self.assertEquals("Not so fancy", side_effect.not_so_fancy)
 
     def do_bad_args_to_python_command(self):
-        exe = self.getBuildArtifact("a.out")
         error = lldb.SBError()
 
-        self.target = self.dbg.CreateTarget(exe)
-        self.assertTrue(self.target, VALID_TARGET)
-
+        self.target = self.createTestTarget()
 
         self.expect("command script import --allow-reload ./bktptcmd.py")
 

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py b/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
index 4e9a65222d5f2..00da4a8c97f92 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
@@ -118,11 +118,7 @@ def breakpoint_conditions(self, inline=False):
 
     def breakpoint_conditions_python(self):
         """Use Python APIs to set breakpoint conditions."""
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py b/lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
index 11f23ef69b754..3c635b253604f 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
@@ -24,10 +24,7 @@ def test_breakpoint_location_hit_count(self):
     def test_breakpoint_one_shot(self):
         """Check that one-shot breakpoints trigger only once."""
         self.build()
-
-        exe = self.getBuildArtifact("a.out")
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         self.runCmd("tb a")
         process = target.LaunchSimple(
@@ -56,10 +53,7 @@ def setUp(self):
 
     def do_test_breakpoint_location_hit_count(self):
         """Use Python APIs to check breakpoint hit count."""
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Create a breakpoint in main.cpp by name 'a',
         # there should be two locations.

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py b/lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py
index 4f1e35cda1148..c54584abab687 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_ignore_count/TestBreakpointIgnoreCount.py
@@ -99,11 +99,7 @@ def breakpoint_ignore_count(self):
 
     def breakpoint_ignore_count_python(self):
         """Use Python APIs to set breakpoint ignore count."""
-        exe = self.getBuildArtifact("a.out")
-
-        # Create a target by the debugger.
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
+        target = self.createTestTarget()
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')

diff  --git a/lldb/test/API/sample_test/TestSampleTest.py b/lldb/test/API/sample_test/TestSampleTest.py
index 9c5b3ea3303b4..a2d56e2fda3d7 100644
--- a/lldb/test/API/sample_test/TestSampleTest.py
+++ b/lldb/test/API/sample_test/TestSampleTest.py
@@ -46,3 +46,8 @@ def sample_test(self):
         test_value = test_var.GetValueAsUnsigned()
         self.assertEqual(test_value, 10, "Got the right value for test_var")
 
+    def sample_test_no_launch(self):
+        """ Same as above but doesn't launch a process."""
+
+        target = self.createTestTarget()
+        self.expect_expr("test_var", result_value="10")

diff  --git a/lldb/test/API/sample_test/main.c b/lldb/test/API/sample_test/main.c
index 0164d7155b097..ac1611b53440d 100644
--- a/lldb/test/API/sample_test/main.c
+++ b/lldb/test/API/sample_test/main.c
@@ -1,9 +1,10 @@
 #include <stdio.h>
 
+int test_var = 10;
+
 int
 main()
 {
-  int test_var = 10;
   printf ("Set a breakpoint here: %d.\n", test_var);
   //% test_var = self.frame().FindVariable("test_var")
   //% test_value = test_var.GetValueAsUnsigned()


        


More information about the lldb-commits mailing list