[CRIU] [PATCHv0 08/12] zdtm: implement capturing of test hooks stdout and stderr
Eugene Batalov
eabatalov89 at gmail.com
Sun Jul 24 11:58:10 PDT 2016
Using this feature hooks can return arbitrary data
to zdtm.py. This will be used in gc tests to tell
zdtm.py what garbage should be found by criu gc --show.
Also added function run_hook for cases when test hook always
should exist. This is needed for gc tests too.
Also this 2 features are generic and can be used in other cases.
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
test/zdtm.py | 42 ++++++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/test/zdtm.py b/test/zdtm.py
index 230902c..2edb9bc 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -830,14 +830,40 @@ class criu_cli:
print "CRIU binary not built"
sys.exit(1)
-
-def try_run_hook(test, args):
- hname = test.getname() + '.hook'
- if os.access(hname, os.X_OK):
- print "Running %s(%s)" % (hname, ', '.join(args))
- hook = subprocess.Popen([hname] + args)
- if hook.wait() != 0:
- raise test_fail_exc("hook " + " ".join(args))
+def hook_name(test):
+ return test.getname() + '.hook'
+
+def run_hook(test, args, cap_output = False):
+ stdout_str = None
+ stderr_str = None
+
+ subproc_args = { "args" : [hook_name(test)] + args }
+ if cap_output:
+ subproc_args["stdout"] = subprocess.PIPE
+ subproc_args["stderr"] = subprocess.PIPE
+ print "Running %s" % str(subproc_args)
+ try:
+ hook = subprocess.Popen(**subproc_args)
+ if cap_output:
+ stdout_str, stderr_str = hook.communicate()
+ else:
+ hook.wait()
+ if hook.returncode != 0:
+ print "Hook %s return code %d" % (
+ hook_name(test), hook.returncode)
+ if cap_output:
+ print stdout_str
+ print stderr_str
+ raise Exception()
+ except:
+ raise test_fail_exc("hook " + " ".join(args))
+
+ return (stdout_str, stderr_str)
+
+def try_run_hook(test, args, cap_output = False):
+ if os.access(hook_name(test), os.X_OK):
+ return run_hook(test, args, cap_output)
+ return (None, None)
#
# Step by step execution
--
1.9.1
More information about the CRIU
mailing list