[CRIU] [PATCH v1 10/12] zdtm: implement criu gc tests
Eugene Batalov
eabatalov89 at gmail.com
Wed Jul 27 22:14:46 PDT 2016
New --gc option was added to zdtm.py.
It implements the following test running logic:
1. Run zdtm test ps tree, dump it, kill it (standard steps)
2. Run criu gc --show and compare its output with
expected output known by test hook of this zdtm test.
3. Run criu gc and check its return code to be 0.
Steps 2 and 3 are created for criu gc testing.
If criu gc --show finds all the expected garbage
and criu gc cleans up it successfully then criu gc
works ok and test is passed.
This is the simplest feasible way to test criu gc.
Why? There are 3 ways to check that garbage is deleted after dump:
1. Do check in ps tree that we left running after dump.
We can't leave ps tree running after dump because criu
gc should work only when ps tree is killed after dump.
Doing gc with running ps tree is a more complicated and
not needed use case.
2. Do check in restored ps tree. But we can't restore after gc
was performed.
3. Run new instance of this zdtm test ps tree and do check in it.
We'll need to run this ps tree in the same environment as dumped ps
tree. There is no such feature in zdtm.py. Its implementation and
maintanance is complicated. Moreover it is probably not needed for
any other use case in the future.
gc test hooks are implemented in this patch too. Hooks tell
zdtm.py about valid garbage generated by gc test in form
of regular expressions that should match output of criu gc --show.
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
test/zdtm.py | 43 ++++++++++++++++++++++++++++++++--
test/zdtm/static/mntns_link_remap.hook | 10 ++++++++
test/zdtm/static/socket-tcp.hook | 9 +++++++
test/zdtm/static/socket-tcp6.hook | 9 +++++++
test/zdtm/static/unlink_regular00.hook | 9 +++++++
5 files changed, 78 insertions(+), 2 deletions(-)
create mode 100755 test/zdtm/static/mntns_link_remap.hook
create mode 100755 test/zdtm/static/socket-tcp.hook
create mode 100755 test/zdtm/static/socket-tcp6.hook
create mode 100755 test/zdtm/static/unlink_regular00.hook
diff --git a/test/zdtm.py b/test/zdtm.py
index ec46d35..7164bfb 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -820,6 +820,12 @@ class criu_cli:
r_opts.append("zdtm:%s" % criu_dir)
self.__criu_act("restore", opts = r_opts + ["--restore-detached"])
+ def gc(self, show):
+ opts = self.__test.getropts()
+ if show:
+ opts.append("--show")
+ return self.__criu_act("gc", opts, cap_output = True)
+
@staticmethod
def check(feature):
return criu_cli.__criu("check", ["-v0", "--feature", feature])[0] == 0
@@ -1090,6 +1096,35 @@ def do_run_test_cr(cr_api, test, opts):
test.stop()
+def do_run_test_gc(cr_api, test, flavor):
+ cr_api.set_test(test)
+ sbs('pre-dump')
+ cr_api.dump("dump")
+ test.gone()
+
+ sbs('pre-gc-show')
+ gc_output = cr_api.gc(True)[1]
+
+ hook_output = eval(run_hook(test, ['--gc'], cap_output = True)[0])
+ hook_lremaps = hook_output.get('lremaps') or []
+ hook_tcps = hook_output.get('tcps') or []
+
+ for lremap in hook_lremaps:
+ regex = 'Link remap: ' + lremap[0] + ' -> ' + lremap[1]
+ if not re.search(regex, gc_output):
+ raise test_fail_exc('No garbage for regex: %s' % regex)
+
+ if flavor == 'h':
+ for tcp in hook_tcps:
+ regex = 'Locked tcp connection: ' + tcp[0] + ' -> ' + tcp[1]
+ if not re.search(regex, gc_output):
+ raise test_fail_exc('No garbage for regex: %s' % regex)
+
+ sbs('pre-gc')
+ cr_api.gc(False)
+ test.kill()
+
+
def do_run_test(tname, tdesc, flavs, opts):
tcname = tname.split('/')[0]
tclass = test_classes.get(tcname, None)
@@ -1116,7 +1151,10 @@ def do_run_test(tname, tdesc, flavs, opts):
try:
t.start()
try:
- do_run_test_cr(cr_api, t, opts)
+ if opts['gc']:
+ do_run_test_gc(cr_api, t, f)
+ else:
+ do_run_test_cr(cr_api, t, opts)
try_run_hook(t, ["--clean"])
except test_fail_expected_exc as e:
if e.cr_action == "dump":
@@ -1194,7 +1232,7 @@ class launcher:
self.__nr += 1
self.__show_progress()
- nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', 'unshare',
+ nd = ('nocr', 'norst', 'gc', 'pre', 'iters', 'page_server', 'sibling', 'unshare',
'fault', 'keep_img', 'report', 'snaps', 'sat', 'script',
'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run')
arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
@@ -1636,6 +1674,7 @@ rp.add_argument("--snaps", help = "Instead of pre-dumps do full dumps", action =
rp.add_argument("--dedup", help = "Auto-deduplicate images on iterations", 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("--gc", help = "Don't restore tasks. Run gc after dump and validate its success", action = 'store_true')
rp.add_argument("--iters", help = "Do CR cycle several times before check (n[:pause])")
rp.add_argument("--fault", help = "Test fault injection")
rp.add_argument("--sat", help = "Generate criu strace-s for sat tool (restore is fake, images are kept)", action = 'store_true')
diff --git a/test/zdtm/static/mntns_link_remap.hook b/test/zdtm/static/mntns_link_remap.hook
new file mode 100755
index 0000000..9561b6e
--- /dev/null
+++ b/test/zdtm/static/mntns_link_remap.hook
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+[ "$1" != "--gc" ] && exit 0
+
+echo '{
+ "lremaps": [
+ ("\/.*", "\/.+\/1\/F"),
+ ("\/.*", "\/.+\/2\/F")
+ ]
+}'
diff --git a/test/zdtm/static/socket-tcp.hook b/test/zdtm/static/socket-tcp.hook
new file mode 100755
index 0000000..f2ee425
--- /dev/null
+++ b/test/zdtm/static/socket-tcp.hook
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+[ "$1" != "--gc" ] && exit 0
+
+echo '{
+ "tcps" : [
+ ("127\.0\.0\.1:8880", "127\.0\.0\.1:[0-9]+")
+ ]
+}'
diff --git a/test/zdtm/static/socket-tcp6.hook b/test/zdtm/static/socket-tcp6.hook
new file mode 100755
index 0000000..19329b0
--- /dev/null
+++ b/test/zdtm/static/socket-tcp6.hook
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+[ "$1" != "--gc" ] && exit 0
+
+echo '{
+ "tcps" : [
+ ("::1:8880", "::1:[0-9]+")
+ ]
+}'
diff --git a/test/zdtm/static/unlink_regular00.hook b/test/zdtm/static/unlink_regular00.hook
new file mode 100755
index 0000000..ed93b98
--- /dev/null
+++ b/test/zdtm/static/unlink_regular00.hook
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+[ "$1" != "--gc" ] && exit 0
+
+echo '{
+ "lremaps": [
+ ("\/.*", "\/.+\/subdir\/testfile")
+ ]
+}'
--
1.9.1
More information about the CRIU
mailing list