summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/oetest.py
diff options
context:
space:
mode:
authorMariano Lopez <mariano.lopez@linux.intel.com>2015-08-18 14:52:38 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-30 12:36:07 +0100
commit48373be8303b620fbddda3298e4eb0c8d188f7dc (patch)
treeaf4a10c39aa73f5bfe0670f301ee1688451a23d6 /meta/lib/oeqa/oetest.py
parentf9f1643eadd6a812904e36a1397cf66ce58ff493 (diff)
downloadpoky-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>
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
-rw-r--r--meta/lib/oeqa/oetest.py48
1 files changed, 33 insertions, 15 deletions
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
12import inspect 12import inspect
13import subprocess 13import subprocess
14import datetime 14import datetime
15import commands
15import bb 16import bb
16from oeqa.utils.decorators import LogResults 17from oeqa.utils.decorators import LogResults
18from sys import exc_info, exc_clear
17 19
18def loadTests(tc, type="runtime"): 20def 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