1"""Test lldb's stepping speed."""
2
3from __future__ import print_function
4
5import sys
6import lldb
7from lldbsuite.test import configuration
8from lldbsuite.test import lldbtest_config
9from lldbsuite.test.lldbbench import *
10from lldbsuite.test.decorators import *
11from lldbsuite.test.lldbtest import *
12from lldbsuite.test import lldbutil
13
14
15class SteppingSpeedBench(BenchBase):
16
17    mydir = TestBase.compute_mydir(__file__)
18
19    def setUp(self):
20        BenchBase.setUp(self)
21        self.exe = lldbtest_config.lldbExec
22        self.break_spec = '-n main'
23        self.count = 50
24
25        self.trace("self.exe=%s" % self.exe)
26        self.trace("self.break_spec=%s" % self.break_spec)
27
28    @benchmarks_test
29    @no_debug_info_test
30    @expectedFailureAll(
31        oslist=["windows"],
32        bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
33    def test_run_lldb_steppings(self):
34        """Test lldb steppings on a large executable."""
35        print()
36        self.run_lldb_steppings(self.exe, self.break_spec, self.count)
37        print("lldb stepping benchmark:", self.stopwatch)
38
39    def run_lldb_steppings(self, exe, break_spec, count):
40        import pexpect
41        # Set self.child_prompt, which is "(lldb) ".
42        self.child_prompt = '(lldb) '
43        prompt = self.child_prompt
44
45        # So that the child gets torn down after the test.
46        self.child = pexpect.spawn(
47            '%s %s %s' %
48            (lldbtest_config.lldbExec, self.lldbOption, exe))
49        child = self.child
50
51        # Turn on logging for what the child sends back.
52        if self.TraceOn():
53            child.logfile_read = sys.stdout
54
55        child.expect_exact(prompt)
56        child.sendline('breakpoint set %s' % break_spec)
57        child.expect_exact(prompt)
58        child.sendline('run')
59        child.expect_exact(prompt)
60
61        # Reset the stopwatch now.
62        self.stopwatch.reset()
63        for i in range(count):
64            with self.stopwatch:
65                # Disassemble the function.
66                child.sendline('next')  # Aka 'thread step-over'.
67                child.expect_exact(prompt)
68
69        child.sendline('quit')
70        try:
71            self.child.expect(pexpect.EOF)
72        except:
73            pass
74
75        self.child = None
76