51 lines · python
1"""2Describe the purpose of the test class here.3"""4 5 6import lldb7import lldbsuite.test.lldbutil as lldbutil8from lldbsuite.test.lldbtest import *9 10 11class RenameThisSampleTestTestCase(TestBase):12 # If your test case doesn't stress debug info, then13 # set this to true. That way it won't be run once for14 # each debug info format.15 NO_DEBUG_INFO_TESTCASE = True16 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 then27 # 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 source33 # breakpoint, runs to it, and returns the thread, process & target.34 # It optionally takes an SBLaunchOption argument if you want to pass35 # arguments or environment variables.36 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(37 self, "Set a breakpoint here", self.main_source_file38 )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