Commit 8ce58ec9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm.py: Ability to run tests with faults injected

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 68baf8e7
...@@ -164,6 +164,10 @@ class test_fail_exc: ...@@ -164,6 +164,10 @@ class test_fail_exc:
def __init__(self, step): def __init__(self, step):
self.step = step self.step = step
class test_fault_injected_exc:
def __init__(self, cr_action):
self.cr_action = cr_action
# #
# A test from zdtm/ directory. # A test from zdtm/ directory.
# #
...@@ -375,6 +379,7 @@ class criu_cli: ...@@ -375,6 +379,7 @@ class criu_cli:
self.__iter = 0 self.__iter = 0
self.__page_server = (opts['page_server'] and True or False) self.__page_server = (opts['page_server'] and True or False)
self.__restore_sibling = (opts['sibling'] and True or False) self.__restore_sibling = (opts['sibling'] and True or False)
self.__fault = (opts['fault'])
def set_test(self, test): def set_test(self, test):
self.__test = test self.__test = test
...@@ -390,8 +395,12 @@ class criu_cli: ...@@ -390,8 +395,12 @@ class criu_cli:
return os.path.join(self.__dump_path, "%d" % self.__iter) return os.path.join(self.__dump_path, "%d" % self.__iter)
@staticmethod @staticmethod
def __criu(action, args): def __criu(action, args, fault = None):
cr = subprocess.Popen(["../criu", action] + args) 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() return cr.wait()
def __criu_act(self, action, opts, log = None): def __criu_act(self, action, opts, log = None):
...@@ -401,10 +410,13 @@ class criu_cli: ...@@ -401,10 +410,13 @@ class criu_cli:
s_args = ["-o", log, "-D", self.__ddir(), "-v4"] + opts s_args = ["-o", log, "-D", self.__ddir(), "-v4"] + opts
print "Run CRIU: [" + action + " " + " ".join(s_args) + "]" print "Run CRIU: [" + action + " " + " ".join(s_args) + "]"
ret = self.__criu(action, s_args) ret = self.__criu(action, s_args, self.__fault)
if ret != 0: if ret != 0:
grep_errors(os.path.join(self.__ddir(), log)) if self.__fault:
raise test_fail_exc("CRIU %s" % action) raise test_fault_injected_exc(action)
else:
grep_errors(os.path.join(self.__ddir(), log))
raise test_fail_exc("CRIU %s" % action)
def dump(self, action, opts = []): def dump(self, action, opts = []):
self.__iter += 1 self.__iter += 1
...@@ -521,10 +533,16 @@ def do_run_test(tname, tdesc, flavs, opts): ...@@ -521,10 +533,16 @@ def do_run_test(tname, tdesc, flavs, opts):
try: try:
t.start() t.start()
s = get_visible_state(t) s = get_visible_state(t)
cr(cr_api, t, opts) try:
check_visible_state(t, s) cr(cr_api, t, opts)
t.stop() except test_fault_injected_exc as e:
try_run_hook(t, ["--clean"]) 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: except test_fail_exc as e:
print "Test %s FAIL at %s" % (tname, e.step) print "Test %s FAIL at %s" % (tname, e.step)
t.print_output() t.print_output()
...@@ -753,6 +771,7 @@ rp.add_argument("--pre", help = "Do some pre-dumps before dump") ...@@ -753,6 +771,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("--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("--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("--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("--page-server", help = "Use page server dump", action = 'store_true')
rp.add_argument("-p", "--parallel", help = "Run test in parallel") rp.add_argument("-p", "--parallel", help = "Run test in parallel")
......
#!/bin/bash #!/bin/bash
[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
set -e set -e
tname=$(mktemp -d cgclean.XXXXXX) tname=$(mktemp -d cgclean.XXXXXX)
......
#!/bin/bash #!/bin/bash
[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
set -e set -e
tname=$(mktemp -d cgclean.XXXXXX) tname=$(mktemp -d cgclean.XXXXXX)
......
#!/bin/bash #!/bin/bash
[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
set -e set -e
rmroots() { rmroots() {
......
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment