• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    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(
23            self.source, '// Set breakpoint here.')
24        self.count = 25
25
26    @benchmarks_test
27    @expectedFailureAll(
28        oslist=["windows"],
29        bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
30    def test_expr_cmd(self):
31        """Test lldb's expression commands and collect statistics."""
32        self.build()
33        self.exe_name = 'a.out'
34
35        print()
36        self.run_lldb_repeated_exprs(self.exe_name, self.count)
37        print("lldb expr cmd benchmark:", self.stopwatch)
38
39    def run_lldb_repeated_exprs(self, exe_name, count):
40        import pexpect
41        exe = self.getBuildArtifact(exe_name)
42
43        # Set self.child_prompt, which is "(lldb) ".
44        self.child_prompt = '(lldb) '
45        prompt = self.child_prompt
46
47        # Reset the stopwatch now.
48        self.stopwatch.reset()
49        for i in range(count):
50            # So that the child gets torn down after the test.
51            self.child = pexpect.spawn(
52                '%s %s %s' %
53                (lldbtest_config.lldbExec, self.lldbOption, exe))
54            child = self.child
55
56            # Turn on logging for what the child sends back.
57            if self.TraceOn():
58                child.logfile_read = sys.stdout
59
60            child.expect_exact(prompt)
61            child.sendline(
62                'breakpoint set -f %s -l %d' %
63                (self.source, self.line_to_break))
64            child.expect_exact(prompt)
65            child.sendline('run')
66            child.expect_exact(prompt)
67            expr_cmd1 = 'expr ptr[j]->point.x'
68            expr_cmd2 = 'expr ptr[j]->point.y'
69
70            with self.stopwatch:
71                child.sendline(expr_cmd1)
72                child.expect_exact(prompt)
73                child.sendline(expr_cmd2)
74                child.expect_exact(prompt)
75
76            child.sendline('quit')
77            try:
78                self.child.expect(pexpect.EOF)
79            except:
80                pass
81
82        self.child = None
83