1"""
2Test lldb data formatter subsystem.
3"""
4
5from __future__ import print_function
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbbench import *
11from lldbsuite.test.lldbtest import *
12from lldbsuite.test import lldbutil
13
14
15class TestBenchmarkContinue(BenchBase):
16
17    @benchmarks_test
18    def test_run_command(self):
19        """Benchmark different ways to continue a process"""
20        self.build()
21        self.data_formatter_commands()
22
23    def setUp(self):
24        # Call super's setUp().
25        BenchBase.setUp(self)
26
27    def data_formatter_commands(self):
28        """Benchmark different ways to continue a process"""
29        self.runCmd("file "+self.getBuildArtifact("a.out"),
30                    CURRENT_EXECUTABLE_SET)
31
32        bkpt = self.target().FindBreakpointByID(
33            lldbutil.run_break_set_by_source_regexp(
34                self, "// break here"))
35
36        self.runCmd("run", RUN_SUCCEEDED)
37
38        # The stop reason of the thread should be breakpoint.
39        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                    substrs=['stopped',
41                             'stop reason = breakpoint'])
42
43        # This is the function to remove the custom formats in order to have a
44        # clean slate for the next test case.
45        def cleanup():
46            self.runCmd('type format clear', check=False)
47            self.runCmd('type summary clear', check=False)
48            self.runCmd('type filter clear', check=False)
49            self.runCmd('type synth clear', check=False)
50            self.runCmd(
51                "settings set target.max-children-count 256",
52                check=False)
53
54        # Execute the cleanup function during test case tear down.
55        self.addTearDownHook(cleanup)
56
57        runCmd_sw = Stopwatch()
58        lldbutil_sw = Stopwatch()
59
60        for i in range(0, 15):
61            runCmd_sw.start()
62            self.runCmd("continue")
63            runCmd_sw.stop()
64
65        for i in range(0, 15):
66            lldbutil_sw.start()
67            lldbutil.continue_to_breakpoint(self.process(), bkpt)
68            lldbutil_sw.stop()
69
70        print("runCmd: %s\nlldbutil: %s" % (runCmd_sw, lldbutil_sw))
71