summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/oetest.py52
-rw-r--r--meta/lib/oeqa/targetcontrol.py6
-rw-r--r--meta/lib/oeqa/utils/dump.py77
3 files changed, 86 insertions, 49 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index fbf6c56376..9cb8a53795 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -11,8 +11,6 @@ import os, re, mmap
11import unittest 11import unittest
12import inspect 12import inspect
13import subprocess 13import subprocess
14import datetime
15import commands
16import bb 14import bb
17from oeqa.utils.decorators import LogResults 15from oeqa.utils.decorators import LogResults
18from sys import exc_info, exc_clear 16from sys import exc_info, exc_clear
@@ -124,51 +122,13 @@ class oeRuntimeTest(oeTest):
124 # If a test fails or there is an exception 122 # If a test fails or there is an exception
125 if not exc_info() == (None, None, None): 123 if not exc_info() == (None, None, None):
126 exc_clear() 124 exc_clear()
127 dump_dir = self.create_dump_dir() 125 self.tc.host_dumper.create_dir(self._testMethodName)
126 self.target.target_dumper.dump_target(
127 self.tc.host_dumper.dump_dir)
128 self.tc.host_dumper.dump_host()
128 print ("%s dump data from host and target " 129 print ("%s dump data from host and target "
129 "stored in %s" % (self._testMethodName, dump_dir)) 130 "stored in %s" % (self._testMethodName,
130 self.dump_host_logs(dump_dir) 131 self.target.target_dumper.dump_dir))
131 self.dump_target_logs(dump_dir)
132
133 def create_dump_dir(self):
134 dump_sub_dir = ("%s_%s" % (
135 datetime.datetime.now().strftime('%Y%m%d%H%M'),
136 self._testMethodName))
137 dump_dir = os.path.join(self.target.dump_dir, dump_sub_dir)
138 os.makedirs(dump_dir)
139 return dump_dir
140
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
156 # This will ping the host from target
157 if cmd == "_ping":
158 comm = "ping -c3 %s" % self.target.server_ip
159 # This will get all the logs from /var/log/
160 elif cmd == "_logs":
161 comm = 'find /var/log/ -type f 2>/dev/null '
162 comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
163 comm = '%s-exec echo {} \\; ' % comm
164 comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
165 comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm
166 else:
167 comm = cmd
168 (status, output) = self.target.run_serial(comm)
169 filename = "target_%s" % cmd.split()[0]
170 with open(os.path.join(dump_dir, filename), 'w') as f:
171 f.write(output)
172 132
173 #TODO: use package_manager.py to install packages on any type of image 133 #TODO: use package_manager.py to install packages on any type of image
174 def install_packages(self, packagelist): 134 def install_packages(self, packagelist):
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 59cae2eff1..2d58f17ddb 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -14,6 +14,7 @@ import logging
14from oeqa.utils.sshcontrol import SSHControl 14from oeqa.utils.sshcontrol import SSHControl
15from oeqa.utils.qemurunner import QemuRunner 15from oeqa.utils.qemurunner import QemuRunner
16from oeqa.utils.qemutinyrunner import QemuTinyRunner 16from oeqa.utils.qemutinyrunner import QemuTinyRunner
17from oeqa.utils.dump import TargetDumper
17from oeqa.controllers.testtargetloader import TestTargetLoader 18from oeqa.controllers.testtargetloader import TestTargetLoader
18from abc import ABCMeta, abstractmethod 19from abc import ABCMeta, abstractmethod
19 20
@@ -123,9 +124,6 @@ class QemuTarget(BaseTarget):
123 self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype) 124 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) 125 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') 126 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)
129 127
130 # Log QemuRunner log output to a file 128 # Log QemuRunner log output to a file
131 import oe.path 129 import oe.path
@@ -155,6 +153,8 @@ class QemuTarget(BaseTarget):
155 logfile = self.qemulog, 153 logfile = self.qemulog,
156 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True))) 154 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
157 155
156 self.target_dumper = TargetDumper(d, self.runner)
157
158 def deploy(self): 158 def deploy(self):
159 try: 159 try:
160 bb.utils.mkdirhier(self.testdir) 160 bb.utils.mkdirhier(self.testdir)
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py
new file mode 100644
index 0000000000..a0fa699a27
--- /dev/null
+++ b/meta/lib/oeqa/utils/dump.py
@@ -0,0 +1,77 @@
1import os
2import sys
3import errno
4import datetime
5import itertools
6from commands import runCmd
7
8def get_host_dumper(d):
9 return HostDumper(d)
10
11
12class BaseDumper(object):
13
14 def __init__(self, d):
15 self.parent_dir = d.getVar("TESTIMAGE_DUMP_DIR", True)
16
17 def create_dir(self, dir_suffix):
18 dump_subdir = ("%s_%s" % (
19 datetime.datetime.now().strftime('%Y%m%d%H%M'),
20 dir_suffix))
21 dump_dir = os.path.join(self.parent_dir, dump_subdir)
22 try:
23 os.makedirs(dump_dir)
24 except OSError as err:
25 if err.errno != errno.EEXIST:
26 raise err
27 self.dump_dir = dump_dir
28
29 def write_dump(self, command, output):
30 if isinstance(self, HostDumper):
31 prefix = "host"
32 elif isinstance(self, TargetDumper):
33 prefix = "target"
34 else:
35 prefix = "unknown"
36 for i in itertools.count():
37 filename = "%s_%02d_%s" % (prefix, i, command)
38 fullname = os.path.join(self.dump_dir, filename)
39 if not os.path.exists(fullname):
40 break
41 with open(fullname, 'w') as dump_file:
42 dump_file.write(output)
43
44
45class HostDumper(BaseDumper):
46
47 def __init__(self, d):
48 super(HostDumper, self).__init__(d)
49 self.host_cmds = d.getVar("testimage_dump_host", True)
50
51 def dump_host(self, dump_dir=""):
52 if dump_dir:
53 self.dump_dir = dump_dir
54 for cmd in self.host_cmds.split('\n'):
55 cmd = cmd.lstrip()
56 if not cmd or cmd[0] == '#':
57 continue
58 result = runCmd(cmd, ignore_status=True)
59 self.write_dump(cmd.split()[0], result.output)
60
61
62class TargetDumper(BaseDumper):
63
64 def __init__(self, d, qemurunner):
65 super(TargetDumper, self).__init__(d)
66 self.target_cmds = d.getVar("testimage_dump_target", True)
67 self.runner = qemurunner
68
69 def dump_target(self, dump_dir=""):
70 if dump_dir:
71 self.dump_dir = dump_dir
72 for cmd in self.target_cmds.split('\n'):
73 cmd = cmd.lstrip()
74 if not cmd or cmd[0] == '#':
75 continue
76 (status, output) = self.runner.run_serial(cmd)
77 self.write_dump(cmd.split()[0], output)