summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/dump.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/dump.py')
-rw-r--r--meta/lib/oeqa/utils/dump.py55
1 files changed, 51 insertions, 4 deletions
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py
index 79c22b75c4..95a79a571c 100644
--- a/meta/lib/oeqa/utils/dump.py
+++ b/meta/lib/oeqa/utils/dump.py
@@ -1,5 +1,10 @@
+#
+# SPDX-License-Identifier: MIT
+#
+
import os
import sys
+import json
import errno
import datetime
import itertools
@@ -13,6 +18,7 @@ class BaseDumper(object):
# Some testing doesn't inherit testimage, so it is needed
# to set some defaults.
self.parent_dir = parent_dir
+ self.dump_dir = parent_dir
dft_cmds = """ top -bn1
iostat -x -z -N -d -p ALL 20 2
ps -ef
@@ -42,11 +48,13 @@ class BaseDumper(object):
raise err
self.dump_dir = dump_dir
- def _write_dump(self, command, output):
+ def _construct_filename(self, command):
if isinstance(self, HostDumper):
prefix = "host"
elif isinstance(self, TargetDumper):
prefix = "target"
+ elif isinstance(self, MonitorDumper):
+ prefix = "qmp"
else:
prefix = "unknown"
for i in itertools.count():
@@ -54,9 +62,17 @@ class BaseDumper(object):
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)
+ return fullname
+ def _write_dump(self, command, output):
+ fullname = self._construct_filename(command)
+ os.makedirs(os.path.dirname(fullname), exist_ok=True)
+ if isinstance(self, MonitorDumper):
+ with open(fullname, 'w') as json_file:
+ json.dump(output, json_file, indent=4)
+ else:
+ with open(fullname, 'w') as dump_file:
+ dump_file.write(output)
class HostDumper(BaseDumper):
""" Class to get dumps from the host running the tests """
@@ -67,8 +83,11 @@ class HostDumper(BaseDumper):
def dump_host(self, dump_dir=""):
if dump_dir:
self.dump_dir = dump_dir
+ env = os.environ.copy()
+ env['PATH'] = '/usr/sbin:/sbin:/usr/bin:/bin'
+ env['COLUMNS'] = '9999'
for cmd in self.cmds:
- result = runCmd(cmd, ignore_status=True)
+ result = runCmd(cmd, ignore_status=True, env=env)
self._write_dump(cmd.split()[0], result.output)
class TargetDumper(BaseDumper):
@@ -89,3 +108,31 @@ class TargetDumper(BaseDumper):
except:
print("Tried to dump info from target but "
"serial console failed")
+ print("Failed CMD: %s" % (cmd))
+
+class MonitorDumper(BaseDumper):
+ """ Class to get dumps via the Qemu Monitor, it only works with QemuRunner """
+
+ def __init__(self, cmds, parent_dir, runner):
+ super(MonitorDumper, self).__init__(cmds, parent_dir)
+ self.runner = runner
+
+ def dump_monitor(self, dump_dir=""):
+ if self.runner is None:
+ return
+ if dump_dir:
+ self.dump_dir = dump_dir
+ for cmd in self.cmds:
+ cmd_name = cmd.split()[0]
+ try:
+ if len(cmd.split()) > 1:
+ cmd_args = cmd.split()[1]
+ if "%s" in cmd_args:
+ filename = self._construct_filename(cmd_name)
+ cmd_data = json.loads(cmd_args % (filename))
+ output = self.runner.run_monitor(cmd_name, cmd_data)
+ else:
+ output = self.runner.run_monitor(cmd_name)
+ self._write_dump(cmd_name, output)
+ except Exception as e:
+ print("Failed to dump QMP CMD: %s with\nException: %s" % (cmd_name, e))