testimage: performace improvements

Refactored processing of QEMU logs.
The original code read QEMU logs every 30 seconds, which
resulted in each test taking at least 30 seconds to finish.
In reality, most tests take only a few seconds.
Although the tests run in parallel, on systems with only a few
CPUs this can make a very noticable difference.

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
This commit is contained in:
Juro Bystricky
2017-02-03 16:48:32 -08:00
parent 02ef240e41
commit a3f51b0ada
3 changed files with 55 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2013-2016 Intel Corporation
# Copyright (C) 2013-2017 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
@@ -62,5 +62,5 @@ class QemuTargetZephyr(QemuTarget):
bb.note("Qemu log file: %s" % self.qemulog)
super(QemuTarget, self).deploy()
def wait_for_serial(self, func_timeout, data_timeout):
return self.runner.wait_for_serial(func_timeout, data_timeout)
def serial_readline(self):
return self.runner.serial_readline()

View File

@@ -5,19 +5,24 @@ class ZephyrTest(oeRuntimeTest):
def test_boot_zephyr(self):
success = False
logfile = self.target.wait_for_serial(180, 30)
logfile = self.target.qemurunnerlog
while True:
line = self.target.serial_readline().decode("utf-8")
with open(logfile) as f:
for line in f:
# All good
if "PROJECT EXECUTION SUCCESSFUL" in line:
success = True
break
# Most likely cause for faults is incorrectly compiled code
if "***** USAGE FAULT *****" in line:
success = False
self.assertTrue(success, msg='***** USAGE FAULT *****" in file:///%s' % logfile)
break
# All good
if "PROJECT EXECUTION SUCCESSFUL" in line:
success = True
break
if "PROJECT EXECUTION FAILED" in line:
success = False
self.assertTrue(success, msg='PROJECT EXECUTION FAILED in file:///%s' % logfile)
break
# Most likely cause for faults is incorrectly compiled code
if "***** USAGE FAULT *****" in line:
success = False
self.assertTrue(success, msg='***** USAGE FAULT *****" in file:///%s' % logfile)
break
# test program finished, complain if no success message
self.assertTrue(success, msg='"PROJECT EXECUTION SUCCESSFUL" not in file:///%s' % logfile)

View File

@@ -1,8 +1,8 @@
# Copyright (C) 2015-2016 Intel Corporation
# Copyright (C) 2015-2017 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
# This module provides a class for starting qemu images of poky tiny.
# This module provides a class for starting qemu images.
# It's used by testimage.bbclass.
import subprocess
@@ -13,6 +13,7 @@ import socket
import select
import bb
import tempfile
import sys
from oeqa.utils.qemurunner import QemuRunner
class QemuZephyrRunner(QemuRunner):
@@ -28,6 +29,10 @@ class QemuZephyrRunner(QemuRunner):
self.socketname = self.socketfile.name
self.server_socket = None
self.kernel = kernel
self.buffers = b''
self._rbufsize = 4096
# 5 minutes timeout...
self.endtime = time.time() + 60*5
def create_socket(self):
bb.note("waiting at most %s seconds for qemu pid" % self.runqemutime)
@@ -117,20 +122,33 @@ class QemuZephyrRunner(QemuRunner):
bb.note("qemu started, pid is %s" % self.runqemu.pid)
return self.create_socket()
def wait_for_serial(self, func_timeout, data_timeout):
stopread = False
check_endtime = False
self.server_socket.setblocking(0)
endtime = time.time() + func_timeout
def _readline(self):
nl = self.buffers.find(b'\n')
if nl >= 0:
nl += 1
line = self.buffers[:nl]
newbuf = self.buffers[nl:]
self.buffers = newbuf
return line
return None
def serial_readline(self):
line = self._readline()
if line is None:
while True:
if time.time() >= self.endtime:
bb.warn("Timeout!")
raise Exception("Timeout")
data = self.server_socket.recv(self._rbufsize)
if data is None:
raise Exception("No data on read ready socket")
self.buffers = self.buffers + data
line = self._readline()
if line is not None:
break
self.log(line)
return line
while time.time() < endtime:
sread, _, _ = select.select([self.server_socket],[],[],data_timeout)
if not sread:
break
answer = self.server_socket.recv(1024)
if answer:
self.log(answer)
else:
break
return self.logfile