1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6class TestCase(TestBase):
7
8    mydir = TestBase.compute_mydir(__file__)
9
10    def test(self):
11        self.build()
12        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c"))
13
14        self.expect("statistics disable", substrs=['need to enable statistics before disabling'], error=True)
15
16        # 'expression' should change the statistics.
17        self.expect("statistics enable")
18        self.expect("statistics enable", substrs=['already enabled'], error=True)
19        self.expect("expr patatino", substrs=['27'])
20        self.expect("statistics disable")
21        self.expect("statistics dump", substrs=['expr evaluation successes : 1\n',
22                                                'expr evaluation failures : 0\n'])
23
24        self.expect("statistics enable")
25        # Doesn't parse.
26        self.expect("expr doesnt_exist", error=True,
27                    substrs=["undeclared identifier 'doesnt_exist'"])
28        # Doesn't successfully execute.
29        self.expect("expr int *i = nullptr; *i", error=True)
30        # Interpret an integer as an array with 3 elements is also a failure.
31        self.expect("expr -Z 3 -- 1", error=True,
32                    substrs=["expression cannot be used with --element-count"])
33        self.expect("statistics disable")
34        # We should have gotten 3 new failures and the previous success.
35        self.expect("statistics dump", substrs=['expr evaluation successes : 1\n',
36                                                'expr evaluation failures : 3\n'])
37
38        # 'frame var' with disabled statistics shouldn't change stats.
39        self.expect("frame var", substrs=['27'])
40
41        self.expect("statistics enable")
42        # 'frame var' with enabled statistics will change stats.
43        self.expect("frame var", substrs=['27'])
44        self.expect("statistics disable")
45        self.expect("statistics dump", substrs=['frame var successes : 1\n',
46                                                'frame var failures : 0\n'])
47