Create the meta-zephyr layer with empty SRC_URI

Initial commit: original work by Randy Witt and Richard Purdie.

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
This commit is contained in:
Randy Witt
2016-12-27 15:35:35 -08:00
committed by Juro Bystricky
commit 7a8d7eb97e
21 changed files with 546 additions and 0 deletions

3
lib/oeqa/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
# Enable other layers to have modules in the same named directory
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@@ -0,0 +1,3 @@
# Enable other layers to have modules in the same named directory
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@@ -0,0 +1,67 @@
# Copyright (C) 2013 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
# This module is used by testimage.bbclass for setting up and controlling a target machine.
import os
import shutil
import bb
import logging
from oeqa.targetcontrol import QemuTarget
from oeqa.utils.dump import TargetDumper
from oeqa.utils.qemuzephyrrunner import QemuZephyrRunner
class QemuTargetZephyr(QemuTarget):
def __init__(self, d):
super(QemuTarget, self).__init__(d)
self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
dump_target_cmds = d.getVar("testimage_dump_target", True)
dump_host_cmds = d.getVar("testimage_dump_host", True)
dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True)
self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("ZEPHYR_IMAGENAME", True))
self.rootfs = ""
# Log QemuRunner log output to a file
import oe.path
bb.utils.mkdirhier(self.testdir)
self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
logger = logging.getLogger('BitBake.QemuRunner')
loggerhandler = logging.FileHandler(self.qemurunnerlog)
loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
logger.addHandler(loggerhandler)
oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)
self.runner = QemuZephyrRunner(machine=d.getVar("MACHINE", True),
rootfs=self.rootfs,
tmpdir = d.getVar("TMPDIR", True),
deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
logfile = self.qemulog,
kernel = self.kernel,
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
def deploy(self):
try:
bb.utils.mkdirhier(self.testdir)
if self.rootfs:
shutil.copyfile(self.origrootfs, self.rootfs)
except Exception as e:
bb.fatal("Error copying rootfs: %s" % e)
qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
if os.path.islink(qemuloglink):
os.unlink(qemuloglink)
os.symlink(self.qemulog, qemuloglink)
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)

View File

@@ -0,0 +1,3 @@
# Enable other layers to have modules in the same named directory
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@@ -0,0 +1,16 @@
import unittest
from oeqa.oetest import oeRuntimeTest
class ZephyrTest(oeRuntimeTest):
def test_boot_tiny(self):
success = False
logfile = self.target.wait_for_serial(300, 30)
with open(logfile) as f:
for line in f:
if "PROJECT EXECUTION SUCCESSFUL" in line:
success = True
break
self.assertTrue(success, msg='"PROJECT EXECUTION SUCCESSFUL" not in %s' % logfile)

View File

@@ -0,0 +1,3 @@
# Enable other layers to have modules in the same named directory
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@@ -0,0 +1,131 @@
# Copyright (C) 2015 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
# This module provides a class for starting qemu images of poky tiny.
# It's used by testimage.bbclass.
import subprocess
import os
import time
import signal
import socket
import select
import bb
import tempfile
from qemurunner import QemuRunner
class QemuZephyrRunner(QemuRunner):
def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, kernel, boottime):
QemuRunner.__init__(self, machine, rootfs, display, tmpdir,
deploy_dir_image, logfile, boottime, None,
None)
# Popen object for runqemu
self.socketfile = tempfile.NamedTemporaryFile()
self.socketname = self.socketfile.name
self.server_socket = None
self.kernel = kernel
def create_socket(self):
tries = 3
while tries > 0:
try:
self.server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.server_socket.connect(self.socketname)
bb.note("Created listening socket for qemu serial console.")
tries = 0
except socket.error, msg:
self.server_socket.close()
bb.error("Failed to create listening socket %s: %s" % (self.socketname, msg))
tries -= 1
def start(self, qemuparams = None):
if not os.path.exists(self.tmpdir):
bb.error("Invalid TMPDIR path %s" % self.tmpdir)
return False
else:
os.environ["OE_TMPDIR"] = self.tmpdir
if not os.path.exists(self.deploy_dir_image):
bb.error("Invalid DEPLOY_DIR_IMAGE path %s" % self.deploy_dir_image)
return False
else:
os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image
if not os.path.exists(self.kernel):
bb.error("Invalid kernel path: %s" % self.deploy_dir_image)
return False
self.qemuparams = '-nographic -serial unix:%s,server' % (self.socketname)
qemu_binary = ""
if 'arm' in self.machine:
qemu_binary = 'qemu-system-arm'
qemu_machine_args = '-machine lm3s6965evb'
elif 'x86' in self.machine:
qemu_binary = 'qemu-system-i386'
qemu_machine_args = '-machine type=pc-0.14'
self.origchldhandler = signal.getsignal(signal.SIGCHLD)
signal.signal(signal.SIGCHLD, self.handleSIGCHLD)
launch_cmd = '%s -kernel %s %s %s' % (qemu_binary, self.kernel, self.qemuparams, qemu_machine_args)
bb.note(launch_cmd)
self.runqemu = subprocess.Popen(launch_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,preexec_fn=os.setpgrp)
#
# We need the preexec_fn above so that all runqemu processes can easily be killed
# (by killing their process group). This presents a problem if this controlling
# process itself is killed however since those processes don't notice the death
# of the parent and merrily continue on.
#
# Rather than hack runqemu to deal with this, we add something here instead.
# Basically we fork off another process which holds an open pipe to the parent
# and also is setpgrp. If/when the pipe sees EOF from the parent dieing, it kills
# the process group. This is like pctrl's PDEATHSIG but for a process group
# rather than a single process.
#
r, w = os.pipe()
self.monitorpid = os.fork()
if self.monitorpid:
os.close(r)
self.monitorpipe = os.fdopen(w, "w")
else:
# child process
os.setpgrp()
os.close(w)
r = os.fdopen(r)
x = r.read()
os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
sys.exit(0)
bb.note("qemu started, pid is %s" % self.runqemu.pid)
#Hack to wait for socket to show up because I'm tired
time.sleep(5)
self.create_socket()
return True
def is_alive(self):
if not self.runqemu:
return False
return True
def wait_for_serial(self, func_timeout, data_timeout):
stopread = False
check_endtime = False
self.server_socket.setblocking(0)
endtime = time.time() + func_timeout
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