1"""Test lldb's stepping speed."""
2
3import os, sys
4import unittest2
5import lldb
6import pexpect
7from lldbbench import *
8
9class RunHooksThenSteppingsBench(BenchBase):
10
11    mydir = os.path.join("benchmarks", "stepping")
12
13    def setUp(self):
14        BenchBase.setUp(self)
15        self.count = lldb.bmIterationCount
16        if self.count <= 0:
17            self.count = 50
18
19    @benchmarks_test
20    def test_lldb_runhooks_then_steppings(self):
21        """Test lldb steppings on a large executable."""
22        print
23        self.run_lldb_runhooks_then_steppings(self.count)
24        print "lldb stepping benchmark:", self.stopwatch
25
26    def run_lldb_runhooks_then_steppings(self, count):
27        # Set self.child_prompt, which is "(lldb) ".
28        self.child_prompt = '(lldb) '
29        prompt = self.child_prompt
30
31        self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption))
32        self.child.expect_exact(prompt)
33        # So that the child gets torn down after the test.
34        child = self.child
35
36        # Turn on logging for what the child sends back.
37        if self.TraceOn():
38            child.logfile_read = sys.stdout
39
40        #lldb.runHooks = ['process attach -n Mail']
41
42        # Perform the run hooks to bring lldb debugger to the desired state.
43        self.runHooks(child=child, child_prompt=prompt)
44
45        # Reset the stopwatch now.
46        self.stopwatch.reset()
47        for i in range(count):
48            with self.stopwatch:
49                # Step through the function.
50                child.sendline('next') # Aka 'thread step-over'.
51                child.expect_exact(prompt)
52
53        child.sendline('quit')
54        try:
55            self.child.expect(pexpect.EOF)
56        except:
57            pass
58
59        self.child = None
60
61
62if __name__ == '__main__':
63    import atexit
64    lldb.SBDebugger.Initialize()
65    atexit.register(lambda: lldb.SBDebugger.Terminate())
66    unittest2.main()
67