1"""
2Test lldb-vscode setBreakpoints request
3"""
4
5
6import unittest2
7import vscode
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11import lldbvscode_testcase
12
13
14class TestVSCode_step(lldbvscode_testcase.VSCodeTestCaseBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @skipIfWindows
19    def test_step(self):
20        '''
21            Tests the stepping in/out/over in threads.
22        '''
23        program = self.getBuildArtifact("a.out")
24        self.build_and_launch(program)
25        source = 'main.cpp'
26        # source_path = os.path.join(os.getcwd(), source)
27        breakpoint1_line = line_number(source, '// breakpoint 1')
28        lines = [breakpoint1_line]
29        # Set breakoint in the thread function so we can step the threads
30        breakpoint_ids = self.set_source_breakpoints(source, lines)
31        self.assertEqual(len(breakpoint_ids), len(lines),
32                        "expect correct number of breakpoints")
33        self.continue_to_breakpoints(breakpoint_ids)
34        threads = self.vscode.get_threads()
35        for thread in threads:
36            if 'reason' in thread:
37                reason = thread['reason']
38                if reason == 'breakpoint':
39                    # We have a thread that is stopped at our breakpoint.
40                    # Get the value of "x" and get the source file and line.
41                    # These will help us determine if we are stepping
42                    # correctly. If we step a thread correctly we will verify
43                    # the correct falue for x as it progresses through the
44                    # program.
45                    tid = thread['id']
46                    x1 = self.get_local_as_int('x', threadId=tid)
47                    (src1, line1) = self.get_source_and_line(threadId=tid)
48
49                    # Now step into the "recurse()" function call again and
50                    # verify, using the new value of "x" and the source file
51                    # and line if we stepped correctly
52                    self.stepIn(threadId=tid, waitForStop=True)
53                    x2 = self.get_local_as_int('x', threadId=tid)
54                    (src2, line2) = self.get_source_and_line(threadId=tid)
55                    self.assertEqual(x1, x2 + 1, 'verify step in variable')
56                    self.assertLess(line2, line1, 'verify step in line')
57                    self.assertEqual(src1, src2, 'verify step in source')
58
59                    # Now step out and verify
60                    self.stepOut(threadId=tid, waitForStop=True)
61                    x3 = self.get_local_as_int('x', threadId=tid)
62                    (src3, line3) = self.get_source_and_line(threadId=tid)
63                    self.assertEqual(x1, x3, 'verify step out variable')
64                    self.assertGreaterEqual(line3, line1, 'verify step out line')
65                    self.assertEqual(src1, src3, 'verify step in source')
66
67                    # Step over and verify
68                    self.stepOver(threadId=tid, waitForStop=True)
69                    x4 = self.get_local_as_int('x', threadId=tid)
70                    (src4, line4) = self.get_source_and_line(threadId=tid)
71                    self.assertEqual(x4, x3, 'verify step over variable')
72                    self.assertGreater(line4, line3, 'verify step over line')
73                    self.assertEqual(src1, src4, 'verify step over source')
74                    # only step one thread that is at the breakpoint and stop
75                    break
76