1"""Test lldb's startup delays creating a target, setting a breakpoint, and run to breakpoint stop.""" 2 3from __future__ import print_function 4 5 6import sys 7import lldb 8from lldbsuite.test import configuration 9from lldbsuite.test import lldbtest_config 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbbench import * 12 13 14class StartupDelaysBench(BenchBase): 15 16 def setUp(self): 17 BenchBase.setUp(self) 18 # Create self.stopwatch2 for measuring "set first breakpoint". 19 # The default self.stopwatch is for "create fresh target". 20 self.stopwatch2 = Stopwatch() 21 # Create self.stopwatch3 for measuring "run to breakpoint". 22 self.stopwatch3 = Stopwatch() 23 self.exe = lldbtest_config.lldbExec 24 self.break_spec = '-n main' 25 self.count = 30 26 27 @benchmarks_test 28 @no_debug_info_test 29 @expectedFailureAll( 30 oslist=["windows"], 31 bugnumber="llvm.org/pr22274: need a pexpect replacement for windows") 32 def test_startup_delay(self): 33 """Test start up delays creating a target, setting a breakpoint, and run to breakpoint stop.""" 34 print() 35 self.run_startup_delays_bench(self.exe, self.break_spec, self.count) 36 print( 37 "lldb startup delay (create fresh target) benchmark:", 38 self.stopwatch) 39 print( 40 "lldb startup delay (set first breakpoint) benchmark:", 41 self.stopwatch2) 42 print( 43 "lldb startup delay (run to breakpoint) benchmark:", 44 self.stopwatch3) 45 46 def run_startup_delays_bench(self, exe, break_spec, count): 47 import pexpect 48 # Set self.child_prompt, which is "(lldb) ". 49 self.child_prompt = '(lldb) ' 50 prompt = self.child_prompt 51 52 # Reset the stopwatchs now. 53 self.stopwatch.reset() 54 self.stopwatch2.reset() 55 for i in range(count): 56 # So that the child gets torn down after the test. 57 self.child = pexpect.spawn( 58 '%s %s' % 59 (lldbtest_config.lldbExec, self.lldbOption)) 60 child = self.child 61 62 # Turn on logging for what the child sends back. 63 if self.TraceOn(): 64 child.logfile_read = sys.stdout 65 66 with self.stopwatch: 67 # Create a fresh target. 68 child.sendline('file %s' % exe) # Aka 'target create'. 69 child.expect_exact(prompt) 70 71 with self.stopwatch2: 72 # Read debug info and set the first breakpoint. 73 child.sendline('breakpoint set %s' % break_spec) 74 child.expect_exact(prompt) 75 76 with self.stopwatch3: 77 # Run to the breakpoint just set. 78 child.sendline('run') 79 child.expect_exact(prompt) 80 81 child.sendline('quit') 82 try: 83 self.child.expect(pexpect.EOF) 84 except: 85 pass 86 87 # The test is about to end and if we come to here, the child process has 88 # been terminated. Mark it so. 89 self.child = None 90