Enrico Granata | 78b7d5f | 2015-02-02 22:12:39 +0000 | [diff] [blame] | 1 | import lldb |
| 2 | from lldbtest import * |
| 3 | import lldbutil |
| 4 | import os |
| 5 | import unittest2 |
| 6 | import sys |
| 7 | import pexpect |
| 8 | |
| 9 | class PExpectTest(TestBase): |
| 10 | |
| 11 | mydir = TestBase.compute_mydir(__file__) |
| 12 | |
| 13 | def setUp(self): |
| 14 | # Call super's setUp(). |
| 15 | TestBase.setUp(self) |
| 16 | |
| 17 | def doTest(self): |
| 18 | # put your commands here |
| 19 | pass |
| 20 | |
| 21 | def launchArgs(self): |
| 22 | return "" |
| 23 | |
| 24 | def launch(self): |
| 25 | self.timeout = 5 |
Enrico Granata | 15c752f | 2015-02-02 22:55:46 +0000 | [diff] [blame^] | 26 | self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.launchArgs())) |
Enrico Granata | 78b7d5f | 2015-02-02 22:12:39 +0000 | [diff] [blame] | 27 | |
| 28 | def expect(self, patterns=None, timeout=None): |
| 29 | if patterns is None: patterns = '.*' |
| 30 | return self.child.expect(patterns, timeout=timeout) |
| 31 | |
| 32 | def sendimpl(self, sender, command, patterns=None, timeout=None): |
| 33 | if timeout is None: timeout = self.timeout |
| 34 | sender(command) |
| 35 | if patterns is not None: return self.expect(patterns=patterns, timeout=timeout) |
| 36 | return None |
| 37 | |
| 38 | def send(self, command, patterns=None, timeout=None): |
| 39 | self.sendimpl(self.child.send, command, patterns, timeout) |
| 40 | |
| 41 | def sendline(self, command, patterns=None, timeout=None): |
| 42 | self.sendimpl(self.child.sendline, command, patterns, timeout) |
| 43 | |
| 44 | def quit(self, gracefully=None): |
| 45 | if gracefully is None: gracefully = True |
| 46 | self.child.sendeof() |
| 47 | self.child.close(force=not gracefully) |
| 48 | self.child = None |