1 """Test evaluating expressions repeatedly comparing lldb against gdb."""
5 from lldbsuite
.test
.lldbbench
import BenchBase
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import configuration
9 from lldbsuite
.test
import lldbutil
12 class RepeatedExprsCase(BenchBase
):
15 self
.source
= "main.cpp"
16 self
.line_to_break
= line_number(self
.source
, "// Set breakpoint here.")
24 bugnumber
="llvm.org/pr22274: need a pexpect replacement for windows",
26 def test_compare_lldb_to_gdb(self
):
27 """Test repeated expressions with lldb vs. gdb."""
29 self
.exe_name
= "a.out"
32 self
.run_lldb_repeated_exprs(self
.exe_name
, self
.count
)
33 print("lldb benchmark:", self
.stopwatch
)
34 self
.run_gdb_repeated_exprs(self
.exe_name
, self
.count
)
35 print("gdb benchmark:", self
.stopwatch
)
36 print("lldb_avg/gdb_avg: %f" % (self
.lldb_avg
/ self
.gdb_avg
))
38 def run_lldb_repeated_exprs(self
, exe_name
, count
):
41 exe
= self
.getBuildArtifact(exe_name
)
43 # Set self.child_prompt, which is "(lldb) ".
44 self
.child_prompt
= "(lldb) "
45 prompt
= self
.child_prompt
47 # So that the child gets torn down after the test.
48 self
.child
= pexpect
.spawn(
49 "%s %s %s" % (lldbtest_config
.lldbExec
, self
.lldbOption
, exe
)
53 # Turn on logging for what the child sends back.
55 child
.logfile_read
= sys
.stdout
57 child
.expect_exact(prompt
)
58 child
.sendline("breakpoint set -f %s -l %d" % (self
.source
, self
.line_to_break
))
59 child
.expect_exact(prompt
)
61 child
.expect_exact(prompt
)
62 expr_cmd1
= "expr ptr[j]->point.x"
63 expr_cmd2
= "expr ptr[j]->point.y"
65 # Reset the stopwatch now.
66 self
.stopwatch
.reset()
67 for i
in range(count
):
69 child
.sendline(expr_cmd1
)
70 child
.expect_exact(prompt
)
71 child
.sendline(expr_cmd2
)
72 child
.expect_exact(prompt
)
73 child
.sendline("process continue")
74 child
.expect_exact(prompt
)
76 child
.sendline("quit")
78 self
.child
.expect(pexpect
.EOF
)
82 self
.lldb_avg
= self
.stopwatch
.avg()
84 print("lldb expression benchmark:", str(self
.stopwatch
))
87 def run_gdb_repeated_exprs(self
, exe_name
, count
):
90 exe
= self
.getBuildArtifact(exe_name
)
92 # Set self.child_prompt, which is "(gdb) ".
93 self
.child_prompt
= "(gdb) "
94 prompt
= self
.child_prompt
96 # So that the child gets torn down after the test.
97 self
.child
= pexpect
.spawn("gdb --nx %s" % exe
)
100 # Turn on logging for what the child sends back.
102 child
.logfile_read
= sys
.stdout
104 child
.expect_exact(prompt
)
105 child
.sendline("break %s:%d" % (self
.source
, self
.line_to_break
))
106 child
.expect_exact(prompt
)
107 child
.sendline("run")
108 child
.expect_exact(prompt
)
109 expr_cmd1
= "print ptr[j]->point.x"
110 expr_cmd2
= "print ptr[j]->point.y"
112 # Reset the stopwatch now.
113 self
.stopwatch
.reset()
114 for i
in range(count
):
116 child
.sendline(expr_cmd1
)
117 child
.expect_exact(prompt
)
118 child
.sendline(expr_cmd2
)
119 child
.expect_exact(prompt
)
120 child
.sendline("continue")
121 child
.expect_exact(prompt
)
123 child
.sendline("quit")
124 child
.expect_exact("The program is running. Exit anyway?")
127 self
.child
.expect(pexpect
.EOF
)
131 self
.gdb_avg
= self
.stopwatch
.avg()
133 print("gdb expression benchmark:", str(self
.stopwatch
))