[oe-commits] Mariano Lopez : oetest.py: Added method tearDown for oeRuntimeTest
git at git.openembedded.org
git at git.openembedded.org
Sun Aug 16 08:32:22 UTC 2015
Module: openembedded-core.git
Branch: master
Commit: 8bbfef69828d9b053e2a33dfa9d8318d9572cf6b
URL: http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=8bbfef69828d9b053e2a33dfa9d8318d9572cf6b
Author: Mariano Lopez <mariano.lopez at linux.intel.com>
Date: Wed Aug 12 10:58:53 2015 +0000
oetest.py: Added method tearDown for oeRuntimeTest
The tearDown method is triggered when a tests ends
it doesn't matter if fails or succeeds. Inside this
method added an evalution to check if fails and then
run some commands in the target to get the data for
later debugging.
[YOCTO #8118]
Signed-off-by: Mariano Lopez <mariano.lopez at linux.intel.com>
Signed-off-by: Ross Burton <ross.burton at intel.com>
---
meta/lib/oeqa/oetest.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 22d76b3..a3f297a 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -11,6 +11,7 @@ import os, re, mmap
import unittest
import inspect
import subprocess
+import datetime
import bb
from oeqa.utils.decorators import LogResults
@@ -117,6 +118,42 @@ class oeRuntimeTest(oeTest):
self.target = oeRuntimeTest.tc.target
super(oeRuntimeTest, self).__init__(methodName)
+ def tearDown(self):
+ # If a test fails or there is an exception
+ if (self._resultForDoCleanups.failures or
+ self._resultForDoCleanups.errors):
+ commands = ["top -bn1", "ps", "free", "df", "_ping", "dmesg", "netstat -a", "ifconfig -a", "_logs"]
+ dump_dir = "/tmp/oe-saved-tests"
+ dump_dir = os.path.join(dump_dir,
+ datetime.datetime.now().strftime('%Y%m%d%H%M'))
+ os.makedirs(dump_dir)
+ bb.warn("Test failed, getting data from target "
+ "and saving it in %s" % dump_dir)
+ output = self.run_bulk_commands(commands)
+ for key,msg in output.iteritems():
+ filename = key.split()[0]
+ with open(os.path.join(dump_dir, filename), 'w') as f:
+ f.write(msg)
+
+ def run_bulk_commands(self, commands):
+ all_output = {}
+ for command in commands:
+ # This will ping the host from target
+ if command == "_ping":
+ comm = "ping -c3 %s" % self.target.server_ip
+ # This will get all the logs from /var/log/
+ elif command == "_logs":
+ comm = 'find /var/log/ -type f 2>/dev/null '
+ comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
+ comm = '%s-exec echo {} \\; ' % comm
+ comm = '%s-exec echo "%s" \\; ' % (comm, '='*20)
+ comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm
+ else:
+ comm = command
+ (status, output) = self.target.run_serial(comm)
+ all_output[command] = output
+ return all_output
+
#TODO: use package_manager.py to install packages on any type of image
def install_packages(self, packagelist):
for package in packagelist:
More information about the Openembedded-commits
mailing list