]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/set_values/TestSetValues.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / set_values / TestSetValues.py
1 """Test settings and readings of program variables."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class SetValuesTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line numbers to break inside main().
22         self.line1 = line_number('main.c', '// Set break point #1.')
23         self.line2 = line_number('main.c', '// Set break point #2.')
24         self.line3 = line_number('main.c', '// Set break point #3.')
25         self.line4 = line_number('main.c', '// Set break point #4.')
26         self.line5 = line_number('main.c', '// Set break point #5.')
27
28     def test(self):
29         """Test settings and readings of program variables."""
30         self.build()
31         exe = self.getBuildArtifact("a.out")
32         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33
34         # Set breakpoints on several places to set program variables.
35         lldbutil.run_break_set_by_file_and_line(
36             self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
37
38         lldbutil.run_break_set_by_file_and_line(
39             self, "main.c", self.line2, num_expected_locations=1, loc_exact=True)
40
41         lldbutil.run_break_set_by_file_and_line(
42             self, "main.c", self.line3, num_expected_locations=1, loc_exact=True)
43
44         lldbutil.run_break_set_by_file_and_line(
45             self, "main.c", self.line4, num_expected_locations=1, loc_exact=True)
46
47         lldbutil.run_break_set_by_file_and_line(
48             self, "main.c", self.line5, num_expected_locations=1, loc_exact=True)
49
50         self.runCmd("run", RUN_SUCCEEDED)
51
52         # The stop reason of the thread should be breakpoint.
53         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
54                     substrs=['stopped',
55                              'stop reason = breakpoint'])
56
57         # The breakpoint should have a hit count of 1.
58         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
59                     substrs=[' resolved, hit count = 1'])
60
61         # main.c:15
62         # Check that 'frame variable --show-types' displays the correct data
63         # type and value.
64         self.expect(
65             "frame variable --show-types",
66             VARIABLES_DISPLAYED_CORRECTLY,
67             startstr="(char) i = 'a'")
68
69         # Now set variable 'i' and check that it is correctly displayed.
70         self.runCmd("expression i = 'b'")
71         self.expect(
72             "frame variable --show-types",
73             VARIABLES_DISPLAYED_CORRECTLY,
74             startstr="(char) i = 'b'")
75
76         self.runCmd("continue")
77
78         # main.c:36
79         # Check that 'frame variable --show-types' displays the correct data
80         # type and value.
81         self.expect(
82             "frame variable --show-types",
83             VARIABLES_DISPLAYED_CORRECTLY,
84             patterns=["\((short unsigned int|unsigned short)\) i = 33"])
85
86         # Now set variable 'i' and check that it is correctly displayed.
87         self.runCmd("expression i = 333")
88         self.expect(
89             "frame variable --show-types",
90             VARIABLES_DISPLAYED_CORRECTLY,
91             patterns=["\((short unsigned int|unsigned short)\) i = 333"])
92
93         self.runCmd("continue")
94
95         # main.c:57
96         # Check that 'frame variable --show-types' displays the correct data
97         # type and value.
98         self.expect(
99             "frame variable --show-types",
100             VARIABLES_DISPLAYED_CORRECTLY,
101             startstr="(long) i = 33")
102
103         # Now set variable 'i' and check that it is correctly displayed.
104         self.runCmd("expression i = 33333")
105         self.expect(
106             "frame variable --show-types",
107             VARIABLES_DISPLAYED_CORRECTLY,
108             startstr="(long) i = 33333")
109
110         self.runCmd("continue")
111
112         # main.c:78
113         # Check that 'frame variable --show-types' displays the correct data
114         # type and value.
115         self.expect(
116             "frame variable --show-types",
117             VARIABLES_DISPLAYED_CORRECTLY,
118             startstr="(double) i = 2.25")
119
120         # Now set variable 'i' and check that it is correctly displayed.
121         self.runCmd("expression i = 1.5")
122         self.expect(
123             "frame variable --show-types",
124             VARIABLES_DISPLAYED_CORRECTLY,
125             startstr="(double) i = 1.5")
126
127         self.runCmd("continue")
128
129         # main.c:85
130         # Check that 'frame variable --show-types' displays the correct data
131         # type and value.
132         self.expect(
133             "frame variable --show-types",
134             VARIABLES_DISPLAYED_CORRECTLY,
135             startstr="(long double) i = 2.25")
136
137         # Now set variable 'i' and check that it is correctly displayed.
138         self.runCmd("expression i = 1.5")
139         self.expect(
140             "frame variable --show-types",
141             VARIABLES_DISPLAYED_CORRECTLY,
142             startstr="(long double) i = 1.5")