2015-02-03 06:12:39 +08:00
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
import lldbutil
|
|
|
|
import os
|
|
|
|
import unittest2
|
|
|
|
import sys
|
|
|
|
import pexpect
|
|
|
|
|
|
|
|
class PExpectTest(TestBase):
|
|
|
|
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
TestBase.setUp(self)
|
|
|
|
|
|
|
|
def launchArgs(self):
|
2015-02-03 07:03:37 +08:00
|
|
|
pass
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2015-02-03 09:06:35 +08:00
|
|
|
def launch(self, timeout=None):
|
|
|
|
if timeout is None: timeout = 30
|
2015-02-03 10:46:36 +08:00
|
|
|
logfile = sys.stdout if self.TraceOn() else None
|
|
|
|
self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.launchArgs()), logfile=logfile)
|
2015-02-03 09:06:35 +08:00
|
|
|
self.child.timeout = timeout
|
|
|
|
self.timeout = timeout
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2015-02-03 09:00:44 +08:00
|
|
|
def expect(self, patterns=None, timeout=None, exact=None):
|
2015-02-03 07:03:37 +08:00
|
|
|
if patterns is None: return None
|
|
|
|
if timeout is None: timeout = self.timeout
|
2015-02-03 08:59:28 +08:00
|
|
|
if exact is None: exact = False
|
|
|
|
if exact:
|
|
|
|
return self.child.expect_exact(patterns, timeout=timeout)
|
|
|
|
else:
|
|
|
|
return self.child.expect(patterns, timeout=timeout)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2015-02-03 11:11:59 +08:00
|
|
|
def expectall(self, patterns=None, timeout=None, exact=None):
|
|
|
|
if patterns is None: return None
|
|
|
|
if timeout is None: timeout = self.timeout
|
|
|
|
if exact is None: exact = False
|
|
|
|
for pattern in patterns:
|
|
|
|
self.expect(pattern, timeout=timeout, exact=exact)
|
|
|
|
|
2015-02-03 08:59:28 +08:00
|
|
|
def sendimpl(self, sender, command, patterns=None, timeout=None, exact=None):
|
2015-02-03 06:12:39 +08:00
|
|
|
sender(command)
|
2015-02-03 08:59:28 +08:00
|
|
|
return self.expect(patterns=patterns, timeout=timeout, exact=exact)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2015-02-03 08:59:28 +08:00
|
|
|
def send(self, command, patterns=None, timeout=None, exact=None):
|
|
|
|
return self.sendimpl(self.child.send, command, patterns, timeout, exact)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
2015-02-03 08:59:28 +08:00
|
|
|
def sendline(self, command, patterns=None, timeout=None, exact=None):
|
|
|
|
return self.sendimpl(self.child.sendline, command, patterns, timeout, exact)
|
2015-02-03 06:12:39 +08:00
|
|
|
|
|
|
|
def quit(self, gracefully=None):
|
|
|
|
if gracefully is None: gracefully = True
|
|
|
|
self.child.sendeof()
|
|
|
|
self.child.close(force=not gracefully)
|
|
|
|
self.child = None
|