]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/benchmarks/disassembly/TestDisassembly.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / benchmarks / disassembly / TestDisassembly.py
1 """Disassemble lldb's Driver::MainLoop() functions comparing lldb against gdb."""
2
3 from __future__ import print_function
4
5
6
7 import os, sys
8 import lldb
9 from lldbsuite.test import configuration
10 from lldbsuite.test.lldbbench import *
11
12 def is_exe(fpath):
13     """Returns true if fpath is an executable."""
14     return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
15
16 class DisassembleDriverMainLoop(BenchBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         """
22         Note that lldbtest_config.lldbExec can be specified with the LLDB_EXEC env variable (see
23         dotest.py), and gdbExec can be specified with the GDB_EXEC env variable.
24         This provides a flexibility in specifying different versions of gdb for
25         comparison purposes.
26         """
27         BenchBase.setUp(self)
28         # If env var GDB_EXEC is specified, use it; otherwise, use gdb in your
29         # PATH env var.
30         if "GDB_EXEC" in os.environ and is_exe(os.environ["GDB_EXEC"]):
31             self.gdbExec = os.environ["GDB_EXEC"]
32         else:
33             self.gdbExec = "gdb"
34
35         self.exe = lldbtest_config.lldbExec
36         self.function = 'Driver::MainLoop()'
37         self.lldb_avg = None
38         self.gdb_avg = None
39         self.count = 5
40
41     @benchmarks_test
42     @no_debug_info_test
43     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
44     def test_run_lldb_then_gdb(self):
45         """Test disassembly on a large function with lldb vs. gdb."""
46         print()
47         print("lldb path: %s" % lldbtest_config.lldbExec)
48         print("gdb path: %s" % self.gdbExec)
49
50         print()
51         self.run_lldb_disassembly(self.exe, self.function, self.count)
52         print("lldb benchmark:", self.stopwatch)
53         self.run_gdb_disassembly(self.exe, self.function, self.count)
54         print("gdb benchmark:", self.stopwatch)
55         print("lldb_avg/gdb_avg: %f" % (self.lldb_avg/self.gdb_avg))
56
57     @benchmarks_test
58     @no_debug_info_test
59     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
60     def test_run_gdb_then_lldb(self):
61         """Test disassembly on a large function with lldb vs. gdb."""
62         print()
63         print("lldb path: %s" % lldbtest_config.lldbExec)
64         print("gdb path: %s" % self.gdbExec)
65
66         print()
67         self.run_gdb_disassembly(self.exe, self.function, self.count)
68         print("gdb benchmark:", self.stopwatch)
69         self.run_lldb_disassembly(self.exe, self.function, self.count)
70         print("lldb benchmark:", self.stopwatch)
71         print("lldb_avg/gdb_avg: %f" % (self.lldb_avg/self.gdb_avg))
72
73     def run_lldb_disassembly(self, exe, function, count):
74         import pexpect
75         # Set self.child_prompt, which is "(lldb) ".
76         self.child_prompt = '(lldb) '
77         prompt = self.child_prompt
78
79         # So that the child gets torn down after the test.
80         self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
81         child = self.child
82
83         # Turn on logging for what the child sends back.
84         if self.TraceOn():
85             child.logfile_read = sys.stdout
86
87         child.expect_exact(prompt)
88         child.sendline('breakpoint set -F %s' % function)
89         child.expect_exact(prompt)
90         child.sendline('run')
91         child.expect_exact(prompt)
92
93         # Reset the stopwatch now.
94         self.stopwatch.reset()
95         for i in range(count):
96             with self.stopwatch:
97                 # Disassemble the function.
98                 child.sendline('disassemble -f')
99                 child.expect_exact(prompt)
100             child.sendline('next')
101             child.expect_exact(prompt)
102
103         child.sendline('quit')
104         try:
105             self.child.expect(pexpect.EOF)
106         except:
107             pass
108
109         self.lldb_avg = self.stopwatch.avg()
110         if self.TraceOn():
111             print("lldb disassembly benchmark:", str(self.stopwatch))
112         self.child = None
113
114     def run_gdb_disassembly(self, exe, function, count):
115         import pexpect
116         # Set self.child_prompt, which is "(gdb) ".
117         self.child_prompt = '(gdb) '
118         prompt = self.child_prompt
119
120         # So that the child gets torn down after the test.
121         self.child = pexpect.spawn('%s --nx %s' % (self.gdbExec, exe))
122         child = self.child
123
124         # Turn on logging for what the child sends back.
125         if self.TraceOn():
126             child.logfile_read = sys.stdout
127
128         child.expect_exact(prompt)
129         child.sendline('break %s' % function)
130         child.expect_exact(prompt)
131         child.sendline('run')
132         child.expect_exact(prompt)
133
134         # Reset the stopwatch now.
135         self.stopwatch.reset()
136         for i in range(count):
137             with self.stopwatch:
138                 # Disassemble the function.
139                 child.sendline('disassemble')
140                 child.expect_exact(prompt)
141             child.sendline('next')
142             child.expect_exact(prompt)
143
144         child.sendline('quit')
145         child.expect_exact('The program is running.  Exit anyway?')
146         child.sendline('y')
147         try:
148             self.child.expect(pexpect.EOF)
149         except:
150             pass
151
152         self.gdb_avg = self.stopwatch.avg()
153         if self.TraceOn():
154             print("gdb disassembly benchmark:", str(self.stopwatch))
155         self.child = None