[CRIU] [PATCH 1/4] zdtm: Introduce per-test hooks

Pavel Emelyanov xemul at parallels.com
Tue Aug 12 06:18:48 PDT 2014


This is inspired by two problems we have with cgroup* tests.

1. Tests cannot easily clean after themselves -- one cannot
   remove a cg dir with tasks in it and the root task of
   a test is in a cgroup it tries to remove.

2. After dump old cgroup dirs are remained after the test,
   while criu should restore them (this is what we write
   tests for).

The proposal is to introduce per-test hooks, for now two of
them: --pre-restore and --clean. For cgroup tests both hooks
will remove the created directories.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/zdtm.sh                        | 10 ++++++++++
 test/zdtm/live/static/cgroup.hook   | 19 +++++++++++++++++++
 test/zdtm/live/static/cgroup00.c    |  9 ---------
 test/zdtm/live/static/cgroup00.hook |  1 +
 test/zdtm/live/static/cgroup01.c    |  5 -----
 test/zdtm/live/static/cgroup01.hook |  1 +
 6 files changed, 31 insertions(+), 14 deletions(-)
 create mode 100755 test/zdtm/live/static/cgroup.hook
 create mode 120000 test/zdtm/live/static/cgroup00.hook
 create mode 120000 test/zdtm/live/static/cgroup01.hook

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 569ce94..e4df6e8 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -621,6 +621,11 @@ EOF
 				done
 			done
 
+			if [ -x "${test}.hook" ]; then
+				echo "Executing pre-restore hook"
+				"${test}.hook" --pre-restore || return 2
+			fi
+
 			echo Restore
 			setsid $CRIU restore -D $ddump -o restore.log -v4 -d $gen_args || return 2
 
@@ -654,6 +659,11 @@ EOF
 		[ $sltime -lt 9 ] && sltime=$((sltime+1))
 	done
 
+	if [ -x "${test}.hook" ]; then
+		echo "Executing cleanup hook"
+		"${test}.hook" --clean
+	fi
+
 	if [ -n "$AUTO_DEDUP" ]; then
 		for img in $ddump/pages-*.img; do
 			img_name="${img##*/}"
diff --git a/test/zdtm/live/static/cgroup.hook b/test/zdtm/live/static/cgroup.hook
new file mode 100755
index 0000000..908d78c
--- /dev/null
+++ b/test/zdtm/live/static/cgroup.hook
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -e
+
+tname=$(mktemp -d cgclean.XXXXXX)
+mount -t cgroup none $tname -o "none,name=zdtmtst"
+
+echo "Cleaning $tname"
+
+set +e
+rmdir "$tname/subcg/subsubcg/"
+rmdir "$tname/subcg/empty/"
+rmdir "$tname/subcg/"
+set -e
+
+echo "Left there is:"
+ls "$tname"
+umount "$tname"
+rmdir "$tname"
diff --git a/test/zdtm/live/static/cgroup00.c b/test/zdtm/live/static/cgroup00.c
index ae4eefc..9b8c3df 100644
--- a/test/zdtm/live/static/cgroup00.c
+++ b/test/zdtm/live/static/cgroup00.c
@@ -70,14 +70,6 @@ static int cg_check(char *name)
 	return found ? 0 : -1;
 }
 
-static void cg_cleanup(void)
-{
-	char paux[256];
-
-	sprintf(paux, "%s/%s", dirname, SUBNAME);
-	rmdir(paux);
-}
-
 int main(int argc, char **argv)
 {
 	char aux[64];
@@ -200,7 +192,6 @@ int main(int argc, char **argv)
 	pass();
 
 out_rs:
-	cg_cleanup();
 	umount(dirname);
 out_rd:
 	rmdir(dirname);
diff --git a/test/zdtm/live/static/cgroup00.hook b/test/zdtm/live/static/cgroup00.hook
new file mode 120000
index 0000000..99dc411
--- /dev/null
+++ b/test/zdtm/live/static/cgroup00.hook
@@ -0,0 +1 @@
+cgroup.hook
\ No newline at end of file
diff --git a/test/zdtm/live/static/cgroup01.c b/test/zdtm/live/static/cgroup01.c
index f6a082f..a715cd8 100644
--- a/test/zdtm/live/static/cgroup01.c
+++ b/test/zdtm/live/static/cgroup01.c
@@ -97,12 +97,7 @@ int main(int argc, char **argv)
 
 out_close:
 	fclose(cgf);
-
-	sprintf(paux, "%s/%s/%s", dirname, subname, empty);
-	rmdir(paux);
 out_rs:
-	sprintf(paux, "%s/%s", dirname, subname);
-	rmdir(paux);
 	umount(dirname);
 out_rd:
 	rmdir(dirname);
diff --git a/test/zdtm/live/static/cgroup01.hook b/test/zdtm/live/static/cgroup01.hook
new file mode 120000
index 0000000..99dc411
--- /dev/null
+++ b/test/zdtm/live/static/cgroup01.hook
@@ -0,0 +1 @@
+cgroup.hook
\ No newline at end of file
-- 
1.8.4.2




More information about the CRIU mailing list