class TestUnitTests(TestBase): mydir = TestBase.compute_mydir(__file__) @decorators.skipUnlessDarwin @decorators.swiftTest @decorators.skipIf(debug_info=decorators.no_match("dsym"), bugnumber="This test only builds one way") def test_cross_module_extension(self): """Test that XCTest-based unit tests work""" self.buildAll() self.do_test() def setUp(self): TestBase.setUp(self) self.XCTest_source = "XCTest.c" self.XCTest_source_spec = lldb.SBFileSpec(self.XCTest_source) def buildAll(self): execute_command("make everything") def do_test(self): """Test that XCTest-based unit tests work""" exe_name = "XCTest" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.XCTest_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") options = lldb.SBExpressionOptions() options.SetLanguage(lldb.eLanguageTypeSwift) self.frame.EvaluateExpression("import test", options) ret = self.frame.EvaluateExpression("doTest()", options) self.assertTrue(ret.GetValueAsUnsigned() == 3)
class TestSwiftDifferentClangFlags(TestBase): mydir = TestBase.compute_mydir(__file__) @decorators.skipUnlessDarwin @decorators.swiftTest @decorators.skipIf( debug_info=decorators.no_match("dsym"), bugnumber="This test requires a stripped binary and a dSYM") @decorators.skipIf(oslist=["macosx"], bugnumber="rdar://26051347") def test_swift_different_clang_flags(self): """Test that we use the right compiler flags when debugging""" self.buildAll() self.do_test() def setUp(self): TestBase.setUp(self) self.main_source = "main.swift" self.main_source_spec = lldb.SBFileSpec(self.main_source) self.modb_source = "modb.swift" self.modb_source_spec = lldb.SBFileSpec(self.modb_source) def buildAll(self): execute_command("make everything") def do_test(self): """Test that we use the right compiler flags when debugging""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(main_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) modb_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.modb_source_spec) self.assertTrue(modb_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, modb_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("myThree") three = var.GetChildMemberWithName("three") lldbutil.check_variable(self, var, False, typename="modb.MyStruct") lldbutil.check_variable(self, three, False, value="3") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") lldbutil.check_variable(self, var, False, value="2") var = self.frame.FindVariable("b") lldbutil.check_variable(self, var, False, value="3") var = self.frame.EvaluateExpression("fA()") lldbutil.check_variable(self, var, False, value="2")
class TestUnitTests(TestBase): mydir = TestBase.compute_mydir(__file__) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll( oslist=["linux"], bugnumber="rdar://28180489") def test_equality_operators_fileprivate(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm1", "true", 1) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll( oslist=["linux"], bugnumber="rdar://28180489") def test_equality_operators_private(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm2", "false", 2) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll( oslist=["linux"], bugnumber="rdar://28180489") @expectedFailureAll(bugnumber="rdar://38483465") def test_equality_operators_other_module(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm3", "false", 3) def setUp(self): TestBase.setUp(self) def do_test(self, bkpt_name, compare_value, counter_value): """Test that we resolve expression operators correctly""" lldbutil.run_to_name_breakpoint(self, bkpt_name, exe_name=self.getBuildArtifact("three"), extra_images=["fooey"]) options = lldb.SBExpressionOptions() value = self.frame().EvaluateExpression("lhs == rhs", options) self.assertTrue( value.GetError().Success(), "Expression in %s was successful" % (bkpt_name)) summary = value.GetSummary() self.assertTrue( summary == compare_value, "Expression in CompareEm has wrong value: %s (expected %s)." % (summary, compare_value)) # And make sure we got did increment the counter by the right value. value = self.frame().EvaluateExpression("Fooey.GetCounter()", options) self.assertTrue(value.GetError().Success(), "GetCounter failed with error %s"%(value.GetError().GetCString())) counter = value.GetValueAsUnsigned() self.assertTrue( counter == counter_value, "Counter value is wrong: %d (expected %d)" % (counter, counter_value)) # Make sure the presence of these type specific == operators doesn't interfere # with finding other unrelated == operators. value = self.frame().EvaluateExpression("1 == 2", options) self.assertTrue( value.GetError().Success(), "1 == 2 expression couldn't run") self.assertTrue( value.GetSummary() == "false", "1 == 2 didn't return false.")
class TestSwiftPlaygrounds(TestBase): mydir = TestBase.compute_mydir(__file__) @decorators.skipUnlessDarwin @decorators.swiftTest @decorators.skipIf( debug_info=decorators.no_match("dsym"), bugnumber="This test only builds one way") def test_cross_module_extension(self): """Test that playgrounds work""" self.buildAll() self.do_test() def setUp(self): TestBase.setUp(self) self.PlaygroundStub_source = "PlaygroundStub.swift" self.PlaygroundStub_source_spec = lldb.SBFileSpec( self.PlaygroundStub_source) def buildAll(self): execute_command("make everything") def do_test(self): """Test that playgrounds work""" exe_name = "PlaygroundStub" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.PlaygroundStub_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") contents = "" with open('Contents.swift', 'r') as contents_file: contents = contents_file.read() options = lldb.SBExpressionOptions() options.SetLanguage(lldb.eLanguageTypeSwift) options.SetPlaygroundTransformEnabled() self.frame.EvaluateExpression(contents, options) ret = self.frame.EvaluateExpression("get_output()") playground_output = ret.GetSummary() self.assertTrue(playground_output is not None) self.assertTrue("a=\\'3\\'" in playground_output) self.assertTrue("b=\\'5\\'" in playground_output) self.assertTrue("=\\'8\\'" in playground_output)
class TestSwiftStructChangeRerun(TestBase): mydir = TestBase.compute_mydir(__file__) @decorators.skipIf(debug_info=decorators.no_match("dsym")) @decorators.swiftTest def test_swift_struct_change_rerun(self): """Test that we display self correctly for an inline-initialized struct""" self.do_test(True) def setUp(self): TestBase.setUp(self) self.main_source = "main.swift" self.main_source_spec = lldb.SBFileSpec(self.main_source) def do_test(self, build_dsym): """Test that we display self correctly for an inline-initialized struct""" # Cleanup the copied source file def cleanup(): if os.path.exists(self.main_source): os.unlink(self.main_source) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) if os.path.exists(self.main_source): os.unlink(self.main_source) shutil.copyfile('main1.swift', self.main_source) print 'build with main1.swift' self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.EvaluateExpression("a") print var_a var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self, var_a_a, False, value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self, var_a_b, False, '"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertFalse(var_a_c.IsValid(), "make sure a.c doesn't exist") process.Kill() print 'build with main2.swift' os.unlink(self.main_source) shutil.copyfile('main2.swift', self.main_source) if build_dsym: self.buildDsym() else: self.buildDwarf() # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.EvaluateExpression("a") print var_a var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self, var_a_a, False, value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self, var_a_b, False, '"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertTrue(var_a_c.IsValid(), "make sure a.c does exist") lldbutil.check_variable(self, var_a_c, False, value='12.125')
class TestUnitTests(TestBase): mydir = TestBase.compute_mydir(__file__) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll(oslist=["linux"], bugnumber="rdar://28180489") def test_equality_operators_fileprivate(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm1", "true", 1) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll(oslist=["linux"], bugnumber="rdar://28180489") def test_equality_operators_private(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm2", "false", 2) @swiftTest @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is building a dSYM") @expectedFailureAll(oslist=["linux"], bugnumber="rdar://28180489") @expectedFailureAll(bugnumber="rdar://38483465") def test_equality_operators_other_module(self): """Test that we resolve expression operators correctly""" self.build() self.do_test("Fooey.CompareEm3", "false", 3) def setUp(self): TestBase.setUp(self) def do_test(self, bkpt_name, compare_value, counter_value): """Test that we resolve expression operators correctly""" exe_name = "three" exe = self.getBuildArtifact(exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints bkpt = target.BreakpointCreateByName(bkpt_name) self.assertTrue(bkpt.GetNumLocations() > 0, VALID_BREAKPOINT) env_arr = self.registerSharedLibrariesWithTarget(target, ["fooey"]) process = target.LaunchSimple(None, env_arr, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt) self.assertTrue(len(threads) == 1) options = lldb.SBExpressionOptions() value = self.frame().EvaluateExpression("lhs == rhs", options) self.assertTrue(value.GetError().Success(), "Expression in %s was successful" % (bkpt_name)) summary = value.GetSummary() self.assertTrue( summary == compare_value, "Expression in CompareEm has wrong value: %s (expected %s)." % (summary, compare_value)) # And make sure we got did increment the counter by the right value. value = self.frame().EvaluateExpression("Fooey.GetCounter()", options) self.assertTrue( value.GetError().Success(), "GetCounter failed with error %s" % (value.GetError().GetCString())) counter = value.GetValueAsUnsigned() self.assertTrue( counter == counter_value, "Counter value is wrong: %d (expected %d)" % (counter, counter_value)) # Make sure the presence of these type specific == operators doesn't interfere # with finding other unrelated == operators. value = self.frame().EvaluateExpression("1 == 2", options) self.assertTrue(value.GetError().Success(), "1 == 2 expression couldn't run") self.assertTrue(value.GetSummary() == "false", "1 == 2 didn't return false.")
from lldbsuite.test import lldbinline from lldbsuite.test import decorators lldbinline.MakeInlineTest( __file__, globals(), [decorators.skipIf(archs=decorators.no_match(['arm64e']))])