1"""Test lldb's expression evaluations and collect statistics.""" 2 3from __future__ import print_function 4 5 6import sys 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbbench import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import configuration 12from lldbsuite.test import lldbutil 13 14 15class ExpressionEvaluationCase(BenchBase): 16 17 def setUp(self): 18 BenchBase.setUp(self) 19 self.source = 'main.cpp' 20 self.line_to_break = line_number( 21 self.source, '// Set breakpoint here.') 22 self.count = 25 23 24 @benchmarks_test 25 @expectedFailureAll( 26 oslist=["windows"], 27 bugnumber="llvm.org/pr22274: need a pexpect replacement for windows") 28 def test_expr_cmd(self): 29 """Test lldb's expression commands and collect statistics.""" 30 self.build() 31 self.exe_name = 'a.out' 32 33 print() 34 self.run_lldb_repeated_exprs(self.exe_name, self.count) 35 print("lldb expr cmd benchmark:", self.stopwatch) 36 37 def run_lldb_repeated_exprs(self, exe_name, count): 38 import pexpect 39 exe = self.getBuildArtifact(exe_name) 40 41 # Set self.child_prompt, which is "(lldb) ". 42 self.child_prompt = '(lldb) ' 43 prompt = self.child_prompt 44 45 # Reset the stopwatch now. 46 self.stopwatch.reset() 47 for i in range(count): 48 # So that the child gets torn down after the test. 49 self.child = pexpect.spawn( 50 '%s %s %s' % 51 (lldbtest_config.lldbExec, self.lldbOption, exe)) 52 child = self.child 53 54 # Turn on logging for what the child sends back. 55 if self.TraceOn(): 56 child.logfile_read = sys.stdout 57 58 child.expect_exact(prompt) 59 child.sendline( 60 'breakpoint set -f %s -l %d' % 61 (self.source, self.line_to_break)) 62 child.expect_exact(prompt) 63 child.sendline('run') 64 child.expect_exact(prompt) 65 expr_cmd1 = 'expr ptr[j]->point.x' 66 expr_cmd2 = 'expr ptr[j]->point.y' 67 68 with self.stopwatch: 69 child.sendline(expr_cmd1) 70 child.expect_exact(prompt) 71 child.sendline(expr_cmd2) 72 child.expect_exact(prompt) 73 74 child.sendline('quit') 75 try: 76 self.child.expect(pexpect.EOF) 77 except: 78 pass 79 80 self.child = None 81