1from __future__ import absolute_import 2 3# System modules 4import os 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 34 args = ['--no-lldbinit', '--no-use-colors'] 35 for cmd in self.setUpCommands(): 36 args += ['-O', cmd] 37 if executable is not None: 38 args += ['--file', executable] 39 if extra_args is not None: 40 args.extend(extra_args) 41 42 env = dict(os.environ) 43 env["TERM"]="vt100" 44 45 self.child = pexpect.spawn( 46 lldbtest_config.lldbExec, args=args, logfile=logfile, 47 timeout=timeout, dimensions=dimensions, env=env) 48 self.expect_prompt() 49 for cmd in self.setUpCommands(): 50 self.child.expect_exact(cmd) 51 self.expect_prompt() 52 if executable is not None: 53 self.child.expect_exact("target create") 54 self.child.expect_exact("Current executable set to") 55 self.expect_prompt() 56 57 def expect(self, cmd, substrs=None): 58 self.assertNotIn('\n', cmd) 59 self.child.sendline(cmd) 60 if substrs is not None: 61 for s in substrs: 62 self.child.expect_exact(s) 63 self.expect_prompt() 64 65 def quit(self, gracefully=True): 66 self.child.sendeof() 67 self.child.close(force=not gracefully) 68 self.child = None 69