[CRIU] [PATCH 2/2] zdtm.py: Ability to run tests with faults injected

Pavel Emelyanov xemul at parallels.com
Tue Oct 13 08:06:44 PDT 2015


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/zdtm.py                              | 35 ++++++++++++++++++++++++-------
 test/zdtm/live/static/cgroup00.hook       |  2 ++
 test/zdtm/live/static/cgroup01.hook       |  2 ++
 test/zdtm/live/static/cgroup02.hook       |  2 ++
 test/zdtm/live/static/unlink_fstat00.hook | 11 ++++++++++
 5 files changed, 44 insertions(+), 8 deletions(-)
 create mode 100755 test/zdtm/live/static/unlink_fstat00.hook

diff --git a/test/zdtm.py b/test/zdtm.py
index cc2bf6c..f9903d8 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -160,6 +160,10 @@ class test_fail_exc:
 	def __init__(self, step):
 		self.step = step
 
+class test_fault_injected_exc:
+	def __init__(self, cr_action):
+		self.cr_action = cr_action
+
 #
 # A test from zdtm/ directory.
 #
@@ -287,13 +291,18 @@ class criu_cli:
 		os.makedirs(self.__dump_path)
 		self.__page_server = (opts['page_server'] and True or False)
 		self.__restore_sibling = (opts['sibling'] and True or False)
+		self.__fault = (opts['fault'])
 
 	def __ddir(self):
 		return os.path.join(self.__dump_path, "%d" % self.__iter)
 
 	@staticmethod
-	def __criu(action, args):
-		cr = subprocess.Popen(["../criu", action] + args)
+	def __criu(action, args, fault = None):
+		env = None
+		if fault:
+			print "Forcing %s fault" % fault
+			env = dict(os.environ, CRIU_FAULT = fault)
+		cr = subprocess.Popen(["../criu", action] + args, env = env)
 		return cr.wait()
 
 	def __criu_act(self, action, opts, log = None):
@@ -303,9 +312,12 @@ class criu_cli:
 		s_args = ["-o", log, "-D", self.__ddir(), "-v4"] + opts
 
 		print "Run CRIU: [" + action + " " + " ".join(s_args) + "]"
-		ret = self.__criu(action, s_args)
+		ret = self.__criu(action, s_args, self.__fault)
 		if ret != 0:
-			raise test_fail_exc("CRIU %s" % action)
+			if self.__fault:
+				raise test_fault_injected_exc(action)
+			else:
+				raise test_fail_exc("CRIU %s" % action)
 
 	def __criu_cr(self, action, opts):
 		self.__criu_act(action, opts = opts + self.__test.getcropts())
@@ -419,10 +431,16 @@ def do_run_test(tname, tdesc, flavs, opts):
 		try:
 			t.start()
 			s = get_visible_state(t)
-			cr(t, opts)
-			check_visible_state(t, s)
-			t.stop()
-			try_run_hook(t, ["--clean"])
+			try:
+				cr(t, opts)
+			except test_fault_injected_exc as e:
+				if e.cr_action == "dump":
+					t.stop()
+				try_run_hook(t, ["--fault", e.cr_action])
+			else:
+				check_visible_state(t, s)
+				t.stop()
+				try_run_hook(t, ["--clean"])
 		except test_fail_exc as e:
 			print "Test %s FAIL at %s" % (tname, e.step)
 			t.print_output()
@@ -631,6 +649,7 @@ rp.add_argument("--pre", help = "Do some pre-dumps before dump")
 rp.add_argument("--nocr", help = "Do not CR anything, just check test works", action = 'store_true')
 rp.add_argument("--norst", help = "Don't restore tasks, leave them running after dump", action = 'store_true')
 rp.add_argument("--iters", help = "Do CR cycle several times before check")
+rp.add_argument("--fault", help = "Test fault injection")
 
 rp.add_argument("--page-server", help = "Use page server dump", action = 'store_true')
 rp.add_argument("-p", "--parallel", help = "Run test in parallel")
diff --git a/test/zdtm/live/static/cgroup00.hook b/test/zdtm/live/static/cgroup00.hook
index 44ad2dd..a8af992 100755
--- a/test/zdtm/live/static/cgroup00.hook
+++ b/test/zdtm/live/static/cgroup00.hook
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
+
 set -e
 
 tname=$(mktemp -d cgclean.XXXXXX)
diff --git a/test/zdtm/live/static/cgroup01.hook b/test/zdtm/live/static/cgroup01.hook
index 9697e1b..d2eacbb 100755
--- a/test/zdtm/live/static/cgroup01.hook
+++ b/test/zdtm/live/static/cgroup01.hook
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
+
 set -e
 
 tname=$(mktemp -d cgclean.XXXXXX)
diff --git a/test/zdtm/live/static/cgroup02.hook b/test/zdtm/live/static/cgroup02.hook
index 3dbbda1..3214552 100755
--- a/test/zdtm/live/static/cgroup02.hook
+++ b/test/zdtm/live/static/cgroup02.hook
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
+
 set -e
 
 rmroots() {
diff --git a/test/zdtm/live/static/unlink_fstat00.hook b/test/zdtm/live/static/unlink_fstat00.hook
new file mode 100755
index 0000000..dfae0f6
--- /dev/null
+++ b/test/zdtm/live/static/unlink_fstat00.hook
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+[ "$1" == "--fault" -a "$2" == "restore" ] || exit 0
+
+if [ $(find -name 'unlink_fstat00*ghost' | wc -l ) -ne 0 ]; then
+	echo "Dangling ghost file"
+	exit 1
+fi
+
+echo "Restore fault handled"
+exit 0
-- 
1.9.3




More information about the CRIU mailing list