[CRIU] [PATCH 3/3] test: check exit codes for criu page-server and criu lazy-pages

Andrei Vagin avagin at openvz.org
Thu Nov 17 12:10:51 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Cc: Mike Rapoport <rppt at linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm.py | 55 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/test/zdtm.py b/test/zdtm.py
index 4dd0f25..cefbf8d 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -675,12 +675,14 @@ join_ns_file = '/run/netns/zdtm_netns'
 
 class criu_cli:
 	@staticmethod
-	def run(action, args, fault = None, strace = [], preexec = None):
+	def run(action, args, fault = None, strace = [], preexec = None, nowait = 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)
+		if nowait:
+			return cr
 		return cr.wait()
 
 
@@ -778,6 +780,7 @@ class criu:
 		self.__user = (opts['user'] and True or False)
 		self.__leave_stopped = (opts['stop'] and True or False)
 		self.__criu = (opts['rpc'] and criu_rpc or criu_cli)
+		self.__lazy_pages_p = None
 
 	def logs(self):
 		return self.__dump_path
@@ -809,7 +812,7 @@ class criu:
 		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, nowait = False):
 		if not log:
 			log = action + ".log"
 
@@ -838,7 +841,20 @@ class criu:
 
 		__ddir = self.__ddir()
 
-		ret = self.__criu.run(action, s_args, self.__fault, strace, preexec)
+		status_fds = None
+		if nowait:
+			status_fds = os.pipe()
+			s_args += ["--status-fd", str(status_fds[1])]
+
+		ret = self.__criu.run(action, s_args, self.__fault, strace, preexec, nowait)
+
+		if nowait:
+			os.close(status_fds[1])
+			if os.read(status_fds[0], 1) != '\0':
+				ret = ret.wait()
+				raise test_fail_exc("criu %s exited with %s" % (action, ret))
+			os.close(status_fds[0])
+			return ret
 
 		grep_errors(os.path.join(__ddir, log))
 		if ret != 0:
@@ -876,11 +892,11 @@ class criu:
 		if self.__page_server:
 			print "Adding page server"
 
-			ps_opts = ["--port", "12345", "--daemon", "--pidfile", "ps.pid"]
+			ps_opts = ["--port", "12345"]
 			if self.__dedup:
 				ps_opts += ["--auto-dedup"]
 
-			self.__criu_act("page-server", opts = ps_opts)
+			self.__page_server_p = self.__criu_act("page-server", opts = ps_opts, nowait = True)
 			a_opts += ["--page-server", "--address", "127.0.0.1", "--port", "12345"]
 
 		a_opts += self.__test.getdopts()
@@ -906,8 +922,11 @@ class criu:
 			pstree_check_stopped(self.__test.getpid())
 			pstree_signal(self.__test.getpid(), signal.SIGKILL)
 
-		if self.__page_server:
-			wait_pid_die(int(rpidfile(self.__ddir() + "/ps.pid")), "page server")
+		if self.__page_server_p:
+                        ret = self.__page_server_p.wait()
+                        self.__page_server_p = None
+                        if ret:
+                                raise test_fail_exc("criu page-server exited with %d" % ret)
 
 	def restore(self):
 		r_opts = []
@@ -926,7 +945,7 @@ class criu:
 			r_opts.append('mnt[zdtm]:%s' % criu_dir)
 
 		if self.__lazy_pages:
-			self.__criu_act("lazy-pages", opts = ["--daemon", "--pidfile", "lp.pid"])
+			self.__lazy_pages_p = self.__criu_act("lazy-pages", nowait = True)
 			r_opts += ["--lazy-pages"]
 
 		if self.__leave_stopped:
@@ -934,13 +953,16 @@ class criu:
 
 		self.__criu_act("restore", opts = r_opts + ["--restore-detached"])
 
+		if self.__lazy_pages_p:
+			ret = self.__lazy_pages_p.wait()
+			self.__lazy_pages_p = None
+			if ret:
+				raise test_fail_exc("criu lazy-pages exited with %s" % ret)
+
 		if self.__leave_stopped:
 			pstree_check_stopped(self.__test.getpid())
 			pstree_signal(self.__test.getpid(), signal.SIGCONT)
 
-		if self.__lazy_pages:
-			wait_pid_die(int(rpidfile(self.__ddir() + "/lp.pid")), "lazy pages daemon")
-
 	@staticmethod
 	def check(feature):
 		return criu_cli.run("check", ["-v0", "--feature", feature]) == 0
@@ -951,6 +973,16 @@ class criu:
 			print "CRIU binary not built"
 			sys.exit(1)
 
+	def kill(self):
+		if self.__lazy_pages_p:
+			self.__lazy_pages_p.terminate()
+			print "criu lazy-pages exited with %s" & self.wait()
+                        sel.__lazy_pages_p = None
+		if self.__page_server_p:
+			self.__page_server_p.terminate()
+			print "criu page-server exited with %s" & self.wait()
+                        sel.__page_server_p = None
+
 
 def try_run_hook(test, args):
 	hname = test.getname() + '.hook'
@@ -1286,6 +1318,7 @@ def do_run_test(tname, tdesc, flavs, opts):
 			print_sep("Test %s FAIL at %s" % (tname, e.step), '#')
 			t.print_output()
 			t.kill()
+			cr_api.kill()
 			try_run_hook(t, ["--clean"])
 			if cr_api.logs():
 				add_to_report(cr_api.logs(), tname.replace('/', '_') + "_" + f + "/images")
-- 
2.7.4



More information about the CRIU mailing list