]> code.ossystems Code Review - openembedded-core.git/commitdiff
qemurunner.py: Add method run_serial
authorMariano Lopez <mariano.lopez@linux.intel.com>
Tue, 11 Aug 2015 13:24:44 +0000 (13:24 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 16 Aug 2015 08:24:17 +0000 (09:24 +0100)
The only need for the console before this patch was
to check if the target has booted. This allows to send
commands to the terminal.

This new method is based on the method with the same name
of the QemuTinyRunner class. The difference here is it will
remove the command and the prompt. The other diference is
it will send an echo $? to check if the last command was
successful.

[YOCTO #8118]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oeqa/utils/qemurunner.py

index 9bb1f4bb2df5e5f1266f19d4f880f586f0fcc4a9..81ca32e11b7181c0285ef0ec2cbfabe9352e56cf 100644 (file)
@@ -262,3 +262,33 @@ class QemuRunner:
             basecmd = os.path.basename(basecmd)
             if "qemu-system" in basecmd and "-serial tcp" in commands[p]:
                 return [int(p),commands[p]]
+
+    def run_serial(self, command):
+        # We assume target system have echo to get command status
+        self.server_socket.sendall("%s; echo $?\n" % command)
+        data = ''
+        status = 0
+        stopread = False
+        endtime = time.time()+5
+        while time.time()<endtime and not stopread:
+                sread, _, _ = select.select([self.server_socket],[],[],5)
+                for sock in sread:
+                        answer = sock.recv(1024)
+                        if answer:
+                                data += answer
+                        else:
+                                sock.close()
+                                stopread = True
+        if data:
+            # Remove first line (command line) and last line (prompt)
+            data = data[data.find('$?\r\n')+4:data.rfind('\r\n')]
+            index = data.rfind('\r\n')
+            if index == -1:
+                status_cmd = data
+                data = ""
+            else:
+                status_cmd = data[index+2:]
+                data = data[:index]
+            if (status_cmd == "0"):
+                status = 1
+        return (status, str(data))