[CRIU] [PATCH 2/2] test: Check action scripts to work as we expect

Pavel Emelyanov xemul at virtuozzo.com
Thu Apr 28 07:46:59 PDT 2016


We expect:

- all 9 scripts are called
- there's always images dir variable
- for 7 of those scripts there's root-pid variable

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 test/check_actions.py   | 40 ++++++++++++++++++++++++++++++++++++++++
 test/jenkins/actions.sh |  8 ++++++++
 test/show_action.sh     |  3 +++
 test/zdtm.py            |  8 ++++++--
 4 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100755 test/check_actions.py
 create mode 100755 test/jenkins/actions.sh
 create mode 100755 test/show_action.sh

diff --git a/test/check_actions.py b/test/check_actions.py
new file mode 100755
index 0000000..70d257f
--- /dev/null
+++ b/test/check_actions.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+import sys
+import os
+
+actions = set(['pre-dump', 'pre-restore', 'post-dump', 'setup-namespaces', \
+		'post-setup-namespaces', 'post-restore', 'post-resume', \
+		'network-lock', 'network-unlock' ])
+errors = []
+af = os.path.dirname(os.path.abspath(__file__)) + '/actions_called.txt'
+
+for act in open(af):
+	act = act.strip().split()
+	act.append('EMPTY')
+	act.append('EMPTY')
+
+	if act[0] == 'EMPTY':
+		raise Exception("Error in test, bogus actions line")
+
+	if act[1] == 'EMPTY':
+		errors.append('Action %s misses CRTOOLS_IMAGE_DIR' % act[0])
+
+	if act[0] in ('post-dump', 'setup-namespaces', 'post-setup-namespaces', \
+			'post-restore', 'post-resume', 'network-lock', 'network-unlock'):
+		if act[2] == 'EMPTY':
+			errors.append('Action %s misses CRTOOLS_INIT_PID' % act[0])
+		elif not act[2].isdigit() or int(act[2]) == 0:
+			errors.append('Action %s PID is not number (%s)' % (act[0], act[2]))
+
+	actions -= set([act[0]])
+
+if actions:
+	errors.append('Not all actions called: %r' % actions)
+
+if errors:
+	for x in errors:
+		print x
+	sys.exit(1)
+
+print 'PASS'
diff --git a/test/jenkins/actions.sh b/test/jenkins/actions.sh
new file mode 100755
index 0000000..8019045
--- /dev/null
+++ b/test/jenkins/actions.sh
@@ -0,0 +1,8 @@
+# Check how crit de/encodes images
+set -e
+source `dirname $0`/criu-lib.sh
+# prep
+rm -f actions_called.txt
+./test/zdtm.py run -t zdtm/static/env00 --script "$(pwd)/test/show_action.sh" || fail
+./test/check_actions.py || fail
+exit 0
diff --git a/test/show_action.sh b/test/show_action.sh
new file mode 100755
index 0000000..86468b6
--- /dev/null
+++ b/test/show_action.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+echo "${CRTOOLS_SCRIPT_ACTION} ${CRTOOLS_IMAGE_DIR} ${CRTOOLS_INIT_PID}" \
+	     >> "$(dirname $0)/actions_called.txt"
diff --git a/test/zdtm.py b/test/zdtm.py
index 87904d7..081c46c 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -613,6 +613,7 @@ class criu_cli:
 		self.__restore_sibling = (opts['sibling'] and True or False)
 		self.__join_ns = (opts['join_ns'] and True or False)
 		self.__fault = (opts['fault'])
+		self.__script = opts['script']
 		self.__sat = (opts['sat'] and True or False)
 		self.__dedup = (opts['dedup'] and True or False)
 		self.__user = (opts['user'] and True or False)
@@ -675,6 +676,9 @@ class criu_cli:
 				strace += [ '-f' ]
 				s_args += [ '--action-script', os.getcwd() + '/../scripts/fake-restore.sh' ]
 
+		if self.__script:
+			s_args += ['--action-script', self.__script]
+
 		preexec = self.__user and self.set_user_id or None
 
 		__ddir = self.__ddir()
@@ -1074,7 +1078,7 @@ class launcher:
 		self.__show_progress()
 
 		nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', 'join_ns', \
-				'fault', 'keep_img', 'report', 'snaps', 'sat', \
+				'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', \
 				'dedup', 'sbs', 'freezecg', 'user', 'dry_run')
 		arg = repr((name, desc, flavor, { d: self.__opts[d] for d in nd }))
 
@@ -1514,7 +1518,7 @@ rp.add_argument("--user", help = "Run CRIU as regular user", action = 'store_tru
 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("--dry-run", help="Don't run tests, just pretend to", action='store_true')
-
+rp.add_argument("--script", help="Add script to get notified by criu")
 rp.add_argument("-k", "--keep-img", help = "Whether or not to keep images after test",
 		choices = [ 'always', 'never', 'failed' ], default = 'failed')
 rp.add_argument("--report", help = "Generate summary report in directory")
-- 
2.5.0


More information about the CRIU mailing list