Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 1 | """Test lldb's response time for 'frame variable' command.""" |
| 2 | |
| 3 | import os, sys |
| 4 | import unittest2 |
| 5 | import lldb |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 6 | from lldbbench import * |
| 7 | |
| 8 | class FrameVariableResponseBench(BenchBase): |
| 9 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 10 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 11 | |
| 12 | def setUp(self): |
| 13 | BenchBase.setUp(self) |
| 14 | if lldb.bmExecutable: |
| 15 | self.exe = lldb.bmExecutable |
| 16 | else: |
Vince Harron | 790d95c | 2015-05-18 19:39:03 +0000 | [diff] [blame^] | 17 | self.exe = lldbtest_config.lldbExec |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 18 | if lldb.bmBreakpointSpec: |
| 19 | self.break_spec = lldb.bmBreakpointSpec |
| 20 | else: |
| 21 | self.break_spec = '-n main' |
| 22 | |
| 23 | self.count = lldb.bmIterationCount |
| 24 | if self.count <= 0: |
| 25 | self.count = 20 |
| 26 | |
| 27 | @benchmarks_test |
Zachary Turner | 0c42631 | 2015-01-20 22:36:03 +0000 | [diff] [blame] | 28 | @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 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): |
Zachary Turner | 045fde5 | 2014-07-18 01:02:02 +0000 | [diff] [blame] | 36 | import pexpect |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 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. |
Vince Harron | 790d95c | 2015-05-18 19:39:03 +0000 | [diff] [blame^] | 45 | self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe)) |
Johnny Chen | 31fdfb1 | 2011-10-21 20:19:51 +0000 | [diff] [blame] | 46 | child = self.child |
| 47 | |
| 48 | # Turn on logging for what the child sends back. |
| 49 | if self.TraceOn(): |
| 50 | child.logfile_read = sys.stdout |
| 51 | |
| 52 | # Set our breakpoint. |
| 53 | child.sendline('breakpoint set %s' % break_spec) |
| 54 | child.expect_exact(prompt) |
| 55 | |
| 56 | # Run the target and expect it to be stopped due to breakpoint. |
| 57 | child.sendline('run') # Aka 'process launch'. |
| 58 | child.expect_exact(prompt) |
| 59 | |
| 60 | with self.stopwatch: |
| 61 | # Measure the 'frame variable' response time. |
| 62 | child.sendline('frame variable') |
| 63 | child.expect_exact(prompt) |
| 64 | |
| 65 | child.sendline('quit') |
| 66 | try: |
| 67 | self.child.expect(pexpect.EOF) |
| 68 | except: |
| 69 | pass |
| 70 | |
| 71 | # The test is about to end and if we come to here, the child process has |
| 72 | # been terminated. Mark it so. |
| 73 | self.child = None |
| 74 | |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | import atexit |
| 78 | lldb.SBDebugger.Initialize() |
| 79 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 80 | unittest2.main() |