Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / benchmarks / expression / TestRepeatedExprs.py
blob104e69b384237c3622642ddb91184900a58b4afc
1 """Test evaluating expressions repeatedly comparing lldb against gdb."""
3 import sys
4 import lldb
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):
13 def setUp(self):
14 BenchBase.setUp(self)
15 self.source = "main.cpp"
16 self.line_to_break = line_number(self.source, "// Set breakpoint here.")
17 self.lldb_avg = None
18 self.gdb_avg = None
19 self.count = 100
21 @benchmarks_test
22 @expectedFailureAll(
23 oslist=["windows"],
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."""
28 self.build()
29 self.exe_name = "a.out"
31 print()
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):
39 import pexpect
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)
51 child = self.child
53 # Turn on logging for what the child sends back.
54 if self.TraceOn():
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)
60 child.sendline("run")
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):
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 child.sendline("process continue")
74 child.expect_exact(prompt)
76 child.sendline("quit")
77 try:
78 self.child.expect(pexpect.EOF)
79 except:
80 pass
82 self.lldb_avg = self.stopwatch.avg()
83 if self.TraceOn():
84 print("lldb expression benchmark:", str(self.stopwatch))
85 self.child = None
87 def run_gdb_repeated_exprs(self, exe_name, count):
88 import pexpect
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)
98 child = self.child
100 # Turn on logging for what the child sends back.
101 if self.TraceOn():
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):
115 with self.stopwatch:
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?")
125 child.sendline("y")
126 try:
127 self.child.expect(pexpect.EOF)
128 except:
129 pass
131 self.gdb_avg = self.stopwatch.avg()
132 if self.TraceOn():
133 print("gdb expression benchmark:", str(self.stopwatch))
134 self.child = None