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