From 6aed52213c7f9c0318cbf6a85c27c25d482f91a6 Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Mon, 26 Sep 2016 17:50:39 +0200 Subject: [PATCH] Add Screenshot to tct/run/common_test.py Add screenshot_test() to tct/run/common_test.py Add screenshot test to tsp/common_test.yaml Change-Id: I28b9945473ff744bcfe3d8336d5c3e43dfe6ee95 Signed-off-by: Aleksander Mistewicz --- tct/run/common_test.py | 33 +++++++++++++++++++++++++++++++++ tsp/common_test.yaml.example | 3 +++ 2 files changed, 36 insertions(+) diff --git a/tct/run/common_test.py b/tct/run/common_test.py index e8fa68f..f02a402 100755 --- a/tct/run/common_test.py +++ b/tct/run/common_test.py @@ -41,6 +41,26 @@ class SDB(object): """ return subprocess.call(["sdb", "-s", self.serial, "pull", src, dest], stdout=subprocess.PIPE) +class Screenshot(object): + def __init__(self, comm, filename, outputdir): + self.comm = comm + self.filename = filename + self.outputdir = outputdir + + def take(self): + # False, output - screenshooter failed + # True, output - screenshot taken and downloaded + # False, None - screenshot download failed + remote_path = os.path.join("/tmp", self.filename) + local_path = os.path.join(self.outputdir, self.filename) + ret_scr = self.comm.run(["XDG_RUNTIME_DIR=/run", "screenshooter", "-f", remote_path]) + if ret_scr.wait() != 0: # SDB won't + return False, ret_scr.stdout.read() + ret_pull = self.comm.pull(remote_path, local_path) + if ret_pull != 0: + return False, None + return True, ret_scr.stdout.read() + class CommonTest(Test): default_params = {'timeout': 60.0} @@ -71,9 +91,22 @@ class CommonTest(Test): self.systemctl_test() elif test == 'crash': self.crash_test() + elif test == 'screenshot': + self.screenshot_test() else: self.error("Unknown test: %s" % test) + def screenshot(self, name): + ret, out = Screenshot(self.comm, name + ".png", self.outputdir).take() + self.log.debug("outputdir: %s" % self.outputdir) + self.log.debug(out) + self.assertTrue(ret, "Screenshot failed") + + def screenshot_test(self): + self.log.debug("screeenshot_test") + name = self.params.get('name', "/*/common/*", default="initial") + self.screenshot(name) + def systemctl_test(self): self.log.debug("systemctl_test") ref_cnt = self.params.get('ref_cnt', "/*/common/*", default=-1) diff --git a/tsp/common_test.yaml.example b/tsp/common_test.yaml.example index 41fd445..cd77e4b 100644 --- a/tsp/common_test.yaml.example +++ b/tsp/common_test.yaml.example @@ -19,3 +19,6 @@ common: !mux ignored_apps: - 'enlightenment' ref_cnt: 10 + screenshot_init: + test: 'screenshot' + name: 'initial' -- 2.7.4