summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/oetest.py
diff options
context:
space:
mode:
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