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

Pavel Emelyanov xemul at virtuozzo.com
Tue Aug 23 05:12:26 PDT 2016


On 08/10/2016 10:12 PM, Eugene Batalov wrote:
> 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 d5e91d2..0037e3c 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -681,22 +681,36 @@ 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)
> +
> +		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)
>  		if action == "lazy-pages":
>  			return cr
> -		return cr.wait()
> +
> +		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"
>  
> @@ -725,7 +739,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)
>  		if action == "lazy-pages":
>  			return ret
>  		grep_errors(os.path.join(__ddir, log))
> @@ -742,14 +757,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)

Tuples are hard to read :( Can we have this return object as dict?

>  
>  	def dump(self, action, opts = []):
>  		self.__iter += 1
> @@ -820,7 +837,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():
> 



More information about the CRIU mailing list