From ad10af6be343b5425fde43055263b0744c161cb3 Mon Sep 17 00:00:00 2001 From: Mariano Lopez Date: Mon, 24 Aug 2015 19:04:02 -0500 Subject: 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] Signed-off-by: Mariano Lopez --- meta/lib/oeqa/utils/dump.py | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 meta/lib/oeqa/utils/dump.py (limited to 'meta/lib/oeqa/utils/dump.py') 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 @@ +import os +import sys +import errno +import datetime +import itertools +from commands import runCmd + +def get_host_dumper(d): + return HostDumper(d) + + +class BaseDumper(object): + + def __init__(self, d): + self.parent_dir = d.getVar("TESTIMAGE_DUMP_DIR", True) + + def create_dir(self, dir_suffix): + dump_subdir = ("%s_%s" % ( + datetime.datetime.now().strftime('%Y%m%d%H%M'), + dir_suffix)) + dump_dir = os.path.join(self.parent_dir, dump_subdir) + try: + os.makedirs(dump_dir) + except OSError as err: + if err.errno != errno.EEXIST: + raise err + self.dump_dir = dump_dir + + def write_dump(self, command, output): + if isinstance(self, HostDumper): + prefix = "host" + elif isinstance(self, TargetDumper): + prefix = "target" + else: + prefix = "unknown" + for i in itertools.count(): + filename = "%s_%02d_%s" % (prefix, i, command) + fullname = os.path.join(self.dump_dir, filename) + if not os.path.exists(fullname): + break + with open(fullname, 'w') as dump_file: + dump_file.write(output) + + +class HostDumper(BaseDumper): + + def __init__(self, d): + super(HostDumper, self).__init__(d) + self.host_cmds = d.getVar("testimage_dump_host", True) + + def dump_host(self, dump_dir=""): + if dump_dir: + self.dump_dir = dump_dir + for cmd in self.host_cmds.split('\n'): + cmd = cmd.lstrip() + if not cmd or cmd[0] == '#': + continue + result = runCmd(cmd, ignore_status=True) + self.write_dump(cmd.split()[0], result.output) + + +class TargetDumper(BaseDumper): + + def __init__(self, d, qemurunner): + super(TargetDumper, self).__init__(d) + self.target_cmds = d.getVar("testimage_dump_target", True) + self.runner = qemurunner + + def dump_target(self, dump_dir=""): + if dump_dir: + self.dump_dir = dump_dir + for cmd in self.target_cmds.split('\n'): + cmd = cmd.lstrip() + if not cmd or cmd[0] == '#': + continue + (status, output) = self.runner.run_serial(cmd) + self.write_dump(cmd.split()[0], output) -- cgit 1.2.3-korg