From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWHdo-0000nI-CL for qemu-devel@nongnu.org; Thu, 01 Dec 2011 20:10:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWHdm-0003J5-PE for qemu-devel@nongnu.org; Thu, 01 Dec 2011 20:10:16 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:51178 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWHdl-0003Cy-Ur for qemu-devel@nongnu.org; Thu, 01 Dec 2011 20:10:14 -0500 From: Anthony Liguori Date: Thu, 1 Dec 2011 12:43:29 -0600 Message-Id: <1322765012-3164-4-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1322765012-3164-1-git-send-email-aliguori@us.ibm.com> References: <1322765012-3164-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [RFC v2 3/6] Add core python test framework List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori --- qtest.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-) create mode 100644 qtest.py diff --git a/qtest.py b/qtest.py new file mode 100644 index 0000000..5ac2e9b --- /dev/null +++ b/qtest.py @@ -0,0 +1,69 @@ +import socket + +q = None + +class QTest(object): + def __init__(self, path): + self._sock = socket.socket(socket.AF_UNIX) + self._sock.connect(path) + self.inbuf = '' + self.irqs = {} + for i in range(16): + self.irqs[i] = False + + def _recv(self): + while self.inbuf.find('\n') == -1: + self.inbuf += self._sock.recv(1024) + + rsp, self.inbuf = self.inbuf.split('\n', 1) + return rsp.split() + + def _send(self, command, *args): + outbuf = ' '.join([command] + map(str, args)) + self._sock.sendall(outbuf + '\n') + + def _cmd(self, command, *args): + self._send(command, *args) + while True: + rsp = self._recv() + if rsp[0] in ['IRQ']: + num = int(rsp[2], 0) + if rsp[1] in ['raise']: + self.irqs[num] = True + else: + self.irqs[num] = False + continue + if rsp[0] != 'OK': + raise Exception('Bad response') + break + return rsp[1:] + + def get_irq(self, num): + return self.irqs[num] + +# Helpers to add expected platform functions in the current namespace + +def init(path): + global q + q = QTest(path) + +def outb(addr, value): + q._cmd('outb', addr, value) + +def outw(addr, value): + q._cmd('outw', addr, value) + +def outl(addr, value): + q._cmd('outl', addr, value) + +def inb(addr): + return int(q._cmd('inb', addr)[0], 0) + +def inw(addr): + return int(q._cmd('inw', addr)[0], 0) + +def inl(addr): + return int(q._cmd('inl', addr)[0], 0) + +def get_irq(num): + return q.get_irq(num) -- 1.7.4.1