[v2] test/zdtm.py: add option to specify external criu for test suite

Submitted by Adrian Reber on June 13, 2018, 1:09 p.m.

Details

Message ID 1528895394-28698-1-git-send-email-adrian@lisas.de
State New
Series "test/zdtm.py: add option to specify external criu for test suite"
Headers show

Commit Message

Adrian Reber June 13, 2018, 1:09 p.m.
From: Adrian Reber <areber@redhat.com>

I am regularly running zdtm.py after updating the CRIU rpm to test if
the new rpm still works. Until know I usually did:

-criu_bin = "../criu/criu"
-crit_bin = "../crit/crit"
+criu_bin = "/usr/sbin/criu"
+crit_bin = "/usr/bin/crit"

This commit adds two arguments to zdtm.py:

  --criu-bin CRIU_BIN   Path to criu binary
  --crit-bin CRIT_BIN   Path to crit binary

It still defaults to the old values from above, but can now easily be
changed to the CRIU binary provided by the packaging system.

This change was more complicated than expected which is probably related
to the fact that zdtm restarts itself in namespaces.

v2:
 - rebase

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 test/zdtm.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index 1e193b2..6754851 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -732,14 +732,11 @@  test_classes = {'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test}
 # CRIU when launched using CLI
 #
 
-criu_bin = "../criu/criu"
-crit_bin = "../crit/crit"
 join_ns_file = '/run/netns/zdtm_netns'
 
-
 class criu_cli:
 	@staticmethod
-	def run(action, args, fault = None, strace = [], preexec = None, nowait = False):
+	def run(action, args, criu_bin, fault = None, strace = [], preexec = None, nowait = False):
 		env = dict(os.environ, ASAN_OPTIONS = "log_path=asan.log:disable_coredump=0:detect_leaks=0")
 
 		if fault:
@@ -820,7 +817,7 @@  class criu_rpc:
 			raise test_fail_exc('RPC for %s required' % arg)
 
 	@staticmethod
-	def run(action, args, fault = None, strace = [], preexec = None, nowait = False):
+	def run(action, args, criu_bin, fault = None, strace = [], preexec = None, nowait = False):
 		if fault:
 			raise test_fail_exc('RPC and FAULT not supported')
 		if strace:
@@ -898,6 +895,8 @@  class criu:
 		self.__lazy_pages_p = None
 		self.__page_server_p = None
 		self.__dump_process = None
+		self.__criu_bin = opts['criu_bin']
+		self.__crit_bin = opts['crit_bin']
 
 	def fini(self):
 		if self.__lazy_migrate:
@@ -1001,7 +1000,7 @@  class criu:
 
 		ns_last_pid = open("/proc/sys/kernel/ns_last_pid").read()
 
-		ret = self.__criu.run(action, s_args, self.__fault, strace, preexec, nowait)
+		ret = self.__criu.run(action, s_args, self.__criu_bin, self.__fault, strace, preexec, nowait)
 
 		if nowait:
 			os.close(status_fds[1])
@@ -1031,7 +1030,7 @@  class criu:
 				open("/proc/sys/kernel/ns_last_pid", "w+").write(ns_last_pid)
 				# try again without faults
 				print("Run criu " + action)
-				ret = self.__criu.run(action, s_args, False, strace, preexec)
+				ret = self.__criu.run(action, s_args, self.__criu_bin, False, strace, preexec)
 				grep_errors(os.path.join(__ddir, log))
 				if ret == 0:
 					return
@@ -1045,7 +1044,7 @@  class criu:
 		if not self.__show_stats:
 			return
 
-		subprocess.Popen([crit_bin, "show",
+		subprocess.Popen([self.__crit_bin, "show",
 				os.path.join(self.__dump_path,
 				str(self.__iter), "stats-%s" % action)]).wait()
 
@@ -1078,7 +1077,7 @@  class criu:
 			logdir = os.getcwd() + "/" + self.__dump_path + "/" + str(self.__iter)
 			print("Adding image cache")
 
-			cache_opts = [criu_bin, "image-cache", "--port", "12345", "-v4", "-o",
+			cache_opts = [self.__criu_bin, "image-cache", "--port", "12345", "-v4", "-o",
 				      logdir + "/image-cache.log", "-D", logdir]
 
 			subprocess.Popen(cache_opts).pid
@@ -1086,7 +1085,7 @@  class criu:
 
 			print("Adding image proxy")
 
-			proxy_opts = [criu_bin, "image-proxy", "--port", "12345", "--address",
+			proxy_opts = [self.__criu_bin, "image-proxy", "--port", "12345", "--address",
 					"localhost", "-v4", "-o", logdir + "/image-proxy.log",
 					"-D", logdir]
 
@@ -1183,12 +1182,12 @@  class criu:
 	@staticmethod
 	def check(feature):
 		return criu_cli.run("check", ["--no-default-config", "-v0",
-				"--feature", feature]) == 0
+				"--feature", feature], opts['criu_bin']) == 0
 
 	@staticmethod
 	def available():
-		if not os.access(criu_bin, os.X_OK):
-			print("CRIU binary not built")
+		if not os.access(opts['criu_bin'], os.X_OK):
+			print("CRIU binary not found at %s" % opts['criu_bin'])
 			sys.exit(1)
 
 	def kill(self):
@@ -1661,7 +1660,8 @@  class Launcher:
 		nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', 'stop', 'empty_ns',
 				'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', 'rpc', 'lazy_pages',
 				'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run', 'noauto_dedup',
-				'remote_lazy_pages', 'show_stats', 'remote', 'check_only', 'lazy_migrate')
+				'remote_lazy_pages', 'show_stats', 'remote', 'check_only', 'lazy_migrate',
+				'criu_bin', 'crit_bin')
 		arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
 
 		if self.__use_log:
@@ -2220,6 +2220,8 @@  rp.add_argument("--remote-lazy-pages", help = "simulate lazy migration", action
 rp.add_argument("--title", help = "A test suite title", default = "criu")
 rp.add_argument("--show-stats", help = "Show criu statistics", action = 'store_true')
 rp.add_argument("--check-only", help = "Additionally try to dump/restore in --check-only mode", action = 'store_true')
+rp.add_argument("--criu-bin", help = "Path to criu binary", default = '../criu/criu')
+rp.add_argument("--crit-bin", help = "Path to crit binary", default = '../crit/crit')
 
 lp = sp.add_parser("list", help = "List tests")
 lp.set_defaults(action = list_tests)

Comments

Andrey Vagin June 13, 2018, 5:14 p.m.
On Wed, Jun 13, 2018 at 01:09:54PM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> I am regularly running zdtm.py after updating the CRIU rpm to test if
> the new rpm still works. Until know I usually did:
> 
> -criu_bin = "../criu/criu"
> -crit_bin = "../crit/crit"
> +criu_bin = "/usr/sbin/criu"
> +crit_bin = "/usr/bin/crit"
> 
> This commit adds two arguments to zdtm.py:
> 
>   --criu-bin CRIU_BIN   Path to criu binary
>   --crit-bin CRIT_BIN   Path to crit binary
> 
> It still defaults to the old values from above, but can now easily be
> changed to the CRIU binary provided by the packaging system.
> 
> This change was more complicated than expected which is probably related
> to the fact that zdtm restarts itself in namespaces.
> 
> v2:
>  - rebase
> 
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  test/zdtm.py | 30 ++++++++++++++++--------------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 1e193b2..6754851 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -732,14 +732,11 @@ test_classes = {'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test}
>  # CRIU when launched using CLI
>  #
>  
> -criu_bin = "../criu/criu"
> -crit_bin = "../crit/crit"
>  join_ns_file = '/run/netns/zdtm_netns'
>  
> -

$ make lint
make[1]: Entering directory `/home/travis/build/criupatchwork/criu'
flake8 --config=scripts/flake8.cfg test/zdtm.py
test/zdtm.py:737:1: E302 expected 2 blank lines, found 1

>  class criu_cli:
>  	@staticmethod
> -	def run(action, args, fault = None, strace = [], preexec = None, nowait = False):
> +	def run(action, args, criu_bin, fault = None, strace = [], preexec = None, nowait = False):
>  		env = dict(os.environ, ASAN_OPTIONS = "log_path=asan.log:disable_coredump=0:detect_leaks=0")
>  
>  		if fault:
> @@ -820,7 +817,7 @@ class criu_rpc:
>  			raise test_fail_exc('RPC for %s required' % arg)
>  
>  	@staticmethod
> -	def run(action, args, fault = None, strace = [], preexec = None, nowait = False):
> +	def run(action, args, criu_bin, fault = None, strace = [], preexec = None, nowait = False):
>  		if fault:
>  			raise test_fail_exc('RPC and FAULT not supported')
>  		if strace:
> @@ -898,6 +895,8 @@ class criu:
>  		self.__lazy_pages_p = None
>  		self.__page_server_p = None
>  		self.__dump_process = None
> +		self.__criu_bin = opts['criu_bin']
> +		self.__crit_bin = opts['crit_bin']
>  
>  	def fini(self):
>  		if self.__lazy_migrate:
> @@ -1001,7 +1000,7 @@ class criu:
>  
>  		ns_last_pid = open("/proc/sys/kernel/ns_last_pid").read()
>  
> -		ret = self.__criu.run(action, s_args, self.__fault, strace, preexec, nowait)
> +		ret = self.__criu.run(action, s_args, self.__criu_bin, self.__fault, strace, preexec, nowait)
>  
>  		if nowait:
>  			os.close(status_fds[1])
> @@ -1031,7 +1030,7 @@ class criu:
>  				open("/proc/sys/kernel/ns_last_pid", "w+").write(ns_last_pid)
>  				# try again without faults
>  				print("Run criu " + action)
> -				ret = self.__criu.run(action, s_args, False, strace, preexec)
> +				ret = self.__criu.run(action, s_args, self.__criu_bin, False, strace, preexec)
>  				grep_errors(os.path.join(__ddir, log))
>  				if ret == 0:
>  					return
> @@ -1045,7 +1044,7 @@ class criu:
>  		if not self.__show_stats:
>  			return
>  
> -		subprocess.Popen([crit_bin, "show",
> +		subprocess.Popen([self.__crit_bin, "show",
>  				os.path.join(self.__dump_path,
>  				str(self.__iter), "stats-%s" % action)]).wait()
>  
> @@ -1078,7 +1077,7 @@ class criu:
>  			logdir = os.getcwd() + "/" + self.__dump_path + "/" + str(self.__iter)
>  			print("Adding image cache")
>  
> -			cache_opts = [criu_bin, "image-cache", "--port", "12345", "-v4", "-o",
> +			cache_opts = [self.__criu_bin, "image-cache", "--port", "12345", "-v4", "-o",
>  				      logdir + "/image-cache.log", "-D", logdir]
>  
>  			subprocess.Popen(cache_opts).pid
> @@ -1086,7 +1085,7 @@ class criu:
>  
>  			print("Adding image proxy")
>  
> -			proxy_opts = [criu_bin, "image-proxy", "--port", "12345", "--address",
> +			proxy_opts = [self.__criu_bin, "image-proxy", "--port", "12345", "--address",
>  					"localhost", "-v4", "-o", logdir + "/image-proxy.log",
>  					"-D", logdir]
>  
> @@ -1183,12 +1182,12 @@ class criu:
>  	@staticmethod
>  	def check(feature):
>  		return criu_cli.run("check", ["--no-default-config", "-v0",
> -				"--feature", feature]) == 0
> +				"--feature", feature], opts['criu_bin']) == 0
>  
>  	@staticmethod
>  	def available():
> -		if not os.access(criu_bin, os.X_OK):
> -			print("CRIU binary not built")
> +		if not os.access(opts['criu_bin'], os.X_OK):
> +			print("CRIU binary not found at %s" % opts['criu_bin'])
>  			sys.exit(1)
>  
>  	def kill(self):
> @@ -1661,7 +1660,8 @@ class Launcher:
>  		nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', 'stop', 'empty_ns',
>  				'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', 'rpc', 'lazy_pages',
>  				'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run', 'noauto_dedup',
> -				'remote_lazy_pages', 'show_stats', 'remote', 'check_only', 'lazy_migrate')
> +				'remote_lazy_pages', 'show_stats', 'remote', 'check_only', 'lazy_migrate',
> +				'criu_bin', 'crit_bin')
>  		arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
>  
>  		if self.__use_log:
> @@ -2220,6 +2220,8 @@ rp.add_argument("--remote-lazy-pages", help = "simulate lazy migration", action
>  rp.add_argument("--title", help = "A test suite title", default = "criu")
>  rp.add_argument("--show-stats", help = "Show criu statistics", action = 'store_true')
>  rp.add_argument("--check-only", help = "Additionally try to dump/restore in --check-only mode", action = 'store_true')
> +rp.add_argument("--criu-bin", help = "Path to criu binary", default = '../criu/criu')
> +rp.add_argument("--crit-bin", help = "Path to crit binary", default = '../crit/crit')
>  
>  lp = sp.add_parser("list", help = "List tests")
>  lp.set_defaults(action = list_tests)
> -- 
> 1.8.3.1
>