1"""Test lldb's response time for 'frame variable' command."""
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 FrameVariableResponseBench(BenchBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    def setUp(self):
19        BenchBase.setUp(self)
20        self.exe = lldbtest_config.lldbExec
21        self.break_spec = '-n main'
22        self.count = 20
23
24    @benchmarks_test
25    @no_debug_info_test
26    @expectedFailureAll(
27        oslist=["windows"],
28        bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
29    def test_startup_delay(self):
30        """Test response time for the 'frame variable' command."""
31        print()
32        self.run_frame_variable_bench(self.exe, self.break_spec, self.count)
33        print("lldb frame variable benchmark:", self.stopwatch)
34
35    def run_frame_variable_bench(self, exe, break_spec, count):
36        import pexpect
37        # Set self.child_prompt, which is "(lldb) ".
38        self.child_prompt = '(lldb) '
39        prompt = self.child_prompt
40
41        # Reset the stopwatchs now.
42        self.stopwatch.reset()
43        for i in range(count):
44            # So that the child gets torn down after the test.
45            self.child = pexpect.spawn(
46                '%s %s %s' %
47                (lldbtest_config.lldbExec, self.lldbOption, exe))
48            child = self.child
49
50            # Turn on logging for what the child sends back.
51            if self.TraceOn():
52                child.logfile_read = sys.stdout
53
54            # Set our breakpoint.
55            child.sendline('breakpoint set %s' % break_spec)
56            child.expect_exact(prompt)
57
58            # Run the target and expect it to be stopped due to breakpoint.
59            child.sendline('run')  # Aka 'process launch'.
60            child.expect_exact(prompt)
61
62            with self.stopwatch:
63                # Measure the 'frame variable' response time.
64                child.sendline('frame variable')
65                child.expect_exact(prompt)
66
67            child.sendline('quit')
68            try:
69                self.child.expect(pexpect.EOF)
70            except:
71                pass
72
73        # The test is about to end and if we come to here, the child process has
74        # been terminated.  Mark it so.
75        self.child = None
76