blob: 03cc09d0a32b867528326a0323e08bc8f5feaab4 [file] [log] [blame]
Johnny Chen31fdfb12011-10-21 20:19:51 +00001"""Test lldb's response time for 'frame variable' command."""
2
3import os, sys
4import unittest2
5import lldb
6import pexpect
7from lldbbench import *
8
9class FrameVariableResponseBench(BenchBase):
10
11 mydir = os.path.join("benchmarks", "frame_variable")
12
13 def setUp(self):
14 BenchBase.setUp(self)
15 if lldb.bmExecutable:
16 self.exe = lldb.bmExecutable
17 else:
18 self.exe = self.lldbHere
19 if lldb.bmBreakpointSpec:
20 self.break_spec = lldb.bmBreakpointSpec
21 else:
22 self.break_spec = '-n main'
23
24 self.count = lldb.bmIterationCount
25 if self.count <= 0:
26 self.count = 20
27
28 @benchmarks_test
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 # Set self.child_prompt, which is "(lldb) ".
37 self.child_prompt = '(lldb) '
38 prompt = self.child_prompt
39
40 # Reset the stopwatchs now.
41 self.stopwatch.reset()
42 for i in range(count):
43 # So that the child gets torn down after the test.
44 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
45 child = self.child
46
47 # Turn on logging for what the child sends back.
48 if self.TraceOn():
49 child.logfile_read = sys.stdout
50
51 # Set our breakpoint.
52 child.sendline('breakpoint set %s' % break_spec)
53 child.expect_exact(prompt)
54
55 # Run the target and expect it to be stopped due to breakpoint.
56 child.sendline('run') # Aka 'process launch'.
57 child.expect_exact(prompt)
58
59 with self.stopwatch:
60 # Measure the 'frame variable' response time.
61 child.sendline('frame variable')
62 child.expect_exact(prompt)
63
64 child.sendline('quit')
65 try:
66 self.child.expect(pexpect.EOF)
67 except:
68 pass
69
70 # The test is about to end and if we come to here, the child process has
71 # been terminated. Mark it so.
72 self.child = None
73
74
75if __name__ == '__main__':
76 import atexit
77 lldb.SBDebugger.Initialize()
78 atexit.register(lambda: lldb.SBDebugger.Terminate())
79 unittest2.main()