mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 00:39:46 +00:00
testimage: Run commands in target and host when test fails
This patch modify three files altought two of them
are minimal modifications. This version includes
the changes proposed by Paul.
testimage.bbclass:
Create new vars for easy modification of the dump
directory and commands to be run on host and target
when a test fails
TESTIMAGE_DUMP_DIR: Directory to save the dumps
testimage_dump_target: Commands to run on target
testimage_dump_host: Commands to run on host
oetest.py:
- Allow to use the vars defined in testimage class
- Now able to run commands in the host and dump the
results
- Fix an issue with the condition where to run the
dump commands (Before it run the commands every
test after a failure, now it runs the commands only
in tests that failed)
- Fix the output to stdout
[YOCTO #8118]
(From OE-Core rev: 26fe645457633f90bb5ddbb12f5f7b9ca4a06cc5)
(From OE-Core rev: 7b4fbbf979ed22434b8e3f83ae145139bb0d9fc7)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
f9f1643ead
commit
48373be830
@@ -56,6 +56,30 @@ TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d
|
|||||||
TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
|
TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
|
||||||
TESTIMAGELOCK_qemuall = ""
|
TESTIMAGELOCK_qemuall = ""
|
||||||
|
|
||||||
|
TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
|
||||||
|
|
||||||
|
testimage_dump_target () {
|
||||||
|
top -bn1
|
||||||
|
ps
|
||||||
|
free
|
||||||
|
df
|
||||||
|
_ping
|
||||||
|
dmesg
|
||||||
|
netstat -an
|
||||||
|
ip address
|
||||||
|
_logs
|
||||||
|
}
|
||||||
|
|
||||||
|
testimage_dump_host () {
|
||||||
|
top -bn1
|
||||||
|
ps -ef
|
||||||
|
free
|
||||||
|
df
|
||||||
|
memstat
|
||||||
|
dmesg
|
||||||
|
netstat -an
|
||||||
|
}
|
||||||
|
|
||||||
python do_testimage() {
|
python do_testimage() {
|
||||||
testimage_main(d)
|
testimage_main(d)
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-14
@@ -12,8 +12,10 @@ import unittest
|
|||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
import subprocess
|
||||||
import datetime
|
import datetime
|
||||||
|
import commands
|
||||||
import bb
|
import bb
|
||||||
from oeqa.utils.decorators import LogResults
|
from oeqa.utils.decorators import LogResults
|
||||||
|
from sys import exc_info, exc_clear
|
||||||
|
|
||||||
def loadTests(tc, type="runtime"):
|
def loadTests(tc, type="runtime"):
|
||||||
if type == "runtime":
|
if type == "runtime":
|
||||||
@@ -120,35 +122,51 @@ class oeRuntimeTest(oeTest):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# If a test fails or there is an exception
|
# If a test fails or there is an exception
|
||||||
if (self._resultForDoCleanups.failures or
|
if not exc_info() == (None, None, None):
|
||||||
self._resultForDoCleanups.errors):
|
exc_clear()
|
||||||
self.dump_target_logs()
|
dump_dir = self.create_dump_dir()
|
||||||
|
print ("%s dump data from host and target "
|
||||||
|
"stored in %s" % (self._testMethodName, dump_dir))
|
||||||
|
self.dump_host_logs(dump_dir)
|
||||||
|
self.dump_target_logs(dump_dir)
|
||||||
|
|
||||||
def dump_target_logs(self):
|
def create_dump_dir(self):
|
||||||
commands = ["top -bn1", "ps", "free", "df", "_ping", "dmesg", "netstat -a", "ifconfig -a", "_logs"]
|
|
||||||
dump_dir = "/tmp/oe-saved-tests"
|
|
||||||
dump_sub_dir = ("%s_%s" % (
|
dump_sub_dir = ("%s_%s" % (
|
||||||
datetime.datetime.now().strftime('%Y%m%d%H%M'),
|
datetime.datetime.now().strftime('%Y%m%d%H%M'),
|
||||||
self._testMethodName))
|
self._testMethodName))
|
||||||
dump_dir = os.path.join(dump_dir, dump_sub_dir)
|
dump_dir = os.path.join(self.target.dump_dir, dump_sub_dir)
|
||||||
os.makedirs(dump_dir)
|
os.makedirs(dump_dir)
|
||||||
bb.warn("%s failed: getting data from target and "
|
return dump_dir
|
||||||
"saving into %s" % (self._testMethodName, dump_dir))
|
|
||||||
for command in commands:
|
def dump_host_logs(self, dump_dir):
|
||||||
|
for cmd in self.target.dump_host.split('\n'):
|
||||||
|
cmd = cmd.lstrip()
|
||||||
|
if not cmd:
|
||||||
|
continue
|
||||||
|
output = commands.getoutput(cmd)
|
||||||
|
filename = "host_%s" % cmd.split()[0]
|
||||||
|
with open(os.path.join(dump_dir, filename), 'w') as f:
|
||||||
|
f.write(output)
|
||||||
|
|
||||||
|
def dump_target_logs(self, dump_dir):
|
||||||
|
for cmd in self.target.dump_target.split('\n'):
|
||||||
|
cmd = cmd.lstrip()
|
||||||
|
if not cmd:
|
||||||
|
continue
|
||||||
# This will ping the host from target
|
# This will ping the host from target
|
||||||
if command == "_ping":
|
if cmd == "_ping":
|
||||||
comm = "ping -c3 %s" % self.target.server_ip
|
comm = "ping -c3 %s" % self.target.server_ip
|
||||||
# This will get all the logs from /var/log/
|
# This will get all the logs from /var/log/
|
||||||
elif command == "_logs":
|
elif cmd == "_logs":
|
||||||
comm = 'find /var/log/ -type f 2>/dev/null '
|
comm = 'find /var/log/ -type f 2>/dev/null '
|
||||||
comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
|
comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
|
||||||
comm = '%s-exec echo {} \\; ' % comm
|
comm = '%s-exec echo {} \\; ' % comm
|
||||||
comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
|
comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
|
||||||
comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm
|
comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm
|
||||||
else:
|
else:
|
||||||
comm = command
|
comm = cmd
|
||||||
(status, output) = self.target.run_serial(comm)
|
(status, output) = self.target.run_serial(comm)
|
||||||
filename = command.split()[0]
|
filename = "target_%s" % cmd.split()[0]
|
||||||
with open(os.path.join(dump_dir, filename), 'w') as f:
|
with open(os.path.join(dump_dir, filename), 'w') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ class QemuTarget(BaseTarget):
|
|||||||
self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
|
self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
|
||||||
self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
|
self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
|
||||||
self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')
|
self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')
|
||||||
|
self.dump_target = d.getVar("testimage_dump_target", True)
|
||||||
|
self.dump_host = d.getVar("testimage_dump_host", True)
|
||||||
|
self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True)
|
||||||
|
|
||||||
# Log QemuRunner log output to a file
|
# Log QemuRunner log output to a file
|
||||||
import oe.path
|
import oe.path
|
||||||
|
|||||||
Reference in New Issue
Block a user