diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-06-28 11:09:28 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-07-09 10:53:44 +0100 |
commit | 962c0a1fc0694403b385a6f11d710c8675399352 (patch) | |
tree | 239d5a70e1368c802b23c10e19489d32f96097db /meta | |
parent | ac341af8fafc5ea6e3f937ea6ad078ab0812b2bc (diff) | |
download | poky-962c0a1fc0694403b385a6f11d710c8675399352.tar.gz |
lib/oeqa/utils/oeqemuconsole.py: handle qemu serial console connection
Python's telnetlib Telnet class connects only to AF_INET sockets, but we
want to use Unix domain socket for the qemu serial connection, so that's
why we override it.
Also we add a new read_all_timeout method similar to Telnet's read_all,
that read until a match or timeout and logs all output.
(From OE-Core rev: 1cfec2f0a1a1ee84cc6b2b6ad890688da85c5e81)
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/utils/oeqemuconsole.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/oeqemuconsole.py b/meta/lib/oeqa/utils/oeqemuconsole.py new file mode 100644 index 0000000000..95a21332de --- /dev/null +++ b/meta/lib/oeqa/utils/oeqemuconsole.py | |||
@@ -0,0 +1,45 @@ | |||
1 | import socket | ||
2 | import time | ||
3 | import re | ||
4 | from telnetlib import Telnet | ||
5 | |||
6 | class oeQemuConsole(Telnet): | ||
7 | |||
8 | """ | ||
9 | Override Telnet class to use unix domain sockets, | ||
10 | Telnet uses AF_INET for socket, we don't want that. | ||
11 | Also, provide a read_all variant with timeout, that | ||
12 | returns whatever output there is. | ||
13 | """ | ||
14 | |||
15 | def __init__(self, stream, logfile): | ||
16 | |||
17 | Telnet.__init__(self, host=None) | ||
18 | self.stream = stream | ||
19 | self.logfile = logfile | ||
20 | self.eof = 0 | ||
21 | self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
22 | self.sock.connect(stream) | ||
23 | |||
24 | def log(self, msg): | ||
25 | if self.logfile: | ||
26 | with open(self.logfile, "a") as f: | ||
27 | f.write("%s\n" % msg) | ||
28 | |||
29 | |||
30 | def read_all_timeout(self, match, timeout=200): | ||
31 | """Read until EOF or until timeout or until match. | ||
32 | """ | ||
33 | ret = False | ||
34 | self.process_rawq() | ||
35 | endtime = time.time() + timeout | ||
36 | while not self.eof and time.time() < endtime: | ||
37 | self.fill_rawq() | ||
38 | self.process_rawq() | ||
39 | if re.search(match, self.cookedq): | ||
40 | ret = True | ||
41 | break | ||
42 | buf = self.cookedq | ||
43 | self.cookedq = '' | ||
44 | self.log(buf) | ||
45 | return (ret, buf) | ||