1""" 2Test that the save_crashlog command functions 3""" 4 5 6import os 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test.decorators import * 11 12 13class TestSaveCrashlog(TestBase): 14 15 # If your test case doesn't stress debug info, then 16 # set this to true. That way it won't be run once for 17 # each debug info format. 18 NO_DEBUG_INFO_TESTCASE = True 19 20 @skipUnlessDarwin 21 def test_save_crashlog(self): 22 """There can be many tests in a test case - describe this test here.""" 23 self.build() 24 self.main_source_file = lldb.SBFileSpec("main.c") 25 self.save_crashlog() 26 27 def save_crashlog(self): 28 29 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 30 "I was called", self.main_source_file) 31 32 self.runCmd("command script import lldb.macosx.crashlog") 33 out_file = os.path.join(self.getBuildDir(), "crash.log") 34 self.runCmd("save_crashlog '%s'"%(out_file)) 35 36 # Make sure we wrote the file: 37 self.assertTrue(os.path.exists(out_file), "We wrote our file") 38 39 # Now scan the file to make sure it looks right: 40 # First get a few facts we'll use: 41 exe_module = target.FindModule(target.GetExecutable()) 42 uuid_str = exe_module.GetUUIDString() 43 44 # We'll set these to true when we find the elements in the file 45 found_call_me = False 46 found_main_line = False 47 found_thread_header = False 48 found_uuid_str = False 49 50 with open(out_file, "r") as f: 51 # We want to see a line with 52 for line in f: 53 if "Thread 0:" in line: 54 found_thread_header = True 55 if "call_me" in line and "main.c:" in line: 56 found_call_me = True 57 if "main" in line and "main.c:" in line: 58 found_main_line = True 59 if uuid_str in line and "a.out" in line: 60 found_uuid_str = True 61 62 self.assertTrue(found_thread_header, "Found thread header") 63 self.assertTrue(found_call_me, "Found call_me line in stack") 64 self.assertTrue(found_uuid_str, "Found main binary UUID") 65 self.assertTrue(found_main_line, "Found main line in call stack") 66 67