[CRIU] [PATCH v1 07/12] zdtm: implement capturing of criu action stdout and stderr

Eugene Batalov eabatalov89 at gmail.com
Wed Jul 27 22:14:43 PDT 2016


This is needed to analyze output of criu gc --show.
Also this feature is generic and can be used in other cases.

Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 test/zdtm.py | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/test/zdtm.py b/test/zdtm.py
index 52b656e..5ac0c3a 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -680,20 +680,34 @@ class criu_cli:
 		return os.path.join(self.__dump_path, "%d" % self.__iter)
 
 	@staticmethod
-	def __criu(action, args, fault = None, strace = [], preexec = None):
+	def __criu(action, args, fault = None, strace = [], preexec = None,
+		cap_output = False):
 		env = None
 		if fault:
 			print "Forcing %s fault" % fault
 			env = dict(os.environ, CRIU_FAULT = fault)
-		cr = subprocess.Popen(strace + [criu_bin, action] + args, env = env, preexec_fn = preexec)
-		return cr.wait()
+
+		subproc_args = {"args": strace + [criu_bin, action] + args,
+			"env": env, "preexec_fn": preexec}
+		if cap_output:
+			subproc_args["stdout"] = subprocess.PIPE
+			subproc_args["stderr"] = subprocess.PIPE
+		cr = subprocess.Popen(**subproc_args)
+
+		stdout_str = None
+		stderr_str = None
+		if cap_output:
+			stdout_str, stderr_str = cr.communicate()
+		else:
+			cr.wait()
+		return (cr.returncode, stdout_str, stderr_str)
 
 	def set_user_id(self):
 		# Numbers should match those in zdtm_test
 		os.setresgid(58467, 58467, 58467)
 		os.setresuid(18943, 18943, 18943)
 
-	def __criu_act(self, action, opts, log = None):
+	def __criu_act(self, action, opts, log = None, cap_output = False):
 		if not log:
 			log = action + ".log"
 
@@ -722,7 +736,8 @@ class criu_cli:
 
 		__ddir = self.__ddir()
 
-		ret = self.__criu(action, s_args, self.__fault, strace, preexec)
+		ret, stdout_str, stderr_str = self.__criu(
+			action, s_args, self.__fault, strace, preexec, cap_output = cap_output)
 		grep_errors(os.path.join(__ddir, log))
 		if ret != 0:
 			if self.__fault and int(self.__fault) < 128:
@@ -737,14 +752,16 @@ class criu_cli:
 					os.rename(os.path.join(__ddir, log), os.path.join(__ddir, log + ".fail"))
 				# try again without faults
 				print "Run criu " + action
-				ret = self.__criu(action, s_args, False, strace, preexec)
+				ret, stdout_str, stderr_str = self.__criu(
+					action, s_args, False, strace, preexec, cap_output = cap_output)
 				grep_errors(os.path.join(__ddir, log))
 				if ret == 0:
-					return
+					return (ret, stdout_str, stderr_str)
 			if self.__test.blocking() or (self.__sat and action == 'restore'):
 				raise test_fail_expected_exc(action)
 			else:
 				raise test_fail_exc("CRIU %s" % action)
+		return (ret, stdout_str, stderr_str)
 
 	def dump(self, action, opts = []):
 		self.__iter += 1
@@ -805,7 +822,7 @@ class criu_cli:
 
 	@staticmethod
 	def check(feature):
-		return criu_cli.__criu("check", ["-v0", "--feature", feature]) == 0
+		return criu_cli.__criu("check", ["-v0", "--feature", feature])[0] == 0
 
 	@staticmethod
 	def available():
-- 
1.9.1



More information about the CRIU mailing list