65 lines · python
1"""2Test that the save_crashlog command functions3"""4 5 6import os7import lldb8import lldbsuite.test.lldbutil as lldbutil9from lldbsuite.test.lldbtest import *10from lldbsuite.test.decorators import *11 12 13class TestSaveCrashlog(TestBase):14 # If your test case doesn't stress debug info, then15 # set this to true. That way it won't be run once for16 # each debug info format.17 NO_DEBUG_INFO_TESTCASE = True18 19 @skipUnlessDarwin20 def test_save_crashlog(self):21 """There can be many tests in a test case - describe this test here."""22 self.build()23 self.main_source_file = lldb.SBFileSpec("main.c")24 self.save_crashlog()25 26 def save_crashlog(self):27 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(28 self, "I was called", self.main_source_file29 )30 31 self.runCmd("command script import lldb.macosx.crashlog")32 out_file = os.path.join(self.getBuildDir(), "crash.log")33 self.runCmd("save_crashlog '%s'" % (out_file))34 35 # Make sure we wrote the file:36 self.assertTrue(os.path.exists(out_file), "We wrote our file")37 38 # Now scan the file to make sure it looks right:39 # First get a few facts we'll use:40 exe_module = target.FindModule(target.GetExecutable())41 uuid_str = exe_module.GetUUIDString()42 43 # We'll set these to true when we find the elements in the file44 found_call_me = False45 found_main_line = False46 found_thread_header = False47 found_uuid_str = False48 49 with open(out_file, "r") as f:50 # We want to see a line with51 for line in f:52 if "Thread 0:" in line:53 found_thread_header = True54 if "call_me" in line and "main.c:" in line:55 found_call_me = True56 if "main" in line and "main.c:" in line:57 found_main_line = True58 if uuid_str in line and "a.out" in line:59 found_uuid_str = True60 61 self.assertTrue(found_thread_header, "Found thread header")62 self.assertTrue(found_call_me, "Found call_me line in stack")63 self.assertTrue(found_uuid_str, "Found main binary UUID")64 self.assertTrue(found_main_line, "Found main line in call stack")65