[v4,11/12] zdtm: implement criu gc tests

Submitted by Eugene Batalov on Sept. 11, 2016, 5:14 p.m.

Details

Message ID 1473614091-4734-12-git-send-email-eabatalov89@gmail.com
State Rejected
Series "Series without cover letter"
Headers show

Commit Message

Eugene Batalov Sept. 11, 2016, 5:14 p.m.
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@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

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index 6490b4c..a924a96 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -957,6 +957,12 @@  class criu:
 		if lazy_pages_p and lazy_pages_p.wait():
 			raise test_fail_exc("CRIU lazy-pages")
 
+	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):
 		result = criu_cli.run("check", ["-v0", "--feature", feature])
@@ -1305,6 +1311,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)['stdout']
+
+	hook_output = eval(run_hook(test, ['--gc'], cap_output = True)['stdout'])
+	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)
@@ -1331,7 +1366,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":
@@ -1412,7 +1450,7 @@  class launcher:
 		nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', 'unshare',
 				'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', 'stop',
 				'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run', 'rpc',
-				'lazy_pages', 'noauto_dedup')
+				'lazy_pages', 'noauto_dedup', 'gc')
 		arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
 
 		if self.__use_log:
@@ -1856,6 +1894,7 @@  rp.add_argument("--noauto-dedup", help = "Manual deduplicate images on iteration
 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("--stop", help = "Check that --leave-stopped option stops ps tree.", 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")
+	]
+}'