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