diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2015-08-24 19:04:02 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-30 12:36:12 +0100 |
commit | 85fd1a7a121daffc3c5c530930f832ecc61ef83d (patch) | |
tree | ee70ad65c0392775d8a4da174bd992e8e760c2e9 /meta/lib/oeqa/utils | |
parent | d14ffaf6a366442bcf88e44ee3e105f9dea1e69c (diff) | |
download | poky-85fd1a7a121daffc3c5c530930f832ecc61ef83d.tar.gz |
dump: Created new classes for dump host and target
It makes sense to separate the dump commands from the
oeRuntimeTest class, this way it can be used in all
the test context.
These are the changes included in this patch:
- Created classes: BaseDumper, HostDumper, TargetDumper
- Create an instance of HostDumper in imagetest.bbclass
and add it to TestContext class, this way any class
that have access to the TestContext would be able
to dump logs from the host
- Create an instance of TargetDumper in QemuTarget
class after get the runner, this way it is
accessible during the tests.
[YOCTO #8118]
(From OE-Core rev: ad10af6be343b5425fde43055263b0744c161cb3)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r-- | meta/lib/oeqa/utils/dump.py | 77 |
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 @@ | |||
1 | import os | ||
2 | import sys | ||
3 | import errno | ||
4 | import datetime | ||
5 | import itertools | ||
6 | from commands import runCmd | ||
7 | |||
8 | def get_host_dumper(d): | ||
9 | return HostDumper(d) | ||
10 | |||
11 | |||
12 | class 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 | |||
45 | class 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 | |||
62 | class 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) | ||