xref: /llvm-project/lldb/test/API/sample_test/TestSampleTest.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Describe the purpose of the test class here.
3"""
4
5
6import lldb
7import lldbsuite.test.lldbutil as lldbutil
8from lldbsuite.test.lldbtest import *
9
10
11class RenameThisSampleTestTestCase(TestBase):
12    # If your test case doesn't stress debug info, then
13    # set this to true.  That way it won't be run once for
14    # each debug info format.
15    NO_DEBUG_INFO_TESTCASE = True
16
17    def test_sample_rename_this(self):
18        """There can be many tests in a test case - describe this test here."""
19        self.build()
20        self.main_source_file = lldb.SBFileSpec("main.c")
21        self.sample_test()
22
23    def setUp(self):
24        # Call super's setUp().
25        TestBase.setUp(self)
26        # Set up your test case here. If your test doesn't need any set up then
27        # remove this method from your TestCase class.
28
29    def sample_test(self):
30        """You might use the test implementation in several ways, say so here."""
31
32        # This function starts a process, "a.out" by default, sets a source
33        # breakpoint, runs to it, and returns the thread, process & target.
34        # It optionally takes an SBLaunchOption argument if you want to pass
35        # arguments or environment variables.
36        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
37            self, "Set a breakpoint here", self.main_source_file
38        )
39
40        frame = thread.GetFrameAtIndex(0)
41        test_var = frame.FindVariable("test_var")
42        self.assertSuccess(test_var.GetError(), "Failed to fetch test_var")
43        test_value = test_var.GetValueAsUnsigned()
44        self.assertEqual(test_value, 10, "Got the right value for test_var")
45
46    def sample_test_no_launch(self):
47        """Same as above but doesn't launch a process."""
48
49        target = self.createTestTarget()
50        self.expect_expr("global_test_var", result_value="10")
51