summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/dump.py77
1 files changed, 77 insertions, 0 deletions
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)