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