1from __future__ import print_function 2from __future__ import absolute_import 3 4# System modules 5import sys 6 7# Third-party modules 8import six 9 10# LLDB Modules 11import lldb 12from .lldbtest import * 13from . import lldbutil 14 15if sys.platform.startswith('win32'): 16 # llvm.org/pr22274: need a pexpect replacement for windows 17 class PExpectTest(object): 18 pass 19else: 20 import pexpect 21 22 class PExpectTest(TestBase): 23 24 NO_DEBUG_INFO_TESTCASE = True 25 PROMPT = "(lldb) " 26 27 def expect_prompt(self): 28 self.child.expect_exact(self.PROMPT) 29 30 def launch(self, executable=None, timeout=30, dimensions=None): 31 logfile = sys.stdout if self.TraceOn() else None 32 args = ['--no-lldbinit', '--no-use-colors'] 33 for cmd in self.setUpCommands(): 34 args += ['-O', cmd] 35 if executable is not None: 36 args += ['--file', executable] 37 self.child = pexpect.spawn( 38 lldbtest_config.lldbExec, args=args, logfile=logfile, 39 timeout=timeout, dimensions=dimensions) 40 self.expect_prompt() 41 for cmd in self.setUpCommands(): 42 self.child.expect_exact(cmd) 43 self.expect_prompt() 44 if executable is not None: 45 self.child.expect_exact("target create") 46 self.child.expect_exact("Current executable set to") 47 self.expect_prompt() 48 49 def expect(self, cmd, substrs=None): 50 self.child.sendline(cmd) 51 if substrs is not None: 52 for s in substrs: 53 self.child.expect_exact(s) 54 self.expect_prompt() 55 56 def quit(self, gracefully=True): 57 self.child.sendeof() 58 self.child.close(force=not gracefully) 59 self.child = None 60