]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / completion / TestCompletion.py
1 """
2 Test the lldb command line completion mechanism.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os
10 import lldb
11 from lldbsuite.test.lldbtest import *
12
13 class CommandLineCompletionTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     @classmethod
18     def classCleanup(cls):
19         """Cleanup the test byproducts."""
20         try:
21             os.remove("child_send.txt")
22             os.remove("child_read.txt")
23         except:
24             pass
25
26     @expectedFailureHostWindows("llvm.org/pr24679")
27     @skipIfFreeBSD # timing out on the FreeBSD buildbot
28     @no_debug_info_test
29     def test_at(self):
30         """Test that 'at' completes to 'attach '."""
31         self.complete_from_to('at', 'attach ')
32
33     @expectedFailureHostWindows("llvm.org/pr24679")
34     @skipIfFreeBSD # timing out on the FreeBSD buildbot
35     @no_debug_info_test
36     def test_de(self):
37         """Test that 'de' completes to 'detach '."""
38         self.complete_from_to('de', 'detach ')
39
40     @expectedFailureHostWindows("llvm.org/pr24679")
41     @skipIfFreeBSD # timing out on the FreeBSD buildbot
42     @no_debug_info_test
43     def test_process_attach_dash_dash_con(self):
44         """Test that 'process attach --con' completes to 'process attach --continue '."""
45         self.complete_from_to('process attach --con', 'process attach --continue ')
46
47     # <rdar://problem/11052829>
48     @expectedFailureHostWindows("llvm.org/pr24679")
49     @skipIfFreeBSD # timing out on the FreeBSD buildbot
50     @no_debug_info_test
51     def test_infinite_loop_while_completing(self):
52         """Test that 'process print hello\' completes to itself and does not infinite loop."""
53         self.complete_from_to('process print hello\\', 'process print hello\\',
54                               turn_off_re_match=True)
55
56     @expectedFailureHostWindows("llvm.org/pr24679")
57     @skipIfFreeBSD # timing out on the FreeBSD buildbot
58     @no_debug_info_test
59     def test_watchpoint_co(self):
60         """Test that 'watchpoint co' completes to 'watchpoint command '."""
61         self.complete_from_to('watchpoint co', 'watchpoint command ')
62
63     @expectedFailureHostWindows("llvm.org/pr24679")
64     @skipIfFreeBSD # timing out on the FreeBSD buildbot
65     @no_debug_info_test
66     def test_watchpoint_command_space(self):
67         """Test that 'watchpoint command ' completes to ['Available completions:', 'add', 'delete', 'list']."""
68         self.complete_from_to('watchpoint command ', ['Available completions:', 'add', 'delete', 'list'])
69
70     @expectedFailureHostWindows("llvm.org/pr24679")
71     @skipIfFreeBSD # timing out on the FreeBSD buildbot
72     @no_debug_info_test
73     def test_watchpoint_command_a(self):
74         """Test that 'watchpoint command a' completes to 'watchpoint command add '."""
75         self.complete_from_to('watchpoint command a', 'watchpoint command add ')
76
77     @expectedFailureHostWindows("llvm.org/pr24679")
78     @skipIfFreeBSD # timing out on the FreeBSD buildbot
79     @no_debug_info_test
80     def test_watchpoint_set_variable_dash_w(self):
81         """Test that 'watchpoint set variable -w' completes to 'watchpoint set variable -w '."""
82         self.complete_from_to('watchpoint set variable -w', 'watchpoint set variable -w ')
83
84     @expectedFailureHostWindows("llvm.org/pr24679")
85     @skipIfFreeBSD # timing out on the FreeBSD buildbot
86     @no_debug_info_test
87     def test_watchpoint_set_variable_dash_w_space(self):
88         """Test that 'watchpoint set variable -w ' completes to ['Available completions:', 'read', 'write', 'read_write']."""
89         self.complete_from_to('watchpoint set variable -w ', ['Available completions:', 'read', 'write', 'read_write'])
90
91     @expectedFailureHostWindows("llvm.org/pr24679")
92     @skipIfFreeBSD # timing out on the FreeBSD buildbot
93     @no_debug_info_test
94     def test_watchpoint_set_ex(self):
95         """Test that 'watchpoint set ex' completes to 'watchpoint set expression '."""
96         self.complete_from_to('watchpoint set ex', 'watchpoint set expression ')
97
98     @expectedFailureHostWindows("llvm.org/pr24679")
99     @skipIfFreeBSD # timing out on the FreeBSD buildbot
100     @no_debug_info_test
101     def test_watchpoint_set_var(self):
102         """Test that 'watchpoint set var' completes to 'watchpoint set variable '."""
103         self.complete_from_to('watchpoint set var', 'watchpoint set variable ')
104
105     @expectedFailureHostWindows("llvm.org/pr24679")
106     @skipIfFreeBSD # timing out on the FreeBSD buildbot
107     @no_debug_info_test
108     def test_watchpoint_set_variable_dash_w_read_underbar(self):
109         """Test that 'watchpoint set variable -w read_' completes to 'watchpoint set variable -w read_write'."""
110         self.complete_from_to('watchpoint set variable -w read_', 'watchpoint set variable -w read_write')
111
112     @expectedFailureHostWindows("llvm.org/pr24679")
113     @skipIfFreeBSD # timing out on the FreeBSD buildbot
114     @no_debug_info_test
115     def test_help_fi(self):
116         """Test that 'help fi' completes to ['Available completions:', 'file', 'finish']."""
117         self.complete_from_to('help fi', ['Available completions:', 'file', 'finish'])
118
119     @expectedFailureHostWindows("llvm.org/pr24679")
120     @skipIfFreeBSD # timing out on the FreeBSD buildbot
121     @no_debug_info_test
122     def test_help_watchpoint_s(self):
123         """Test that 'help watchpoint s' completes to 'help watchpoint set '."""
124         self.complete_from_to('help watchpoint s', 'help watchpoint set ')
125
126     @expectedFailureHostWindows("llvm.org/pr24679")
127     @skipIfFreeBSD # timing out on the FreeBSD buildbot
128     @no_debug_info_test
129     def test_settings_append_target_er(self):
130         """Test that 'settings append target.er' completes to 'settings append target.error-path'."""
131         self.complete_from_to('settings append target.er', 'settings append target.error-path')
132
133     @expectedFailureHostWindows("llvm.org/pr24679")
134     @skipIfFreeBSD # timing out on the FreeBSD buildbot
135     @no_debug_info_test
136     def test_settings_insert_after_target_en(self):
137         """Test that 'settings insert-after target.env' completes to 'settings insert-after target.env-vars'."""
138         self.complete_from_to('settings insert-after target.env', 'settings insert-after target.env-vars')
139
140     @expectedFailureHostWindows("llvm.org/pr24679")
141     @skipIfFreeBSD # timing out on the FreeBSD buildbot
142     @no_debug_info_test
143     def test_settings_insert_before_target_en(self):
144         """Test that 'settings insert-before target.env' completes to 'settings insert-before target.env-vars'."""
145         self.complete_from_to('settings insert-before target.env', 'settings insert-before target.env-vars')
146
147     @expectedFailureHostWindows("llvm.org/pr24679")
148     @skipIfFreeBSD # timing out on the FreeBSD buildbot
149     @no_debug_info_test
150     def test_settings_replace_target_ru(self):
151         """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'."""
152         self.complete_from_to('settings replace target.ru', 'settings replace target.run-args')
153
154     @expectedFailureHostWindows("llvm.org/pr24679")
155     @skipIfFreeBSD # timing out on the FreeBSD buildbot
156     @no_debug_info_test
157     def test_settings_s(self):
158         """Test that 'settings s' completes to ['Available completions:', 'set', 'show']."""
159         self.complete_from_to('settings s', ['Available completions:', 'set', 'show'])
160
161     @expectedFailureHostWindows("llvm.org/pr24679")
162     @skipIfFreeBSD # timing out on the FreeBSD buildbot
163     @no_debug_info_test
164     def test_settings_set_th(self):
165         """Test that 'settings set th' completes to 'settings set thread-format'."""
166         self.complete_from_to('settings set th', 'settings set thread-format')
167
168     @expectedFailureHostWindows("llvm.org/pr24679")
169     @skipIfFreeBSD # timing out on the FreeBSD buildbot
170     @no_debug_info_test
171     def test_settings_s_dash(self):
172         """Test that 'settings set -' completes to 'settings set -g'."""
173         self.complete_from_to('settings set -', 'settings set -g')
174
175     @expectedFailureHostWindows("llvm.org/pr24679")
176     @skipIfFreeBSD # timing out on the FreeBSD buildbot
177     @no_debug_info_test
178     def test_settings_clear_th(self):
179         """Test that 'settings clear th' completes to 'settings clear thread-format'."""
180         self.complete_from_to('settings clear th', 'settings clear thread-format')
181
182     @expectedFailureHostWindows("llvm.org/pr24679")
183     @skipIfFreeBSD # timing out on the FreeBSD buildbot
184     @no_debug_info_test
185     def test_settings_set_ta(self):
186         """Test that 'settings set ta' completes to 'settings set target.'."""
187         self.complete_from_to('settings set target.ma', 'settings set target.max-')
188
189     @expectedFailureHostWindows("llvm.org/pr24679")
190     @skipIfFreeBSD # timing out on the FreeBSD buildbot
191     @no_debug_info_test
192     def test_settings_set_target_exec(self):
193         """Test that 'settings set target.exec' completes to 'settings set target.exec-search-paths '."""
194         self.complete_from_to('settings set target.exec', 'settings set target.exec-search-paths')
195
196     @expectedFailureHostWindows("llvm.org/pr24679")
197     @skipIfFreeBSD # timing out on the FreeBSD buildbot
198     @no_debug_info_test
199     def test_settings_set_target_pr(self):
200         """Test that 'settings set target.pr' completes to ['Available completions:',
201         'target.prefer-dynamic-value', 'target.process.']."""
202         self.complete_from_to('settings set target.pr',
203                               ['Available completions:',
204                                'target.prefer-dynamic-value',
205                                'target.process.'])
206
207     @expectedFailureHostWindows("llvm.org/pr24679")
208     @skipIfFreeBSD # timing out on the FreeBSD buildbot
209     @no_debug_info_test
210     def test_settings_set_target_process(self):
211         """Test that 'settings set target.process' completes to 'settings set target.process.'."""
212         self.complete_from_to('settings set target.process', 'settings set target.process.')
213
214     @expectedFailureHostWindows("llvm.org/pr24679")
215     @skipIfFreeBSD # timing out on the FreeBSD buildbot
216     @no_debug_info_test
217     def test_settings_set_target_process_dot(self):
218         """Test that 'settings set target.process.t' completes to 'settings set target.process.thread.'."""
219         self.complete_from_to('settings set target.process.t', 'settings set target.process.thread.')
220
221     @expectedFailureHostWindows("llvm.org/pr24679")
222     @skipIfFreeBSD # timing out on the FreeBSD buildbot
223     @no_debug_info_test
224     def test_settings_set_target_process_thread_dot(self):
225         """Test that 'settings set target.process.thread.' completes to ['Available completions:',
226         'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread']."""
227         self.complete_from_to('settings set target.process.thread.',
228                               ['Available completions:',
229                                'target.process.thread.step-avoid-regexp',
230                                'target.process.thread.trace-thread'])
231
232     @expectedFailureHostWindows("llvm.org/pr24679")
233     @skipIfFreeBSD # timing out on the FreeBSD buildbot
234     @no_debug_info_test
235     def test_target_space(self):
236         """Test that 'target ' completes to ['Available completions:', 'create', 'delete', 'list',
237         'modules', 'select', 'stop-hook', 'variable']."""
238         self.complete_from_to('target ',
239                               ['Available completions:', 'create', 'delete', 'list',
240                                'modules', 'select', 'stop-hook', 'variable'])
241
242     @expectedFailureHostWindows("llvm.org/pr24679")
243     @skipIfFreeBSD # timing out on the FreeBSD buildbot
244     @no_debug_info_test
245     def test_target_create_dash_co(self):
246         """Test that 'target create --co' completes to 'target variable --core '."""
247         self.complete_from_to('target create --co', 'target create --core ')
248
249     @expectedFailureHostWindows("llvm.org/pr24679")
250     @skipIfFreeBSD # timing out on the FreeBSD buildbot
251     @no_debug_info_test
252     def test_target_va(self):
253         """Test that 'target va' completes to 'target variable '."""
254         self.complete_from_to('target va', 'target variable ')
255
256     @expectedFailureHostWindows("llvm.org/pr24679")
257     @expectedFailureDarwin("llvm.org/pr25485")
258     def test_symbol_name(self):
259         self.build()
260         self.complete_from_to('''file a.out
261                                  breakpoint set -n Fo''',
262                               'breakpoint set -n Foo::Bar(int,\\ int)',
263                               turn_off_re_match=True)
264
265     def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
266         """Test that the completion mechanism completes str_input to patterns,
267         where patterns could be a pattern-string or a list of pattern-strings"""
268         import pexpect
269         # Patterns should not be None in order to proceed.
270         self.assertFalse(patterns is None)
271         # And should be either a string or list of strings.  Check for list type
272         # below, if not, make a list out of the singleton string.  If patterns
273         # is not a string or not a list of strings, there'll be runtime errors
274         # later on.
275         if not isinstance(patterns, list):
276             patterns = [patterns]
277         
278         # The default lldb prompt.
279         prompt = "(lldb) "
280
281         # So that the child gets torn down after the test.
282         self.child = pexpect.spawn(lldbtest_config.lldbExec,
283                                    [self.lldbOption] + ['--no-use-colors'])
284         child = self.child
285         # Turn on logging for input/output to/from the child.
286         with open('child_send.txt', 'w') as f_send:
287             with open('child_read.txt', 'w') as f_read:
288                 child.logfile_send = f_send
289                 child.logfile_read = f_read
290
291                 child.expect_exact(prompt)
292                 child.setecho(True)
293                 # Sends str_input and a Tab to invoke the completion machinery.
294                 child.send("%s\t" % str_input)
295                 child.sendline('')
296                 child.expect_exact(prompt)
297                 child.sendline('')
298                 child.expect_exact(prompt)
299
300         # Now that the necessary logging is done, restore logfile to None to
301         # stop further logging.
302         child.logfile_send = None
303         child.logfile_read = None
304         
305         with open('child_send.txt', 'r') as fs:
306             if self.TraceOn():
307                 print("\n\nContents of child_send.txt:")
308                 print(fs.read())
309         with open('child_read.txt', 'r') as fr:
310             from_child = fr.read()
311             if self.TraceOn():
312                 print("\n\nContents of child_read.txt:")
313                 print(from_child)
314
315             # The matching could be verbatim or using generic re pattern.
316             for p in patterns:
317                 # Test that str_input completes to our patterns or substrings.
318                 # If each pattern/substring matches from_child, the completion mechanism works!
319                 if turn_off_re_match:
320                     self.expect(from_child, msg=COMPLETION_MSG(str_input, p), exe=False,
321                         substrs = [p])
322                 else:
323                     self.expect(from_child, msg=COMPLETION_MSG(str_input, p), exe=False,
324                         patterns = [p])