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, extra_args=None, timeout=30, dimensions=None): 31 logfile = getattr(sys.stdout, 'buffer', 32 sys.stdout) if self.TraceOn() else None 33 args = ['--no-lldbinit', '--no-use-colors'] 34 for cmd in self.setUpCommands(): 35 args += ['-O', cmd] 36 if executable is not None: 37 args += ['--file', executable] 38 if extra_args is not None: 39 args.extend(extra_args) 40 self.child = pexpect.spawn( 41 lldbtest_config.lldbExec, args=args, logfile=logfile, 42 timeout=timeout, dimensions=dimensions) 43 self.expect_prompt() 44 for cmd in self.setUpCommands(): 45 self.child.expect_exact(cmd) 46 self.expect_prompt() 47 if executable is not None: 48 self.child.expect_exact("target create") 49 self.child.expect_exact("Current executable set to") 50 self.expect_prompt() 51 52 def expect(self, cmd, substrs=None): 53 self.assertNotIn('\n', cmd) 54 self.child.sendline(cmd) 55 if substrs is not None: 56 for s in substrs: 57 self.child.expect_exact(s) 58 self.expect_prompt() 59 60 def quit(self, gracefully=True): 61 self.child.sendeof() 62 self.child.close(force=not gracefully) 63 self.child = None 64