diff options
| author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2015-08-18 14:52:38 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-30 12:36:07 +0100 |
| commit | 48373be8303b620fbddda3298e4eb0c8d188f7dc (patch) | |
| tree | af4a10c39aa73f5bfe0670f301ee1688451a23d6 | |
| parent | f9f1643eadd6a812904e36a1397cf66ce58ff493 (diff) | |
| download | poky-48373be8303b620fbddda3298e4eb0c8d188f7dc.tar.gz | |
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>
| -rw-r--r-- | meta/classes/testimage.bbclass | 24 | ||||
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 48 | ||||
| -rw-r--r-- | meta/lib/oeqa/targetcontrol.py | 3 |
3 files changed, 60 insertions, 15 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 140babed74..1d9464f5e9 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass | |||
| @@ -56,6 +56,30 @@ TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d | |||
| 56 | TESTIMAGELOCK = "${TMPDIR}/testimage.lock" | 56 | TESTIMAGELOCK = "${TMPDIR}/testimage.lock" |
| 57 | TESTIMAGELOCK_qemuall = "" | 57 | TESTIMAGELOCK_qemuall = "" |
| 58 | 58 | ||
| 59 | TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/" | ||
| 60 | |||
| 61 | testimage_dump_target () { | ||
| 62 | top -bn1 | ||
| 63 | ps | ||
| 64 | free | ||
| 65 | df | ||
| 66 | _ping | ||
| 67 | dmesg | ||
| 68 | netstat -an | ||
| 69 | ip address | ||
| 70 | _logs | ||
| 71 | } | ||
| 72 | |||
| 73 | testimage_dump_host () { | ||
| 74 | top -bn1 | ||
| 75 | ps -ef | ||
| 76 | free | ||
| 77 | df | ||
| 78 | memstat | ||
| 79 | dmesg | ||
| 80 | netstat -an | ||
| 81 | } | ||
| 82 | |||
| 59 | python do_testimage() { | 83 | python do_testimage() { |
| 60 | testimage_main(d) | 84 | testimage_main(d) |
| 61 | } | 85 | } |
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index b6d2a2ca64..fbf6c56376 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
| @@ -12,8 +12,10 @@ import unittest | |||
| 12 | import inspect | 12 | import inspect |
| 13 | import subprocess | 13 | import subprocess |
| 14 | import datetime | 14 | import datetime |
| 15 | import commands | ||
| 15 | import bb | 16 | import bb |
| 16 | from oeqa.utils.decorators import LogResults | 17 | from oeqa.utils.decorators import LogResults |
| 18 | from sys import exc_info, exc_clear | ||
| 17 | 19 | ||
| 18 | def loadTests(tc, type="runtime"): | 20 | def loadTests(tc, type="runtime"): |
| 19 | if type == "runtime": | 21 | if type == "runtime": |
| @@ -120,35 +122,51 @@ class oeRuntimeTest(oeTest): | |||
| 120 | 122 | ||
| 121 | def tearDown(self): | 123 | def tearDown(self): |
| 122 | # If a test fails or there is an exception | 124 | # If a test fails or there is an exception |
| 123 | if (self._resultForDoCleanups.failures or | 125 | if not exc_info() == (None, None, None): |
| 124 | self._resultForDoCleanups.errors): | 126 | exc_clear() |
| 125 | self.dump_target_logs() | 127 | dump_dir = self.create_dump_dir() |
| 126 | 128 | print ("%s dump data from host and target " | |
| 127 | def dump_target_logs(self): | 129 | "stored in %s" % (self._testMethodName, dump_dir)) |
| 128 | commands = ["top -bn1", "ps", "free", "df", "_ping", "dmesg", "netstat -a", "ifconfig -a", "_logs"] | 130 | self.dump_host_logs(dump_dir) |
| 129 | dump_dir = "/tmp/oe-saved-tests" | 131 | self.dump_target_logs(dump_dir) |
| 132 | |||
| 133 | def create_dump_dir(self): | ||
| 130 | dump_sub_dir = ("%s_%s" % ( | 134 | dump_sub_dir = ("%s_%s" % ( |
| 131 | datetime.datetime.now().strftime('%Y%m%d%H%M'), | 135 | datetime.datetime.now().strftime('%Y%m%d%H%M'), |
| 132 | self._testMethodName)) | 136 | self._testMethodName)) |
| 133 | dump_dir = os.path.join(dump_dir, dump_sub_dir) | 137 | dump_dir = os.path.join(self.target.dump_dir, dump_sub_dir) |
| 134 | os.makedirs(dump_dir) | 138 | os.makedirs(dump_dir) |
| 135 | bb.warn("%s failed: getting data from target and " | 139 | return dump_dir |
| 136 | "saving into %s" % (self._testMethodName, dump_dir)) | 140 | |
| 137 | for command in commands: | 141 | def dump_host_logs(self, dump_dir): |
| 142 | for cmd in self.target.dump_host.split('\n'): | ||
| 143 | cmd = cmd.lstrip() | ||
| 144 | if not cmd: | ||
| 145 | continue | ||
| 146 | output = commands.getoutput(cmd) | ||
| 147 | filename = "host_%s" % cmd.split()[0] | ||
| 148 | with open(os.path.join(dump_dir, filename), 'w') as f: | ||
| 149 | f.write(output) | ||
| 150 | |||
| 151 | def dump_target_logs(self, dump_dir): | ||
| 152 | for cmd in self.target.dump_target.split('\n'): | ||
| 153 | cmd = cmd.lstrip() | ||
| 154 | if not cmd: | ||
| 155 | continue | ||
| 138 | # This will ping the host from target | 156 | # This will ping the host from target |
| 139 | if command == "_ping": | 157 | if cmd == "_ping": |
| 140 | comm = "ping -c3 %s" % self.target.server_ip | 158 | comm = "ping -c3 %s" % self.target.server_ip |
| 141 | # This will get all the logs from /var/log/ | 159 | # This will get all the logs from /var/log/ |
| 142 | elif command == "_logs": | 160 | elif cmd == "_logs": |
| 143 | comm = 'find /var/log/ -type f 2>/dev/null ' | 161 | comm = 'find /var/log/ -type f 2>/dev/null ' |
| 144 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | 162 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) |
| 145 | comm = '%s-exec echo {} \\; ' % comm | 163 | comm = '%s-exec echo {} \\; ' % comm |
| 146 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | 164 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) |
| 147 | comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm | 165 | comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm |
| 148 | else: | 166 | else: |
| 149 | comm = command | 167 | comm = cmd |
| 150 | (status, output) = self.target.run_serial(comm) | 168 | (status, output) = self.target.run_serial(comm) |
| 151 | filename = command.split()[0] | 169 | filename = "target_%s" % cmd.split()[0] |
| 152 | with open(os.path.join(dump_dir, filename), 'w') as f: | 170 | with open(os.path.join(dump_dir, filename), 'w') as f: |
| 153 | f.write(output) | 171 | f.write(output) |
| 154 | 172 | ||
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py index c76887bae1..59cae2eff1 100644 --- a/meta/lib/oeqa/targetcontrol.py +++ b/meta/lib/oeqa/targetcontrol.py | |||
| @@ -123,6 +123,9 @@ class QemuTarget(BaseTarget): | |||
| 123 | self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype) | 123 | self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype) |
| 124 | self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype) | 124 | self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype) |
| 125 | self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') | 125 | self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') |
| 126 | self.dump_target = d.getVar("testimage_dump_target", True) | ||
| 127 | self.dump_host = d.getVar("testimage_dump_host", True) | ||
| 128 | self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True) | ||
| 126 | 129 | ||
| 127 | # Log QemuRunner log output to a file | 130 | # Log QemuRunner log output to a file |
| 128 | import oe.path | 131 | import oe.path |
