summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2017-03-24 22:46:16 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-27 08:15:06 +0100
commit58e6e7c2043d7f4b48ec3b4b9daf25f5766fa5d2 (patch)
tree292df67088c5a987b3b046670cda5c807d0ffd0b /meta
parent1e3f04f86aac7f547b10c187f82983fa3137be55 (diff)
downloadpoky-58e6e7c2043d7f4b48ec3b4b9daf25f5766fa5d2.tar.gz
qemurunner: configurable timeout for run_serial()
Some commands might need to run longer than the default timeout of five seconds. If that occurred, run_serial() returned with a status code of zero (sic!) and no other indication of what went wrong. Now the timeout is configurable (with five still the default) and an explicit warning ("<<< run_serial(): command timed out after 5 seconds without output >>>") gets appended at the end of the data returned to the caller. While at it, the logic for checking for the timeout was updated a bit because both implementations could overshoot the timeout when entering select() right before the final deadline. (From OE-Core rev: accf0362f964cc9d6330b6e52e83d748d890521f) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/targetcontrol.py4
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py17
-rw-r--r--meta/lib/oeqa/utils/qemutinyrunner.py8
3 files changed, 17 insertions, 12 deletions
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 0ad3a6bf14..2f071e0901 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -206,8 +206,8 @@ class QemuTarget(BaseTarget):
206 else: 206 else:
207 raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn) 207 raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn)
208 208
209 def run_serial(self, command): 209 def run_serial(self, command, timeout=5):
210 return self.runner.run_serial(command) 210 return self.runner.run_serial(command, timeout=timeout)
211 211
212 212
213class SimpleRemoteTarget(BaseTarget): 213class SimpleRemoteTarget(BaseTarget):
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 9ef7629c11..c0abb96546 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -416,7 +416,7 @@ class QemuRunner:
416 if "qemu-system" in basecmd and "-serial tcp" in commands[p]: 416 if "qemu-system" in basecmd and "-serial tcp" in commands[p]:
417 return [int(p),commands[p]] 417 return [int(p),commands[p]]
418 418
419 def run_serial(self, command, raw=False): 419 def run_serial(self, command, raw=False, timeout=5):
420 # We assume target system have echo to get command status 420 # We assume target system have echo to get command status
421 if not raw: 421 if not raw:
422 command = "%s; echo $?\n" % command 422 command = "%s; echo $?\n" % command
@@ -424,20 +424,23 @@ class QemuRunner:
424 data = '' 424 data = ''
425 status = 0 425 status = 0
426 self.server_socket.sendall(command.encode('utf-8')) 426 self.server_socket.sendall(command.encode('utf-8'))
427 keepreading = True 427 start = time.time()
428 while keepreading: 428 end = start + timeout
429 sread, _, _ = select.select([self.server_socket],[],[],5) 429 while True:
430 now = time.time()
431 if now >= end:
432 data += "<<< run_serial(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
433 break
434 sread, _, _ = select.select([self.server_socket],[],[], end - now)
430 if sread: 435 if sread:
431 answer = self.server_socket.recv(1024) 436 answer = self.server_socket.recv(1024)
432 if answer: 437 if answer:
433 data += answer.decode('utf-8') 438 data += answer.decode('utf-8')
434 # Search the prompt to stop 439 # Search the prompt to stop
435 if re.search("[a-zA-Z0-9]+@[a-zA-Z0-9\-]+:~#", data): 440 if re.search("[a-zA-Z0-9]+@[a-zA-Z0-9\-]+:~#", data):
436 keepreading = False 441 break
437 else: 442 else:
438 raise Exception("No data on serial console socket") 443 raise Exception("No data on serial console socket")
439 else:
440 keepreading = False
441 444
442 if data: 445 if data:
443 if raw: 446 if raw:
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py
index ec52473834..b1009a0a37 100644
--- a/meta/lib/oeqa/utils/qemutinyrunner.py
+++ b/meta/lib/oeqa/utils/qemutinyrunner.py
@@ -107,14 +107,14 @@ class QemuTinyRunner(QemuRunner):
107 107
108 return self.is_alive() 108 return self.is_alive()
109 109
110 def run_serial(self, command): 110 def run_serial(self, command, timeout=5):
111 self.server_socket.sendall(command+'\n') 111 self.server_socket.sendall(command+'\n')
112 data = '' 112 data = ''
113 status = 0 113 status = 0
114 stopread = False 114 stopread = False
115 endtime = time.time()+5 115 endtime = time.time()+timeout
116 while time.time()<endtime and not stopread: 116 while time.time()<endtime and not stopread:
117 sread, _, _ = select.select([self.server_socket],[],[],5) 117 sread, _, _ = select.select([self.server_socket],[],[],1)
118 for sock in sread: 118 for sock in sread:
119 answer = sock.recv(1024) 119 answer = sock.recv(1024)
120 if answer: 120 if answer:
@@ -124,6 +124,8 @@ class QemuTinyRunner(QemuRunner):
124 stopread = True 124 stopread = True
125 if not data: 125 if not data:
126 status = 1 126 status = 1
127 if not stopread:
128 data += "<<< run_serial(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
127 return (status, str(data)) 129 return (status, str(data))
128 130
129 def find_child(self,parent_pid): 131 def find_child(self,parent_pid):